Skip to content

Commit 6dd448b

Browse files
authored
Fix: applyStack() returned the sum of all values for hidden dataset indices, which resulted in wrong show animations (#11938)
1 parent bb5ca38 commit 6dd448b

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

src/core/core.datasetController.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,11 @@ function applyStack(stack, value, dsIndex, options = {}) {
7676
return;
7777
}
7878

79+
let found = false;
7980
for (i = 0, ilen = keys.length; i < ilen; ++i) {
8081
datasetIndex = +keys[i];
8182
if (datasetIndex === dsIndex) {
83+
found = true;
8284
if (options.all) {
8385
continue;
8486
}
@@ -89,6 +91,11 @@ function applyStack(stack, value, dsIndex, options = {}) {
8991
value += otherValue;
9092
}
9193
}
94+
95+
if (!found && !options.all) {
96+
return 0;
97+
}
98+
9299
return value;
93100
}
94101

test/specs/controller.bar.tests.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,6 +1613,49 @@ describe('Chart.controllers.bar', function() {
16131613
expect(data[0].y).toBeCloseToPixel(512);
16141614
});
16151615

1616+
it('should hide bar dataset beneath the chart for correct animations', function() {
1617+
var chart = window.acquireChart({
1618+
type: 'bar',
1619+
data: {
1620+
datasets: [{
1621+
data: [1, 2, 3, 4]
1622+
}, {
1623+
data: [1, 2, 3, 4]
1624+
}],
1625+
labels: ['A', 'B', 'C', 'D']
1626+
},
1627+
options: {
1628+
plugins: {
1629+
legend: false,
1630+
title: false
1631+
},
1632+
scales: {
1633+
x: {
1634+
type: 'category',
1635+
display: false,
1636+
stacked: true,
1637+
},
1638+
y: {
1639+
type: 'linear',
1640+
display: false,
1641+
stacked: true,
1642+
}
1643+
}
1644+
}
1645+
});
1646+
1647+
var data = chart.getDatasetMeta(0).data;
1648+
expect(data[0].base).toBeCloseToPixel(512);
1649+
expect(data[0].y).toBeCloseToPixel(448);
1650+
1651+
chart.setDatasetVisibility(0, false);
1652+
chart.update();
1653+
1654+
data = chart.getDatasetMeta(0).data;
1655+
expect(data[0].base).toBeCloseToPixel(640);
1656+
expect(data[0].y).toBeCloseToPixel(512);
1657+
});
1658+
16161659
describe('Float bar', function() {
16171660
it('Should return correct values from getMinMax', function() {
16181661
var chart = window.acquireChart({

0 commit comments

Comments
 (0)