Skip to content

Commit 0dc733a

Browse files
authored
Configure all datasets before updating any (#9872)
* Update misleading sample comment * Configure all datasets before updating any
1 parent 6bc47d3 commit 0dc733a

File tree

6 files changed

+41
-9
lines changed

6 files changed

+41
-9
lines changed

src/controllers/controller.doughnut.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,6 @@ export default class DoughnutController extends DatasetController {
250250
meta = chart.getDatasetMeta(i);
251251
arcs = meta.data;
252252
controller = meta.controller;
253-
if (controller !== this) {
254-
controller.configure();
255-
}
256253
break;
257254
}
258255
}

src/core/core.controller.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,10 @@ class Chart {
540540
return;
541541
}
542542

543+
for (let i = 0, ilen = this.data.datasets.length; i < ilen; ++i) {
544+
this.getDatasetMeta(i).controller.configure();
545+
}
546+
543547
for (let i = 0, ilen = this.data.datasets.length; i < ilen; ++i) {
544548
this._updateDataset(i, isFunction(mode) ? mode({datasetIndex: i}) : mode);
545549
}

src/core/core.datasetController.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ export default class DatasetController {
401401
const scopes = config.getOptionScopes(this.getDataset(), scopeKeys, true);
402402
this.options = config.createResolver(scopes, this.getContext());
403403
this._parsing = this.options.parsing;
404+
this._cachedDataOpts = {};
404405
}
405406

406407
/**
@@ -659,8 +660,6 @@ export default class DatasetController {
659660
*/
660661
_update(mode) {
661662
const meta = this._cachedMeta;
662-
this.configure();
663-
this._cachedDataOpts = {};
664663
this.update(mode || 'default');
665664
meta._clip = toClip(valueOrDefault(this.options.clip, defaultClip(meta.xScale, meta.yScale, this.getMaxOverflow())));
666665
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module.exports = {
2+
description: 'https://github.com/chartjs/Chart.js/issues/9832',
3+
config: {
4+
type: 'doughnut',
5+
data: {
6+
datasets: [{
7+
label: 'Set 1',
8+
data: [50, 50, 25],
9+
backgroundColor: ['#BF616A', '#D08770', '#EBCB8B'],
10+
borderWidth: 0
11+
},
12+
{
13+
label: 'Se1 2',
14+
data: [50, 50, 25],
15+
backgroundColor: ['#BF616A', '#D08770', '#EBCB8B'],
16+
borderWidth: 0
17+
}]
18+
},
19+
options: {
20+
rotation: -90
21+
}
22+
},
23+
options: {
24+
canvas: {
25+
width: 512,
26+
height: 512
27+
},
28+
run(chart) {
29+
chart.options.circumference = 180;
30+
chart.update();
31+
}
32+
}
33+
};
21.1 KB
Loading

test/specs/controller.radar.tests.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ describe('Chart.controllers.radar', function() {
117117

118118
var meta = chart.getDatasetMeta(0);
119119

120-
meta.controller.reset(); // reset first
120+
chart.reset(); // reset first
121121

122122
// Line element
123123
expect(meta.dataset.options).toEqual(jasmine.objectContaining({
@@ -150,8 +150,7 @@ describe('Chart.controllers.radar', function() {
150150
}));
151151
});
152152

153-
// Now update controller and ensure proper updates
154-
meta.controller._update();
153+
chart.update();
155154

156155
[
157156
{x: 256, y: 120, cppx: 246, cppy: 120, cpnx: 272, cpny: 120},
@@ -193,7 +192,7 @@ describe('Chart.controllers.radar', function() {
193192
chart.data.datasets[0].pointBorderColor = 'rgb(56, 57, 58)';
194193
chart.data.datasets[0].pointBorderWidth = 1.123;
195194

196-
meta.controller._update();
195+
chart.update();
197196

198197
expect(meta.dataset.options).toEqual(jasmine.objectContaining({
199198
backgroundColor: 'rgb(98, 98, 98)',

0 commit comments

Comments
 (0)