Skip to content

Commit

Permalink
Add zIndex API to series
Browse files Browse the repository at this point in the history
zIndex was not added to PlotOptions as it only makes sense
when used in a Series and not when used in Configuration
Alternate implementation to #562
Fixes #565
Fixes #331
  • Loading branch information
alvarezguille committed Mar 22, 2019
1 parent d0d623f commit 34363e9
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

}
16 changes: 16 additions & 0 deletions addon/src/main/java/com/vaadin/addon/charts/model/Series.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<T1, T2> {
private T1 t1;
private T2 t2;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Series> seriesList = configuration.getSeries();
AtomicInteger seriesCount = new AtomicInteger(seriesList.size());
seriesList.forEach(
series -> series.setZIndex(seriesCount.decrementAndGet()));
return chart;
}

}
Original file line number Diff line number Diff line change
@@ -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";
}

}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 34363e9

Please sign in to comment.