]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Skip delete undefined stack (#8291)
authorLeeLenaleee <39033624+LeeLenaleee@users.noreply.github.com>
Sat, 9 Jan 2021 15:27:18 +0000 (16:27 +0100)
committerGitHub <noreply@github.com>
Sat, 9 Jan 2021 15:27:18 +0000 (10:27 -0500)
* fixes error on undefined stacks
* added test for functionality

src/core/core.datasetController.js
test/specs/core.datasetController.tests.js

index beb973a74dd55713ce43b94a29bcd85871b74f6e..9aec58bbb4646ccf6f160ff4056569b3532ee254 100644 (file)
@@ -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];
        });
 }
index 533dee62def7b6998d537ad96d8288447c8fb94e..473611e1a90157509fa83f33d3b3c5ed5cabf169 100644 (file)
@@ -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() {