From 549ce91ff576ca8d1caf1bf9974d724380676934 Mon Sep 17 00:00:00 2001 From: "Hu, Vince" Date: Fri, 12 Jul 2024 17:55:18 +0800 Subject: [PATCH 1/4] fix issue #11717 Signed-off-by: Hu, Vince --- src/controllers/controller.bar.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index 7257bc23992..2f10f9cacec 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -437,9 +437,12 @@ export default class BarController extends DatasetController { .filter(meta => meta.controller.options.grouped); const stacked = iScale.options.stacked; const stacks = []; + const currentParsed = this._cachedMeta.controller.getParsed(dataIndex); + const xStackIndex = currentParsed && currentParsed[iScale.axis]; const skipNull = (meta) => { - const parsed = meta.controller.getParsed(dataIndex); + const filtered = meta._parsed.filter(item => item[iScale.axis] === xStackIndex); + const parsed = filtered.length > 0 ? filtered[0] : undefined; const val = parsed && parsed[meta.vScale.axis]; if (isNullOrUndef(val) || isNaN(val)) { From 170f4ce9e8bcb761d448e16784152f7d3dfa98d4 Mon Sep 17 00:00:00 2001 From: "Hu, Vince" Date: Wed, 31 Jul 2024 09:31:47 +0800 Subject: [PATCH 2/4] unit test for issue #11717 --- test/specs/controller.bar.tests.js | 86 ++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/test/specs/controller.bar.tests.js b/test/specs/controller.bar.tests.js index 53a4738477c..6f61e9e2ff8 100644 --- a/test/specs/controller.bar.tests.js +++ b/test/specs/controller.bar.tests.js @@ -1676,6 +1676,92 @@ describe('Chart.controllers.bar', function() { expect(unevenChart).not.toThrow(); }); + it('should correctly count the number of stacks when skipNull and different order datasets', function() { + + const chart = window.acquireChart({ + type: "bar", + data: { + datasets: [ + { + id: "1", + label: "USA", + data: [ + { + xScale: "First", + Country: "USA", + yScale: 524 + }, + { + xScale: "Second", + Country: "USA", + yScale: 325 + } + ], + + yAxisID: "yScale", + xAxisID: "xScale", + + parsing: { + yAxisKey: "yScale", + xAxisKey: "xScale" + } + }, + { + id: "2", + label: "BRA", + data: [ + { + xScale: "Second", + Country: "BRA", + yScale: 183 + }, + { + xScale: "First", + Country: "BRA", + yScale: 177 + } + ], + + yAxisID: "yScale", + xAxisID: "xScale", + + parsing: { + yAxisKey: "yScale", + xAxisKey: "xScale" + } + }, + { + id: "3", + label: "DEU", + data: [ + { + xScale: "First", + Country: "DEU", + yScale: 162 + } + ], + + yAxisID: "yScale", + xAxisID: "xScale", + + parsing: { + yAxisKey: "yScale", + xAxisKey: "xScale" + } + } + ] + }, + options: { + skipNull: true + } + }) + + var meta = chart.getDatasetMeta(0); + expect(meta.controller._getStackCount(0)).toBe(3); + expect(meta.controller._getStackCount(1)).toBe(2); + + }); + it('should not override tooltip title and label callbacks', async() => { const chart = window.acquireChart({ type: 'bar', From e5ec33e6852bdf6bdd9732782bc4259a063c0888 Mon Sep 17 00:00:00 2001 From: "Hu, Vince" Date: Fri, 2 Aug 2024 17:09:23 +0800 Subject: [PATCH 3/4] fixing test lint style issue --- test/specs/controller.bar.tests.js | 62 +++++++++++++++--------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/test/specs/controller.bar.tests.js b/test/specs/controller.bar.tests.js index 6f61e9e2ff8..a64af1a878b 100644 --- a/test/specs/controller.bar.tests.js +++ b/test/specs/controller.bar.tests.js @@ -1679,74 +1679,74 @@ describe('Chart.controllers.bar', function() { it('should correctly count the number of stacks when skipNull and different order datasets', function() { const chart = window.acquireChart({ - type: "bar", + type: 'bar', data: { datasets: [ { - id: "1", - label: "USA", + id: '1', + label: 'USA', data: [ { - xScale: "First", - Country: "USA", + xScale: 'First', + Country: 'USA', yScale: 524 }, { - xScale: "Second", - Country: "USA", + xScale: 'Second', + Country: 'USA', yScale: 325 } ], - yAxisID: "yScale", - xAxisID: "xScale", + yAxisID: 'yScale', + xAxisID: 'xScale', parsing: { - yAxisKey: "yScale", - xAxisKey: "xScale" + yAxisKey: 'yScale', + xAxisKey: 'xScale' } }, { - id: "2", - label: "BRA", + id: '2', + label: 'BRA', data: [ { - xScale: "Second", - Country: "BRA", + xScale: 'Second', + Country: 'BRA', yScale: 183 }, { - xScale: "First", - Country: "BRA", + xScale: 'First', + Country: 'BRA', yScale: 177 } ], - yAxisID: "yScale", - xAxisID: "xScale", - + yAxisID: 'yScale', + xAxisID: 'xScale', + parsing: { - yAxisKey: "yScale", - xAxisKey: "xScale" + yAxisKey: 'yScale', + xAxisKey: 'xScale' } }, { - id: "3", - label: "DEU", + id: '3', + label: 'DEU', data: [ { - xScale: "First", - Country: "DEU", + xScale: 'First', + Country: 'DEU', yScale: 162 } ], - yAxisID: "yScale", - xAxisID: "xScale", + yAxisID: 'yScale', + xAxisID: 'xScale', parsing: { - yAxisKey: "yScale", - xAxisKey: "xScale" + yAxisKey: 'yScale', + xAxisKey: 'xScale' } } ] @@ -1754,7 +1754,7 @@ describe('Chart.controllers.bar', function() { options: { skipNull: true } - }) + }); var meta = chart.getDatasetMeta(0); expect(meta.controller._getStackCount(0)).toBe(3); From d0963c12ac65053a7b403f66ab2b79456b3cddfe Mon Sep 17 00:00:00 2001 From: "Hu, Vince" Date: Mon, 5 Aug 2024 16:58:43 +0800 Subject: [PATCH 4/4] update codes according review comments --- src/controllers/controller.bar.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index 2f10f9cacec..82138f3fb74 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -438,11 +438,10 @@ export default class BarController extends DatasetController { const stacked = iScale.options.stacked; const stacks = []; const currentParsed = this._cachedMeta.controller.getParsed(dataIndex); - const xStackIndex = currentParsed && currentParsed[iScale.axis]; + const iScaleValue = currentParsed && currentParsed[iScale.axis]; const skipNull = (meta) => { - const filtered = meta._parsed.filter(item => item[iScale.axis] === xStackIndex); - const parsed = filtered.length > 0 ? filtered[0] : undefined; + const parsed = meta._parsed.find(item => item[iScale.axis] === iScaleValue); const val = parsed && parsed[meta.vScale.axis]; if (isNullOrUndef(val) || isNaN(val)) {