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

Properly update stacks when datasets index changes #9425

Merged
merged 1 commit into from Jul 16, 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
6 changes: 4 additions & 2 deletions src/core/core.datasetController.js
Expand Up @@ -193,6 +193,8 @@ function createDataContext(parent, index, element) {
}

function clearStacks(meta, items) {
// Not using meta.index here, because it might be already updated if the dataset changed location
const datasetIndex = meta.controller.index;
const axis = meta.vScale && meta.vScale.axis;
if (!axis) {
return;
Expand All @@ -201,10 +203,10 @@ function clearStacks(meta, items) {
items = items || meta._parsed;
for (const parsed of items) {
const stacks = parsed._stacks;
if (!stacks || stacks[axis] === undefined || stacks[axis][meta.index] === undefined) {
if (!stacks || stacks[axis] === undefined || stacks[axis][datasetIndex] === undefined) {
return;
}
delete stacks[axis][meta.index];
delete stacks[axis][datasetIndex];
}
}

Expand Down
40 changes: 40 additions & 0 deletions test/fixtures/controller.line/stacking/updates.js
@@ -0,0 +1,40 @@
module.exports = {
description: 'https://github.com/chartjs/Chart.js/issues/9424',
config: {
type: 'line',
data: {
labels: [0, 1, 2],
datasets: [
{
data: [1, 1, 1],
stack: 's1',
borderColor: '#ff0000',
},
{
data: [2, 2, 2],
stack: 's1',
borderColor: '#00ff00',
},
{
data: [3, 3, 3],
stack: 's1',
borderColor: '#0000ff',
}
]
},
options: {
borderWidth: 5,
scales: {
x: {display: false},
y: {display: true, stacked: true}
}
}
},
options: {
spriteText: true,
run(chart) {
chart.data.datasets.splice(1, 0, {data: [1.5, 1.5, 1.5], stack: 's2', borderColor: '#000000'});
chart.update();
}
}
};
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.