Skip to content

Commit

Permalink
added parameters for styling line cap and join (#626)
Browse files Browse the repository at this point in the history
  • Loading branch information
ennerf authored Sep 28, 2023
1 parent 380940a commit 0f6c923
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,8 @@ protected void render(GraphicsContext gc, DataSet dataSet, DataSetNode style) {
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());

// 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 @@ protected void drawBars(final GraphicsContext gc, final DataSetNode style, final
final boolean isHistogram = ds instanceof Histogram;

gc.save();

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

for (int i = 0; i < nRange; i++) {
Expand Down Expand Up @@ -275,9 +272,7 @@ protected static void drawPolyLineHistogram(final GraphicsContext gc, final Data
newY[2 * (nRange + 1) - 1] = axisMin;

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

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

Expand Down Expand Up @@ -315,9 +310,7 @@ protected static void drawPolyLineHistogramBezier(final GraphicsContext gc, fina
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);

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

Expand Down Expand Up @@ -433,9 +424,7 @@ protected static void drawPolyLineStairCase(final GraphicsContext gc, final Data
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);

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 @@ protected ReducingLineRenderer getThis() {
@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);

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 @@ public abstract class DataSetNodeParameter extends Parent implements StyleUtil.S
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 @@ public ObjectBinding<double[]> lineDashesProperty() {
return lineDashes;
}

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

public DoubleProperty lineMiterLimitProperty() {
return lineMiterLimit;
}

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

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

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

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

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

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

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

// ======================== 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();

0 comments on commit 0f6c923

Please sign in to comment.