]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
check the data set type in DoughnutController (#10867)
authort-mangoe <m.takashi.xpair@gmail.com>
Sat, 12 Nov 2022 20:41:21 +0000 (05:41 +0900)
committerGitHub <noreply@github.com>
Sat, 12 Nov 2022 20:41:21 +0000 (15:41 -0500)
src/controllers/controller.doughnut.js
test/specs/mixed.tests.js

index 31efea7858709dd6b04895370fdf65f9141e4512..e270e4df98dd1cab525d702cc5d63fabaef03fda 100644 (file)
@@ -183,7 +183,7 @@ export default class DoughnutController extends DatasetController {
     let max = -TAU;
 
     for (let i = 0; i < this.chart.data.datasets.length; ++i) {
-      if (this.chart.isDatasetVisible(i)) {
+      if (this.chart.isDatasetVisible(i) && this.chart.getDatasetMeta(i).type === this._type) {
         const controller = this.chart.getDatasetMeta(i).controller;
         const rotation = controller._getRotation();
         const circumference = controller._getCircumference();
index 0d501e558288a248f26eeb36c1f41882c40e0faa..16d7d2f485cf59e54caa00fb1ff69e01412acb14 100644 (file)
@@ -1,3 +1,46 @@
 describe('Mixed charts', function() {
   describe('auto', jasmine.fixture.specs('mixed'));
+
+  it('shoud be constructed with doughnuts chart', function() {
+    const chart = window.acquireChart({
+      data: {
+        datasets: [{
+          type: 'line',
+          data: [10, 20, 30, 40],
+        }, {
+          type: 'doughnut',
+          data: [10, 20, 30, 50],
+        }
+        ],
+        labels: []
+      }
+    });
+
+    const meta0 = chart.getDatasetMeta(0);
+    expect(meta0.type).toEqual('line');
+    const meta1 = chart.getDatasetMeta(1);
+    expect(meta1.type).toEqual('doughnut');
+  });
+
+  it('shoud be constructed with pie chart', function() {
+    const chart = window.acquireChart({
+      data: {
+        datasets: [{
+          type: 'bar',
+          data: [10, 20, 30, 40],
+        }, {
+          type: 'pie',
+          data: [10, 20, 30, 50],
+        }
+        ],
+        labels: []
+      }
+    });
+
+    const meta0 = chart.getDatasetMeta(0);
+    expect(meta0.type).toEqual('bar');
+    const meta1 = chart.getDatasetMeta(1);
+    expect(meta1.type).toEqual('pie');
+  });
+
 });