From 255d082753ce09c2da91b0fc5702e1dca6085b9f Mon Sep 17 00:00:00 2001 From: Riya Jethwa <76566868+RiyaJethwa@users.noreply.github.com> Date: Wed, 28 Feb 2024 16:15:10 +0530 Subject: [PATCH 1/2] fix(model):Adding null check for model value --- packages/core/src/model/alluvial.ts | 2 +- packages/core/src/model/choropleth.ts | 2 +- packages/core/src/model/heatmap.ts | 2 +- packages/core/src/model/treemap.ts | 6 +++++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/core/src/model/alluvial.ts b/packages/core/src/model/alluvial.ts index c6f2551b85..3c50232b07 100644 --- a/packages/core/src/model/alluvial.ts +++ b/packages/core/src/model/alluvial.ts @@ -20,7 +20,7 @@ export class AlluvialChartModel extends ChartModelCartesian { ...displayData.map((datum: any) => [ datum['source'], datum['target'], - numberFormatter(datum['value'], localeCode) + datum['value'] === null ? '–' : numberFormatter(datum['value'], localeCode) ]) ] diff --git a/packages/core/src/model/choropleth.ts b/packages/core/src/model/choropleth.ts index 7b710499b9..0ced2d7115 100644 --- a/packages/core/src/model/choropleth.ts +++ b/packages/core/src/model/choropleth.ts @@ -75,7 +75,7 @@ export class ChoroplethModel extends ChartModel { ...displayData.map(datum => [ datum['id'] === null ? '–' : datum['id'], datum['name'], - numberFormatter(datum['value'], localeCode) + datum['value'] === null ? '–' : numberFormatter(datum['value'], localeCode) ]) ] diff --git a/packages/core/src/model/heatmap.ts b/packages/core/src/model/heatmap.ts index b476a47fd3..51e6850ee5 100644 --- a/packages/core/src/model/heatmap.ts +++ b/packages/core/src/model/heatmap.ts @@ -250,7 +250,7 @@ export class HeatmapModel extends ChartModelCartesian { : datum[primaryDomain.identifier], datum[primaryRange.identifier] === null ? '–' : datum[primaryRange.identifier], - numberFormatter(datum['value'], localeCode) + datum['value'] === null ? '–' : numberFormatter(datum['value'], localeCode) ]) ] diff --git a/packages/core/src/model/treemap.ts b/packages/core/src/model/treemap.ts index 5a408f7844..dee9269985 100644 --- a/packages/core/src/model/treemap.ts +++ b/packages/core/src/model/treemap.ts @@ -18,7 +18,11 @@ export class TreemapChartModel extends ChartModel { displayData.forEach((datum: any) => { if (Array.isArray(datum.children)) { datum.children.forEach((child: any) => { - cells.push([child.name, datum.name, numberFormatter(child.value, localeCode)]) + cells.push([ + child.name, + datum.name, + child.value === null ? '–' : numberFormatter(child.value, localeCode) + ]) }) } else if (getProperty(datum.name) !== null && getProperty(datum.value)) { cells.push(['–', datum.name, numberFormatter(datum.value, localeCode)]) From 1b5a8672d102ab51713c9759d95955019c37feae Mon Sep 17 00:00:00 2001 From: Riya Jethwa <76566868+RiyaJethwa@users.noreply.github.com> Date: Fri, 8 Mar 2024 16:13:43 +0530 Subject: [PATCH 2/2] fix(meter):added meter null fallback --- .../core/src/components/essentials/title-meter.ts | 2 +- packages/core/src/model/meter.ts | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/core/src/components/essentials/title-meter.ts b/packages/core/src/components/essentials/title-meter.ts index df5727a067..becb2b0f3f 100644 --- a/packages/core/src/components/essentials/title-meter.ts +++ b/packages/core/src/components/essentials/title-meter.ts @@ -230,7 +230,7 @@ export class MeterTitle extends Title { .append('text') .classed('percent-value', true) .merge(percentage as any) - .text((d: any) => `${numberFormatter(d, localeCode)}%`) + .text((d: any) => `${d !== null && d !== undefined ? numberFormatter(d, localeCode) : 0}%`) .attr('x', +title.attr('x') + title.node().getComputedTextLength() + offset) // set the position to after the title .attr('y', title.attr('y')) diff --git a/packages/core/src/model/meter.ts b/packages/core/src/model/meter.ts index d234935a8a..809d58b27f 100644 --- a/packages/core/src/model/meter.ts +++ b/packages/core/src/model/meter.ts @@ -86,7 +86,7 @@ export class MeterChartModel extends ChartModel { cells = [ [ datum[groupMapsTo], - numberFormatter(datum['value'], localeCode), + datum['value'] === null ? '–' : numberFormatter(datum['value'], localeCode), ...(status ? [status] : []) ] ] @@ -96,11 +96,14 @@ export class MeterChartModel extends ChartModel { headers = ['Group', 'Value', 'Percentage of total'] cells = [ ...displayData.map((datum: any) => { - const value = datum['value'] - const percentValue = Number(((datum['value'] / domainMax) * 100).toFixed(2)) + let value + datum['value'] !== null && datum['value'] !== undefined + ? (value = Number(datum['value'])) + : (value = 0) + let percentValue = Number(((datum['value'] / domainMax) * 100).toFixed(2)) return [ datum[groupMapsTo], - numberFormatter(value, localeCode), + datum['value'] === null ? '–' : numberFormatter(value, localeCode), numberFormatter(percentValue, localeCode) + ' %' ] })