vaadin / web-components

A set of high-quality standards based web components for enterprise web applications. Part of Vaadin 20+
https://vaadin.com/docs/latest/components
470 stars 83 forks source link

fix: save userOptions charts disconnect #8206

Open DiegoCardoso opened 22 hours ago

DiegoCardoso commented 22 hours ago

Description

Fix an issue where a chart defined using the updateConfiguration method loses its configuration after detaching and re-attaching. This fix stores the userOptions object when the component is disconnected to use it again when the component is connected back later.

The userOptions, according to the Highcharts documentation is:

The original options given to the constructor or a chart factory like Highcharts.chart and Highcharts.stockChart. The original options are shallow copied to avoid mutation. The copy, chart.userOptions, may later be mutated to reflect updated options throughout the lifetime of the chart.

While this is true in the latest version of the library, I could verify that adding and removing series dynamically through Chart#addSeries() and Series#remove() (these are methods in the HighCharts API) are not reflected on the userOptions object in the version we are current using. That might be problematic for cases where series are added through the Configuration#addSeries() API in the Flow component. I believe that this fix proposal will cover most of the cases, hence I am creating it for discussion.

Fixes https://github.com/vaadin/flow-components/issues/6802

Type of change

sonarcloud[bot] commented 22 hours ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

tomivirkki commented 5 hours ago

While this is true in the latest version of the library, I could verify that adding and removing series dynamically through Chart#addSeries() and Series#remove() (these are methods in the HighCharts API) are not reflected on the userOptions object in the version we are current using

I noticed that addSeries works as long as you also call drawChart:

chart.getConfiguration().addSeries(new ListSeries("Foobar", 107, 31, 635, 203, 2));
chart.drawChart();