Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure all datasets before updating any #9872

Merged
merged 3 commits into from Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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