Search in sources :

Example 21 with Configuration

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

the class ChartDesignWriterTest method writeConfiguration_stringValueDefinedInConfiguration_theValueIsAddedAsAttribute.

@Test
public void writeConfiguration_stringValueDefinedInConfiguration_theValueIsAddedAsAttribute() {
    DesignContext designContext = new DesignContext();
    Configuration configuration = new Configuration();
    configuration.setTitle(new Title("my title"));
    Element parent = new Element(Tag.valueOf("test"), "");
    ChartDesignWriter.writeConfigurationToElement(configuration, parent, designContext);
    assertEquals("<chart-title text=\"my title\"></chart-title>", parent.child(0).toString());
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) Element(org.jsoup.nodes.Element) DesignContext(com.vaadin.ui.declarative.DesignContext) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) Title(com.vaadin.addon.charts.model.Title) Test(org.junit.Test)

Example 22 with Configuration

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

the class ChartDesignWriterTest method writeConfiguration_multiplePlotOptions_allPlotOptionsAreChildrenOfPlotOptionsTag.

@Test
public void writeConfiguration_multiplePlotOptions_allPlotOptionsAreChildrenOfPlotOptionsTag() {
    DesignContext designContext = new DesignContext();
    Configuration configuration = new Configuration();
    PlotOptionsLine plotOptionsLine = new PlotOptionsLine();
    plotOptionsLine.setAnimation(false);
    PlotOptionsSpline plotOptionsSpline = new PlotOptionsSpline();
    plotOptionsSpline.setVisible(false);
    configuration.setPlotOptions(plotOptionsLine, plotOptionsSpline);
    Element parent = new Element(Tag.valueOf("test"), "");
    ChartDesignWriter.writeConfigurationToElement(configuration, parent, designContext);
    // Expected (the order of plot options is unknown):
    // "<plot-options>
    // <line animation=\"false\">
    // </line>
    // <spline visible=\"false\">
    // </spline>
    // </plot-options>"
    assertEquals("plot-options", parent.child(0).tagName());
    Elements plotOptions = parent.child(0).children();
    assertEquals(2, plotOptions.size());
    assertPlotOptions("line", "animation", "false", plotOptions);
    assertPlotOptions("spline", "visible", "false", plotOptions);
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) PlotOptionsLine(com.vaadin.addon.charts.model.PlotOptionsLine) Element(org.jsoup.nodes.Element) DesignContext(com.vaadin.ui.declarative.DesignContext) PlotOptionsSpline(com.vaadin.addon.charts.model.PlotOptionsSpline) Elements(org.jsoup.select.Elements) Test(org.junit.Test)

Example 23 with Configuration

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

the class ChartDesignWriterTest method writeConfiguration_chartHasLinearGradientBackgroundColor_theLinearGradientIsWrittenAsElement.

@Test
public void writeConfiguration_chartHasLinearGradientBackgroundColor_theLinearGradientIsWrittenAsElement() {
    Configuration configuration = new Configuration();
    GradientColor gradientColor = GradientColor.createLinear(0, 0, 1, 1);
    gradientColor.addColorStop(0, new SolidColor("white"));
    gradientColor.addColorStop(1, new SolidColor("black"));
    configuration.getChart().setBackgroundColor(gradientColor);
    Element parent = new Element(Tag.valueOf("test"), "");
    DesignContext designContext = new DesignContext();
    ChartDesignWriter.writeConfigurationToElement(configuration, parent, designContext);
    assertEquals("<chart><background-color><linear-gradient x1=\"0\" y1=\"0\" x2=\"1\" y2=\"1\"></linear-gradient>" + "<stops position=\"0\" color=\"white\"></stops>" + "<stops position=\"1\" color=\"black\"></stops>" + "</background-color></chart>", removeWhitespacesBetweenTags(parent.child(0).toString()));
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) GradientColor(com.vaadin.addon.charts.model.style.GradientColor) Element(org.jsoup.nodes.Element) DesignContext(com.vaadin.ui.declarative.DesignContext) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) Test(org.junit.Test)

Example 24 with Configuration

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

the class ChartDataSeriesJSONSerializationTest method serialize_ContainerWithNameAndStack_NameAndStackSerialized.

@Test
public void serialize_ContainerWithNameAndStack_NameAndStackSerialized() {
    final Pair<ListDataProvider<TestItem>, DataProviderSeries<TestItem>> pair = createTuple();
    final DataProviderSeries<TestItem> dataProviderSeries = pair.getT2();
    dataProviderSeries.setY(TestItem::getY);
    dataProviderSeries.setName("foo");
    dataProviderSeries.setStack("bar");
    Configuration config = new Configuration();
    config.addSeries(dataProviderSeries);
    String actual = toJSON(dataProviderSeries);
    String expected = "{\"name\":\"foo\",\"stack\":\"bar\",\"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) Test(org.junit.Test)

Example 25 with Configuration

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

the class ChartDesignWriterTest method writeConfiguration_enumValueDefinedInConfiguration_theValueIsAddedAsAttribute.

@Test
public void writeConfiguration_enumValueDefinedInConfiguration_theValueIsAddedAsAttribute() {
    DesignContext designContext = new DesignContext();
    Configuration configuration = new Configuration();
    Legend legend = new Legend();
    legend.setLayout(LayoutDirection.VERTICAL);
    configuration.setLegend(legend);
    Element parent = new Element(Tag.valueOf("test"), "");
    ChartDesignWriter.writeConfigurationToElement(configuration, parent, designContext);
    assertEquals("<legend layout=\"vertical\"></legend>", parent.child(0).toString());
}
Also used : Legend(com.vaadin.addon.charts.model.Legend) Configuration(com.vaadin.addon.charts.model.Configuration) Element(org.jsoup.nodes.Element) DesignContext(com.vaadin.ui.declarative.DesignContext) Test(org.junit.Test)

Aggregations

Configuration (com.vaadin.addon.charts.model.Configuration)257 Chart (com.vaadin.addon.charts.Chart)196 YAxis (com.vaadin.addon.charts.model.YAxis)100 DataSeries (com.vaadin.addon.charts.model.DataSeries)72 ListSeries (com.vaadin.addon.charts.model.ListSeries)70 XAxis (com.vaadin.addon.charts.model.XAxis)65 Test (org.junit.Test)58 SolidColor (com.vaadin.addon.charts.model.style.SolidColor)56 AxisTitle (com.vaadin.addon.charts.model.AxisTitle)54 DataSeriesItem (com.vaadin.addon.charts.model.DataSeriesItem)51 Tooltip (com.vaadin.addon.charts.model.Tooltip)42 DataLabels (com.vaadin.addon.charts.model.DataLabels)41 Legend (com.vaadin.addon.charts.model.Legend)30 PlotOptionsColumn (com.vaadin.addon.charts.model.PlotOptionsColumn)30 PlotOptionsLine (com.vaadin.addon.charts.model.PlotOptionsLine)27 Elements (org.jsoup.select.Elements)27 Marker (com.vaadin.addon.charts.model.Marker)22 DesignContext (com.vaadin.ui.declarative.DesignContext)22 Element (org.jsoup.nodes.Element)22 PlotOptionsPie (com.vaadin.addon.charts.model.PlotOptionsPie)20