Skip to content

Commit

Permalink
added hatch shift so multiple errors can be drawn on top of each other
Browse files Browse the repository at this point in the history
  • Loading branch information
ennerf committed Aug 18, 2023
1 parent cc94276 commit c427a6f
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package io.fair_acc.chartfx.ui.css;

import io.fair_acc.chartfx.renderer.spi.AbstractRenderer;
import io.fair_acc.chartfx.renderer.spi.utils.FillPatternStyleHelper;
import io.fair_acc.chartfx.utils.PropUtil;
import io.fair_acc.dataset.DataSet;
import io.fair_acc.dataset.event.EventSource;
import io.fair_acc.dataset.events.BitState;
import io.fair_acc.dataset.events.ChartBits;
import io.fair_acc.dataset.events.StateListener;
import io.fair_acc.dataset.utils.AssertUtils;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;

/**
* A dataset wrapper that lives in the SceneGraph for CSS styling
Expand All @@ -16,6 +19,45 @@
*/
public class DataSetNode extends DataSetNodeParameter implements EventSource {

public Paint getLineColor() {
if (lineColor == null) {
lineColor = getIntensifiedColor(getStroke());
}
return lineColor;
}
private Paint lineColor = null;

public Paint getFillColor() {
if(fillColor == null) {
fillColor = getIntensifiedColor(getFill());
}
return fillColor;
}
private Paint fillColor = null;

/**
* @return a fill pattern of crossed lines using the lineFill color
*/
public Paint getLineFillPattern() {
if (lineFillPattern == null) {
var color = getLineColor();
color = color instanceof Color ? ((Color) color).brighter() : color;
var hatchShift = getHatchShiftByIndex() * (getGlobalIndex() + 1); // start at 1 to look better
lineFillPattern = FillPatternStyleHelper.getDefaultHatch(color, hatchShift);
}
return lineFillPattern;
}

private Paint lineFillPattern = null;

{
// Reset cached colors
PropUtil.runOnChange(() -> lineColor = null, intensityProperty(), strokeProperty());
PropUtil.runOnChange(() -> fillColor = null, intensityProperty(), fillProperty());
PropUtil.runOnChange(() -> lineFillPattern = null, intensityProperty(), strokeProperty(),
hatchShiftByIndexProperty(), globalIndexProperty());
}

public DataSetNode(AbstractRenderer<?> renderer, DataSet dataSet) {
this.renderer = AssertUtils.notNull("renderer", renderer);
this.dataSet = AssertUtils.notNull("dataSet", dataSet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import io.fair_acc.chartfx.marker.DefaultMarker;
import io.fair_acc.chartfx.marker.Marker;
import io.fair_acc.chartfx.renderer.spi.utils.FillPatternStyleHelper;
import io.fair_acc.chartfx.utils.PropUtil;
import javafx.beans.binding.Bindings;
import javafx.beans.binding.ObjectBinding;
Expand All @@ -14,7 +13,6 @@
import javafx.scene.paint.Paint;

import java.util.List;
import java.util.WeakHashMap;

/**
* Holds the styleable parameters of the DataSetNode
Expand All @@ -24,38 +22,19 @@
public abstract class DataSetNodeParameter extends TextStyle {

public Paint getMarkerColor() {
return getModifiedColor(getStroke());
return getIntensifiedColor(getStroke());
}

public double getMarkerLineWidth() {
return getMarkerStrokeWidth();
}

public Paint getLineColor() {
return getModifiedColor(getStroke());
}


public double getLineWidth() {
return getStrokeWidth();
}

public Paint getFillColor() {
return getModifiedColor(getFill());
}

/**
* @return a fill pattern of crossed lines using the lineFill color
*/
public Paint getLineFillPattern() {
return lineFillPattern.computeIfAbsent(getLineColor(), color -> {
color = color instanceof Color ? ((Color) color).brighter() : color;
var defaultHatchShift = 1.5;
return FillPatternStyleHelper.getDefaultHatch(color, defaultHatchShift);
});
}

private static WeakHashMap<Paint, Paint> lineFillPattern = new WeakHashMap<>(31);

public double[] getLineDashes() {
if (getStrokeDashArray().isEmpty()) {
return null;
Expand All @@ -71,7 +50,7 @@ public double[] getLineDashes() {

private double[] dashArray = null;

private Paint getModifiedColor(Paint color) {
protected Paint getIntensifiedColor(Paint color) {
if (getIntensity() >= 100 || !(color instanceof Color)) {
return color;
}
Expand Down Expand Up @@ -106,6 +85,8 @@ protected <T extends ObservableValue<?>> T addOnChange(T observable) {
return newVal >= 0 ? newVal : oldVal;
}));

private final DoubleProperty hatchShiftByIndex = addOnChange(css().createDoubleProperty(this, "hatchShiftByIndex", 1.5));

public int getLocalIndex() {
return localIndex.get();
}
Expand Down Expand Up @@ -202,6 +183,18 @@ public void setMarkerSize(double markerSize) {
this.markerSize.set(markerSize);
}

public double getHatchShiftByIndex() {
return hatchShiftByIndex.get();
}

public DoubleProperty hatchShiftByIndexProperty() {
return hatchShiftByIndex;
}

public void setHatchShiftByIndex(double hatchShiftByIndex) {
this.hatchShiftByIndex.set(hatchShiftByIndex);
}

@Override
public Node getStyleableNode() {
return this;
Expand Down

0 comments on commit c427a6f

Please sign in to comment.