]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Bar: ignore not-grouped bars from group bar count (#9291)
authorJukka Kurkela <jukka.kurkela@gmail.com>
Sat, 19 Jun 2021 22:28:05 +0000 (01:28 +0300)
committerGitHub <noreply@github.com>
Sat, 19 Jun 2021 22:28:05 +0000 (18:28 -0400)
src/controllers/controller.bar.js
test/fixtures/controller.bar/not-grouped/mixed.js [new file with mode: 0644]
test/fixtures/controller.bar/not-grouped/mixed.png [new file with mode: 0644]

index cf08851f361259c8cb8910e5f2fb41418a58cc3a..9a568cdeb9914337ee3d57d189f6d75f395141fb 100644 (file)
@@ -324,6 +324,10 @@ export default class BarController extends DatasetController {
     for (i = 0; i < ilen; ++i) {
       item = metasets[i];
 
+      if (!item.controller.options.grouped) {
+        continue;
+      }
+
       if (typeof dataIndex !== 'undefined') {
         const val = item.controller.getParsed(dataIndex)[
           item.controller._cachedMeta.vScale.axis
diff --git a/test/fixtures/controller.bar/not-grouped/mixed.js b/test/fixtures/controller.bar/not-grouped/mixed.js
new file mode 100644 (file)
index 0000000..7505953
--- /dev/null
@@ -0,0 +1,35 @@
+module.exports = {
+  description: 'https://github.com/chartjs/Chart.js/issues/9281',
+  config: {
+    type: 'bar',
+    data: {
+      labels: [0, 1, 2],
+      datasets: [
+        {
+          label: 'data 1',
+          data: [1, 2, 2],
+          backgroundColor: 'rgb(255,0,0,0.7)',
+          grouped: true
+        },
+        {
+          label: 'data 2',
+          data: [4, 4, 1],
+          backgroundColor: 'rgb(0,255,0,0.7)',
+          grouped: true
+        },
+        {
+          label: 'data 3',
+          data: [2, 1, 3],
+          backgroundColor: 'rgb(0,0,255,0.7)',
+          grouped: false
+        }
+      ]
+    },
+    options: {
+      scales: {
+        x: {display: false},
+        y: {display: false}
+      }
+    }
+  },
+};
diff --git a/test/fixtures/controller.bar/not-grouped/mixed.png b/test/fixtures/controller.bar/not-grouped/mixed.png
new file mode 100644 (file)
index 0000000..af2c9fd
Binary files /dev/null and b/test/fixtures/controller.bar/not-grouped/mixed.png differ