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