From e9b1bd4a1c99ea00f997624df61e2b01764a018b Mon Sep 17 00:00:00 2001 From: Sophia Mersmann Date: Wed, 8 Jan 2025 10:46:58 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20introduce=20displayUnit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/@ourworldindata/core-table/src/CoreTableColumns.ts | 6 ++++++ .../@ourworldindata/grapher/src/tooltip/TooltipContents.tsx | 6 +----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/@ourworldindata/core-table/src/CoreTableColumns.ts b/packages/@ourworldindata/core-table/src/CoreTableColumns.ts index 72bfe436e0..09120f2fba 100644 --- a/packages/@ourworldindata/core-table/src/CoreTableColumns.ts +++ b/packages/@ourworldindata/core-table/src/CoreTableColumns.ts @@ -269,6 +269,12 @@ export abstract class AbstractCoreColumn { return undefined } + @imemo get displayUnit(): string | undefined { + return this.unit && this.unit !== this.shortUnit + ? this.unit.replace(/^\((.*)\)$/, "$1") + : undefined + } + // Returns a map where the key is a series slug such as "name" and the value is a set // of all the unique values that this column has for that particular series. getUniqueValuesGroupedBy( diff --git a/packages/@ourworldindata/grapher/src/tooltip/TooltipContents.tsx b/packages/@ourworldindata/grapher/src/tooltip/TooltipContents.tsx index 18fad5e9d4..a5e6d85c76 100644 --- a/packages/@ourworldindata/grapher/src/tooltip/TooltipContents.tsx +++ b/packages/@ourworldindata/grapher/src/tooltip/TooltipContents.tsx @@ -132,11 +132,7 @@ class Variable extends React.Component<{ if (column.isMissing || column.name === "time") return null - const { unit, shortUnit, displayName } = column, - displayUnit = - unit && unit !== shortUnit - ? unit.replace(/^\((.*)\)$/, "$1") - : undefined, + const { displayUnit, displayName } = column, displayNotice = uniq((notice ?? []).filter((t) => t !== undefined)) .map((time) =>