Search in sources :

Example 1 with DataProvider

use of io.jmix.ui.data.DataProvider in project jmix by jmix-framework.

the class ChartsSerializationTest method testSerialChart.

@Test
public void testSerialChart() throws IOException, URISyntaxException, ParseException {
    DataProvider dataProvider = new ListDataProvider();
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "1", "date", "2012-07-27", "value", 13)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "2", "date", "2012-07-28", "value", 11)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "3", "date", "2012-07-29", "value", 15)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "4", "date", "2012-07-30", "value", 16)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "5", "date", "2012-07-31", "value", 18)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "6", "date", "2012-08-01", "value", 13)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "7", "date", "2012-08-02", "value", 22)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "8", "date", "2012-08-03", "value", 23)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "9", "date", "2012-08-04", "value", 20)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "10", "date", "2012-08-05", "value", 17)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "11", "date", "2012-08-06", "value", 16)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "12", "date", "2012-08-07", "value", 18)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "13", "date", "2012-08-08", "value", 21)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "14", "date", "2012-08-09", "value", 26)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "15", "date", "2012-08-10", "value", 24)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "16", "date", "2012-08-11", "value", 29)));
    AbstractChart chart = new SerialChartModelImpl().setCategoryField("date").setDataProvider(dataProvider).addValueAxes(new ValueAxis().setAxisAlpha(0.0).setPosition(Position.LEFT)).addGraphs(new Graph().setId("g1").setBullet(BulletType.ROUND).setBulletBorderAlpha(1.0).setBulletColor(Color.WHITE).setBulletSize(5).setHideBulletsCount(50).setLineThickness(2).setTitle("Red line").setValueField("value")).setCategoryAxis(new CategoryAxis().setDashLength(1).setMinorGridEnabled(true).setPosition(Position.TOP)).setChartScrollbar(new Scrollbar().setGraph("g1").setScrollbarHeight(30)).setChartCursor(new Cursor().setCursorPosition(CursorPosition.MOUSE).setPan(true)).setExport(new Export());
    ChartSerializer serializer = getTestSerializer();
    String json = serializer.serialize(chart);
    String expected = readFile("SerialChart.json");
    assertEquals(prettyJson(expected), prettyJson(json));
}
Also used : ListDataProvider(io.jmix.ui.data.impl.ListDataProvider) ChartSerializer(io.jmix.charts.widget.amcharts.serialization.ChartSerializer) Cursor(io.jmix.charts.model.cursor.Cursor) ListDataProvider(io.jmix.ui.data.impl.ListDataProvider) DataProvider(io.jmix.ui.data.DataProvider) Graph(io.jmix.charts.model.graph.Graph) CategoryAxis(io.jmix.charts.model.axis.CategoryAxis) ValueAxis(io.jmix.charts.model.axis.ValueAxis) Export(io.jmix.charts.model.export.Export) MapDataItem(io.jmix.ui.data.impl.MapDataItem) Scrollbar(io.jmix.charts.model.Scrollbar) Test(org.junit.jupiter.api.Test)

Example 2 with DataProvider

use of io.jmix.ui.data.DataProvider in project jmix by jmix-framework.

the class JmixChartSerializer method serialize.

@Override
public String serialize(AbstractChart chart) {
    JsonElement jsonTree = chartGson.toJsonTree(chart);
    ChartJsonSerializationContext context = createChartJsonSerializationContext(chart);
    DataProvider dataProvider = chart.getDataProvider();
    if (dataProvider != null) {
        JsonArray dataProviderElement = itemsSerializer.serialize(dataProvider.getItems(), context);
        // Prevent errors on client for empty data provider
        if (dataProviderElement.size() == 0) {
            dataProviderElement.add(new JsonObject());
        }
        jsonTree.getAsJsonObject().add("dataProvider", dataProviderElement);
    }
    beforeConvertToJson(jsonTree, context);
    return chartGson.toJson(jsonTree);
}
Also used : DataProvider(io.jmix.ui.data.DataProvider)

Example 3 with DataProvider

use of io.jmix.ui.data.DataProvider in project jmix by jmix-framework.

the class ChartsSerializationTest method testPieChart.

@Test
public void testPieChart() throws IOException, URISyntaxException {
    DataProvider dataProvider = new ListDataProvider();
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "1", "country", "Czech Republic", "litres", 256.9)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "2", "country", "Ireland", "litres", 131.1)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "3", "country", "Germany", "litres", 115.8)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "4", "country", "Australia", "litres", 109.9)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "5", "country", "Austria", "litres", 108.3)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "6", "country", "UK", "litres", 65.0)));
    dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "7", "country", "Belgium", "litres", 40.0)));
    AbstractChart chart = new PieChartModelImpl().setDataProvider(dataProvider).setDepth3D(15).setAngle(30).setValueField("litres").setTitleField("country").setBalloonText("[[title]] - [[percents]]%").setLegend(new Legend().setMarkerType(MarkerType.CIRCLE).setPosition(LegendPosition.RIGHT).setMarginRight(80).setAutoMargins(false)).setExport(new Export());
    ChartSerializer serializer = getTestSerializer();
    String json = serializer.serialize(chart);
    String expected = readFile("PieChart.json");
    assertEquals(prettyJson(expected), prettyJson(json));
}
Also used : ListDataProvider(io.jmix.ui.data.impl.ListDataProvider) DataProvider(io.jmix.ui.data.DataProvider) ListDataProvider(io.jmix.ui.data.impl.ListDataProvider) Legend(io.jmix.charts.model.legend.Legend) ChartSerializer(io.jmix.charts.widget.amcharts.serialization.ChartSerializer) Export(io.jmix.charts.model.export.Export) MapDataItem(io.jmix.ui.data.impl.MapDataItem) Test(org.junit.jupiter.api.Test)

Example 4 with DataProvider

use of io.jmix.ui.data.DataProvider in project jmix by jmix-framework.

the class JmixPivotTableSerializer method serializeData.

@Override
@Nullable
public String serializeData(PivotTableModel pivotTable, Consumer<PivotTableSerializationContext> postSerializationHandler) {
    DataProvider dataProvider = pivotTable.getDataProvider();
    if (dataProvider != null) {
        PivotJsonSerializationContext context = createPivotJsonSerializationContext(pivotTable);
        JsonElement dataProviderElement = itemsSerializer.serialize(dataProvider.getItems(), context, postSerializationHandler);
        return gson.toJson(dataProviderElement);
    }
    return null;
}
Also used : DataProvider(io.jmix.ui.data.DataProvider) Nullable(javax.annotation.Nullable)

Aggregations

DataProvider (io.jmix.ui.data.DataProvider)4 Export (io.jmix.charts.model.export.Export)2 ChartSerializer (io.jmix.charts.widget.amcharts.serialization.ChartSerializer)2 ListDataProvider (io.jmix.ui.data.impl.ListDataProvider)2 MapDataItem (io.jmix.ui.data.impl.MapDataItem)2 Test (org.junit.jupiter.api.Test)2 Scrollbar (io.jmix.charts.model.Scrollbar)1 CategoryAxis (io.jmix.charts.model.axis.CategoryAxis)1 ValueAxis (io.jmix.charts.model.axis.ValueAxis)1 Cursor (io.jmix.charts.model.cursor.Cursor)1 Graph (io.jmix.charts.model.graph.Graph)1 Legend (io.jmix.charts.model.legend.Legend)1 Nullable (javax.annotation.Nullable)1