]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Fix early exit from clearStacks (#12155) master
authormarkw65 <mark@replayroutes.com>
Wed, 27 May 2026 21:17:31 +0000 (14:17 -0700)
committerGitHub <noreply@github.com>
Wed, 27 May 2026 21:17:31 +0000 (17:17 -0400)
Fixes #12154

Co-authored-by: markw65 <mark_st@myosotissp.com>
src/core/core.datasetController.js
test/fixtures/controller.line/stacking/stack-cache.js [new file with mode: 0644]
test/fixtures/controller.line/stacking/stack-cache.png [new file with mode: 0644]

index 9b7126a93fd5facfbe79df129d64dd356690e2b1..145a2b6a11e4f3b526d7abdfe173b120eb8b6b10 100644 (file)
@@ -217,7 +217,7 @@ function clearStacks(meta, items) {
   for (const parsed of items) {
     const stacks = parsed._stacks;
     if (!stacks || stacks[axis] === undefined || stacks[axis][datasetIndex] === undefined) {
-      return;
+      continue;
     }
     delete stacks[axis][datasetIndex];
     if (stacks[axis]._visualValues !== undefined && stacks[axis]._visualValues[datasetIndex] !== undefined) {
diff --git a/test/fixtures/controller.line/stacking/stack-cache.js b/test/fixtures/controller.line/stacking/stack-cache.js
new file mode 100644 (file)
index 0000000..7bf42d3
--- /dev/null
@@ -0,0 +1,56 @@
+function makeDs(label, offset) {
+  return {
+    label,
+    data: [
+      [0, 12],
+      [1, 19],
+      [2, 3],
+      [2, 5],
+      [3, 2],
+      [4, 3],
+    ].map(([x, y]) => ({x, y: y === null ? null : y + offset})),
+    showLine: true,
+    spanGaps: false,
+    stack: `stack${label}`,
+    borderColor: label === 'A' ? '#c00' : '#00c'
+  };
+}
+
+const dsA = makeDs('A', 0);
+const dsB = makeDs('B', 1);
+
+module.exports = {
+  config: {
+    type: 'scatter',
+    data: {
+      datasets: [dsA, dsB],
+    },
+    options: {
+      scales: {
+        x: {display: false},
+        y: {display: false},
+      },
+      elements: {
+        point: {
+          backgroundColor: '#444',
+        },
+      },
+      layout: {
+        padding: {
+          left: 24,
+          right: 24,
+        },
+      },
+    },
+  },
+  options: {
+    canvas: {
+      height: 128,
+      width: 256,
+    },
+    async run(chart) {
+      chart.data = {datasets: [dsB, dsA]};
+      chart.update();
+    }
+  },
+};
diff --git a/test/fixtures/controller.line/stacking/stack-cache.png b/test/fixtures/controller.line/stacking/stack-cache.png
new file mode 100644 (file)
index 0000000..4ef82b1
Binary files /dev/null and b/test/fixtures/controller.line/stacking/stack-cache.png differ