Search in sources :

Example 1 with LumoDarkTheme

use of com.vaadin.flow.component.charts.themes.LumoDarkTheme 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 LumoDarkTheme

use of com.vaadin.flow.component.charts.themes.LumoDarkTheme in project flow-components by vaadin.

the class SVGGeneratorTest method exportWithCustomTheme.

@Test
public void exportWithCustomTheme() throws IOException, InterruptedException {
    Configuration conf = createPieChartConfiguration();
    ExportOptions options = new ExportOptions();
    options.setTheme(new LumoDarkTheme());
    String svg = svgGenerator.generate(conf, options);
    Path pieChartPath = Paths.get("src", "test", "resources", "lumo-dark.svg");
    String expectedSVG = readUtf8File(pieChartPath);
    assertEquals(replaceIds(expectedSVG), replaceIds(svg));
}
Also used : Path(java.nio.file.Path) LumoDarkTheme(com.vaadin.flow.component.charts.themes.LumoDarkTheme) Configuration(com.vaadin.flow.component.charts.model.Configuration) Test(org.junit.Test)

Aggregations

Configuration (com.vaadin.flow.component.charts.model.Configuration)2 LumoDarkTheme (com.vaadin.flow.component.charts.themes.LumoDarkTheme)2 Chart (com.vaadin.flow.component.charts.Chart)1 Lang (com.vaadin.flow.component.charts.model.Lang)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 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 Test (org.junit.Test)1