From dad3ac9c82da52047bf639b5085683218d7fc221 Mon Sep 17 00:00:00 2001 From: Florian Enner Date: Thu, 10 Aug 2023 14:59:06 +0200 Subject: [PATCH] made error ds renderer properties stylable --- .../chartfx/legend/spi/DefaultLegend.java | 3 +- ...AbstractErrorDataSetRendererParameter.java | 58 ++++++++++++------- .../spi/AbstractPointReducingRenderer.java | 19 +++--- .../renderer/spi/AbstractRenderer.java | 12 ++-- .../resources/io/fair_acc/chartfx/chart.css | 16 +++++ .../resources/io/fair_acc/chartfx/chart.scss | 19 ++++++ 6 files changed, 86 insertions(+), 41 deletions(-) diff --git a/chartfx-chart/src/main/java/io/fair_acc/chartfx/legend/spi/DefaultLegend.java b/chartfx-chart/src/main/java/io/fair_acc/chartfx/legend/spi/DefaultLegend.java index eb5cb8d25..618c2d3d5 100644 --- a/chartfx-chart/src/main/java/io/fair_acc/chartfx/legend/spi/DefaultLegend.java +++ b/chartfx-chart/src/main/java/io/fair_acc/chartfx/legend/spi/DefaultLegend.java @@ -51,8 +51,7 @@ public class DefaultLegend extends FlowPane implements Legend { private final ObservableList items = FXCollections.observableArrayList(); public DefaultLegend() { - getStyleClass().setAll("chart-legend"); - managedProperty().bind(visibleProperty().and(Bindings.size(items).isNotEqualTo(0))); + StyleUtil.addStyles(this, "chart-legend"); items.addListener((ListChangeListener) c -> getChildren().setAll(items)); PropUtil.runOnChange(this::applyCss, sideProperty()); diff --git a/chartfx-chart/src/main/java/io/fair_acc/chartfx/renderer/spi/AbstractErrorDataSetRendererParameter.java b/chartfx-chart/src/main/java/io/fair_acc/chartfx/renderer/spi/AbstractErrorDataSetRendererParameter.java index 20533456b..17a55cb4c 100644 --- a/chartfx-chart/src/main/java/io/fair_acc/chartfx/renderer/spi/AbstractErrorDataSetRendererParameter.java +++ b/chartfx-chart/src/main/java/io/fair_acc/chartfx/renderer/spi/AbstractErrorDataSetRendererParameter.java @@ -1,8 +1,12 @@ package io.fair_acc.chartfx.renderer.spi; +import java.util.List; import java.util.Objects; +import io.fair_acc.chartfx.ui.css.CssPropertyFactory; +import io.fair_acc.chartfx.ui.css.StyleUtil; import io.fair_acc.chartfx.utils.PropUtil; +import javafx.application.Platform; import javafx.beans.property.BooleanProperty; import javafx.beans.property.DoubleProperty; import javafx.beans.property.IntegerProperty; @@ -22,6 +26,8 @@ import io.fair_acc.chartfx.renderer.datareduction.RamanDouglasPeukerDataReducer; import io.fair_acc.chartfx.renderer.datareduction.VisvalingamMaheswariWhyattDataReducer; import io.fair_acc.dataset.utils.AssertUtils; +import javafx.css.CssMetaData; +import javafx.css.Styleable; /** * simple class to move the various parameters out of the class containing the algorithms uses the shadow field pattern @@ -36,33 +42,34 @@ public abstract class AbstractErrorDataSetRendererParameter { // intensity fading factor per stage protected static final double DEFAULT_HISTORY_INTENSITY_FADING = 0.65; - private final ObjectProperty errorStyle = new SimpleObjectProperty<>(this, "errorStyle", - ErrorStyle.ERRORCOMBO); + private final ObjectProperty errorStyle = css().createEnumPropertyWithPseudoclasses(this, "errorStyle", + ErrorStyle.ERRORCOMBO, ErrorStyle.class); private final ObjectProperty rendererDataReducer = new SimpleObjectProperty<>(this, "rendererDataReducer", new DefaultDataReducer()); - private final IntegerProperty dashSize = new SimpleIntegerProperty(this, "dashSize", 3); - private final DoubleProperty markerSize = new SimpleDoubleProperty(this, "markerSize", 1.5); - private final BooleanProperty drawMarker = new SimpleBooleanProperty(this, "drawMarker", true); - private final ObjectProperty polyLineStyle = new SimpleObjectProperty<>(this, "polyLineStyle", - LineStyle.NORMAL); + private final IntegerProperty dashSize = css().createIntegerProperty(this, "dashSize", 3); + private final DoubleProperty markerSize = css().createDoubleProperty(this, "markerSize", 1.5); + private final BooleanProperty drawMarker = css().createBooleanProperty(this, "drawMarker", true); + private final ObjectProperty polyLineStyle = css().createEnumPropertyWithPseudoclasses(this, "polyLineStyle", + LineStyle.NORMAL, LineStyle.class); private final BooleanProperty drawChartDataSets = new SimpleBooleanProperty(this, "drawChartDataSets", true); - private final BooleanProperty drawBars = new SimpleBooleanProperty(this, "drawBars", false); - private final BooleanProperty shiftBar = new SimpleBooleanProperty(this, "shiftBar", true); - private final IntegerProperty shiftBarOffset = new SimpleIntegerProperty(this, "shiftBarOffset", 3); - private final BooleanProperty dynamicBarWidth = new SimpleBooleanProperty(this, "dynamicBarWidth", true); - private final DoubleProperty barWidthPercentage = new SimpleDoubleProperty(this, "barWidthPercentage", 70.0); - private final IntegerProperty barWidth = new SimpleIntegerProperty(this, "barWidth", 5); - private final DoubleProperty intensityFading = new SimpleDoubleProperty(this, "intensityFading", + private final BooleanProperty drawBars = css().createBooleanProperty(this, "drawBars", false); + private final BooleanProperty shiftBar = css().createBooleanProperty(this, "shiftBar", true); + private final IntegerProperty shiftBarOffset = css().createIntegerProperty(this, "shiftBarOffset", 3); + private final BooleanProperty dynamicBarWidth = css().createBooleanProperty(this, "dynamicBarWidth", true); + private final DoubleProperty barWidthPercentage = css().createDoubleProperty(this, "barWidthPercentage", 70.0); + private final IntegerProperty barWidth = css().createIntegerProperty(this, "barWidth", 5); + private final DoubleProperty intensityFading = css().createDoubleProperty(this, "intensityFading", AbstractErrorDataSetRendererParameter.DEFAULT_HISTORY_INTENSITY_FADING); - private final BooleanProperty drawBubbles = new SimpleBooleanProperty(this, "drawBubbles", false); - private final BooleanProperty allowNaNs = new SimpleBooleanProperty(this, "allowNaNs", false); + private final BooleanProperty drawBubbles = css().createBooleanProperty(this, "drawBubbles", false); + private final BooleanProperty allowNans = css().createBooleanProperty(this, "allowNans", false); /** * */ public AbstractErrorDataSetRendererParameter() { super(); + StyleUtil.addStyles(this,"error-dataset-renderer"); PropUtil.runOnChange(this::invalidateCanvas, errorStyle, rendererDataReducer, @@ -79,17 +86,14 @@ public AbstractErrorDataSetRendererParameter() { barWidth, intensityFading, drawBubbles, - allowNaNs); - } - - protected void invalidateCanvas() { + allowNans); } /** * @return the drawBubbles property */ public BooleanProperty allowNaNsProperty() { - return allowNaNs; + return allowNans; } public DoubleProperty barWidthPercentageProperty() { @@ -178,7 +182,9 @@ public int getDashSize() { * @see ErrorDataSetRenderer#setErrorType(ErrorStyle style) for details */ public ErrorStyle getErrorType() { - return errorStyleProperty().get(); + // TODO: figure out why 'none' in CSS maps to null + var type = errorStyleProperty().get(); + return type == null ? ErrorStyle.NONE : type; } /** @@ -542,4 +548,12 @@ protected R unbind() { return getThis(); } + + @Override + protected CssPropertyFactory> css() { + return CSS; + } + + private static final CssPropertyFactory> CSS = new CssPropertyFactory<>(AbstractPointReducingRenderer.getClassCssMetaData()); + } diff --git a/chartfx-chart/src/main/java/io/fair_acc/chartfx/renderer/spi/AbstractPointReducingRenderer.java b/chartfx-chart/src/main/java/io/fair_acc/chartfx/renderer/spi/AbstractPointReducingRenderer.java index 5870bce72..fae9f0f7f 100644 --- a/chartfx-chart/src/main/java/io/fair_acc/chartfx/renderer/spi/AbstractPointReducingRenderer.java +++ b/chartfx-chart/src/main/java/io/fair_acc/chartfx/renderer/spi/AbstractPointReducingRenderer.java @@ -1,6 +1,7 @@ package io.fair_acc.chartfx.renderer.spi; import io.fair_acc.chartfx.ui.css.CssPropertyFactory; +import io.fair_acc.chartfx.ui.css.StyleUtil; import javafx.beans.binding.Bindings; import javafx.beans.property.BooleanProperty; import javafx.beans.property.IntegerProperty; @@ -15,12 +16,12 @@ public abstract class AbstractPointReducingRenderer { private final ReadOnlyBooleanWrapper actualPointReduction = registerCanvasProp(new ReadOnlyBooleanWrapper(this, "actualPointReduction", true)); - private final BooleanProperty assumeSortedData = CSS.createBooleanProperty(this, "assumeSortedData", true); - private final IntegerProperty minRequiredReductionSize = registerCanvasProp(CSS.createIntegerProperty(this, "minRequiredReductionSize", + private final BooleanProperty assumeSortedData = css().createBooleanProperty(this, "assumeSortedData", true); + private final IntegerProperty minRequiredReductionSize = registerCanvasProp(css().createIntegerProperty(this, "minRequiredReductionSize", 5)); - private final BooleanProperty parallelImplementation = registerCanvasProp(CSS.createBooleanProperty(this, "parallelImplementation", + private final BooleanProperty parallelImplementation = registerCanvasProp(css().createBooleanProperty(this, "parallelImplementation", true)); - private final BooleanProperty pointReduction = CSS.createBooleanProperty(this, "pointReduction", true); + private final BooleanProperty pointReduction = css().createBooleanProperty(this, "pointReduction", true); public AbstractPointReducingRenderer() { super(); @@ -160,14 +161,10 @@ public R setPointReduction(final boolean state) { } @Override - public List> getCssMetaData() { - return getClassCssMetaData(); + protected CssPropertyFactory> css() { + return CSS; } - public static List> getClassCssMetaData() { - return CSS.getCssMetaData(); - } - - private static final CssPropertyFactory> CSS = new CssPropertyFactory<>(AbstractRenderer.getClassCssMetaData()); + private static final CssPropertyFactory> CSS = new CssPropertyFactory<>(AbstractPointReducingRenderer.getClassCssMetaData()); } diff --git a/chartfx-chart/src/main/java/io/fair_acc/chartfx/renderer/spi/AbstractRenderer.java b/chartfx-chart/src/main/java/io/fair_acc/chartfx/renderer/spi/AbstractRenderer.java index ff7cb7f8b..35c7edadb 100644 --- a/chartfx-chart/src/main/java/io/fair_acc/chartfx/renderer/spi/AbstractRenderer.java +++ b/chartfx-chart/src/main/java/io/fair_acc/chartfx/renderer/spi/AbstractRenderer.java @@ -33,7 +33,7 @@ */ public abstract class AbstractRenderer extends Parent implements Renderer { - protected final StyleableBooleanProperty showInLegend = CSS.createBooleanProperty(this, "showInLegend", true, this::invalidateCanvas); + protected final StyleableBooleanProperty showInLegend = css().createBooleanProperty(this, "showInLegend", true); private final ObservableList datasets = FXCollections.observableArrayList(); private final ObservableList axesList = FXCollections.observableList(new NoDuplicatesList<>()); private final ObjectProperty chart = new SimpleObjectProperty<>(); @@ -184,13 +184,13 @@ protected void fireInvalidated(IntSupplier bit) { } } - @Override - public List> getCssMetaData() { - return getClassCssMetaData(); + protected CssPropertyFactory> css() { + return CSS; // subclass specific CSS due to inheritance issues otherwise } - public static List> getClassCssMetaData() { - return CSS.getCssMetaData(); + @Override + public List> getCssMetaData() { + return css().getCssMetaData(); } private static final CssPropertyFactory> CSS = new CssPropertyFactory<>(Parent.getClassCssMetaData()); diff --git a/chartfx-chart/src/main/resources/io/fair_acc/chartfx/chart.css b/chartfx-chart/src/main/resources/io/fair_acc/chartfx/chart.css index 77046a552..0617fa31d 100644 --- a/chartfx-chart/src/main/resources/io/fair_acc/chartfx/chart.css +++ b/chartfx-chart/src/main/resources/io/fair_acc/chartfx/chart.css @@ -165,6 +165,22 @@ -fx-parallel-implementation: true; -fx-point-reduction: true; } +.chart .error-dataset-renderer { + -fx-poly-line-style: normal; + -fx-error-style: errorcombo; + -fx-dash-size: 3; + -fx-allow-nans: false; + -fx-draw-bubbles: false; + -fx-draw-marker: true; + -fx-marker-size: 1.5; + -fx-draw-bars: false; + -fx-shift-bar: true; + -fx-shift-bar-offset: 3; + -fx-dynamic-bar-width: true; + -fx-bar-width-percentage: 70; + -fx-bar-width: 5; + -fx-intensity-fading: 0.65; +} .axis { -fx-border-width: 0px; diff --git a/chartfx-chart/src/main/resources/io/fair_acc/chartfx/chart.scss b/chartfx-chart/src/main/resources/io/fair_acc/chartfx/chart.scss index 6a3c084c8..104d21461 100644 --- a/chartfx-chart/src/main/resources/io/fair_acc/chartfx/chart.scss +++ b/chartfx-chart/src/main/resources/io/fair_acc/chartfx/chart.scss @@ -222,6 +222,25 @@ $null: null; // null gets removed from Sass. Maybe create a placeholder and repl -fx-point-reduction: true; } + .error-dataset-renderer { + -fx-poly-line-style: normal; // normal, area, zero-order-holder, stair-case, histogram, histogram-filled, bezier-curve + -fx-error-style: errorcombo; // none, errorbars, errorsurface, errorcombo + -fx-dash-size: 3; + -fx-allow-nans: false; + + -fx-draw-bubbles: false; + -fx-draw-marker: true; + -fx-marker-size: 1.5; + + -fx-draw-bars: false; + -fx-shift-bar: true; + -fx-shift-bar-offset: 3; + -fx-dynamic-bar-width: true; + -fx-bar-width-percentage: 70.0; + -fx-bar-width: 5; + -fx-intensity-fading: 0.65; + } + } // Axis styles