Skip to content

Commit

Permalink
Configure all datasets before updating any (#9872)
Browse files Browse the repository at this point in the history
* Update misleading sample comment

* Configure all datasets before updating any
  • Loading branch information
kurkle committed Nov 17, 2021
1 parent 6bc47d3 commit 0dc733a
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 9 deletions.
3 changes: 0 additions & 3 deletions src/controllers/controller.doughnut.js
Expand Up @@ -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;
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/core/core.controller.js
Expand Up @@ -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);
}
Expand Down
3 changes: 1 addition & 2 deletions src/core/core.datasetController.js
Expand Up @@ -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 = {};
}

/**
Expand Down Expand Up @@ -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())));
}
Expand Down
33 changes: 33 additions & 0 deletions 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();
}
}
};
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 3 additions & 4 deletions test/specs/controller.radar.tests.js
Expand Up @@ -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({
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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)',
Expand Down

0 comments on commit 0dc733a

Please sign in to comment.