Skip to content

Commit

Permalink
Fix: applyStack() returned the sum of all values for hidden dataset i…
Browse files Browse the repository at this point in the history
…ndices, which resulted in wrong show animations (#11938)
  • Loading branch information
DeyLak authored Oct 24, 2024
1 parent bb5ca38 commit 6dd448b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/core/core.datasetController.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ function applyStack(stack, value, dsIndex, options = {}) {
return;
}

let found = false;
for (i = 0, ilen = keys.length; i < ilen; ++i) {
datasetIndex = +keys[i];
if (datasetIndex === dsIndex) {
found = true;
if (options.all) {
continue;
}
Expand All @@ -89,6 +91,11 @@ function applyStack(stack, value, dsIndex, options = {}) {
value += otherValue;
}
}

if (!found && !options.all) {
return 0;
}

return value;
}

Expand Down
43 changes: 43 additions & 0 deletions test/specs/controller.bar.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1613,6 +1613,49 @@ describe('Chart.controllers.bar', function() {
expect(data[0].y).toBeCloseToPixel(512);
});

it('should hide bar dataset beneath the chart for correct animations', function() {
var chart = window.acquireChart({
type: 'bar',
data: {
datasets: [{
data: [1, 2, 3, 4]
}, {
data: [1, 2, 3, 4]
}],
labels: ['A', 'B', 'C', 'D']
},
options: {
plugins: {
legend: false,
title: false
},
scales: {
x: {
type: 'category',
display: false,
stacked: true,
},
y: {
type: 'linear',
display: false,
stacked: true,
}
}
}
});

var data = chart.getDatasetMeta(0).data;
expect(data[0].base).toBeCloseToPixel(512);
expect(data[0].y).toBeCloseToPixel(448);

chart.setDatasetVisibility(0, false);
chart.update();

data = chart.getDatasetMeta(0).data;
expect(data[0].base).toBeCloseToPixel(640);
expect(data[0].y).toBeCloseToPixel(512);
});

describe('Float bar', function() {
it('Should return correct values from getMinMax', function() {
var chart = window.acquireChart({
Expand Down

0 comments on commit 6dd448b

Please sign in to comment.