Skip to content

Commit 147ee59

Browse files
authored
fix issue #11717 (#11844)
* fix issue #11717 Signed-off-by: Hu, Vince <Qingkun.Hu@fmr.com> * unit test for issue #11717 * fixing test lint style issue * update codes according review comments --------- Signed-off-by: Hu, Vince <Qingkun.Hu@fmr.com>
1 parent 0ca1b6e commit 147ee59

File tree

2 files changed

+89
-1
lines changed

2 files changed

+89
-1
lines changed

src/controllers/controller.bar.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,9 +437,11 @@ export default class BarController extends DatasetController {
437437
.filter(meta => meta.controller.options.grouped);
438438
const stacked = iScale.options.stacked;
439439
const stacks = [];
440+
const currentParsed = this._cachedMeta.controller.getParsed(dataIndex);
441+
const iScaleValue = currentParsed && currentParsed[iScale.axis];
440442

441443
const skipNull = (meta) => {
442-
const parsed = meta.controller.getParsed(dataIndex);
444+
const parsed = meta._parsed.find(item => item[iScale.axis] === iScaleValue);
443445
const val = parsed && parsed[meta.vScale.axis];
444446

445447
if (isNullOrUndef(val) || isNaN(val)) {

test/specs/controller.bar.tests.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,6 +1676,92 @@ describe('Chart.controllers.bar', function() {
16761676
expect(unevenChart).not.toThrow();
16771677
});
16781678

1679+
it('should correctly count the number of stacks when skipNull and different order datasets', function() {
1680+
1681+
const chart = window.acquireChart({
1682+
type: 'bar',
1683+
data: {
1684+
datasets: [
1685+
{
1686+
id: '1',
1687+
label: 'USA',
1688+
data: [
1689+
{
1690+
xScale: 'First',
1691+
Country: 'USA',
1692+
yScale: 524
1693+
},
1694+
{
1695+
xScale: 'Second',
1696+
Country: 'USA',
1697+
yScale: 325
1698+
}
1699+
],
1700+
1701+
yAxisID: 'yScale',
1702+
xAxisID: 'xScale',
1703+
1704+
parsing: {
1705+
yAxisKey: 'yScale',
1706+
xAxisKey: 'xScale'
1707+
}
1708+
},
1709+
{
1710+
id: '2',
1711+
label: 'BRA',
1712+
data: [
1713+
{
1714+
xScale: 'Second',
1715+
Country: 'BRA',
1716+
yScale: 183
1717+
},
1718+
{
1719+
xScale: 'First',
1720+
Country: 'BRA',
1721+
yScale: 177
1722+
}
1723+
],
1724+
1725+
yAxisID: 'yScale',
1726+
xAxisID: 'xScale',
1727+
1728+
parsing: {
1729+
yAxisKey: 'yScale',
1730+
xAxisKey: 'xScale'
1731+
}
1732+
},
1733+
{
1734+
id: '3',
1735+
label: 'DEU',
1736+
data: [
1737+
{
1738+
xScale: 'First',
1739+
Country: 'DEU',
1740+
yScale: 162
1741+
}
1742+
],
1743+
1744+
yAxisID: 'yScale',
1745+
xAxisID: 'xScale',
1746+
1747+
parsing: {
1748+
yAxisKey: 'yScale',
1749+
xAxisKey: 'xScale'
1750+
}
1751+
}
1752+
]
1753+
},
1754+
options: {
1755+
skipNull: true
1756+
}
1757+
});
1758+
1759+
var meta = chart.getDatasetMeta(0);
1760+
expect(meta.controller._getStackCount(0)).toBe(3);
1761+
expect(meta.controller._getStackCount(1)).toBe(2);
1762+
1763+
});
1764+
16791765
it('should not override tooltip title and label callbacks', async() => {
16801766
const chart = window.acquireChart({
16811767
type: 'bar',

0 commit comments

Comments
 (0)