]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Fix clearStacks with custom scaleId (#9170)
authorJukka Kurkela <jukka.kurkela@gmail.com>
Fri, 28 May 2021 04:36:59 +0000 (07:36 +0300)
committerGitHub <noreply@github.com>
Fri, 28 May 2021 04:36:59 +0000 (07:36 +0300)
src/core/core.datasetController.js
test/fixtures/controller.bar/stacking/issue-9105.js [new file with mode: 0644]
test/fixtures/controller.bar/stacking/issue-9105.png [new file with mode: 0644]

index dbf08e77f2bb2ed90139016da7ff19a175420651..81d865810e45300446a2d827cff055b923312062 100644 (file)
@@ -192,13 +192,18 @@ function createDataContext(parent, index, element) {
 }
 
 function clearStacks(meta, items) {
+  const axis = meta.vScale && meta.vScale.axis;
+  if (!axis) {
+    return;
+  }
+
   items = items || meta._parsed;
   for (const parsed of items) {
     const stacks = parsed._stacks;
-    if (!stacks || stacks[meta.vScale.id] === undefined || stacks[meta.vScale.id][meta.index] === undefined) {
+    if (!stacks || stacks[axis] === undefined || stacks[axis][meta.index] === undefined) {
       return;
     }
-    delete stacks[meta.vScale.id][meta.index];
+    delete stacks[axis][meta.index];
   }
 }
 
diff --git a/test/fixtures/controller.bar/stacking/issue-9105.js b/test/fixtures/controller.bar/stacking/issue-9105.js
new file mode 100644 (file)
index 0000000..200ce4d
--- /dev/null
@@ -0,0 +1,49 @@
+module.exports = {
+  description: 'https://github.com/chartjs/Chart.js/issues/9105',
+  config: {
+    type: 'bar',
+    data: {
+      labels: ['January', 'February', 'March', 'April', 'May', 'June'],
+      datasets: [
+        {
+          backgroundColor: 'rgba(255,99,132,0.8)',
+          label: 'Dataset 1',
+          data: [12, 19, 3, 5, 2, 3],
+          stack: '0',
+          yAxisID: 'y-axis-1'
+        },
+        {
+          backgroundColor: 'rgba(54,162,235,0.8)',
+          label: 'Dataset 2',
+          data: [13, 19, 3, 5, 8, 3],
+          stack: '0',
+          yAxisID: 'y-axis-1'
+        },
+        {
+          backgroundColor: 'rgba(75,192,192,0.8)',
+          label: 'Dataset 3',
+          data: [13, 19, 3, 5, 8, 3],
+          stack: '0',
+          yAxisID: 'y-axis-1'
+        }
+      ]
+    },
+    options: {
+      plugins: false,
+      scales: {
+        xaxis: {
+          display: false,
+        },
+        'y-axis-1': {
+          display: false
+        }
+      }
+    }
+  },
+  options: {
+    run(chart) {
+      chart.data.datasets[1].stack = '1';
+      chart.update();
+    }
+  }
+};
diff --git a/test/fixtures/controller.bar/stacking/issue-9105.png b/test/fixtures/controller.bar/stacking/issue-9105.png
new file mode 100644 (file)
index 0000000..14a2168
Binary files /dev/null and b/test/fixtures/controller.bar/stacking/issue-9105.png differ