From 8e4f30fbb3dc73af5caa181e3641f2085c8aee13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Bona=C4=87i?= Date: Mon, 13 Nov 2023 12:34:43 +0100 Subject: [PATCH 1/2] Update controller.bar.js getLabelAndValue: Verify parsed was set before using it Fixes: Cannot read properties of undefined (reading '_custom') in Bar chart --- src/controllers/controller.bar.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index 1221b64c323..4b2deee4aab 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -365,15 +365,18 @@ export default class BarController extends DatasetController { const meta = this._cachedMeta; const {iScale, vScale} = meta; const parsed = this.getParsed(index); - const custom = parsed._custom; - const value = isFloatBar(custom) - ? '[' + custom.start + ', ' + custom.end + ']' - : '' + vScale.getLabelForValue(parsed[vScale.axis]); - - return { - label: '' + iScale.getLabelForValue(parsed[iScale.axis]), - value - }; + if (parsed) { + const custom = parsed._custom; + const value = isFloatBar(custom) + ? '[' + custom.start + ', ' + custom.end + ']' + : '' + vScale.getLabelForValue(parsed[vScale.axis]); + + return { + label: '' + iScale.getLabelForValue(parsed[iScale.axis]), + value + }; + } + return {label: '', value: 0}; } initialize() { From 9a3809cfc3a59b692d472ef8638b103e63fc3ac4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Bona=C4=87i?= Date: Sun, 19 Nov 2023 13:14:10 +0100 Subject: [PATCH 2/2] Update controller.bar.js: getLabelAndValue: Make value a string when 'parsed' in not set Because a test was failing: Types of property 'value' are incompatible. Type 'number' is not assignable to type 'string'. --- src/controllers/controller.bar.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index 4b2deee4aab..82e0bdecb5d 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -376,7 +376,7 @@ export default class BarController extends DatasetController { value }; } - return {label: '', value: 0}; + return {label: '', value: ''}; } initialize() {