diff --git a/packages/@ourworldindata/core-table/src/CoreTableColumns.ts b/packages/@ourworldindata/core-table/src/CoreTableColumns.ts index e34dfecb092..28f7d54906b 100644 --- a/packages/@ourworldindata/core-table/src/CoreTableColumns.ts +++ b/packages/@ourworldindata/core-table/src/CoreTableColumns.ts @@ -247,7 +247,8 @@ export abstract class AbstractCoreColumn { } @imemo get unit(): string | undefined { - return this.display?.unit ?? this.def.unit + const unit = this.display?.unit ?? this.def.unit + return unit?.trim() } @imemo get shortUnit(): string | undefined { diff --git a/packages/@ourworldindata/grapher/src/dataTable/DataTable.tsx b/packages/@ourworldindata/grapher/src/dataTable/DataTable.tsx index da23e24d602..52bff70e895 100644 --- a/packages/@ourworldindata/grapher/src/dataTable/DataTable.tsx +++ b/packages/@ourworldindata/grapher/src/dataTable/DataTable.tsx @@ -789,15 +789,18 @@ export class DataTable extends React.Component<{ targetTimes: number[] targetTimeMode: TargetTimeMode }): DimensionColumn[] { - // Inject delta columns if we have start & end values to compare in the table. - // One column for absolute difference, another for % difference. + // Inject delta columns if the data is numerical and we have start & end + // values to compare in the table. One column for absolute difference, + // another for % difference. const deltaColumns: DimensionColumn[] = [] - if (targetTimeMode === TargetTimeMode.range) { - const { tableDisplay = {} } = sourceColumn.display ?? {} - if (!tableDisplay.hideAbsoluteChange) - deltaColumns.push({ key: RangeValueKey.delta }) - if (!tableDisplay.hideRelativeChange) - deltaColumns.push({ key: RangeValueKey.deltaRatio }) + if (sourceColumn.hasNumberFormatting) { + if (targetTimeMode === TargetTimeMode.range) { + const { tableDisplay = {} } = sourceColumn.display ?? {} + if (!tableDisplay.hideAbsoluteChange) + deltaColumns.push({ key: RangeValueKey.delta }) + if (!tableDisplay.hideRelativeChange) + deltaColumns.push({ key: RangeValueKey.deltaRatio }) + } } const valueColumns = targetTimes.map((targetTime, index) => ({