use of com.vaadin.flow.component.charts.model.Lang in project flow-components by vaadin.
the class GlobalOptions method initDemo.
@Override
public void initDemo() {
List<Chart> charts = new ArrayList();
NativeButton changeTitleButton = new NativeButton();
changeTitleButton.setId("add_chart");
changeTitleButton.setText("Add chart");
changeTitleButton.addClickListener(e -> {
final Chart chart = new Chart();
Configuration configuration = chart.getConfiguration();
configuration.setTitle("First Chart for Flow");
chart.getConfiguration().getChart().setType(ChartType.AREA);
Tooltip tooltip = configuration.getTooltip();
tooltip.setEnabled(true);
tooltip.setShared(true);
PlotOptionsSeries options = new PlotOptionsSeries();
options.setPointStart(0);
options.setPointIntervalUnit(IntervalUnit.DAY);
configuration.setPlotOptions(options);
configuration.addSeries(new ListSeries("Tokyo", 20, 12, 34, 23, 65, 8, 4, 7, 76, 19, 20, 8));
configuration.addSeries(new ListSeries("Miami", 34, 29, 23, 65, 8, 4, 7, 7, 59, 8, 9, 19));
XAxis x = new XAxis();
x.setType(AxisType.DATETIME);
x.getLabels().setFormat("{value:%a}");
configuration.addxAxis(x);
YAxis y = new YAxis();
y.setMin(0);
y.setTitle("Rainfall (mm)");
configuration.addyAxis(y);
charts.add(chart);
add(chart);
});
add(changeTitleButton);
NativeButton changeLangButton = new NativeButton();
changeLangButton.setId("change_lang");
changeLangButton.setText("Change lang");
changeLangButton.addClickListener(e -> {
Lang lang = new Lang();
lang.setShortMonths(new String[] { "Tammi", "Helmi", "Maalis", "Huhti", "Touko", "Kesä", "Heinä", "Elo", "Syys", "Loka", "Marras", "Joulu" });
lang.setMonths(new String[] { "Tammikuu", "Helmikuu", "Maaliskuu", "Huhtikuu", "Toukokuu", "Kesäkuu", "Heinäkuu", "Elokuu", "Syyskuu", "Lokakuu", "Marraskuu", "Joulukuu" });
lang.setWeekdays(new String[] { "Sunnuntai", "Maanantai", "Tiistai", "Keskiviikko", "Torstai", "Perjantai", "Lauantai" });
lang.setShortWeekdays(new String[] { "su", "ma", "ti", "ke", "to", "pe", "la" });
ChartOptions.get().setLang(lang);
});
add(changeLangButton);
NativeButton changeThemeLightButton = new NativeButton();
changeThemeLightButton.setId("change_theme_light");
changeThemeLightButton.setText("Change theme light");
changeThemeLightButton.addClickListener(e -> {
ChartOptions.get().setTheme(new LumoLightTheme());
for (Chart chart : charts) {
chart.drawChart(true);
}
});
add(changeThemeLightButton);
NativeButton changeThemeDarkButton = new NativeButton();
changeThemeDarkButton.setId("change_theme_dark");
changeThemeDarkButton.setText("Change theme Dark");
changeThemeDarkButton.addClickListener(e -> {
ChartOptions.get().setTheme(new LumoDarkTheme());
for (Chart chart : charts) {
chart.drawChart(true);
}
});
add(changeThemeDarkButton);
}
use of com.vaadin.flow.component.charts.model.Lang in project flow-components by vaadin.
the class SVGGeneratorTest method exportWithCustomLang.
@Test
public void exportWithCustomLang() throws IOException, InterruptedException {
Configuration conf = createAreaChartConfiguration();
ExportOptions options = new ExportOptions();
Lang lang = createLang();
options.setLang(lang);
String svg = svgGenerator.generate(conf, options);
Path pieChartPath = Paths.get("src", "test", "resources", "custom-lang.svg");
String expectedSVG = readUtf8File(pieChartPath);
assertEquals(replaceIds(expectedSVG), replaceIds(svg));
}
use of com.vaadin.flow.component.charts.model.Lang in project flow-components by vaadin.
the class SVGGeneratorTest method createLang.
private Lang createLang() {
Lang lang = new Lang();
lang.setShortMonths(new String[] { "Tammi", "Helmi", "Maalis", "Huhti", "Touko", "Kesä", "Heinä", "Elo", "Syys", "Loka", "Marras", "Joulu" });
lang.setMonths(new String[] { "Tammikuu", "Helmikuu", "Maaliskuu", "Huhtikuu", "Toukokuu", "Kesäkuu", "Heinäkuu", "Elokuu", "Syyskuu", "Lokakuu", "Marraskuu", "Joulukuu" });
lang.setWeekdays(new String[] { "Sunnuntai", "Maanantai", "Tiistai", "Keskiviikko", "Torstai", "Perjantai", "Lauantai" });
lang.setShortWeekdays(new String[] { "su", "ma", "ti", "ke", "to", "pe", "la" });
return lang;
}
use of com.vaadin.flow.component.charts.model.Lang in project flow-components by vaadin.
the class ChartOptionsJSONSerializationTest method toJSON_LangWithFinnishLocale_LocaleSerialized_Days.
@Test
public void toJSON_LangWithFinnishLocale_LocaleSerialized_Days() throws IOException {
final String[] fiDays = new String[] { "Ma", "Ti", "Ke", "To", "Pe", "La", "Su" };
final Lang fi = new Lang();
fi.setWeekdays(fiDays);
options.setLang(fi);
String json = toJSON(options);
ObjectMapper om = ChartSerialization.createObjectMapper();
ChartOptions chartOptions = om.readValue(json, ChartOptions.class);
Assert.assertArrayEquals(fiDays, chartOptions.getLang().getWeekdays());
}
use of com.vaadin.flow.component.charts.model.Lang in project flow-components by vaadin.
the class ChartOptionsJSONSerializationTest method toJSON_LangWithFinnishLocale_LocaleSerialized_Months.
@Test
public void toJSON_LangWithFinnishLocale_LocaleSerialized_Months() throws IOException {
final String[] fiMonths = new String[] { "Tammikuu", "Helmikuu", "Maaliskuu", "Huhtikuu", "Toukokuu", "Kesäkuu", "Heinäkuu", "Elokuu", "Syyskuu", "Lokakuu", "Marraskuu", "Joulukuu" };
final Lang fi = new Lang();
fi.setMonths(fiMonths);
options.setLang(fi);
String json = toJSON(options);
ObjectMapper om = ChartSerialization.createObjectMapper();
ChartOptions chartOptions = om.readValue(json, ChartOptions.class);
Assert.assertArrayEquals(fiMonths, chartOptions.getLang().getMonths());
}
Aggregations