diff --git a/pom.xml b/pom.xml index acba6af31f6..4e09ac83c51 100644 --- a/pom.xml +++ b/pom.xml @@ -452,7 +452,7 @@ maven-gpg-plugin - 1.6 + 3.0.1 maven-install-plugin diff --git a/vaadin-charts-flow-parent/vaadin-charts-flow/src/main/java/com/vaadin/flow/component/charts/ChartOptions.java b/vaadin-charts-flow-parent/vaadin-charts-flow/src/main/java/com/vaadin/flow/component/charts/ChartOptions.java index 3edd61ddc78..9846ad61fb5 100644 --- a/vaadin-charts-flow-parent/vaadin-charts-flow/src/main/java/com/vaadin/flow/component/charts/ChartOptions.java +++ b/vaadin-charts-flow-parent/vaadin-charts-flow/src/main/java/com/vaadin/flow/component/charts/ChartOptions.java @@ -6,6 +6,7 @@ import com.vaadin.flow.component.ComponentUtil; import com.vaadin.flow.component.UI; import com.vaadin.flow.component.charts.model.AbstractConfigurationObject; +import com.vaadin.flow.component.charts.model.Global; import com.vaadin.flow.component.charts.model.Lang; import com.vaadin.flow.component.charts.model.style.Theme; import com.vaadin.flow.component.charts.util.ChartSerialization; @@ -25,6 +26,7 @@ public class ChartOptions extends AbstractConfigurationObject { @JsonUnwrapped private Theme theme; private Lang lang; + private Global global; private transient JreJsonFactory jsonFactory; protected ChartOptions() { @@ -94,6 +96,30 @@ public void setTheme(Theme theme) { updateOptions(); } + /** + * Returns the {@link Global} in use or {@code null} if no global configuration + * has been set. + * + * @return the {@link Global} in use or {@code null}. + */ + public Global getGlobal() { + return global; + } + + /** + * Changes the Global params of all charts. + *

+ * Note that if the view is already drawn, all existing {@link Chart}s will + * be redrawn. + * + * @param global + */ + public void setGlobal(Global global) { + this.global = global; + updateOptions(); + } + + /** * Returns a ChartOptions instance for the given UI. If a ChartOptions * extension has not yet been added, a new one is created and added. diff --git a/vaadin-charts-flow-parent/vaadin-charts-flow/src/test/java/com/vaadin/flow/component/charts/ChartOptionsJSONSerializationTest.java b/vaadin-charts-flow-parent/vaadin-charts-flow/src/test/java/com/vaadin/flow/component/charts/ChartOptionsJSONSerializationTest.java index 3f3f61fcb65..2079e22f1b0 100644 --- a/vaadin-charts-flow-parent/vaadin-charts-flow/src/test/java/com/vaadin/flow/component/charts/ChartOptionsJSONSerializationTest.java +++ b/vaadin-charts-flow-parent/vaadin-charts-flow/src/test/java/com/vaadin/flow/component/charts/ChartOptionsJSONSerializationTest.java @@ -13,6 +13,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.vaadin.flow.component.UI; +import com.vaadin.flow.component.charts.model.Global; import com.vaadin.flow.component.charts.model.Lang; import com.vaadin.flow.component.charts.util.ChartSerialization; import org.mockito.junit.MockitoJUnitRunner; @@ -84,4 +85,34 @@ public void toJSON_LangWithFinnishLocale_LocaleSerialized_Days() Assert.assertArrayEquals(fiDays, chartOptions.getLang().getWeekdays()); } + + @Test + public void toJSON_GlobalWithoutUTC() + throws IOException { + final Global noUTC = new Global(); + noUTC.setUseUTC(false); + + options.setGlobal(noUTC); + String json = toJSON(options); + + ObjectMapper om = ChartSerialization.createObjectMapper(); + ChartOptions chartOptions = om.readValue(json, ChartOptions.class); + + Assert.assertFalse(chartOptions.getGlobal().getUseUTC()); + } + + @Test + public void toJSON_GlobalWithUTC() + throws IOException { + final Global withUTC = new Global(); + withUTC.setUseUTC(true); + + options.setGlobal(withUTC); + String json = toJSON(options); + + ObjectMapper om = ChartSerialization.createObjectMapper(); + ChartOptions chartOptions = om.readValue(json, ChartOptions.class); + + Assert.assertTrue(chartOptions.getGlobal().getUseUTC()); + } } \ No newline at end of file