Search in sources :

Example 1 with DataSet

use of io.jmix.charts.model.dataset.DataSet in project jmix by jmix-framework.

the class JmixStockChartSerializer method serialize.

@Override
public String serialize(StockChartGroup chart) {
    JsonElement jsonTree = chartGson.toJsonTree(chart);
    if (CollectionUtils.isNotEmpty(chart.getDataSets())) {
        ChartJsonSerializationContext context = createChartJsonSerializationContext(chart);
        JsonArray jsonDataSets = (JsonArray) jsonTree.getAsJsonObject().get("dataSets");
        for (JsonElement dataSetElement : jsonDataSets) {
            JsonObject dataSetObject = (JsonObject) dataSetElement;
            String dataSetId = dataSetObject.get("id").getAsString();
            DataSet dataSet = chart.getDataSet(dataSetId);
            if (dataSet != null && dataSet.getDataProvider() != null) {
                JsonArray dataProviderElement = itemsSerializer.serialize(dataSet.getDataProvider().getItems(), context);
                // Prevent errors on client for empty data provider
                if (dataProviderElement.size() == 0) {
                    dataProviderElement.add(new JsonObject());
                }
                dataSetObject.add("dataProvider", dataProviderElement);
            }
        }
    }
    return chartGson.toJson(jsonTree);
}
Also used : DataSet(io.jmix.charts.model.dataset.DataSet)

Example 2 with DataSet

use of io.jmix.charts.model.dataset.DataSet in project jmix by jmix-framework.

the class StockChartGroup method addDataSets.

@Override
public StockChartGroup addDataSets(DataSet... dataSets) {
    if (dataSets != null) {
        if (this.dataSets == null) {
            this.dataSets = new ArrayList<>();
        }
        List<DataSet> dataSetList = Arrays.asList(dataSets);
        for (DataSet dataSet : dataSetList) {
            dataSet.addDataProviderChangeListener(this);
        }
        this.dataSets.addAll(Arrays.asList(dataSets));
        fireDataSetsChanged(dataSetList, Operation.ADD);
    }
    return this;
}
Also used : DataSet(io.jmix.charts.model.dataset.DataSet)

Example 3 with DataSet

use of io.jmix.charts.model.dataset.DataSet in project jmix by jmix-framework.

the class StockChartGroup method setDataSets.

@Override
public StockChartGroup setDataSets(List<DataSet> dataSets) {
    if (CollectionUtils.isNotEmpty(this.dataSets)) {
        for (DataSet dataSet : this.dataSets) {
            dataSet.removeDataProviderChangeListener(this);
        }
    }
    if (CollectionUtils.isNotEmpty(dataSets)) {
        for (DataSet dataSet : dataSets) {
            dataSet.addDataProviderChangeListener(this);
        }
    }
    this.dataSets = dataSets;
    fireDataSetsChanged(dataSets, Operation.SET);
    return this;
}
Also used : DataSet(io.jmix.charts.model.dataset.DataSet)

Example 4 with DataSet

use of io.jmix.charts.model.dataset.DataSet in project jmix by jmix-framework.

the class JmixAmStockChartScene method beforeClientResponse.

@Override
public void beforeClientResponse(boolean initial) {
    super.beforeClientResponse(initial);
    if (initial || dirty) {
        if (chart != null) {
            // Full repaint
            setupDefaults(chart);
            setupPaths(chart);
            dataItemKeys.removeAll();
            if (chart.getDataSets() != null) {
                for (DataSet dataSet : chart.getDataSets()) {
                    if (dataSet.getDataProvider() != null) {
                        dataSet.getDataProvider().addChangeListener(new ProxyChangeForwarder(this, dataSet));
                    }
                }
            }
            String jsonString = chartSerializer.serialize(chart);
            log.trace("Chart full JSON:\n{}", jsonString);
            getRpcProxy(JmixAmStockChartSceneClientRpc.class).draw(jsonString);
        }
        dirty = false;
    } else if (changedItems != null && !changedItems.isEmpty()) {
        // Incremental repaint
        String jsonString = chartSerializer.serializeChanges(chart, changedItems);
        log.trace("Chart update JSON:\n{}", jsonString);
        for (ChartIncrementalChanges changes : changedItems.values()) {
            List<DataItem> removedItems = changes.getRemovedItems();
            if (removedItems != null) {
                for (DataItem removedItem : removedItems) {
                    dataItemKeys.remove(removedItem);
                }
            }
        }
        getRpcProxy(JmixAmStockChartSceneClientRpc.class).updatePoints(jsonString);
    }
    forgetChangedItems();
}
Also used : JmixAmStockChartSceneClientRpc(io.jmix.charts.widget.client.amstockcharts.rpc.JmixAmStockChartSceneClientRpc) DataSet(io.jmix.charts.model.dataset.DataSet) DataItem(io.jmix.ui.data.DataItem) List(java.util.List) ChartIncrementalChanges(io.jmix.charts.widget.amcharts.serialization.ChartIncrementalChanges)

Example 5 with DataSet

use of io.jmix.charts.model.dataset.DataSet in project jmix by jmix-framework.

the class StockChartLoader method loadDataSets.

protected List<DataSet> loadDataSets(Element dataSetsElement) {
    List<DataSet> dataSets = new ArrayList<>();
    for (Object dataSetItem : dataSetsElement.elements("dataSet")) {
        Element dataSetElement = (Element) dataSetItem;
        DataSet dataSet = new DataSet();
        loadDataSet(dataSet, dataSetElement);
        dataSets.add(dataSet);
    }
    return dataSets;
}
Also used : DataSet(io.jmix.charts.model.dataset.DataSet) Element(org.dom4j.Element) ArrayList(java.util.ArrayList)

Aggregations

DataSet (io.jmix.charts.model.dataset.DataSet)7 StockChartGroup (io.jmix.charts.model.chart.impl.StockChartGroup)2 StockPanel (io.jmix.charts.model.chart.impl.StockPanel)2 FieldMapping (io.jmix.charts.model.dataset.FieldMapping)2 Export (io.jmix.charts.model.export.Export)2 Period (io.jmix.charts.model.period.Period)2 PeriodSelector (io.jmix.charts.model.period.PeriodSelector)2 ChartCursorSettings (io.jmix.charts.model.settings.ChartCursorSettings)2 ChartScrollbarSettings (io.jmix.charts.model.settings.ChartScrollbarSettings)2 StockGraph (io.jmix.charts.model.stock.StockGraph)2 StockLegend (io.jmix.charts.model.stock.StockLegend)2 JmixStockChartSerializer (io.jmix.charts.serialization.JmixStockChartSerializer)2 StockChartSerializer (io.jmix.charts.widget.amcharts.serialization.StockChartSerializer)2 ListDataProvider (io.jmix.ui.data.impl.ListDataProvider)2 Test (org.junit.jupiter.api.Test)2 CategoryAxesSettings (io.jmix.charts.model.axis.CategoryAxesSettings)1 DataSetSelector (io.jmix.charts.model.dataset.DataSetSelector)1 PanelsSettings (io.jmix.charts.model.settings.PanelsSettings)1 ChartIncrementalChanges (io.jmix.charts.widget.amcharts.serialization.ChartIncrementalChanges)1 JmixAmStockChartSceneClientRpc (io.jmix.charts.widget.client.amstockcharts.rpc.JmixAmStockChartSceneClientRpc)1