From: Jukka Kurkela Date: Wed, 17 Nov 2021 22:09:25 +0000 (+0200) Subject: Configure all datasets before updating any (#9872) X-Git-Tag: v3.6.1~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0dc733a96ce758f22e61d22222264d2593474a78;p=thirdparty%2FChart.js.git Configure all datasets before updating any (#9872) * Update misleading sample comment * Configure all datasets before updating any --- diff --git a/src/controllers/controller.doughnut.js b/src/controllers/controller.doughnut.js index 3e0da3335..2be27615b 100644 --- a/src/controllers/controller.doughnut.js +++ b/src/controllers/controller.doughnut.js @@ -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; } } diff --git a/src/core/core.controller.js b/src/core/core.controller.js index ce6fbc7a8..cfa3ad937 100644 --- a/src/core/core.controller.js +++ b/src/core/core.controller.js @@ -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); } diff --git a/src/core/core.datasetController.js b/src/core/core.datasetController.js index 1794c7031..ccbba2320 100644 --- a/src/core/core.datasetController.js +++ b/src/core/core.datasetController.js @@ -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 index 000000000..3e7058a8c --- /dev/null +++ b/test/fixtures/controller.doughnut/doughnut-full-to-semi.js @@ -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 index 000000000..0585b4922 Binary files /dev/null and b/test/fixtures/controller.doughnut/doughnut-full-to-semi.png differ diff --git a/test/specs/controller.radar.tests.js b/test/specs/controller.radar.tests.js index b87031585..5a6fecb54 100644 --- a/test/specs/controller.radar.tests.js +++ b/test/specs/controller.radar.tests.js @@ -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)',