< prev index next >
modules/controls/src/main/java/javafx/scene/chart/BarChart.java
Print this page
rev 9950 : 8152418: Memory Leak in StackedBarChart when series are removed
*** 339,362 ****
}
}
pt.play();
} else {
for (Data<X,Y> d : series.getData()) {
! final Node bar = d.getNode();
! getPlotChildren().remove(bar);
! updateMap(series, d);
}
removeSeriesFromDisplay(series);
}
}
/** @inheritDoc */
@Override protected void layoutPlotChildren() {
double catSpace = categoryAxis.getCategorySpacing();
// calculate bar spacing
! final double avilableBarSpace = catSpace - (getCategoryGap() + getBarGap());
! double barWidth = (avilableBarSpace / getSeriesSize()) - getBarGap();
final double barOffset = -((catSpace - getCategoryGap()) / 2);
final double zeroPos = (valueAxis.getLowerBound() > 0) ?
valueAxis.getDisplayPosition(valueAxis.getLowerBound()) : valueAxis.getZeroPosition();
// RT-24813 : if the data in a series gets too large, barWidth can get negative.
if (barWidth <= 0) barWidth = 1;
--- 339,360 ----
}
}
pt.play();
} else {
for (Data<X,Y> d : series.getData()) {
! processDataRemove(series, d);
}
removeSeriesFromDisplay(series);
}
}
/** @inheritDoc */
@Override protected void layoutPlotChildren() {
double catSpace = categoryAxis.getCategorySpacing();
// calculate bar spacing
! final double availableBarSpace = catSpace - (getCategoryGap() + getBarGap());
! double barWidth = (availableBarSpace / getSeriesSize()) - getBarGap();
final double barOffset = -((catSpace - getCategoryGap()) / 2);
final double zeroPos = (valueAxis.getLowerBound() > 0) ?
valueAxis.getDisplayPosition(valueAxis.getLowerBound()) : valueAxis.getZeroPosition();
// RT-24813 : if the data in a series gets too large, barWidth can get negative.
if (barWidth <= 0) barWidth = 1;
*** 404,417 ****
* This is called whenever a series is added or removed and the legend needs to be updated
*/
@Override protected void updateLegend() {
legend.getItems().clear();
if (getData() != null) {
! for (int seriesIndex=0; seriesIndex < getData().size(); seriesIndex++) {
Series<X,Y> series = getData().get(seriesIndex);
LegendItem legenditem = new LegendItem(series.getName());
! legenditem.getSymbol().getStyleClass().addAll("chart-bar","series"+seriesIndex,"bar-legend-symbol",
series.defaultColorStyleClass);
legend.getItems().add(legenditem);
}
}
if (legend.getItems().size() > 0) {
--- 402,415 ----
* This is called whenever a series is added or removed and the legend needs to be updated
*/
@Override protected void updateLegend() {
legend.getItems().clear();
if (getData() != null) {
! for (int seriesIndex = 0; seriesIndex < getData().size(); seriesIndex++) {
Series<X,Y> series = getData().get(seriesIndex);
LegendItem legenditem = new LegendItem(series.getName());
! legenditem.getSymbol().getStyleClass().addAll("chart-bar", "series" + seriesIndex, "bar-legend-symbol",
series.defaultColorStyleClass);
legend.getItems().add(legenditem);
}
}
if (legend.getItems().size() > 0) {
*** 451,478 ****
}
item.setCurrentY(getYAxis().toRealValue((barVal < 0) ? -bottomPos : bottomPos));
getPlotChildren().add(bar);
item.setYValue(getYAxis().toRealValue(barVal));
animate(
! new KeyFrame(Duration.ZERO, new KeyValue(item.currentYProperty(),
item.getCurrentY())),
! new KeyFrame(Duration.millis(700),
! new KeyValue(item.currentYProperty(), item.getYValue(), Interpolator.EASE_BOTH))
);
} else {
barVal = ((Number)item.getXValue()).doubleValue();
if (barVal < 0) {
bar.getStyleClass().add(NEGATIVE_STYLE);
}
item.setCurrentX(getXAxis().toRealValue((barVal < 0) ? -bottomPos : bottomPos));
getPlotChildren().add(bar);
item.setXValue(getXAxis().toRealValue(barVal));
animate(
! new KeyFrame(Duration.ZERO, new KeyValue(item.currentXProperty(),
item.getCurrentX())),
! new KeyFrame(Duration.millis(700),
! new KeyValue(item.currentXProperty(), item.getXValue(), Interpolator.EASE_BOTH))
);
}
}
private Timeline createDataRemoveTimeline(final Data<X,Y> item, final Node bar, final Series<X,Y> series) {
--- 449,480 ----
}
item.setCurrentY(getYAxis().toRealValue((barVal < 0) ? -bottomPos : bottomPos));
getPlotChildren().add(bar);
item.setYValue(getYAxis().toRealValue(barVal));
animate(
! new KeyFrame(Duration.ZERO, new KeyValue(
! item.currentYProperty(),
item.getCurrentY())),
! new KeyFrame(Duration.millis(700), new KeyValue(
! item.currentYProperty(),
! item.getYValue(), Interpolator.EASE_BOTH))
);
} else {
barVal = ((Number)item.getXValue()).doubleValue();
if (barVal < 0) {
bar.getStyleClass().add(NEGATIVE_STYLE);
}
item.setCurrentX(getXAxis().toRealValue((barVal < 0) ? -bottomPos : bottomPos));
getPlotChildren().add(bar);
item.setXValue(getXAxis().toRealValue(barVal));
animate(
! new KeyFrame(Duration.ZERO, new KeyValue(
! item.currentXProperty(),
item.getCurrentX())),
! new KeyFrame(Duration.millis(700), new KeyValue(
! item.currentXProperty(),
! item.getXValue(), Interpolator.EASE_BOTH))
);
}
}
private Timeline createDataRemoveTimeline(final Data<X,Y> item, final Node bar, final Series<X,Y> series) {
*** 481,509 ****
// item.setYValue(getYAxis().toRealValue(getYAxis().getZeroPosition()));
// save data values in case the same data item gets added immediately.
XYValueMap.put(item, ((Number)item.getYValue()).doubleValue());
item.setYValue(getYAxis().toRealValue(bottomPos));
! t.getKeyFrames().addAll(new KeyFrame(Duration.ZERO,
! new KeyValue(item.currentYProperty(), item.getCurrentY())),
new KeyFrame(Duration.millis(700), actionEvent -> {
processDataRemove(series, item);
XYValueMap.clear();
! },
! new KeyValue(item.currentYProperty(), item.getYValue(),
! Interpolator.EASE_BOTH) ));
} else {
// save data values in case the same data item gets added immediately.
XYValueMap.put(item, ((Number)item.getXValue()).doubleValue());
item.setXValue(getXAxis().toRealValue(getXAxis().getZeroPosition()));
! t.getKeyFrames().addAll(new KeyFrame(Duration.ZERO, new KeyValue(item.currentXProperty(), item.getCurrentX())),
new KeyFrame(Duration.millis(700), actionEvent -> {
processDataRemove(series, item);
XYValueMap.clear();
! },
! new KeyValue(item.currentXProperty(), item.getXValue(),
! Interpolator.EASE_BOTH) ));
}
return t;
}
@Override void dataBeingRemovedIsAdded(Data<X,Y> item, Series<X,Y> series) {
--- 483,516 ----
// item.setYValue(getYAxis().toRealValue(getYAxis().getZeroPosition()));
// save data values in case the same data item gets added immediately.
XYValueMap.put(item, ((Number)item.getYValue()).doubleValue());
item.setYValue(getYAxis().toRealValue(bottomPos));
! t.getKeyFrames().addAll(
! new KeyFrame(Duration.ZERO, new KeyValue(
! item.currentYProperty(), item.getCurrentY())),
new KeyFrame(Duration.millis(700), actionEvent -> {
processDataRemove(series, item);
XYValueMap.clear();
! }, new KeyValue(
! item.currentYProperty(),
! item.getYValue(), Interpolator.EASE_BOTH))
! );
} else {
// save data values in case the same data item gets added immediately.
XYValueMap.put(item, ((Number)item.getXValue()).doubleValue());
item.setXValue(getXAxis().toRealValue(getXAxis().getZeroPosition()));
! t.getKeyFrames().addAll(
! new KeyFrame(Duration.ZERO, new KeyValue(
! item.currentXProperty(), item.getCurrentX())),
new KeyFrame(Duration.millis(700), actionEvent -> {
processDataRemove(series, item);
XYValueMap.clear();
! }, new KeyValue(
! item.currentXProperty(),
! item.getXValue(), Interpolator.EASE_BOTH))
! );
}
return t;
}
@Override void dataBeingRemovedIsAdded(Data<X,Y> item, Series<X,Y> series) {
*** 561,571 ****
bar.setAccessibleRole(AccessibleRole.TEXT);
bar.setAccessibleRoleDescription("Bar");
bar.focusTraversableProperty().bind(Platform.accessibilityActiveProperty());
item.setNode(bar);
}
! bar.getStyleClass().setAll("chart-bar", "series" + seriesIndex, "data" + itemIndex,series.defaultColorStyleClass);
return bar;
}
private Data<X,Y> getDataItem(Series<X,Y> series, int seriesIndex, int itemIndex, String category) {
Map<String, Data<X,Y>> catmap = seriesCategoryMap.get(series);
--- 568,578 ----
bar.setAccessibleRole(AccessibleRole.TEXT);
bar.setAccessibleRoleDescription("Bar");
bar.focusTraversableProperty().bind(Platform.accessibilityActiveProperty());
item.setNode(bar);
}
! bar.getStyleClass().setAll("chart-bar", "series" + seriesIndex, "data" + itemIndex, series.defaultColorStyleClass);
return bar;
}
private Data<X,Y> getDataItem(Series<X,Y> series, int seriesIndex, int itemIndex, String category) {
Map<String, Data<X,Y>> catmap = seriesCategoryMap.get(series);
*** 610,620 ****
private static final List<CssMetaData<? extends Styleable, ?>> STYLEABLES;
static {
final List<CssMetaData<? extends Styleable, ?>> styleables =
! new ArrayList<CssMetaData<? extends Styleable, ?>>(XYChart.getClassCssMetaData());
styleables.add(BAR_GAP);
styleables.add(CATEGORY_GAP);
STYLEABLES = Collections.unmodifiableList(styleables);
}
}
--- 617,627 ----
private static final List<CssMetaData<? extends Styleable, ?>> STYLEABLES;
static {
final List<CssMetaData<? extends Styleable, ?>> styleables =
! new ArrayList<>(XYChart.getClassCssMetaData());
styleables.add(BAR_GAP);
styleables.add(CATEGORY_GAP);
STYLEABLES = Collections.unmodifiableList(styleables);
}
}
< prev index next >