Search in sources :

Example 86 with DataSeriesItem

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

the class ChartOptionsJSONSerializationTest method toJSON_itemWithRadialGradientColor_RadialGradientSerialized.

@Test
public void toJSON_itemWithRadialGradientColor_RadialGradientSerialized() {
    GradientColor color = GradientColor.createRadial(0.5, 0.3, 0.7);
    color.addColorStop(0, new SolidColor(255, 128, 0));
    color.addColorStop(1, new SolidColor(128, 64, 0));
    DataSeriesItem item = new DataSeriesItem("Foobar", 45.0);
    item.setColor(color);
    DataSeries series = new DataSeries();
    series.add(item);
    String expected = "{\"data\":[{\"name\":\"Foobar\",\"y\":45.0,\"color\":{\"stops\":[[0.0,\"#FF8000\"],[1.0,\"#804000\"]],\"radialGradient\":{\"cx\":0.5,\"cy\":0.3,\"r\":0.7}}}]}";
    assertEquals(expected, toJSON(series));
}
Also used : GradientColor(com.vaadin.addon.charts.model.style.GradientColor) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) DataSeries(com.vaadin.addon.charts.model.DataSeries) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem) Test(org.junit.Test)

Example 87 with DataSeriesItem

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

the class SerializationTest method serializeChart_configurationWithDrilldown_drilldownSeriesListSerializedCorrectly.

@Test
public void serializeChart_configurationWithDrilldown_drilldownSeriesListSerializedCorrectly() throws IOException, ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
    Chart input = new Chart();
    DataSeries dataSeries = new DataSeries();
    ListSeries drilldownSeries = new ListSeries();
    drilldownSeries.setId("id");
    dataSeries.addItemWithDrilldown(new DataSeriesItem("foobar", 42), drilldownSeries);
    input.getConfiguration().addSeries(dataSeries);
    Chart output = serializeObject(input);
    DataSeries outputSeries = (DataSeries) output.getConfiguration().getSeries().get(0);
    List<Series> outputDrilldownSeries = getPrivateField("drilldownSeries", outputSeries, DataSeries.class);
    assertNotNull("Drilldown series list was null after serialization", outputDrilldownSeries);
    assertThat("Drilldown series list was empty after serialization", outputDrilldownSeries, is(not(empty())));
}
Also used : Series(com.vaadin.addon.charts.model.Series) ListSeries(com.vaadin.addon.charts.model.ListSeries) DataSeries(com.vaadin.addon.charts.model.DataSeries) ListSeries(com.vaadin.addon.charts.model.ListSeries) DataSeries(com.vaadin.addon.charts.model.DataSeries) Chart(com.vaadin.addon.charts.Chart) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem) Test(org.junit.Test)

Example 88 with DataSeriesItem

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

the class SerializationTest method serializeDataSeries_seriesWithOneItem_dataSeriesItemsSerializedCorrectly.

@Test
public void serializeDataSeries_seriesWithOneItem_dataSeriesItemsSerializedCorrectly() throws IOException, ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
    // this should make the item customized
    final DataSeriesItem dataSeriesItem = new DataSeriesItem("foobar", 42);
    DataSeries input = new DataSeries(dataSeriesItem);
    DataSeries output = serializeObject(input);
    final DataSeriesItem outputDataSeriesItem = output.get(0);
    assertTrue("DataSeriesItem.isCustomized() was false after serialization", outputDataSeriesItem.isCustomized());
}
Also used : DataSeries(com.vaadin.addon.charts.model.DataSeries) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem) Test(org.junit.Test)

Aggregations

DataSeriesItem (com.vaadin.addon.charts.model.DataSeriesItem)88 DataSeries (com.vaadin.addon.charts.model.DataSeries)81 Chart (com.vaadin.addon.charts.Chart)57 Configuration (com.vaadin.addon.charts.model.Configuration)51 YAxis (com.vaadin.addon.charts.model.YAxis)27 SolidColor (com.vaadin.addon.charts.model.style.SolidColor)19 DataLabels (com.vaadin.addon.charts.model.DataLabels)17 XAxis (com.vaadin.addon.charts.model.XAxis)17 AxisTitle (com.vaadin.addon.charts.model.AxisTitle)12 Random (java.util.Random)12 PlotOptionsPie (com.vaadin.addon.charts.model.PlotOptionsPie)11 Test (org.junit.Test)11 Tooltip (com.vaadin.addon.charts.model.Tooltip)10 Marker (com.vaadin.addon.charts.model.Marker)9 PlotOptionsSpline (com.vaadin.addon.charts.model.PlotOptionsSpline)8 PlotLine (com.vaadin.addon.charts.model.PlotLine)7 PlotOptionsColumn (com.vaadin.addon.charts.model.PlotOptionsColumn)7 StockPrices (com.vaadin.addon.charts.examples.timeline.util.StockPrices)6 ListSeries (com.vaadin.addon.charts.model.ListSeries)6 Style (com.vaadin.addon.charts.model.style.Style)6