Skip to content

Commit

Permalink
changed error data set renderer to use static points rather than the …
Browse files Browse the repository at this point in the history
…shared array cache (#370 and #557)
  • Loading branch information
ennerf committed Aug 16, 2023
1 parent a12372b commit c482470
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 155 deletions.
6 changes: 1 addition & 5 deletions chartfx-chart/src/main/java/io/fair_acc/chartfx/XYChart.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.fair_acc.chartfx;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
Expand All @@ -26,7 +25,6 @@
import io.fair_acc.chartfx.axes.Axis;
import io.fair_acc.chartfx.renderer.PolarTickStep;
import io.fair_acc.chartfx.renderer.Renderer;
import io.fair_acc.chartfx.renderer.spi.ErrorDataSetRenderer;
import io.fair_acc.chartfx.renderer.spi.GridRenderer;
import io.fair_acc.chartfx.renderer.spi.LabelledMarkerRenderer;
import io.fair_acc.chartfx.ui.geometry.Side;
Expand Down Expand Up @@ -311,10 +309,8 @@ protected void redrawCanvas() {
}

// Data
int dataSetOffset = 0;
for (final Renderer renderer : getRenderers()) {
final List<DataSet> drawnDataSets = renderer.render(gc, this, dataSetOffset, getDatasets());
dataSetOffset += drawnDataSets == null ? 0 : drawnDataSets.size();
renderer.render(gc, this, renderer.getIndexOffset(), FXCollections.emptyObservableList());
}

// Top grid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ public DataSetMeasurements(final ParameterMeasurements plugin, final Measurement
yAxis.setAutoRanging(true);
yAxis.setAutoUnitScaling(true);
renderer.getAxes().addAll(xAxis, yAxis);
renderer.setDrawChartDataSets(false);
renderer.getDatasets().add(isTrending ? trendingDataSet : mathDataSet);

localChart.addListener(localChartChangeListener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public abstract class AbstractErrorDataSetRendererParameter<R extends AbstractEr
private final BooleanProperty drawMarker = css().createBooleanProperty(this, "drawMarker", true);
private final ObjectProperty<LineStyle> polyLineStyle = css().createEnumProperty(this, "polyLineStyle",
LineStyle.NORMAL, false, LineStyle.class);
private final BooleanProperty drawChartDataSets = new SimpleBooleanProperty(this, "drawChartDataSets", true);
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);
Expand All @@ -77,7 +76,6 @@ public AbstractErrorDataSetRendererParameter() {
markerSize,
drawMarker,
polyLineStyle,
drawChartDataSets,
drawBars,
shiftBar,
shiftBarOffset,
Expand Down Expand Up @@ -122,13 +120,6 @@ public BooleanProperty drawBubblesProperty() {
return drawBubbles;
}

/**
* @return the drawChartDataSets state, ie. if all or only the DataSets attached to the Renderer shall be drawn
*/
public BooleanProperty drawChartDataSetsProperty() {
return drawChartDataSets;
}

/**
* @return the drawMarker state
*/
Expand Down Expand Up @@ -256,14 +247,6 @@ public boolean isDrawBubbles() {
return drawBubblesProperty().get();
}

/**
*
* @return whether all or only the DataSets attached to the Renderer shall be drawn
*/
public boolean isDrawChartDataSets() {
return drawChartDataSetsProperty().get();
}

/**
* @return true if point reduction is on (default) else false.
*/
Expand Down Expand Up @@ -374,14 +357,6 @@ public R setDrawBubbles(final boolean state) {
return getThis();
}

/**
*
* @param state whether all (true) or only the DataSets attached to the Renderer shall be drawn (false)
*/
public void setDrawChartDataSets(final boolean state) {
drawChartDataSetsProperty().set(state);
}

/**
* @param state true -&gt; draws markers
* @return itself (fluent design)
Expand Down Expand Up @@ -498,7 +473,6 @@ protected R bind(final R other) {
markerSizeProperty().bind(other.markerSizeProperty());
drawMarkerProperty().bind(other.drawMarkerProperty());
polyLineStyleProperty().bind(other.polyLineStyleProperty());
drawChartDataSetsProperty().bind(other.drawChartDataSetsProperty());
drawBarsProperty().bind(other.drawBarsProperty());
drawBubblesProperty().bind(other.drawBubblesProperty());
allowNaNsProperty().bind(other.allowNaNsProperty());
Expand Down Expand Up @@ -535,7 +509,6 @@ protected R unbind() {
markerSizeProperty().unbind();
drawMarkerProperty().unbind();
polyLineStyleProperty().unbind();
drawChartDataSetsProperty().unbind();
drawBarsProperty().unbind();
drawBubblesProperty().unbind();
allowNaNsProperty().unbind();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.fair_acc.chartfx.renderer.spi;

import io.fair_acc.chartfx.Chart;
import io.fair_acc.chartfx.XYChart;
import io.fair_acc.chartfx.axes.Axis;
import io.fair_acc.chartfx.renderer.Renderer;
import io.fair_acc.chartfx.ui.css.CssPropertyFactory;
Expand All @@ -13,6 +12,7 @@
import io.fair_acc.dataset.events.ChartBits;
import io.fair_acc.dataset.spi.DoubleDataSet;
import io.fair_acc.dataset.spi.DoubleErrorDataSet;
import io.fair_acc.dataset.utils.AssertUtils;
import io.fair_acc.dataset.utils.NoDuplicatesList;
import io.fair_acc.dataset.utils.ProcessingProfiler;
import javafx.beans.property.*;
Expand Down Expand Up @@ -108,6 +108,16 @@ protected ObservableList<DataSet> getDatasetsCopy(final ObservableList<DataSet>
return dataSets;
}

public Axis getFirstHorizontalAxis() {
AssertUtils.notNull("chart", getChart());
return getFirstAxis(Orientation.HORIZONTAL, getChart());
}

public Axis getFirstVerticalAxis() {
AssertUtils.notNull("chart", getChart());
return getFirstAxis(Orientation.VERTICAL, getChart());
}

public Axis getFirstAxis(final Orientation orientation) {
for (final Axis axis : getAxes()) {
if (axis.getSide() == null) {
Expand Down Expand Up @@ -142,7 +152,7 @@ public Axis getFirstAxis(final Orientation orientation) {
* @param fallback The chart from which to get the axis if no axis is present
* @return The requested axis
*/
protected Axis getFirstAxis(final Orientation orientation, final XYChart fallback) {
protected Axis getFirstAxis(final Orientation orientation, final Chart fallback) {
final Axis axis = getFirstAxis(orientation);
if (axis == null) {
return fallback.getFirstAxis(orientation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static io.fair_acc.dataset.DataSet.DIM_X;
import static io.fair_acc.dataset.DataSet.DIM_Y;
import static io.fair_acc.math.ArrayUtils.*;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -17,9 +18,7 @@
import io.fair_acc.dataset.DataSet;
import io.fair_acc.dataset.DataSetError;
import io.fair_acc.dataset.DataSetError.ErrorType;
import io.fair_acc.dataset.utils.ArrayCache;
import io.fair_acc.dataset.utils.CachedDaemonThreadFactory;
import io.fair_acc.dataset.utils.DoubleArrayCache;
import io.fair_acc.dataset.utils.ProcessingProfiler;
import io.fair_acc.math.ArrayUtils;

Expand All @@ -31,8 +30,6 @@
*/
@SuppressWarnings({ "PMD.TooManyMethods", "PMD.TooManyFields" }) // designated purpose of this class
class CachedDataPoints {
private static final String STYLES2 = "styles";
private static final String SELECTED2 = "selected";
private static final double DEG_TO_RAD = Math.PI / 180.0;

protected double[] xValues;
Expand Down Expand Up @@ -67,21 +64,35 @@ class CachedDataPoints {
protected int maxDataCount;
protected int actualDataCount; // number of data points that remain after data reduction

public CachedDataPoints(final int indexMin, final int indexMax, final int dataLength, final boolean full) {
maxDataCount = dataLength;
xValues = DoubleArrayCache.getInstance().getArrayExact(maxDataCount);
yValues = DoubleArrayCache.getInstance().getArrayExact(maxDataCount);
styles = ArrayCache.getCachedStringArray(STYLES2, dataLength);
public void trim() {
xValues = clearIfLarger(xValues, maxDataCount);
yValues = clearIfLarger(yValues, maxDataCount);
errorYNeg = clearIfLarger(errorYNeg, maxDataCount);
errorYPos = clearIfLarger(errorYPos, maxDataCount);
errorXNeg = clearIfLarger(errorXNeg, maxDataCount);
errorXPos = clearIfLarger(errorXPos, maxDataCount);
selected = clearIfLarger(selected, maxDataCount);
styles = clearIfLarger(styles, maxDataCount);
errorType = clearIfLarger(errorType, 10); // depends on ds dimensions
}

public CachedDataPoints resizeMin(final int indexMin, final int indexMax, final int dataLength, final boolean full) {
this.indexMin = indexMin;
this.indexMax = indexMax;
errorYNeg = DoubleArrayCache.getInstance().getArrayExact(maxDataCount);
errorYPos = DoubleArrayCache.getInstance().getArrayExact(maxDataCount);
maxDataCount = dataLength;
xValues = ArrayUtils.resizeMin(xValues, dataLength);
yValues = ArrayUtils.resizeMin(yValues, dataLength);
errorYNeg = ArrayUtils.resizeMin(errorYNeg, dataLength);
errorYPos = ArrayUtils.resizeMin(errorYPos, dataLength);
if (full) {
errorXNeg = DoubleArrayCache.getInstance().getArrayExact(maxDataCount);
errorXPos = DoubleArrayCache.getInstance().getArrayExact(maxDataCount);
errorXNeg = ArrayUtils.resizeMin(errorXNeg, dataLength);
errorXPos = ArrayUtils.resizeMin(errorXPos, dataLength);
}
selected = ArrayCache.getCachedBooleanArray(SELECTED2, dataLength);
ArrayUtils.fillArray(styles, null);
selected = ArrayUtils.resizeMin(selected, dataLength);

// TODO: do we really need to extract all point styles?
styles = ArrayUtils.resizeMinNulled(styles, dataLength, String[]::new);
return this;
}

protected void computeBoundaryVariables(final Axis xAxis, final Axis yAxis) {
Expand Down Expand Up @@ -493,17 +504,6 @@ protected void reduce(final RendererDataReducer cruncher, final boolean isReduce
minDataPointDistanceX();
}

public void release() {
DoubleArrayCache.getInstance().add(xValues);
DoubleArrayCache.getInstance().add(yValues);
DoubleArrayCache.getInstance().add(errorYNeg);
DoubleArrayCache.getInstance().add(errorYPos);
DoubleArrayCache.getInstance().add(errorXNeg);
DoubleArrayCache.getInstance().add(errorXPos);
ArrayCache.release(SELECTED2, selected);
ArrayCache.release(STYLES2, styles);
}

private void setBoundaryConditions(final Axis xAxis, final Axis yAxis, final DataSet dataSet, final int dsIndex,
final int min, final int max, final ErrorStyle rendererErrorStyle, final boolean isPolarPlot,
final boolean doAllowForNaNs) {
Expand All @@ -519,12 +519,11 @@ private void setBoundaryConditions(final Axis xAxis, final Axis yAxis, final Dat
}

protected void setErrorType(final DataSet dataSet, final ErrorStyle errorStyle) {
errorType = new ErrorType[dataSet.getDimension()];
errorType = ArrayUtils.resizeMinNulled(errorType, dataSet.getDimension(), ErrorType[]::new);
if (dataSet instanceof DataSetError) {
final DataSetError ds = (DataSetError) dataSet;
for (int dimIndex = 0; dimIndex < ds.getDimension(); dimIndex++) {
final int tmpIndex = dimIndex;
errorType[dimIndex] = ds.getErrorType(tmpIndex);
errorType[dimIndex] = ds.getErrorType(dimIndex);
}
} else if (errorStyle == ErrorStyle.NONE) {
// special case where users does not want error bars
Expand Down
Loading

0 comments on commit c482470

Please sign in to comment.