Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added parameters for styling line cap and join #626

Merged
merged 3 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,8 @@
int numCoords;

gc.save();
gc.setLineWidth(style.getLineWidth());
gc.setLineDashes(style.getLineDashes());
gc.setStroke(style.getLineColor());
gc.setFill(style.getLineColor());
style.applyLineStrokeStyle(gc);
gc.setFill(style.getMarkerColor());

Check warning on line 59 in chartfx-chart/src/main/java/io/fair_acc/chartfx/renderer/spi/BasicDataSetRenderer.java

View check run for this annotation

Codecov / codecov/patch

chartfx-chart/src/main/java/io/fair_acc/chartfx/renderer/spi/BasicDataSetRenderer.java#L58-L59

Added lines #L58 - L59 were not covered by tests

// compute local screen coordinates
double xi, yi, prevX = Double.NaN, prevY = Double.NaN;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.fair_acc.chartfx.marker.DefaultMarker;
import io.fair_acc.chartfx.marker.Marker;
import io.fair_acc.chartfx.renderer.ErrorStyle;
import io.fair_acc.chartfx.renderer.Renderer;
Expand Down Expand Up @@ -621,9 +620,7 @@ protected static void drawPolyLineHistogram(final GraphicsContext gc, final Data
newY[length - 1] = points.yZero;

gc.save();
gc.setStroke(style.getLineColor());
gc.setLineWidth(style.getLineWidth());
gc.setLineDashes(style.getLineDashes());
style.applyLineStrokeStyle(gc);

for (int i = 0; i < length - 1; i++) {
final double x1 = newX[i];
Expand Down Expand Up @@ -654,11 +651,7 @@ protected static void drawPolyLineHistogramBezier(final GraphicsContext gc,
points.actualDataCount);

gc.save();

gc.setLineWidth(style.getLineWidth());
gc.setLineDashes(style.getLineDashes());
gc.setStroke(style.getLineColor());
gc.setFill(gc.getStroke());
style.applyLineStrokeStyle(gc);

gc.beginPath();
for (int i = 0; i < n - 1; i++) {
Expand Down Expand Up @@ -724,11 +717,7 @@ protected static void drawPolyLineHistogramFilled(final GraphicsContext gc,

protected static void drawPolyLineLine(final GraphicsContext gc, final DataSetNode style, final CachedDataPoints points) {
gc.save();

gc.setLineWidth(style.getLineWidth());
gc.setLineDashes(style.getLineDashes());
gc.setStroke(style.getLineColor());
gc.setFill(gc.getStroke());
style.applyLineStrokeStyle(gc);

if (points.allowForNaNs) {
gc.beginPath();
Expand Down Expand Up @@ -798,11 +787,7 @@ protected static void drawPolyLineStairCase(final GraphicsContext gc, final Data
newY[length - 1] = points.yValues[n - 1];

gc.save();

gc.setStroke(style.getLineColor());
gc.setFill(gc.getStroke());
gc.setLineWidth(style.getLineWidth());
gc.setLineDashes(style.getLineDashes());
style.applyLineStrokeStyle(gc);

// gc.strokePolyline(newX, newY, 2*n);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,7 @@
final boolean isHistogram = ds instanceof Histogram;

gc.save();

gc.setLineWidth(style.getLineWidth());
gc.setLineDashes(style.getLineDashes());
gc.setStroke(style.getLineColor());
style.applyLineStrokeStyle(gc);

Check warning on line 165 in chartfx-chart/src/main/java/io/fair_acc/chartfx/renderer/spi/HistogramRenderer.java

View check run for this annotation

Codecov / codecov/patch

chartfx-chart/src/main/java/io/fair_acc/chartfx/renderer/spi/HistogramRenderer.java#L165

Added line #L165 was not covered by tests
gc.setFill(style.getLineColor());

for (int i = 0; i < nRange; i++) {
Expand Down Expand Up @@ -275,9 +272,7 @@
newY[2 * (nRange + 1) - 1] = axisMin;

gc.save();
gc.setLineWidth(style.getLineWidth());
gc.setLineDashes(style.getLineDashes());
gc.setStroke(style.getLineColor());
style.applyLineStrokeStyle(gc);

Check warning on line 275 in chartfx-chart/src/main/java/io/fair_acc/chartfx/renderer/spi/HistogramRenderer.java

View check run for this annotation

Codecov / codecov/patch

chartfx-chart/src/main/java/io/fair_acc/chartfx/renderer/spi/HistogramRenderer.java#L275

Added line #L275 was not covered by tests

drawPolygon(gc, newX, newY, filled, isVerticalDataSet, 2 * nRange + 2);

Expand Down Expand Up @@ -315,9 +310,7 @@
BezierCurve.calcCurveControlPoints(xValues, yValues, xCp1, yCp1, xCp2, yCp2, nRange);

gc.save();
gc.setLineWidth(style.getLineWidth());
gc.setLineDashes(style.getLineDashes());
gc.setStroke(style.getLineColor());
style.applyLineStrokeStyle(gc);

Check warning on line 313 in chartfx-chart/src/main/java/io/fair_acc/chartfx/renderer/spi/HistogramRenderer.java

View check run for this annotation

Codecov / codecov/patch

chartfx-chart/src/main/java/io/fair_acc/chartfx/renderer/spi/HistogramRenderer.java#L313

Added line #L313 was not covered by tests

gc.beginPath();
for (int i = 0; i < nRange - 1; i++) {
Expand Down Expand Up @@ -387,9 +380,7 @@
gc.setFill(style.getLineColor());
gc.fill();
} else {
gc.setLineWidth(style.getLineWidth());
gc.setLineDashes(style.getLineDashes());
gc.setStroke(style.getLineColor());
style.applyLineStrokeStyle(gc);

Check warning on line 383 in chartfx-chart/src/main/java/io/fair_acc/chartfx/renderer/spi/HistogramRenderer.java

View check run for this annotation

Codecov / codecov/patch

chartfx-chart/src/main/java/io/fair_acc/chartfx/renderer/spi/HistogramRenderer.java#L383

Added line #L383 was not covered by tests
gc.stroke();
}

Expand Down Expand Up @@ -433,9 +424,7 @@
newY[2 * nRange - 1] = newY[2 * (nRange - 1)];

gc.save();
gc.setLineWidth(style.getLineWidth());
gc.setLineDashes(style.getLineDashes());
gc.setStroke(style.getLineColor());
style.applyLineStrokeStyle(gc);

Check warning on line 427 in chartfx-chart/src/main/java/io/fair_acc/chartfx/renderer/spi/HistogramRenderer.java

View check run for this annotation

Codecov / codecov/patch

chartfx-chart/src/main/java/io/fair_acc/chartfx/renderer/spi/HistogramRenderer.java#L427

Added line #L427 was not covered by tests

drawPolygon(gc, newX, newY, filled, isVerticalDataSet, 2 * nRange);
gc.restore();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,11 @@
import static io.fair_acc.dataset.DataSet.DIM_X;
import static io.fair_acc.dataset.DataSet.DIM_Y;

import java.security.InvalidParameterException;
import java.util.ArrayList;
import java.util.List;

import javafx.collections.ObservableList;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;

import io.fair_acc.chartfx.Chart;
import io.fair_acc.chartfx.XYChart;
import io.fair_acc.chartfx.axes.Axis;
import io.fair_acc.chartfx.axes.spi.CategoryAxis;
import io.fair_acc.chartfx.renderer.Renderer;
import io.fair_acc.chartfx.ui.css.DataSetNode;
import io.fair_acc.dataset.DataSet;
import io.fair_acc.dataset.utils.ProcessingProfiler;

/**
* Simple, uncomplicated reducing line renderer
Expand Down Expand Up @@ -55,9 +44,7 @@
@Override
protected void render(GraphicsContext gc, DataSet ds, DataSetNode style) {
gc.save();
gc.setLineWidth(style.getLineWidth());
gc.setLineDashes(style.getLineDashes());
gc.setStroke(style.getLineColor());
style.applyLineStrokeStyle(gc);

Check warning on line 47 in chartfx-chart/src/main/java/io/fair_acc/chartfx/renderer/spi/ReducingLineRenderer.java

View check run for this annotation

Codecov / codecov/patch

chartfx-chart/src/main/java/io/fair_acc/chartfx/renderer/spi/ReducingLineRenderer.java#L47

Added line #L47 was not covered by tests

if (ds.getDataCount() > 0) {
final int indexMin = Math.max(0, ds.getIndex(DIM_X, xMin));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
import javafx.css.*;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.shape.StrokeLineCap;
import javafx.scene.shape.StrokeLineJoin;

import io.fair_acc.chartfx.marker.DefaultMarker;
import io.fair_acc.chartfx.marker.Marker;
Expand Down Expand Up @@ -61,6 +64,9 @@
private final ObjectBinding<Paint> lineFillPattern = hatchFillPattern(intensifiedLineColor);
private final ObjectProperty<Number[]> lineDashArray = addOnChange(css().createNumberArrayProperty(this, "lineDashArray", null));
private final ObjectBinding<double[]> lineDashes = StyleUtil.toUnboxedDoubleArray(lineDashArray);
private final DoubleProperty lineMiterLimit = addOnChange(css().createDoubleProperty(this, "lineMiterLimit", 1d));
private final ObjectProperty<StrokeLineJoin> lineJoin = addOnChange(css().createEnumProperty(this, "lineJoin", StrokeLineJoin.BEVEL, true, StrokeLineJoin.class));
private final ObjectProperty<StrokeLineCap> lineCap = addOnChange(css().createEnumProperty(this, "lineCap", StrokeLineCap.BUTT, true, StrokeLineCap.class));

// ======================== Overriden accessors ========================

Expand Down Expand Up @@ -320,8 +326,58 @@
return lineDashes;
}

public double getLineMiterLimit() {
return lineMiterLimit.get();
}

public DoubleProperty lineMiterLimitProperty() {
return lineMiterLimit;

Check warning on line 334 in chartfx-chart/src/main/java/io/fair_acc/chartfx/ui/css/DataSetNodeParameter.java

View check run for this annotation

Codecov / codecov/patch

chartfx-chart/src/main/java/io/fair_acc/chartfx/ui/css/DataSetNodeParameter.java#L334

Added line #L334 was not covered by tests
}

public void setLineMiterLimit(double lineMiterLimit) {
this.lineMiterLimit.set(lineMiterLimit);
}

Check warning on line 339 in chartfx-chart/src/main/java/io/fair_acc/chartfx/ui/css/DataSetNodeParameter.java

View check run for this annotation

Codecov / codecov/patch

chartfx-chart/src/main/java/io/fair_acc/chartfx/ui/css/DataSetNodeParameter.java#L338-L339

Added lines #L338 - L339 were not covered by tests

public StrokeLineJoin getLineJoin() {
return lineJoin.get();
}

public ObjectProperty<StrokeLineJoin> lineJoinProperty() {
return lineJoin;

Check warning on line 346 in chartfx-chart/src/main/java/io/fair_acc/chartfx/ui/css/DataSetNodeParameter.java

View check run for this annotation

Codecov / codecov/patch

chartfx-chart/src/main/java/io/fair_acc/chartfx/ui/css/DataSetNodeParameter.java#L346

Added line #L346 was not covered by tests
}

public void setLineJoin(StrokeLineJoin lineJoin) {
this.lineJoin.set(lineJoin);
}

Check warning on line 351 in chartfx-chart/src/main/java/io/fair_acc/chartfx/ui/css/DataSetNodeParameter.java

View check run for this annotation

Codecov / codecov/patch

chartfx-chart/src/main/java/io/fair_acc/chartfx/ui/css/DataSetNodeParameter.java#L350-L351

Added lines #L350 - L351 were not covered by tests

public StrokeLineCap getLineCap() {
return lineCap.get();
}

public ObjectProperty<StrokeLineCap> lineCapProperty() {
return lineCap;

Check warning on line 358 in chartfx-chart/src/main/java/io/fair_acc/chartfx/ui/css/DataSetNodeParameter.java

View check run for this annotation

Codecov / codecov/patch

chartfx-chart/src/main/java/io/fair_acc/chartfx/ui/css/DataSetNodeParameter.java#L358

Added line #L358 was not covered by tests
}

public void setLineCap(StrokeLineCap lineCap) {
this.lineCap.set(lineCap);
}

Check warning on line 363 in chartfx-chart/src/main/java/io/fair_acc/chartfx/ui/css/DataSetNodeParameter.java

View check run for this annotation

Codecov / codecov/patch

chartfx-chart/src/main/java/io/fair_acc/chartfx/ui/css/DataSetNodeParameter.java#L362-L363

Added lines #L362 - L363 were not covered by tests

// ======================== Utility methods ========================

/**
* Sets all styles that apply to a gc.strokeLine() call.
*
* @param gc target context
*/
public void applyLineStrokeStyle(GraphicsContext gc) {
gc.setMiterLimit(getLineMiterLimit());
gc.setLineJoin(getLineJoin());
gc.setLineCap(getLineCap());
gc.setLineWidth(getLineWidth());
gc.setLineDashes(getLineDashes());
gc.setStroke(getLineColor());
}

protected ObjectBinding<Paint> intensifiedColor(ObservableValue<Paint> base) {
return Bindings.createObjectBinding(() -> getIntensifiedColor(base.getValue()), base, intensity);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@
-fx-marker-line-width: 0.5;
-fx-line-color: -color-dataset;
-fx-line-width: 1;
-fx-line-miter-limit: 1;
-fx-line-cap: butt;
-fx-line-join: bevel;
}
.dataset.default-color0 {
-color-dataset: -color-dataset-1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ $null: null; // null gets removed from Sass. Maybe create a placeholder and repl
-fx-line-color: -color-dataset;
-fx-line-width: 1.0; // 0 to disable
-fx-line-dash-array: null;
-fx-line-miter-limit: 1.0;
-fx-line-cap: butt;
-fx-line-join: bevel;

}

Expand Down Expand Up @@ -396,4 +399,4 @@ $null: null; // null gets removed from Sass. Maybe create a placeholder and repl
-fx-stroke: derive(-fx-text-background-color, 40%);
}

@include financial.financial-themes();
@include financial.financial-themes();