Skip to content

Commit

Permalink
Fix clearStacks with custom scaleId (#9170)
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle committed May 28, 2021
1 parent 77cfac1 commit 188da82
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/core/core.datasetController.js
Expand Up @@ -192,13 +192,18 @@ function createDataContext(parent, index, element) {
}

function clearStacks(meta, items) {
const axis = meta.vScale && meta.vScale.axis;
if (!axis) {
return;
}

items = items || meta._parsed;
for (const parsed of items) {
const stacks = parsed._stacks;
if (!stacks || stacks[meta.vScale.id] === undefined || stacks[meta.vScale.id][meta.index] === undefined) {
if (!stacks || stacks[axis] === undefined || stacks[axis][meta.index] === undefined) {
return;
}
delete stacks[meta.vScale.id][meta.index];
delete stacks[axis][meta.index];
}
}

Expand Down
49 changes: 49 additions & 0 deletions test/fixtures/controller.bar/stacking/issue-9105.js
@@ -0,0 +1,49 @@
module.exports = {
description: 'https://github.com/chartjs/Chart.js/issues/9105',
config: {
type: 'bar',
data: {
labels: ['January', 'February', 'March', 'April', 'May', 'June'],
datasets: [
{
backgroundColor: 'rgba(255,99,132,0.8)',
label: 'Dataset 1',
data: [12, 19, 3, 5, 2, 3],
stack: '0',
yAxisID: 'y-axis-1'
},
{
backgroundColor: 'rgba(54,162,235,0.8)',
label: 'Dataset 2',
data: [13, 19, 3, 5, 8, 3],
stack: '0',
yAxisID: 'y-axis-1'
},
{
backgroundColor: 'rgba(75,192,192,0.8)',
label: 'Dataset 3',
data: [13, 19, 3, 5, 8, 3],
stack: '0',
yAxisID: 'y-axis-1'
}
]
},
options: {
plugins: false,
scales: {
xaxis: {
display: false,
},
'y-axis-1': {
display: false
}
}
}
},
options: {
run(chart) {
chart.data.datasets[1].stack = '1';
chart.update();
}
}
};
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 188da82

Please sign in to comment.