Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reset charts series objects when chart is detached (#8115) (CP: 24.4) #8124

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions packages/charts/src/vaadin-chart-series.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ class ChartSeries extends PolymerElement {

/** @private */
__valueMinObserver(valueMin, series) {
if (valueMin === undefined || series === undefined) {
if (valueMin === undefined || series == null) {
return;
}

Expand All @@ -340,7 +340,7 @@ class ChartSeries extends PolymerElement {

/** @private */
__valueMaxObserver(valueMax, series) {
if (valueMax === undefined || series === undefined) {
if (valueMax === undefined || series == null) {
return;
}

Expand All @@ -356,23 +356,23 @@ class ChartSeries extends PolymerElement {

/** @private */
__titleObserver(title, series) {
if (title === undefined || series === undefined) {
if (title === undefined || series == null) {
return;
}
series.update({ name: title });
}

/** @private */
__stackObserver(stack, series) {
if (stack === undefined || series === undefined) {
if (stack === undefined || series == null) {
return;
}
series.update({ stack });
}

/** @private */
__neckPositionObserver(neckPosition, series) {
if (neckPosition === undefined || series === undefined) {
if (neckPosition === undefined || series == null) {
return;
}

Expand All @@ -381,7 +381,7 @@ class ChartSeries extends PolymerElement {

/** @private */
__neckWidthObserver(neckWidth, series) {
if (neckWidth === undefined || series === undefined) {
if (neckWidth === undefined || series == null) {
return;
}

Expand Down Expand Up @@ -425,7 +425,7 @@ class ChartSeries extends PolymerElement {

/** @private */
__markersObserver(markers, series) {
if (markers === undefined || series === undefined) {
if (markers === undefined || series == null) {
return;
}

Expand Down
6 changes: 6 additions & 0 deletions packages/charts/src/vaadin-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,12 @@ class Chart extends ResizeMixin(ElementMixin(ThemableMixin(PolymerElement))) {
if (this.configuration) {
this.configuration.destroy();
this.configuration = undefined;

// Reset series objects to avoid errors while detached
const seriesNodes = Array.from(this.childNodes).filter(this.__filterSeriesNodes);
seriesNodes.forEach((series) => {
series.setSeries(null);
});
}

if (this._childObserver) {
Expand Down
115 changes: 115 additions & 0 deletions packages/charts/test/reattach.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,119 @@ describe('reattach', () => {
await oneEvent(chart, 'chart-load');
expect(chart.configuration.inverted).to.be.undefined;
});

describe('series', () => {
let series;

beforeEach(async () => {
await oneEvent(chart, 'chart-load');
series = chart.querySelector('vaadin-chart-series');
});

it('should apply the series title updated while detached after reattach', async () => {
wrapper.removeChild(chart);
await nextFrame();

series.title = 'Title';

wrapper.appendChild(chart);
await oneEvent(chart, 'chart-load');

expect(chart.configuration.series[0].name).to.be.equal('Title');
});

it('should apply the series type updated while detached after reattach', async () => {
wrapper.removeChild(chart);
await nextFrame();

series.type = 'area';

wrapper.appendChild(chart);
await oneEvent(chart, 'chart-load');

expect(chart.configuration.series[0].type).to.be.equal('area');
});

it('should apply the series unit updated while detached after reattach', async () => {
wrapper.removeChild(chart);
await nextFrame();

series.unit = 'unit';

wrapper.appendChild(chart);
await oneEvent(chart, 'chart-load');

expect(chart.configuration.yAxis[0].options.id).to.be.equal('unit');
});

it('should apply the series neck-width updated while detached after reattach', async () => {
wrapper.removeChild(chart);
await nextFrame();

series.neckWidth = 20;

wrapper.appendChild(chart);
await oneEvent(chart, 'chart-load');
expect(chart.configuration.series[0].options.neckWidth).to.be.equal(20);
});

it('should apply the series neck-position updated while detached after reattach', async () => {
wrapper.removeChild(chart);
await nextFrame();

series.neckPosition = 50;

wrapper.appendChild(chart);
await oneEvent(chart, 'chart-load');
expect(chart.configuration.series[0].options.neckHeight).to.be.equal(50);
});

it('should apply the series valueMin updated while detached after reattach', async () => {
wrapper.removeChild(chart);
await nextFrame();

series.valueMin = 5;

wrapper.appendChild(chart);
await oneEvent(chart, 'chart-load');

expect(chart.configuration.yAxis[0].options.min).to.be.equal(5);
});

it('should apply the series valueMax updated while detached after reattach', async () => {
wrapper.removeChild(chart);
await nextFrame();

series.valueMax = 10;

wrapper.appendChild(chart);
await oneEvent(chart, 'chart-load');

expect(chart.configuration.yAxis[0].options.max).to.be.equal(10);
});

it('should apply the series markers updated while detached after reattach', async () => {
wrapper.removeChild(chart);
await nextFrame();

series.markers = 'auto';

wrapper.appendChild(chart);
await oneEvent(chart, 'chart-load');

expect(chart.configuration.series[0].options.marker.enabled).to.be.equal(null);
});

it('should apply the series stack updated while detached after reattach', async () => {
wrapper.removeChild(chart);
await nextFrame();

series.stack = '1';

wrapper.appendChild(chart);
await oneEvent(chart, 'chart-load');

expect(chart.configuration.series[0].options.stack).to.be.equal('1');
});
});
});