Search in sources :

Example 1 with Lang

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);
}
Also used : NativeButton(com.vaadin.flow.component.html.NativeButton) Configuration(com.vaadin.flow.component.charts.model.Configuration) Tooltip(com.vaadin.flow.component.charts.model.Tooltip) ArrayList(java.util.ArrayList) Lang(com.vaadin.flow.component.charts.model.Lang) XAxis(com.vaadin.flow.component.charts.model.XAxis) LumoDarkTheme(com.vaadin.flow.component.charts.themes.LumoDarkTheme) ListSeries(com.vaadin.flow.component.charts.model.ListSeries) LumoLightTheme(com.vaadin.flow.component.charts.themes.LumoLightTheme) Chart(com.vaadin.flow.component.charts.Chart) PlotOptionsSeries(com.vaadin.flow.component.charts.model.PlotOptionsSeries) YAxis(com.vaadin.flow.component.charts.model.YAxis)

Example 2 with Lang

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));
}
Also used : Path(java.nio.file.Path) Configuration(com.vaadin.flow.component.charts.model.Configuration) Lang(com.vaadin.flow.component.charts.model.Lang) Test(org.junit.Test)

Example 3 with Lang

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;
}
Also used : Lang(com.vaadin.flow.component.charts.model.Lang)

Example 4 with 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());
}
Also used : Lang(com.vaadin.flow.component.charts.model.Lang) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 5 with Lang

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());
}
Also used : Lang(com.vaadin.flow.component.charts.model.Lang) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

Lang (com.vaadin.flow.component.charts.model.Lang)6 Test (org.junit.Test)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Configuration (com.vaadin.flow.component.charts.model.Configuration)2 Chart (com.vaadin.flow.component.charts.Chart)1 ListSeries (com.vaadin.flow.component.charts.model.ListSeries)1 PlotOptionsSeries (com.vaadin.flow.component.charts.model.PlotOptionsSeries)1 Tooltip (com.vaadin.flow.component.charts.model.Tooltip)1 XAxis (com.vaadin.flow.component.charts.model.XAxis)1 YAxis (com.vaadin.flow.component.charts.model.YAxis)1 LumoDarkTheme (com.vaadin.flow.component.charts.themes.LumoDarkTheme)1 LumoLightTheme (com.vaadin.flow.component.charts.themes.LumoLightTheme)1 NativeButton (com.vaadin.flow.component.html.NativeButton)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1