Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tabular-rep): better handling of null values #1779

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/src/components/essentials/title-meter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'))

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/model/alluvial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
])
]

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/model/choropleth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
])
]

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/model/heatmap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
])
]

Expand Down
11 changes: 7 additions & 4 deletions packages/core/src/model/meter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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] : [])
]
]
Expand All @@ -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) + ' %'
]
})
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/model/treemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)])
Expand Down