Skip to content

Commit 1498547

Browse files
authored
Merge pull request #12 from xdev-software/develop
Release
2 parents 7bd0d22 + 84630ea commit 1498547

11 files changed

Lines changed: 234 additions & 119 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# 0.x
2-
_Initial release_
1+
# 1.0.0
2+
_Initial stable release_
33

4-
_Test releases for evaluation_
4+
# 0.x
5+
_Initial preview release for evaluation_

README.md

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,48 @@
1-
[![Published on Vaadin Directory](https://img.shields.io/badge/Vaadin%20Directory-published-00b4f0?logo=vaadin)](https://vaadin.com/directory/component/vaadin-chartjs-wrapper)
1+
[![Published on Vaadin Directory](https://img.shields.io/badge/Vaadin%20Directory-published-00b4f0?logo=vaadin)](https://vaadin.com/directory/component/chartjs-wrapper-for-vaadin)
22
[![Latest version](https://img.shields.io/maven-central/v/software.xdev/vaadin-chartjs-wrapper?logo=apache%20maven)](https://mvnrepository.com/artifact/software.xdev/vaadin-chartjs-wrapper)
33
[![Build](https://img.shields.io/github/actions/workflow/status/xdev-software/vaadin-chartjs-wrapper/check-build.yml?branch=develop)](https://github.com/xdev-software/vaadin-chartjs-wrapper/actions/workflows/check-build.yml?query=branch%3Adevelop)
44
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=xdev-software_vaadin-chartjs-wrapper&metric=alert_status)](https://sonarcloud.io/dashboard?id=xdev-software_vaadin-chartjs-wrapper)
55
![Vaadin 24+](https://img.shields.io/badge/Vaadin%20Platform/Flow-24+-00b4f0)
66

77
# <img src="https://www.chartjs.org/media/logo.svg" height="38" /> Chart.js Wrapper for Vaadin
88

9-
A Chart.js 4+ Wrapper for Vaadin
9+
A [Chart.js](https://www.chartjs.org/) 4+ Wrapper for Vaadin
1010

1111
![demo](assets/demo.png)
1212

1313
## Usage
1414

15-
0. You may want to use a Java model of Chart.js's configuration, like [XDEV's chartjs-java-model](https://github.com/xdev-software/chartjs-java-model).<br/>Otherwise you have to write the JSON yourself.
15+
For more and detailed usage examples please have a look at [the demo](./vaadin-chartjs-wrapper-demo/src/main/java/software/xdev/vaadin/chartjs/demo/).
16+
17+
### Minimal
18+
19+
```java
20+
// Assumes that this code is in some kind of Vaadin component or view
21+
ChartContainer chart = new ChartContainer();
22+
this.add(chart);
23+
24+
chart.showChart(
25+
"{\"data\":{\"labels\":[\"A\",\"B\"],\"datasets\":[{\"data\":[1,2],\"label\":\"X\"}]},\"type\":\"bar\"}");
26+
27+
// Or utilizing chartjs-java-model
28+
chart.showChart(new BarChart(new BarData()
29+
.addLabels("A", "B")
30+
.addDataset(new BarDataset()
31+
.setLabel("X")
32+
.addData(1)
33+
.addData(2)))
34+
.toJson());
35+
```
36+
37+
### Recommended
38+
39+
1. Use a Java model of Java model of Chart.js's configuration, like [XDEV's chartjs-java-model](https://github.com/xdev-software/chartjs-java-model).<br/>
40+
Otherwise you have to write the JSON yourself.
41+
2. Optionally derive classes for your charts (from e.g. ``ChartContainer``) that also handle the data-to-JSON conversion logic.<br/>
42+
Therefore you can encapsulate the components properly, for example like this: ``FetchFromBackendService.class → Model for chart → ChartContainer.class → Build JSON and show chart``
43+
44+
<details><summary>Here is a example how the code could look (click to expand)</summary>
45+
1646
1. Define a custom chart or use the ``showChart``-method directly.<br/>Example:
1747
```java
1848
public class ExampleChartContainer extends ChartContainer
@@ -63,7 +93,7 @@ A Chart.js 4+ Wrapper for Vaadin
6393
}
6494
```
6595

66-
For more usage examples please have a look at [the demo](./vaadin-chartjs-wrapper-demo/src/main/java/software/xdev/vaadin/chartjs/demo/).
96+
</details>
6797

6898
## Installation
6999
[Installation guide for the latest release](https://github.com/xdev-software/vaadin-chartjs-wrapper/releases/latest#Installation)
@@ -90,3 +120,5 @@ See the [contributing guide](./CONTRIBUTING.md) for detailed instructions on how
90120
91121
## Dependencies and Licenses
92122
View the [license of the current project](LICENSE) or the [summary including all dependencies](https://xdev-software.github.io/vaadin-chartjs-wrapper/dependencies)
123+
124+
<sub>Disclaimer: This is not an official Chart.js product and not associated</sub>

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>software.xdev</groupId>
88
<artifactId>vaadin-chartjs-wrapper-root</artifactId>
9-
<version>0.0.4-SNAPSHOT</version>
9+
<version>1.0.0-SNAPSHOT</version>
1010
<packaging>pom</packaging>
1111

1212
<organization>
@@ -45,7 +45,7 @@
4545
<dependency>
4646
<groupId>com.puppycrawl.tools</groupId>
4747
<artifactId>checkstyle</artifactId>
48-
<version>10.25.1</version>
48+
<version>10.26.0</version>
4949
</dependency>
5050
</dependencies>
5151
<configuration>
@@ -70,7 +70,7 @@
7070
<plugin>
7171
<groupId>org.apache.maven.plugins</groupId>
7272
<artifactId>maven-pmd-plugin</artifactId>
73-
<version>3.26.0</version>
73+
<version>3.27.0</version>
7474
<configuration>
7575
<includeTests>true</includeTests>
7676
<printFailingErrors>true</printFailingErrors>

vaadin-chartjs-wrapper-demo/pom.xml

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
<parent>
88
<groupId>software.xdev</groupId>
99
<artifactId>vaadin-chartjs-wrapper-root</artifactId>
10-
<version>0.0.4-SNAPSHOT</version>
10+
<version>1.0.0-SNAPSHOT</version>
1111
</parent>
1212

1313
<artifactId>vaadin-chartjs-wrapper-demo</artifactId>
14-
<version>0.0.4-SNAPSHOT</version>
14+
<version>1.0.0-SNAPSHOT</version>
1515
<packaging>jar</packaging>
1616

1717
<organization>
@@ -29,7 +29,7 @@
2929
<mainClass>software.xdev.vaadin.Application</mainClass>
3030

3131
<!-- Dependency-Versions -->
32-
<vaadin.version>24.7.6</vaadin.version>
32+
<vaadin.version>24.8.0</vaadin.version>
3333

3434
<org.springframework.boot.version>3.5.3</org.springframework.boot.version>
3535
</properties>
@@ -62,10 +62,35 @@
6262
<groupId>com.vaadin</groupId>
6363
<artifactId>vaadin-core</artifactId>
6464
<exclusions>
65+
<!-- No Hilla is used -->
6566
<exclusion>
6667
<groupId>com.vaadin</groupId>
6768
<artifactId>hilla-dev</artifactId>
6869
</exclusion>
70+
<exclusion>
71+
<groupId>com.vaadin</groupId>
72+
<artifactId>copilot</artifactId>
73+
</exclusion>
74+
<!-- Lumo is used instead -->
75+
<exclusion>
76+
<groupId>com.vaadin</groupId>
77+
<artifactId>vaadin-material-theme</artifactId>
78+
</exclusion>
79+
<!-- React is not enabled and thus not required -->
80+
<exclusion>
81+
<groupId>com.vaadin</groupId>
82+
<artifactId>flow-react</artifactId>
83+
</exclusion>
84+
<!-- There is like 10 people on the planet that need this by default -->
85+
<exclusion>
86+
<groupId>com.vaadin</groupId>
87+
<artifactId>collaboration-engine</artifactId>
88+
</exclusion>
89+
<!-- No Wildfly used here -->
90+
<exclusion>
91+
<groupId>com.vaadin.servletdetector</groupId>
92+
<artifactId>throw-if-servlet3</artifactId>
93+
</exclusion>
6994
</exclusions>
7095
</dependency>
7196
<dependency>
@@ -85,6 +110,7 @@
85110
<groupId>com.vaadin</groupId>
86111
<artifactId>vaadin-spring-boot-starter</artifactId>
87112
<exclusions>
113+
<!-- No Hilla is used -->
88114
<exclusion>
89115
<groupId>com.vaadin</groupId>
90116
<artifactId>hilla</artifactId>
@@ -128,6 +154,30 @@
128154
</goals>
129155
</execution>
130156
</executions>
157+
<configuration>
158+
<!-- Can only be true if hilla is used -->
159+
<!-- Takes a few seconds to scan everything for hilla -->
160+
<frontendHotdeploy>false</frontendHotdeploy>
161+
<!-- Prevent scanning for react (not used) -->
162+
<reactEnable>false</reactEnable>
163+
<!-- Only scan required -->
164+
<frontendScanner>
165+
<includes>
166+
<include>
167+
<groupId>software.xdev</groupId>
168+
<artifactId>*vaadin*</artifactId>
169+
</include>
170+
<include>
171+
<groupId>com.vaadin</groupId>
172+
</include>
173+
</includes>
174+
<excludes>
175+
<exclude>
176+
<groupId>com.vaadin.external*</groupId>
177+
</exclude>
178+
</excludes>
179+
</frontendScanner>
180+
</configuration>
131181
</plugin>
132182
<plugin>
133183
<groupId>org.apache.maven.plugins</groupId>

vaadin-chartjs-wrapper-demo/src/main/java/software/xdev/vaadin/chartjs/DemoView.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.vaadin.flow.router.Route;
1515

1616
import software.xdev.vaadin.chartjs.demo.ClientToServerUpdateableDemo;
17+
import software.xdev.vaadin.chartjs.demo.FunctionalityShowcaseDemo;
1718
import software.xdev.vaadin.chartjs.demo.MinimalisticDemo;
1819

1920

@@ -53,7 +54,13 @@ protected void onAttach(final AttachEvent attachEvent)
5354
new Example(
5455
MinimalisticDemo.NAV,
5556
"Minimalistic",
56-
"Showcasing the simplest form of using ChartJS"
57+
"Showcasing the simplest form of using Chart.js"
58+
),
59+
new Example(
60+
FunctionalityShowcaseDemo.NAV,
61+
"Functionality showcase",
62+
"Showcases most functionality, including lazy-loaded data, displaying errors & problems "
63+
+ "and the dark mode 🌙"
5764
),
5865
new Example(
5966
ClientToServerUpdateableDemo.NAV,

vaadin-chartjs-wrapper-demo/src/main/java/software/xdev/vaadin/chartjs/demo/ClientToServerUpdateableDemo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static String buildChartPayload(final int value, final int max)
8686
.toJson();
8787
}
8888

89-
@SuppressWarnings("java:S110") // Not caused by us!
89+
@SuppressWarnings("java:S110")
9090
static class BrokenChartContainer extends ChartContainer
9191
{
9292
public BrokenChartContainer(final int value, final int max)
@@ -96,7 +96,7 @@ public BrokenChartContainer(final int value, final int max)
9696
}
9797

9898

99-
@SuppressWarnings("java:S110") // Not caused by us!
99+
@SuppressWarnings("java:S110")
100100
static class WorkingChartContainer extends ClientToServerUpdateableChartContainer
101101
{
102102
private final String payload;
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
package software.xdev.vaadin.chartjs.demo;
2+
3+
import java.util.concurrent.CompletableFuture;
4+
5+
import com.vaadin.flow.component.AttachEvent;
6+
import com.vaadin.flow.component.UI;
7+
import com.vaadin.flow.component.button.Button;
8+
import com.vaadin.flow.component.checkbox.Checkbox;
9+
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
10+
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
11+
import com.vaadin.flow.router.Route;
12+
import com.vaadin.flow.theme.lumo.Lumo;
13+
14+
import software.xdev.chartjs.model.charts.BarChart;
15+
import software.xdev.chartjs.model.data.BarData;
16+
import software.xdev.chartjs.model.dataset.BarDataset;
17+
import software.xdev.chartjs.model.options.BarOptions;
18+
import software.xdev.chartjs.model.options.Plugins;
19+
import software.xdev.chartjs.model.options.Title;
20+
import software.xdev.vaadin.chartjs.ChartContainer;
21+
import software.xdev.vaadin.chartjs.resources.js.src.ChartThemeManager;
22+
23+
24+
@Route(FunctionalityShowcaseDemo.NAV)
25+
public class FunctionalityShowcaseDemo extends VerticalLayout
26+
{
27+
public static final String NAV = "/functionality";
28+
29+
private final DummyChartContainer chart = new DummyChartContainer();
30+
31+
public FunctionalityShowcaseDemo()
32+
{
33+
this.setSizeFull();
34+
this.chart.setHeight("50%");
35+
36+
this.add(
37+
this.chart,
38+
new Button("Run dummy load", ev -> this.runDummyLoad()),
39+
new HorizontalLayout(
40+
new Button("Load", ev -> this.chart.showLoading()),
41+
new Button("Show data", ev -> this.chart.show()),
42+
new Button(
43+
"Show data with problem indicator", ev -> {
44+
this.chart.show();
45+
this.chart.showProblemsIndicator("Failed to load some data because ...");
46+
}),
47+
new Button("Error", ev -> this.chart.showFailed("Something went wrong"))
48+
),
49+
new Checkbox(
50+
"DarkMode (requires chart rebuild)", ev -> {
51+
this.getElement().executeJs(
52+
"document.documentElement.setAttribute('theme', $0)",
53+
Boolean.TRUE.equals(ev.getValue()) ? Lumo.DARK : Lumo.LIGHT);
54+
this.getElement().executeJs(ChartThemeManager.TRY_UPDATE_CHART_JS_THEMING.formatted(true));
55+
}));
56+
}
57+
58+
private void runDummyLoad()
59+
{
60+
this.chart.showLoading();
61+
62+
final UI ui = UI.getCurrent();
63+
CompletableFuture.runAsync(() -> {
64+
try
65+
{
66+
Thread.sleep(1000);
67+
}
68+
catch(final InterruptedException iex)
69+
{
70+
Thread.currentThread().interrupt();
71+
}
72+
ui.access(this.chart::show);
73+
});
74+
}
75+
76+
@Override
77+
protected void onAttach(final AttachEvent attachEvent)
78+
{
79+
this.runDummyLoad();
80+
}
81+
82+
@SuppressWarnings("java:S110")
83+
public static class DummyChartContainer extends ChartContainer
84+
{
85+
public void show()
86+
{
87+
this.showChart(new BarChart(new BarData()
88+
.addLabels("2020", "2021", "2022", "2023")
89+
.addDataset(new BarDataset()
90+
.setBackgroundColor("#c02222")
91+
.setLabel("Hans")
92+
.addData(1)
93+
.addData(2)
94+
.addData(3)
95+
.addData(4))
96+
.addDataset(new BarDataset()
97+
.setBackgroundColor("orange")
98+
.setLabel("Franz")
99+
.addData(2)
100+
.addData(3)
101+
.addData(4)
102+
.addData(5)))
103+
.setOptions(new BarOptions()
104+
.setResponsive(true)
105+
.setMaintainAspectRatio(false)
106+
.setPlugins(new Plugins()
107+
.setTitle(new Title()
108+
.setText("Age")
109+
.setDisplay(true))))
110+
.toJson());
111+
}
112+
}
113+
}

0 commit comments

Comments
 (0)