Skip to content

Commit

Permalink
made error ds renderer properties stylable
Browse files Browse the repository at this point in the history
  • Loading branch information
ennerf committed Aug 10, 2023
1 parent 2d307f8 commit dad3ac9
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ public class DefaultLegend extends FlowPane implements Legend {
private final ObservableList<LegendItem> 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<LegendItem>) c -> getChildren().setAll(items));
PropUtil.runOnChange(this::applyCss, sideProperty());

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand All @@ -36,33 +42,34 @@ public abstract class AbstractErrorDataSetRendererParameter<R extends AbstractEr
extends AbstractPointReducingRenderer<R> {
// intensity fading factor per stage
protected static final double DEFAULT_HISTORY_INTENSITY_FADING = 0.65;
private final ObjectProperty<ErrorStyle> errorStyle = new SimpleObjectProperty<>(this, "errorStyle",
ErrorStyle.ERRORCOMBO);
private final ObjectProperty<ErrorStyle> errorStyle = css().createEnumPropertyWithPseudoclasses(this, "errorStyle",
ErrorStyle.ERRORCOMBO, ErrorStyle.class);
private final ObjectProperty<RendererDataReducer> 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<LineStyle> 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<LineStyle> 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,
Expand All @@ -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() {
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -542,4 +548,12 @@ protected R unbind() {

return getThis();
}

@Override
protected CssPropertyFactory<AbstractRenderer<?>> css() {
return CSS;
}

private static final CssPropertyFactory<AbstractRenderer<?>> CSS = new CssPropertyFactory<>(AbstractPointReducingRenderer.getClassCssMetaData());

}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,12 +16,12 @@ public abstract class AbstractPointReducingRenderer<R extends AbstractPointReduc
extends AbstractRenderer<R> {
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();
Expand Down Expand Up @@ -160,14 +161,10 @@ public R setPointReduction(final boolean state) {
}

@Override
public List<CssMetaData<? extends Styleable, ?>> getCssMetaData() {
return getClassCssMetaData();
protected CssPropertyFactory<AbstractRenderer<?>> css() {
return CSS;
}

public static List<CssMetaData<? extends Styleable, ?>> getClassCssMetaData() {
return CSS.getCssMetaData();
}

private static final CssPropertyFactory<AbstractRenderer<?>> CSS = new CssPropertyFactory<>(AbstractRenderer.getClassCssMetaData());
private static final CssPropertyFactory<AbstractRenderer<?>> CSS = new CssPropertyFactory<>(AbstractPointReducingRenderer.getClassCssMetaData());

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
public abstract class AbstractRenderer<R extends Renderer> 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<DataSet> datasets = FXCollections.observableArrayList();
private final ObservableList<Axis> axesList = FXCollections.observableList(new NoDuplicatesList<>());
private final ObjectProperty<Chart> chart = new SimpleObjectProperty<>();
Expand Down Expand Up @@ -184,13 +184,13 @@ protected void fireInvalidated(IntSupplier bit) {
}
}

@Override
public List<CssMetaData<? extends Styleable, ?>> getCssMetaData() {
return getClassCssMetaData();
protected CssPropertyFactory<AbstractRenderer<?>> css() {
return CSS; // subclass specific CSS due to inheritance issues otherwise
}

public static List<CssMetaData<? extends Styleable, ?>> getClassCssMetaData() {
return CSS.getCssMetaData();
@Override
public List<CssMetaData<? extends Styleable, ?>> getCssMetaData() {
return css().getCssMetaData();
}

private static final CssPropertyFactory<AbstractRenderer<?>> CSS = new CssPropertyFactory<>(Parent.getClassCssMetaData());
Expand Down
16 changes: 16 additions & 0 deletions chartfx-chart/src/main/resources/io/fair_acc/chartfx/chart.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 19 additions & 0 deletions chartfx-chart/src/main/resources/io/fair_acc/chartfx/chart.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dad3ac9

Please sign in to comment.