Skip to content

Commit 342868b

Browse files
fix: save userOptions on charts disconnect (#8206) (#8263)
Co-authored-by: Diego Cardoso <diego@vaadin.com>
1 parent aebdc75 commit 342868b

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

packages/charts/src/vaadin-chart.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,6 +1078,10 @@ class Chart extends ResizeMixin(ElementMixin(ThemableMixin(PolymerElement))) {
10781078
disconnectedCallback() {
10791079
super.disconnectedCallback();
10801080

1081+
if (this.configuration) {
1082+
this._jsonConfigurationBuffer = this.configuration.userOptions;
1083+
}
1084+
10811085
queueMicrotask(() => {
10821086
if (this.isConnected) {
10831087
return;

packages/charts/test/reattach.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,20 @@ describe('reattach', () => {
186186
expect(chart.configuration.options.plotOptions.series.stacking).to.be.equal('percent');
187187
});
188188

189+
it('should restore configuration done through `updateConfigaration` after reattach', async () => {
190+
const wrapper = fixtureSync(`<div><vaadin-chart></vaadin-chart></div>`);
191+
const chart = wrapper.firstElementChild;
192+
chart.updateConfiguration({ title: { text: 'New title' }, series: [{ name: 'series', data: [1, 2, 3] }] });
193+
await nextFrame();
194+
wrapper.removeChild(chart);
195+
await nextFrame();
196+
wrapper.appendChild(chart);
197+
await nextFrame();
198+
expect(chart.configuration.options.title.text).to.be.equal('New title');
199+
expect(chart.configuration.options.series.length).to.be.equal(1);
200+
expect(chart.configuration.options.series[0].name).to.be.equal('series');
201+
});
202+
189203
it('should apply categories updated while detached after reattach', async () => {
190204
chart.categories = ['Jan', 'Feb', 'Mar'];
191205
await oneEvent(chart, 'chart-load');

0 commit comments

Comments
 (0)