]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Configure all datasets before updating any (#9872)
authorJukka Kurkela <jukka.kurkela@gmail.com>
Wed, 17 Nov 2021 22:09:25 +0000 (00:09 +0200)
committerGitHub <noreply@github.com>
Wed, 17 Nov 2021 22:09:25 +0000 (00:09 +0200)
* Update misleading sample comment

* Configure all datasets before updating any

src/controllers/controller.doughnut.js
src/core/core.controller.js
src/core/core.datasetController.js
test/fixtures/controller.doughnut/doughnut-full-to-semi.js [new file with mode: 0644]
test/fixtures/controller.doughnut/doughnut-full-to-semi.png [new file with mode: 0644]
test/specs/controller.radar.tests.js

index 3e0da3335982456ae5f9a6ddbcf67c1fea4afe8d..2be27615bcdd0602454af7f10bf7819fe124b523 100644 (file)
@@ -250,9 +250,6 @@ export default class DoughnutController extends DatasetController {
           meta = chart.getDatasetMeta(i);
           arcs = meta.data;
           controller = meta.controller;
-          if (controller !== this) {
-            controller.configure();
-          }
           break;
         }
       }
index ce6fbc7a87650babf27199d581f84714ce5c7c2c..cfa3ad937f8c3be33784020c1751d83680b6715a 100644 (file)
@@ -540,6 +540,10 @@ class Chart {
       return;
     }
 
+    for (let i = 0, ilen = this.data.datasets.length; i < ilen; ++i) {
+      this.getDatasetMeta(i).controller.configure();
+    }
+
     for (let i = 0, ilen = this.data.datasets.length; i < ilen; ++i) {
       this._updateDataset(i, isFunction(mode) ? mode({datasetIndex: i}) : mode);
     }
index 1794c7031b97af0682da58d2f6735db85f28c373..ccbba232051950cc1e7daebbb1f7c01aaf5484bf 100644 (file)
@@ -401,6 +401,7 @@ export default class DatasetController {
     const scopes = config.getOptionScopes(this.getDataset(), scopeKeys, true);
     this.options = config.createResolver(scopes, this.getContext());
     this._parsing = this.options.parsing;
+    this._cachedDataOpts = {};
   }
 
   /**
@@ -659,8 +660,6 @@ export default class DatasetController {
         */
   _update(mode) {
     const meta = this._cachedMeta;
-    this.configure();
-    this._cachedDataOpts = {};
     this.update(mode || 'default');
     meta._clip = toClip(valueOrDefault(this.options.clip, defaultClip(meta.xScale, meta.yScale, this.getMaxOverflow())));
   }
diff --git a/test/fixtures/controller.doughnut/doughnut-full-to-semi.js b/test/fixtures/controller.doughnut/doughnut-full-to-semi.js
new file mode 100644 (file)
index 0000000..3e7058a
--- /dev/null
@@ -0,0 +1,33 @@
+module.exports = {
+  description: 'https://github.com/chartjs/Chart.js/issues/9832',
+  config: {
+    type: 'doughnut',
+    data: {
+      datasets: [{
+        label: 'Set 1',
+        data: [50, 50, 25],
+        backgroundColor: ['#BF616A', '#D08770', '#EBCB8B'],
+        borderWidth: 0
+      },
+      {
+        label: 'Se1 2',
+        data: [50, 50, 25],
+        backgroundColor: ['#BF616A', '#D08770', '#EBCB8B'],
+        borderWidth: 0
+      }]
+    },
+    options: {
+      rotation: -90
+    }
+  },
+  options: {
+    canvas: {
+      width: 512,
+      height: 512
+    },
+    run(chart) {
+      chart.options.circumference = 180;
+      chart.update();
+    }
+  }
+};
diff --git a/test/fixtures/controller.doughnut/doughnut-full-to-semi.png b/test/fixtures/controller.doughnut/doughnut-full-to-semi.png
new file mode 100644 (file)
index 0000000..0585b49
Binary files /dev/null and b/test/fixtures/controller.doughnut/doughnut-full-to-semi.png differ
index b870315854f7f14fd30ee2e69f28c6e852463b4f..5a6fecb54098ece87e389fae0d0ceb072e08d080 100644 (file)
@@ -117,7 +117,7 @@ describe('Chart.controllers.radar', function() {
 
     var meta = chart.getDatasetMeta(0);
 
-    meta.controller.reset(); // reset first
+    chart.reset(); // reset first
 
     // Line element
     expect(meta.dataset.options).toEqual(jasmine.objectContaining({
@@ -150,8 +150,7 @@ describe('Chart.controllers.radar', function() {
       }));
     });
 
-    // Now update controller and ensure proper updates
-    meta.controller._update();
+    chart.update();
 
     [
       {x: 256, y: 120, cppx: 246, cppy: 120, cpnx: 272, cpny: 120},
@@ -193,7 +192,7 @@ describe('Chart.controllers.radar', function() {
     chart.data.datasets[0].pointBorderColor = 'rgb(56, 57, 58)';
     chart.data.datasets[0].pointBorderWidth = 1.123;
 
-    meta.controller._update();
+    chart.update();
 
     expect(meta.dataset.options).toEqual(jasmine.objectContaining({
       backgroundColor: 'rgb(98, 98, 98)',