use of com.canoo.dp.impl.platform.projector.graph.GraphDataBean in project dolphin-platform by canoo.
the class GraphComponent method onUpdate.
private void onUpdate() {
getChildren().clear();
bindings.forEach(b -> b.unbind());
bindings.clear();
if (metadataSubscription != null) {
metadataSubscription.unsubscribe();
}
metadataSubscription = MetadataUtilities.addListenerToMetadata(data.get(), () -> {
onUpdate();
});
GraphDataBean currentBean = data.get();
if (currentBean != null) {
if (GraphType.PIE.equals(GraphMetadata.getGraphType(data.get()))) {
PieChart chart = new PieChart();
bindings.add(FXBinder.bind(chart.dataProperty().get()).to(currentBean.getValues(), valueBean -> {
PieChart.Data data = new PieChart.Data(valueBean.getName(), valueBean.getValue());
bindings.add(FXBinder.bind(data.nameProperty()).to(valueBean.nameProperty()));
bindings.add(FXBinder.bind(data.pieValueProperty()).to(valueBean.valueProperty()));
return data;
}));
getChildren().add(chart);
} else {
BarChart<String, Number> barChart = new BarChart<>(new CategoryAxis(), new NumberAxis());
XYChart.Series<String, Number> defaulSeries = new XYChart.Series<>();
barChart.getData().add(defaulSeries);
bindings.add(FXBinder.bind(defaulSeries.dataProperty().get()).to(currentBean.getValues(), valueBean -> {
XYChart.Data<String, Number> data = new XYChart.Data<>(valueBean.getName(), valueBean.getValue());
bindings.add(FXBinder.bind(data.XValueProperty()).to(valueBean.nameProperty()));
bindings.add(FXBinder.bind(data.YValueProperty()).to(valueBean.valueProperty()));
return data;
}));
getChildren().add(barChart);
}
}
}
Aggregations