@Override protected void dataItemAdded( Series<String, Number> series, int itemIndex, Data<String, Number> item) { Node candle = createCandle(getData().indexOf(series), item, itemIndex); if (shouldAnimate()) { candle.setOpacity(0); getPlotChildren().add(candle); // fade in new candle FadeTransition ft = new FadeTransition(Duration.millis(500), candle); ft.setToValue(1); ft.play(); } else { getPlotChildren().add(candle); } // always draw average line on top if (series.getNode() != null) { series.getNode().toFront(); } }
/** Called to update and layout the content for the plot */ @Override protected void layoutPlotChildren() { // we have nothing to layout if no data is present if (getData() == null) { return; } // update candle positions for (int seriesIndex = 0; seriesIndex < getData().size(); seriesIndex++) { Series<String, Number> series = getData().get(seriesIndex); Iterator<Data<String, Number>> iter = getDisplayedDataIterator(series); Path seriesPath = null; if (series.getNode() instanceof Path) { seriesPath = (Path) series.getNode(); seriesPath.getElements().clear(); } while (iter.hasNext()) { Data<String, Number> item = iter.next(); double x = getXAxis().getDisplayPosition(getCurrentDisplayedXValue(item)); double y = getYAxis().getDisplayPosition(getCurrentDisplayedYValue(item)); Node itemNode = item.getNode(); BarData bar = (BarData) item.getExtraValue(); if (itemNode instanceof Candle && item.getYValue() != null) { Candle candle = (Candle) itemNode; double close = getYAxis().getDisplayPosition(bar.getClose()); double high = getYAxis().getDisplayPosition(bar.getHigh()); double low = getYAxis().getDisplayPosition(bar.getLow()); double candleWidth = 10; // update candle candle.update(close - y, high - y, low - y, candleWidth); // update tooltip content candle.updateTooltip(bar.getOpen(), bar.getClose(), bar.getHigh(), bar.getLow()); // position the candle candle.setLayoutX(x); candle.setLayoutY(y); } } } }