< prev index next >

modules/controls/src/main/java/javafx/scene/chart/XYChart.java

Print this page
rev 8907 : RT-46086: StackedAreaChart doesn't fade out removed series

*** 923,932 **** --- 923,962 ---- protected final Iterator<Series<X,Y>> getDisplayedSeriesIterator() { return Collections.unmodifiableList(displayedSeries).iterator(); } /** + * Creates an array of KeyFrames for fading out nodes representing a series + * + * @param series The series to remove + * @param fadeOutTime Time to fade out, in milliseconds + * @return array of two KeyFrames from zero to fadeOutTime + */ + protected final KeyFrame[] createSeriesRemoveTimeLine(Series<X, Y> series, long fadeOutTime) { + final List<Node> nodes = new ArrayList<>(); + nodes.add(series.getNode()); + for (Data<X, Y> d : series.getData()) { + if (d.getNode() != null) { + nodes.add(d.getNode()); + } + } + // fade out series node and symbols + KeyValue[] startValues = new KeyValue[nodes.size()]; + KeyValue[] endValues = new KeyValue[nodes.size()]; + for (int j = 0; j < nodes.size(); j++) { + startValues[j] = new KeyValue(nodes.get(j).opacityProperty(), 1); + endValues[j] = new KeyValue(nodes.get(j).opacityProperty(), 0); + } + return new KeyFrame[] { + new KeyFrame(Duration.ZERO, startValues), + new KeyFrame(Duration.millis(fadeOutTime), actionEvent -> { + getPlotChildren().removeAll(nodes); + removeSeriesFromDisplay(series); + }, endValues) + }; + } + /** * The current displayed data value plotted on the X axis. This may be the same as xValue or different. It is * used by XYChart to animate the xValue from the old value to the new value. This is what you should plot * in any custom XYChart implementations. Some XYChart chart implementations such as LineChart also use this * to animate when data is added or removed. */
< prev index next >