diff --git a/addon/src/main/java/com/vaadin/addon/charts/model/AbstractSeries.java b/addon/src/main/java/com/vaadin/addon/charts/model/AbstractSeries.java index 391a242a2..43c2e6f1e 100644 --- a/addon/src/main/java/com/vaadin/addon/charts/model/AbstractSeries.java +++ b/addon/src/main/java/com/vaadin/addon/charts/model/AbstractSeries.java @@ -30,6 +30,7 @@ public abstract class AbstractSeries extends AbstractConfigurationObject private String name; private String stack; private String id; + private Number zIndex; @JsonUnwrapped private AbstractPlotOptions plotOptions; @@ -241,4 +242,14 @@ public void setyAxis(YAxis secondaryAxis) { setyAxis(indexOf); } + @Override + public Number getZIndex() { + return zIndex; + } + + @Override + public void setZIndex(Number zIndex) { + this.zIndex = zIndex; + } + } diff --git a/addon/src/main/java/com/vaadin/addon/charts/model/Series.java b/addon/src/main/java/com/vaadin/addon/charts/model/Series.java index 90dcc92e5..49745c0ca 100644 --- a/addon/src/main/java/com/vaadin/addon/charts/model/Series.java +++ b/addon/src/main/java/com/vaadin/addon/charts/model/Series.java @@ -36,6 +36,22 @@ public interface Series { */ void setName(String name); + /** + * @see #setZIndex(String) + * @return the visual z index of the series. + */ + Number getZIndex(); + + /** + * Define the visual z index of the series. With no z index, the series + * defined last are on top. With a z index, the series with the highest z + * index is on top. + * + * @param zIndex + * to set to the series + */ + void setZIndex(Number zIndex); + /** * Sets the configuration to which this series is linked. * diff --git a/addon/src/test/java/com/vaadin/addon/charts/model/junittests/ChartDataSeriesJSONSerializationTest.java b/addon/src/test/java/com/vaadin/addon/charts/model/junittests/ChartDataSeriesJSONSerializationTest.java index 405fcc0f4..68b183d77 100644 --- a/addon/src/test/java/com/vaadin/addon/charts/model/junittests/ChartDataSeriesJSONSerializationTest.java +++ b/addon/src/test/java/com/vaadin/addon/charts/model/junittests/ChartDataSeriesJSONSerializationTest.java @@ -4,6 +4,7 @@ import static java.util.Collections.singletonList; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; + import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; @@ -18,6 +19,7 @@ import com.vaadin.addon.charts.model.Configuration; import com.vaadin.addon.charts.model.DataProviderSeries; +import com.vaadin.addon.charts.model.ListSeries; import com.vaadin.addon.charts.model.PlotOptionsLine; import com.vaadin.addon.charts.model.PlotOptionsSeries; import com.vaadin.data.provider.DataProvider; @@ -382,6 +384,17 @@ public void serialize_ContainerWithFilteredValues_dataWasFiltered() { assertEquals(expected, actual); } + @Test + public void serialize_SeriesHasZIndex_zIndexSerialized() { + final ListSeries dataSeries = new ListSeries(1,2,3); + dataSeries.setZIndex(134); + + String actual = toJSON(dataSeries); + String expected = "{\"zIndex\":134,\"data\":[1,2,3]}"; + assertEquals(expected, actual); + } + + public static class Pair { private T1 t1; private T2 t2; diff --git a/examples/src/main/java/com/vaadin/addon/charts/examples/lineandscatter/BasicLineZIndex.java b/examples/src/main/java/com/vaadin/addon/charts/examples/lineandscatter/BasicLineZIndex.java new file mode 100644 index 000000000..35a8ea3e1 --- /dev/null +++ b/examples/src/main/java/com/vaadin/addon/charts/examples/lineandscatter/BasicLineZIndex.java @@ -0,0 +1,31 @@ +package com.vaadin.addon.charts.examples.lineandscatter; + +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; + +import com.vaadin.addon.charts.Chart; +import com.vaadin.addon.charts.examples.SkipFromDemo; +import com.vaadin.addon.charts.model.ChartType; +import com.vaadin.addon.charts.model.Configuration; +import com.vaadin.addon.charts.model.PlotOptionsLine; +import com.vaadin.addon.charts.model.Series; +import com.vaadin.ui.Component; + +@SkipFromDemo +public class BasicLineZIndex extends BasicLine { + + @Override + protected Component getChart() { + Chart chart = (Chart) super.getChart(); + Configuration configuration = chart.getConfiguration(); + PlotOptionsLine options = (PlotOptionsLine) configuration + .getPlotOptions(ChartType.LINE); + options.setLineWidth(5); + List seriesList = configuration.getSeries(); + AtomicInteger seriesCount = new AtomicInteger(seriesList.size()); + seriesList.forEach( + series -> series.setZIndex(seriesCount.decrementAndGet())); + return chart; + } + +} diff --git a/integration-tests/src/test/java/com/vaadin/addon/charts/testbenchtests/BasicLineZIndexTBTest.java b/integration-tests/src/test/java/com/vaadin/addon/charts/testbenchtests/BasicLineZIndexTBTest.java new file mode 100644 index 000000000..455a37b34 --- /dev/null +++ b/integration-tests/src/test/java/com/vaadin/addon/charts/testbenchtests/BasicLineZIndexTBTest.java @@ -0,0 +1,17 @@ +package com.vaadin.addon.charts.testbenchtests; + +import com.vaadin.addon.charts.examples.lineandscatter.BasicLineZIndex; + +public class BasicLineZIndexTBTest + extends AbstractSimpleScreenShotTestBenchTest { + + protected String getTestViewName() { + return BasicLineZIndex.class.getSimpleName(); + } + + @Override + protected String getPackageName() { + return "lineandscatter"; + } + +} diff --git a/integration-tests/src/test/resources/screenshots/reference/BasicLineZIndex_linux_phantomjs_2.png b/integration-tests/src/test/resources/screenshots/reference/BasicLineZIndex_linux_phantomjs_2.png new file mode 100644 index 000000000..9d5cea61a Binary files /dev/null and b/integration-tests/src/test/resources/screenshots/reference/BasicLineZIndex_linux_phantomjs_2.png differ diff --git a/integration-tests/src/test/resources/screenshots/reference/BasicLineZIndex_windows_firefox_45.png b/integration-tests/src/test/resources/screenshots/reference/BasicLineZIndex_windows_firefox_45.png new file mode 100644 index 000000000..8e24e3119 Binary files /dev/null and b/integration-tests/src/test/resources/screenshots/reference/BasicLineZIndex_windows_firefox_45.png differ diff --git a/integration-tests/src/test/resources/screenshots/reference/BasicLineZIndex_windows_internet explorer_11.png b/integration-tests/src/test/resources/screenshots/reference/BasicLineZIndex_windows_internet explorer_11.png new file mode 100644 index 000000000..e7e2183f2 Binary files /dev/null and b/integration-tests/src/test/resources/screenshots/reference/BasicLineZIndex_windows_internet explorer_11.png differ diff --git a/integration-tests/src/test/resources/screenshots/reference/BasicLineZIndex_xp_chrome_70.png b/integration-tests/src/test/resources/screenshots/reference/BasicLineZIndex_xp_chrome_70.png new file mode 100644 index 000000000..4bb03f8dc Binary files /dev/null and b/integration-tests/src/test/resources/screenshots/reference/BasicLineZIndex_xp_chrome_70.png differ