From: LeeLenaleee <39033624+LeeLenaleee@users.noreply.github.com> Date: Sat, 9 Jan 2021 15:27:18 +0000 (+0100) Subject: Skip delete undefined stack (#8291) X-Git-Tag: v3.0.0-beta.8~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aa9a04a0144e58c50a92d5ac34455dc9f5108e97;p=thirdparty%2FChart.js.git Skip delete undefined stack (#8291) * fixes error on undefined stacks * added test for functionality --- diff --git a/src/core/core.datasetController.js b/src/core/core.datasetController.js index beb973a74..9aec58bbb 100644 --- a/src/core/core.datasetController.js +++ b/src/core/core.datasetController.js @@ -200,6 +200,9 @@ function createDataContext(parent, index, point, element) { function clearStacks(meta, items) { items = items || meta._parsed; items.forEach((parsed) => { + if (parsed._stacks[meta.vScale.id] === undefined || parsed._stacks[meta.vScale.id][meta.index] === undefined) { + return; + } delete parsed._stacks[meta.vScale.id][meta.index]; }); } diff --git a/test/specs/core.datasetController.tests.js b/test/specs/core.datasetController.tests.js index 533dee62d..473611e1a 100644 --- a/test/specs/core.datasetController.tests.js +++ b/test/specs/core.datasetController.tests.js @@ -38,6 +38,51 @@ describe('Chart.DatasetController', function() { }); }); + it('should not try to delete non existent stacks', function() { + function createAndUpdateChart() { + var chart = acquireChart({ + data: { + labels: ['q'], + datasets: [ + { + id: 'dismissed', + label: 'Test before', + yAxisID: 'count', + data: [816], + type: 'bar', + stack: 'stack' + } + ] + }, + options: { + scales: { + count: { + axis: 'y', + type: 'linear' + } + } + } + }); + + chart.data = { + datasets: [ + { + id: 'tests', + yAxisID: 'count', + label: 'Test after', + data: [38300], + type: 'bar' + } + ], + labels: ['q'] + }; + + chart.update(); + } + + expect(createAndUpdateChart).not.toThrow(); + }); + describe('inextensible data', function() { it('should handle a frozen data object', function() { function createChart() {