Search in sources :

Example 1 with GraphDataBean

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);
        }
    }
}
Also used : Binding(com.canoo.platform.core.functional.Binding) ObjectProperty(javafx.beans.property.ObjectProperty) Subscription(com.canoo.platform.core.functional.Subscription) GraphDataBean(com.canoo.dp.impl.platform.projector.graph.GraphDataBean) MetadataUtilities(com.canoo.dp.impl.platform.projector.metadata.MetadataUtilities) GraphType(com.canoo.dp.impl.platform.projector.graph.GraphType) CategoryAxis(javafx.scene.chart.CategoryAxis) StackPane(javafx.scene.layout.StackPane) FXBinder(com.canoo.platform.remoting.client.javafx.FXBinder) BarChart(javafx.scene.chart.BarChart) XYChart(javafx.scene.chart.XYChart) GraphMetadata(com.canoo.dp.impl.platform.projector.graph.GraphMetadata) ArrayList(java.util.ArrayList) PieChart(javafx.scene.chart.PieChart) List(java.util.List) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) NumberAxis(javafx.scene.chart.NumberAxis) NumberAxis(javafx.scene.chart.NumberAxis) PieChart(javafx.scene.chart.PieChart) GraphDataBean(com.canoo.dp.impl.platform.projector.graph.GraphDataBean) CategoryAxis(javafx.scene.chart.CategoryAxis) BarChart(javafx.scene.chart.BarChart) XYChart(javafx.scene.chart.XYChart)

Aggregations

GraphDataBean (com.canoo.dp.impl.platform.projector.graph.GraphDataBean)1 GraphMetadata (com.canoo.dp.impl.platform.projector.graph.GraphMetadata)1 GraphType (com.canoo.dp.impl.platform.projector.graph.GraphType)1 MetadataUtilities (com.canoo.dp.impl.platform.projector.metadata.MetadataUtilities)1 Binding (com.canoo.platform.core.functional.Binding)1 Subscription (com.canoo.platform.core.functional.Subscription)1 FXBinder (com.canoo.platform.remoting.client.javafx.FXBinder)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ObjectProperty (javafx.beans.property.ObjectProperty)1 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)1 BarChart (javafx.scene.chart.BarChart)1 CategoryAxis (javafx.scene.chart.CategoryAxis)1 NumberAxis (javafx.scene.chart.NumberAxis)1 PieChart (javafx.scene.chart.PieChart)1 XYChart (javafx.scene.chart.XYChart)1 StackPane (javafx.scene.layout.StackPane)1