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);
}
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;
}
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;
}
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();
}
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;
}
Aggregations