Search in sources :

Example 16 with DataProviderSeries

use of com.vaadin.addon.charts.model.DataProviderSeries in project charts by vaadin.

the class ChartDataSeriesJSONSerializationTest method serialize_ContainerWithNonUTCDate_DateSerializedAsUTC.

@Test
public void serialize_ContainerWithNonUTCDate_DateSerializedAsUTC() {
    final ZonedDateTime nowUTC = ZonedDateTime.of(2010, 10, 10, 10, 39, 00, 00, ZoneId.of("UTC"));
    final ZonedDateTime nowEuropeParis = ZonedDateTime.of(2010, 10, 10, 10, 39, 00, 00, ZoneId.of("Europe/Paris"));
    final Collection<TestDateItem> colEurope = singletonList(new TestDateItem(nowEuropeParis, 80));
    final DataProvider<TestDateItem, ?> dataProviderEurope = new ListDataProvider<>(colEurope);
    final DataProviderSeries<TestDateItem> chartDataSeriesEurope = new DataProviderSeries<>(dataProviderEurope);
    chartDataSeriesEurope.setX(TestDateItem::getDate);
    chartDataSeriesEurope.setY(TestDateItem::getValue);
    final Collection<TestDateItem> colUTC = singletonList(new TestDateItem(nowUTC, 80));
    final DataProvider<TestDateItem, ?> dataProviderUTC = new ListDataProvider<>(colUTC);
    final DataProviderSeries<TestDateItem> chartDataSeriesUTC = new DataProviderSeries<>(dataProviderUTC);
    chartDataSeriesUTC.setX(TestDateItem::getDate);
    chartDataSeriesUTC.setY(TestDateItem::getValue);
    final String actualEurope = toJSON(chartDataSeriesEurope);
    final String actualUTC = toJSON(chartDataSeriesUTC);
    // not loosing TimeZone
    assertNotEquals(actualUTC, actualEurope);
}
Also used : ListDataProvider(com.vaadin.data.provider.ListDataProvider) DataProviderSeries(com.vaadin.addon.charts.model.DataProviderSeries) ZonedDateTime(java.time.ZonedDateTime) Test(org.junit.Test)

Example 17 with DataProviderSeries

use of com.vaadin.addon.charts.model.DataProviderSeries in project charts by vaadin.

the class ChartDataSeriesJSONSerializationTest method serialize_ContainerWithLinePlotOptions_PlotOptionsAndTypeSerialized.

@Test
public void serialize_ContainerWithLinePlotOptions_PlotOptionsAndTypeSerialized() {
    PlotOptionsLine plotOptions = new PlotOptionsLine();
    plotOptions.setShowInLegend(true);
    final Pair<ListDataProvider<TestItem>, DataProviderSeries<TestItem>> pair = createTuple();
    final DataProviderSeries<TestItem> dataProviderSeries = pair.getT2();
    dataProviderSeries.setY(TestItem::getY);
    dataProviderSeries.setPlotOptions(plotOptions);
    Configuration config = new Configuration();
    config.addSeries(dataProviderSeries);
    String actual = toJSON(dataProviderSeries);
    String expected = "{\"type\":\"line\",\"showInLegend\":true,\"data\":[]}";
    assertEquals(expected, actual);
}
Also used : ListDataProvider(com.vaadin.data.provider.ListDataProvider) DataProviderSeries(com.vaadin.addon.charts.model.DataProviderSeries) Configuration(com.vaadin.addon.charts.model.Configuration) PlotOptionsLine(com.vaadin.addon.charts.model.PlotOptionsLine) Test(org.junit.Test)

Aggregations

DataProviderSeries (com.vaadin.addon.charts.model.DataProviderSeries)17 Configuration (com.vaadin.addon.charts.model.Configuration)12 ListDataProvider (com.vaadin.data.provider.ListDataProvider)10 Chart (com.vaadin.addon.charts.Chart)8 Test (org.junit.Test)6 PlotOptionsColumn (com.vaadin.addon.charts.model.PlotOptionsColumn)4 YAxis (com.vaadin.addon.charts.model.YAxis)4 ArrayList (java.util.ArrayList)3 PlotOptionsSeries (com.vaadin.addon.charts.model.PlotOptionsSeries)2 XAxis (com.vaadin.addon.charts.model.XAxis)2 LocalDateTime (java.time.LocalDateTime)2 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 SerializerProvider (com.fasterxml.jackson.databind.SerializerProvider)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 JsonNodeFactory (com.fasterxml.jackson.databind.node.JsonNodeFactory)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ValueNode (com.fasterxml.jackson.databind.node.ValueNode)1 AxisTitle (com.vaadin.addon.charts.model.AxisTitle)1 CLOSE_PROPERTY (com.vaadin.addon.charts.model.DataProviderSeries.CLOSE_PROPERTY)1 HIGH_PROPERTY (com.vaadin.addon.charts.model.DataProviderSeries.HIGH_PROPERTY)1