mirror of
https://github.com/chartjs/Chart.js.git
synced 2024-10-06 12:19:08 +02:00
Properly update stacks when datasets index changes (#9425)
This commit is contained in:
parent
11045a731a
commit
0094a58ef1
@ -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;
|
||||
@ -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];
|
||||
}
|
||||
}
|
||||
|
||||
|
40
test/fixtures/controller.line/stacking/updates.js
vendored
Normal file
40
test/fixtures/controller.line/stacking/updates.js
vendored
Normal file
@ -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();
|
||||
}
|
||||
}
|
||||
};
|
BIN
test/fixtures/controller.line/stacking/updates.png
vendored
Normal file
BIN
test/fixtures/controller.line/stacking/updates.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
Loading…
Reference in New Issue
Block a user