From 60f2e341da43bfc57f025f8b98d27c1dd0345b06 Mon Sep 17 00:00:00 2001 From: sophiamersmann Date: Wed, 27 Nov 2024 15:52:13 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20(owid=20table)=20add=20time=20to?= =?UTF-8?q?=20owidRows?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../@ourworldindata/core-table/src/CoreTableColumns.ts | 8 +++++--- packages/@ourworldindata/core-table/src/OwidTable.test.ts | 8 ++++---- .../grapher/src/entitySelector/EntitySelector.tsx | 2 +- .../@ourworldindata/grapher/src/mapCharts/MapChart.tsx | 4 ++-- .../grapher/src/mapCharts/MapSparkline.tsx | 2 +- .../@ourworldindata/grapher/src/mapCharts/MapTooltip.tsx | 6 +++--- .../grapher/src/stackedCharts/AbstractStackedChart.tsx | 4 ++-- .../grapher/src/stackedCharts/MarimekkoChart.tsx | 4 ++-- .../grapher/src/stackedCharts/StackedDiscreteBarChart.tsx | 2 +- .../types/src/domainTypes/CoreTableTypes.ts | 1 + 10 files changed, 22 insertions(+), 19 deletions(-) diff --git a/packages/@ourworldindata/core-table/src/CoreTableColumns.ts b/packages/@ourworldindata/core-table/src/CoreTableColumns.ts index 390dfb88bcd..89014482505 100644 --- a/packages/@ourworldindata/core-table/src/CoreTableColumns.ts +++ b/packages/@ourworldindata/core-table/src/CoreTableColumns.ts @@ -536,14 +536,16 @@ export abstract class AbstractCoreColumn { // assumes table is sorted by time @imemo get owidRows(): OwidVariableRow[] { const entities = this.allEntityNames - const times = this.originalTimes + const times = this.allTimes const values = this.values + const originalTimes = this.originalTimes const originalValues = this.originalValues - return range(0, times.length).map((index) => { + return range(0, originalTimes.length).map((index) => { return omitUndefinedValues({ entityName: entities[index], time: times[index], value: values[index], + originalTime: originalTimes[index], originalValue: originalValues[index], }) }) @@ -577,7 +579,7 @@ export abstract class AbstractCoreColumn { valueByEntityNameAndTime.set(row.entityName, new Map()) valueByEntityNameAndTime .get(row.entityName)! - .set(row.time, row.value) + .set(row.originalTime, row.value) }) return valueByEntityNameAndTime } diff --git a/packages/@ourworldindata/core-table/src/OwidTable.test.ts b/packages/@ourworldindata/core-table/src/OwidTable.test.ts index a58250a1ec7..32208310965 100755 --- a/packages/@ourworldindata/core-table/src/OwidTable.test.ts +++ b/packages/@ourworldindata/core-table/src/OwidTable.test.ts @@ -72,7 +72,7 @@ it("can parse data to Javascript data structures", () => { table.get("Population").owidRows.forEach((row) => { expect(typeof row.entityName).toBe("string") expect(row.value).toBeGreaterThan(100) - expect(row.time).toBeGreaterThan(1999) + expect(row.originalTime).toBeGreaterThan(1999) }) }) @@ -632,7 +632,7 @@ describe("tolerance", () => { }) }) -it("assigns originalTime as 'time' in owidRows", () => { +it("assigns originalTime as 'originalTime' in owidRows", () => { const csv = `gdp,year,entityName,entityId,entityCode 1000,2019,USA,, 1001,2020,UK,,` @@ -642,7 +642,7 @@ it("assigns originalTime as 'time' in owidRows", () => { expect.not.arrayContaining([ expect.objectContaining({ entityName: "USA", - time: 2020, + originalTime: 2020, value: 1000, }), ]) @@ -651,7 +651,7 @@ it("assigns originalTime as 'time' in owidRows", () => { expect.not.arrayContaining([ expect.objectContaining({ entityName: "UK", - time: 2019, + originalTime: 2019, value: 1001, }), ]) diff --git a/packages/@ourworldindata/grapher/src/entitySelector/EntitySelector.tsx b/packages/@ourworldindata/grapher/src/entitySelector/EntitySelector.tsx index ebce9d92057..a6590dcf0be 100644 --- a/packages/@ourworldindata/grapher/src/entitySelector/EntitySelector.tsx +++ b/packages/@ourworldindata/grapher/src/entitySelector/EntitySelector.tsx @@ -453,7 +453,7 @@ export class EntitySelector extends React.Component<{ const rows = column.owidRowsByEntityName.get(entityName) ?? [] searchableEntity[column.slug] = maxBy( rows, - (row) => row.time + (row) => row.originalTime )?.value } diff --git a/packages/@ourworldindata/grapher/src/mapCharts/MapChart.tsx b/packages/@ourworldindata/grapher/src/mapCharts/MapChart.tsx index f641a1b939b..a07da5438fa 100644 --- a/packages/@ourworldindata/grapher/src/mapCharts/MapChart.tsx +++ b/packages/@ourworldindata/grapher/src/mapCharts/MapChart.tsx @@ -346,12 +346,12 @@ export class MapChart return mapColumn.owidRows .map((row) => { - const { entityName, value, time } = row + const { entityName, value, originalTime } = row const color = this.colorScale.getColor(value) || "red" // todo: color fix if (!color) return undefined return { seriesName: entityName, - time, + time: originalTime, value, isSelected: selectionArray.selectedSet.has(entityName), color, diff --git a/packages/@ourworldindata/grapher/src/mapCharts/MapSparkline.tsx b/packages/@ourworldindata/grapher/src/mapCharts/MapSparkline.tsx index 7fa2a61dbfb..72977920cdb 100644 --- a/packages/@ourworldindata/grapher/src/mapCharts/MapSparkline.tsx +++ b/packages/@ourworldindata/grapher/src/mapCharts/MapSparkline.tsx @@ -118,7 +118,7 @@ export class MapSparkline extends React.Component<{ lineStrokeWidth: 2, entityYearHighlight: { entityName: this.manager.entityName, - year: this.manager.datum?.time, + year: this.manager.datum?.originalTime, }, yAxisConfig: { hideAxis: true, diff --git a/packages/@ourworldindata/grapher/src/mapCharts/MapTooltip.tsx b/packages/@ourworldindata/grapher/src/mapCharts/MapTooltip.tsx index e58b90c5484..65775d51db1 100644 --- a/packages/@ourworldindata/grapher/src/mapCharts/MapTooltip.tsx +++ b/packages/@ourworldindata/grapher/src/mapCharts/MapTooltip.tsx @@ -119,8 +119,8 @@ export class MapTooltip : targetTime?.toString() const displayDatumTime = timeColumn && datum - ? timeColumn.formatValue(datum?.time) - : (datum?.time.toString() ?? "") + ? timeColumn.formatValue(datum?.originalTime) + : (datum?.originalTime.toString() ?? "") const valueColor: string | undefined = darkenColorForHighContrastText( lineColorScale?.getColor(datum?.value) ?? "#333" ) @@ -143,7 +143,7 @@ export class MapTooltip const yColumn = this.mapTable.get(this.mapColumnSlug) const targetNotice = - datum && datum.time !== targetTime ? displayTime : undefined + datum && datum.originalTime !== targetTime ? displayTime : undefined const toleranceNotice = targetNotice ? { icon: TooltipFooterIcon.notice, diff --git a/packages/@ourworldindata/grapher/src/stackedCharts/AbstractStackedChart.tsx b/packages/@ourworldindata/grapher/src/stackedCharts/AbstractStackedChart.tsx index 2a5110442d5..5b40a3086bb 100644 --- a/packages/@ourworldindata/grapher/src/stackedCharts/AbstractStackedChart.tsx +++ b/packages/@ourworldindata/grapher/src/stackedCharts/AbstractStackedChart.tsx @@ -407,8 +407,8 @@ export class AbstractStackedChart const pointColor = row.value > 0 ? POSITIVE_COLOR : NEGATIVE_COLOR return { - position: row.time, - time: row.time, + position: row.originalTime, + time: row.originalTime, value: row.value, valueOffset: 0, interpolated: diff --git a/packages/@ourworldindata/grapher/src/stackedCharts/MarimekkoChart.tsx b/packages/@ourworldindata/grapher/src/stackedCharts/MarimekkoChart.tsx index 9fa7f41afd6..e89b176b4da 100644 --- a/packages/@ourworldindata/grapher/src/stackedCharts/MarimekkoChart.tsx +++ b/packages/@ourworldindata/grapher/src/stackedCharts/MarimekkoChart.tsx @@ -383,7 +383,7 @@ export class MarimekkoChart col.def.color ?? colorScheme.getColors(yColumns.length)[i], points: col.owidRows.map((row) => ({ - time: row.time, + time: row.originalTime, position: row.entityName, value: row.value, valueOffset: 0, @@ -417,7 +417,7 @@ export class MarimekkoChart const points: SimplePoint[] = [] for (const row of rows) { points.push({ - time: row.time, + time: row.originalTime, value: row.value, entity: row.entityName, }) diff --git a/packages/@ourworldindata/grapher/src/stackedCharts/StackedDiscreteBarChart.tsx b/packages/@ourworldindata/grapher/src/stackedCharts/StackedDiscreteBarChart.tsx index c575e65c476..b298d2ae160 100644 --- a/packages/@ourworldindata/grapher/src/stackedCharts/StackedDiscreteBarChart.tsx +++ b/packages/@ourworldindata/grapher/src/stackedCharts/StackedDiscreteBarChart.tsx @@ -1006,7 +1006,7 @@ export class StackedDiscreteBarChart col.displayName ), points: col.owidRows.map((row) => ({ - time: row.time, + time: row.originalTime, position: row.entityName, value: row.value, valueOffset: 0, diff --git a/packages/@ourworldindata/types/src/domainTypes/CoreTableTypes.ts b/packages/@ourworldindata/types/src/domainTypes/CoreTableTypes.ts index 5fa5ba92b00..a44d6d42459 100644 --- a/packages/@ourworldindata/types/src/domainTypes/CoreTableTypes.ts +++ b/packages/@ourworldindata/types/src/domainTypes/CoreTableTypes.ts @@ -300,5 +300,6 @@ export interface OwidVariableRow { entityName: EntityName time: Time value: ValueType + originalTime: Time originalValue?: ValueType }