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

Fix updating of active elements #9261

Merged
merged 1 commit into from Jun 12, 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
2 changes: 1 addition & 1 deletion src/controllers/controller.bar.js
Expand Up @@ -290,7 +290,7 @@ export default class BarController extends DatasetController {
};

if (includeOptions) {
properties.options = sharedOptions || me.resolveDataElementOptions(i, mode);
properties.options = sharedOptions || me.resolveDataElementOptions(i, bars[i].active ? 'active' : mode);
}
me.updateElement(bars[i], i, properties, mode);
}
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/controller.bubble.js
Expand Up @@ -86,7 +86,7 @@ export default class BubbleController extends DatasetController {
properties.skip = isNaN(iPixel) || isNaN(vPixel);

if (includeOptions) {
properties.options = me.resolveDataElementOptions(i, mode);
properties.options = me.resolveDataElementOptions(i, point.active ? 'active' : mode);

if (reset) {
properties.options.radius = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/controller.doughnut.js
Expand Up @@ -186,7 +186,7 @@ export default class DoughnutController extends DatasetController {
innerRadius
};
if (includeOptions) {
properties.options = sharedOptions || me.resolveDataElementOptions(i, mode);
properties.options = sharedOptions || me.resolveDataElementOptions(i, arc.active ? 'active' : mode);
}
startAngle += circumference;

Expand Down
2 changes: 1 addition & 1 deletion src/controllers/controller.line.js
Expand Up @@ -71,7 +71,7 @@ export default class LineController extends DatasetController {
properties.parsed = parsed;

if (includeOptions) {
properties.options = sharedOptions || me.resolveDataElementOptions(i, mode);
properties.options = sharedOptions || me.resolveDataElementOptions(i, point.active ? 'active' : mode);
}

if (!directUpdate) {
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/controller.polarArea.js
Expand Up @@ -91,7 +91,7 @@ export default class PolarAreaController extends DatasetController {
outerRadius,
startAngle,
endAngle,
options: me.resolveDataElementOptions(i, mode)
options: me.resolveDataElementOptions(i, arc.active ? 'active' : mode)
};

me.updateElement(arc, i, properties, mode);
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/controller.radar.js
Expand Up @@ -53,7 +53,7 @@ export default class RadarController extends DatasetController {

for (let i = start; i < start + count; i++) {
const point = points[i];
const options = me.resolveDataElementOptions(i, mode);
const options = me.resolveDataElementOptions(i, point.active ? 'active' : mode);
const pointPosition = scale.getPointPositionForValue(i, dataset.data[i]);

const x = reset ? scale.xCenter : pointPosition.x;
Expand Down
27 changes: 27 additions & 0 deletions test/fixtures/controller.doughnut/doughnut-set-active-elements.js
@@ -0,0 +1,27 @@
module.exports = {
description: 'https://github.com/chartjs/Chart.js/issues/9248',
config: {
type: 'doughnut',
data: {
datasets: [
{
data: [34, 33, 17, 16],
backgroundColor: ['#D92323', '#E45757', '#ED8D8D', '#F5C4C4']
}
]
},
options: {
events: [], // for easier saving of the fixture only
borderWidth: 0,
hoverBorderWidth: 4,
hoverBorderColor: 'black',
cutout: '80%',
}
},
options: {
run(chart) {
chart.setActiveElements([{datasetIndex: 0, index: 1}]);
chart.update();
}
}
};
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.