Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add visibility state and toggling of datasets #481

Merged
merged 13 commits into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ jobs:
if: matrix.java == env.JAVA_REFERENCE_VERSION
- name: Codacy coverage Reporter
if: matrix.java == env.JAVA_REFERENCE_VERSION
continue-on-error: true # codacy coverage sometimes fails for external PRs, ignore since it is not our main coverage tracking
uses: codacy/[email protected]
with:
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
Expand Down
13 changes: 10 additions & 3 deletions chartfx-chart/src/main/java/de/gsi/chart/Chart.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,14 @@ public abstract class Chart extends HiddenSidesPane implements Observable {
protected BooleanBinding showingBinding;
protected final BooleanProperty showing = new SimpleBooleanProperty(this, "showing", false);
protected final ChangeListener<? super Boolean> showingListener = (ch2, o, n) -> showing.set(n);
/** When true any data changes will be animated. */
/**
* When true any data changes will be animated.
*/
private final BooleanProperty animated = new SimpleBooleanProperty(this, "animated", true);
// TODO: Check whether 'this' or chart contents need to be added
/** Animator for animating stuff on the chart */
/**
* Animator for animating stuff on the chart
*/
protected final ChartLayoutAnimator animator = new ChartLayoutAnimator(this);

/**
Expand Down Expand Up @@ -310,7 +314,7 @@ protected void invalidated() {

/**
* Creates a new default Chart instance.
*
*
* @param axes axes to be added to the chart
*/
public Chart(Axis... axes) {
Expand Down Expand Up @@ -985,6 +989,9 @@ protected void datasetsChanged(final ListChangeListener.Change<? extends DataSet
FXUtils.assertJavaFxThread();
while (change.next()) {
for (final DataSet set : change.getRemoved()) {
// remove Legend listeners from removed datasets
set.updateEventListener().removeIf(l -> l instanceof DefaultLegend.DatasetVisibilityListener);

set.removeListener(dataSetDataListener);
dataSetChanges = true;
}
Expand Down
6 changes: 3 additions & 3 deletions chartfx-chart/src/main/java/de/gsi/chart/XYChart.java
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ public void updateAxisRange() {
// lock datasets to prevent writes while updating the axes
ObservableList<DataSet> dataSets = this.getAllDatasets();
// check that all registered data sets have proper ranges defined
dataSets.parallelStream().forEach(dataset -> dataset.getAxisDescriptions().parallelStream().filter(axisD -> !axisD.isDefined()) //
.forEach(axisDescription -> dataset.lock().writeLockGuard(() -> dataset.recomputeLimits(axisDescription.getDimIndex()))));
dataSets.parallelStream()
.forEach(dataset -> dataset.getAxisDescriptions().parallelStream().filter(axisD -> !axisD.isDefined()).forEach(axisDescription -> dataset.lock().writeLockGuard(() -> dataset.recomputeLimits(axisDescription.getDimIndex()))));

final ArrayDeque<DataSet> lockQueue = new ArrayDeque<>(dataSets);
recursiveLockGuard(lockQueue, () -> getAxes().forEach(chartAxis -> {
Expand Down Expand Up @@ -455,7 +455,7 @@ protected static void updateNumericAxis(final Axis axis, final List<DataSet> dat
final boolean isHorizontal = axis.getSide().isHorizontal();
final Side side = axis.getSide();
axis.getAutoRange().clear();
dataSets.forEach(dataset -> dataset.lock().readLockGuard(() -> {
dataSets.stream().filter(DataSet::isVisible).forEach(dataset -> dataset.lock().readLockGuard(() -> {
if (dataset.getDimension() > 2 && (side == Side.RIGHT || side == Side.TOP)) {
if (!dataset.getAxisDescription(DataSet.DIM_Z).isDefined()) {
dataset.recomputeLimits(DataSet.DIM_Z);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.css.PseudoClass;
import javafx.geometry.Orientation;
import javafx.geometry.Pos;
import javafx.scene.Node;
Expand All @@ -24,6 +25,9 @@
import de.gsi.chart.renderer.Renderer;
import de.gsi.chart.utils.StyleParser;
import de.gsi.dataset.DataSet;
import de.gsi.dataset.event.EventListener;
import de.gsi.dataset.event.UpdateEvent;
import de.gsi.dataset.event.UpdatedMetaDataEvent;

/**
* A chart legend that displays a list of items with symbols in a box
Expand All @@ -35,6 +39,7 @@ public class DefaultLegend extends FlowPane implements Legend {
private static final int GAP = 5;
private static final int SYMBOL_WIDTH = 20;
private static final int SYMBOL_HEIGHT = 20;
private static final PseudoClass disabledClass = PseudoClass.getPseudoClass("disabled");

// -------------- PRIVATE FIELDS ------------------------------------------

Expand All @@ -56,7 +61,9 @@ protected void invalidated() {
}
};

/** The legend items to display in this legend */
/**
* The legend items to display in this legend
*/
private final ObjectProperty<ObservableList<LegendItem>> items = new SimpleObjectProperty<>(
this, "items") {
private ObservableList<LegendItem> oldItems = null;
Expand Down Expand Up @@ -106,7 +113,28 @@ public final ObservableList<LegendItem> getItems() {

public LegendItem getNewLegendItem(final Renderer renderer, final DataSet series, final int seriesIndex) {
final Canvas symbol = renderer.drawLegendSymbol(series, seriesIndex, SYMBOL_WIDTH, SYMBOL_HEIGHT);
return new LegendItem(series.getName(), symbol);
var item = new LegendItem(series.getName(), symbol);
item.setOnMouseClicked(event -> series.setVisible(!series.isVisible()));
item.pseudoClassStateChanged(disabledClass, !series.isVisible());
series.addListener(new DatasetVisibilityListener(item, series));
return item;
}

public static class DatasetVisibilityListener implements EventListener {
private LegendItem item;
private DataSet series;

public DatasetVisibilityListener(final LegendItem item, final DataSet series) {
this.item = item;
this.series = series;
}

@Override
public void handle(final UpdateEvent evt) {
if (evt instanceof UpdatedMetaDataEvent) {
item.pseudoClassStateChanged(disabledClass, !series.isVisible());
}
}
}

@Override
Expand All @@ -116,7 +144,7 @@ public Node getNode() {

/*
* (non-Javadoc)
*
*
* @see de.gsi.chart.legend.Legend#isVertical()
*/
@Override
Expand All @@ -134,7 +162,7 @@ public final void setItems(final ObservableList<LegendItem> value) {

/*
* (non-Javadoc)
*
*
* @see de.gsi.chart.legend.Legend#setVertical(boolean)
*/
@Override
Expand All @@ -144,7 +172,7 @@ public final void setVertical(final boolean value) {

/*
* (non-Javadoc)
*
*
* @see de.gsi.chart.legend.Legend#updateLegend(java.util.List, java.util.List)
*/
@Override
Expand Down Expand Up @@ -221,7 +249,9 @@ public final BooleanProperty verticalProperty() {
return vertical;
}

/** A item to be displayed on a Legend */
/**
* A item to be displayed on a Legend
*/
public static class LegendItem extends Label {
public LegendItem(final String text, final Node symbol) {
setText(text);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,10 @@ protected class SelectedDataPoint extends Circle {
}

public void applyDrag(final double deltaX, final double deltaY) {
if (!dataSet.isVisible()) {
return;
}

double nX = getX();
double nY = getY();
int index = getIndex();
Expand Down Expand Up @@ -1016,6 +1020,10 @@ public void applyDrag(final double deltaX, final double deltaY) {
}

public boolean delete() {
if (!dataSet.isVisible()) {
return false;
}

final EditConstraints constraints = dataSet.getEditConstraints();
int index = getIndex();
if (constraints == null || constraints.canDelete(index)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ public List<DataSet> render(final GraphicsContext gc, final Chart chart, final i
List<DataSet> drawnDataSet = new ArrayList<>(localDataSetList.size());
for (int dataSetIndex = localDataSetList.size() - 1; dataSetIndex >= 0; dataSetIndex--) {
final DataSet dataSet = localDataSetList.get(dataSetIndex);
if (!(dataSet instanceof GridDataSet) || dataSet.getDimension() <= 2) {
if (!dataSet.isVisible() || !(dataSet instanceof GridDataSet) || dataSet.getDimension() <= 2) {
continue; // DataSet not applicable to ContourChartRenderer
}

Expand Down Expand Up @@ -460,9 +460,9 @@ public void shiftZAxisToRight() {

public static double convolution(final double[][] pixelMatrix) {
final double gy = pixelMatrix[0][0] * -1 + pixelMatrix[0][1] * -2 + pixelMatrix[0][2] * -1 + pixelMatrix[2][0] + pixelMatrix[2][1] * 2
+ pixelMatrix[2][2] * 1;
+ pixelMatrix[2][2] * 1;
final double gx = pixelMatrix[0][0] + pixelMatrix[0][2] * -1 + pixelMatrix[1][0] * 2 + pixelMatrix[1][2] * -2 + pixelMatrix[2][0]
+ pixelMatrix[2][2] * -1;
+ pixelMatrix[2][2] * -1;
return Math.sqrt(Math.pow(gy, 2) + Math.pow(gx, 2));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,13 @@ public List<DataSet> render(final GraphicsContext gc, final Chart chart, final i
ProcessingProfiler.getTimeDiff(start, "init");
}

List<DataSet> drawnDataSet = new ArrayList<>(localDataSetList.size());
for (int dataSetIndex = localDataSetList.size() - 1; dataSetIndex >= 0; dataSetIndex--) {
final int ldataSetIndex = dataSetIndex;
stopStamp = ProcessingProfiler.getTimeStamp();
final DataSet dataSet = localDataSetList.get(dataSetIndex);
if (!dataSet.isVisible()) {
continue;
}

// N.B. print out for debugging purposes, please keep (used for
// detecting redundant or too frequent render updates)
Expand Down Expand Up @@ -230,7 +232,6 @@ public List<DataSet> render(final GraphicsContext gc, final Chart chart, final i
return Optional.of(localCachedPoints);
});

drawnDataSet.add(dataSet);
cachedPoints.ifPresent(value -> {
// invoke data reduction algorithm
value.reduce(rendererDataReducerProperty().get(), isReducePoints(),
Expand All @@ -250,7 +251,7 @@ public List<DataSet> render(final GraphicsContext gc, final Chart chart, final i
} // end of 'dataSetIndex' loop
ProcessingProfiler.getTimeDiff(start);

return drawnDataSet;
return localDataSetList;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ public List<DataSet> render(final GraphicsContext gc, final Chart chart, final i
// replace DataSet with sorted variety
// do not need to do this for Histograms as they are always sorted by design
LimitedIndexedTreeDataSet newDataSet = new LimitedIndexedTreeDataSet(dataSet.getName(), Integer.MAX_VALUE);
newDataSet.setVisible(dataSet.isVisible());
newDataSet.set(dataSet);
localDataSetList.set(index, newDataSet);
}
Expand Down Expand Up @@ -215,7 +216,7 @@ protected void drawBars(final GraphicsContext gc, final List<DataSet> dataSets,
int lindex = dataSetOffset - 1;
for (DataSet ds : dataSets) {
lindex++;
if (ds.getDataCount() == 0) {
if (!ds.isVisible() || ds.getDataCount() == 0) {
continue;
}
final double scaleValue = isAnimate() ? scaling.getOrDefault(ds.getName(), 1.0) : 1.0;
Expand Down Expand Up @@ -328,7 +329,7 @@ protected static void drawPolyLineHistogram(final GraphicsContext gc, final List
int lindex = dataSetOffset - 1;
for (DataSet ds : dataSets) {
lindex++;
if (ds.getDataCount() == 0) {
if (!ds.isVisible() || ds.getDataCount() == 0) {
continue;
}
final boolean isVerticalDataSet = isVerticalDataSet(ds);
Expand Down Expand Up @@ -382,6 +383,9 @@ protected static void drawPolyLineHistogramBezier(final GraphicsContext gc, fina
int lindex = dataSetOffset - 1;
for (DataSet ds : dataSets) {
lindex++;
if (!ds.isVisible()) {
continue;
}
final boolean isVerticalDataSet = isVerticalDataSet(ds);

final int dimIndexAbscissa = isVerticalDataSet ? DIM_Y : DIM_X;
Expand Down Expand Up @@ -454,6 +458,9 @@ protected static void drawPolyLineLine(final GraphicsContext gc, final List<Data
int lindex = dataSetOffset - 1;
for (DataSet ds : dataSets) {
lindex++;
if (!ds.isVisible()) {
continue;
}
final boolean isVerticalDataSet = isVerticalDataSet(ds);

final int dimIndexAbscissa = isVerticalDataSet ? DIM_Y : DIM_X;
Expand Down Expand Up @@ -510,6 +517,9 @@ protected static void drawPolyLineStairCase(final GraphicsContext gc, final List
int lindex = dataSetOffset - 1;
for (DataSet ds : dataSets) {
lindex++;
if (!ds.isVisible()) {
continue;
}
final boolean isVerticalDataSet = isVerticalDataSet(ds);

final int dimIndexAbscissa = isVerticalDataSet ? DIM_Y : DIM_X;
Expand Down Expand Up @@ -693,7 +703,7 @@ public void handle(final long now) {

for (final DataSet dataSet : localDataSetList) {
// scheme 1
//final Double val = scaling.put(dataSet.getName(), Math.min(scaling.computeIfAbsent(dataSet.getName(), ds -> 0.0) + 0.05, 1.0))
// final Double val = scaling.put(dataSet.getName(), Math.min(scaling.computeIfAbsent(dataSet.getName(), ds -> 0.0) + 0.05, 1.0))
// scheme 2
final Double val = scaling.put(dataSet.getName(), Math.min(scaling.computeIfAbsent(dataSet.getName(), ds -> 0.0) + 0.05, dataSet.getDataCount() + 1.0));
if (val != null && val < dataSet.getDataCount() + 1.0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ public List<DataSet> render(final GraphicsContext gc, final Chart chart, final i
List<DataSet> drawnDataSet = new ArrayList<>(localDataSetList.size());
for (int dataSetIndex = localDataSetList.size() - 1; dataSetIndex >= 0; dataSetIndex--) {
final DataSet dataSet = localDataSetList.get(dataSetIndex);
if (!dataSet.isVisible()) {
continue;
}
dataSet.lock().readLockGuard(() -> {
// check for potentially reduced data range we are supposed to plot
final int indexMin = Math.max(0, dataSet.getIndex(DataSet.DIM_X, xMin));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package de.gsi.chart.renderer.spi;

import static de.gsi.dataset.DataSet.DIM_X;
import static de.gsi.dataset.DataSet.DIM_Y;
import static de.gsi.dataset.DataSet.DIM_Z;

Expand Down Expand Up @@ -90,16 +89,14 @@ public List<DataSet> render(final GraphicsContext gc, final Chart chart, final i
final double zRangeMax = localDataSetList.stream().mapToDouble(ds -> ds.getAxisDescription(DIM_Z).getMax()).max().orElse(+1.0);

// render in reverse order
List<DataSet> drawnDataSet = new ArrayList<>(localDataSetList.size());
for (int dataSetIndex = localDataSetList.size() - 1; dataSetIndex >= 0; dataSetIndex--) {
final DataSet dataSet = localDataSetList.get(dataSetIndex);

// detect and fish-out 3D DataSet, ignore others
if (!(dataSet instanceof GridDataSet)) {
if (!dataSet.isVisible() || !(dataSet instanceof GridDataSet)) {
continue;
}

drawnDataSet.add(dataSet);
dataSet.lock().readLockGuardOptimistic(() -> {
xWeakIndexMap.clear();
yWeakIndexMap.clear();
Expand Down Expand Up @@ -127,7 +124,7 @@ public List<DataSet> render(final GraphicsContext gc, final Chart chart, final i
}

ProcessingProfiler.getTimeDiff(start);
return drawnDataSet;
return localDataSetList;
}

/**
Expand Down Expand Up @@ -308,6 +305,16 @@ public DataSet set(final DataSet other, final boolean copy) {
throw new UnsupportedOperationException("copy setter not implemented for Demux3dTo2dDataSet");
}

@Override
public boolean isVisible() {
return dataSet.isVisible();
}

@Override
public DataSet setVisible(boolean visible) {
return dataSet.setVisible(visible);
}

@Override
public List<EventListener> updateEventListener() {
return updateListener;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ public List<DataSet> render(final GraphicsContext gc, final Chart chart, final i
final double xmin = xAxis.getValueForDisplay(0);
final double xmax = xAxis.getValueForDisplay(xAxisWidth);
int index = 0;
List<DataSet> drawnDataSet = new ArrayList<>(localDataSetList.size());
for (final DataSet ds : localDataSetList) {
if (!ds.isVisible()) {
continue;
}
final int lindex = index;
ds.lock().readLockGuardOptimistic(() -> {
// update categories in case of category axes for the first
Expand Down Expand Up @@ -159,7 +161,7 @@ public List<DataSet> render(final GraphicsContext gc, final Chart chart, final i
}
ProcessingProfiler.getTimeDiff(start);

return drawnDataSet;
return localDataSetList;
}

public void setMaxPoints(final int maxPoints) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public List<DataSet> render(final GraphicsContext gc, final Chart chart, final i
var index = 0;

for (final DataSet ds : localDataSetList) {
if (ds.getDimension() < 7)
if (!ds.isVisible() || ds.getDimension() < 7)
continue;
final int lindex = index;

Expand Down
Loading