From 03f828030363047cb2a7ec6bf77e43ba7a545ebf Mon Sep 17 00:00:00 2001 From: sophiamersmann Date: Thu, 26 Oct 2023 10:14:51 +0000 Subject: [PATCH 1/4] fix(data-table): respect tolerance --- .../grapher/src/dataTable/DataTable.tsx | 24 ++++--------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/packages/@ourworldindata/grapher/src/dataTable/DataTable.tsx b/packages/@ourworldindata/grapher/src/dataTable/DataTable.tsx index 7a94a2c2167..f79a41ca9bf 100644 --- a/packages/@ourworldindata/grapher/src/dataTable/DataTable.tsx +++ b/packages/@ourworldindata/grapher/src/dataTable/DataTable.tsx @@ -675,7 +675,6 @@ export class DataTable extends React.Component<{ : TargetTimeMode.range const prelimValuesByEntity = this.preliminaryDimensionValues( - targetTimeMode, sourceColumn, targetTimes ) @@ -728,27 +727,14 @@ export class DataTable extends React.Component<{ } private preliminaryDimensionValues( - targetTimeMode: TargetTimeMode, sourceColumn: CoreColumn, targetTimes: number[] ): Map { - return targetTimeMode === TargetTimeMode.range - ? // In the "range" mode, we receive all data values within the range. But we - - // only want to plot the start & end values in the table. - // getStartEndValues() extracts these two values. - es6mapValues( - valuesByEntityWithinTimes( - sourceColumn.valueByEntityNameAndOriginalTime, - targetTimes - ), - getStartEndValues - ) - : valuesByEntityAtTimes( - sourceColumn.valueByEntityNameAndOriginalTime, - targetTimes, - sourceColumn.tolerance - ) + return valuesByEntityAtTimes( + sourceColumn.valueByEntityNameAndOriginalTime, + targetTimes, + sourceColumn.tolerance + ) } private dataValuesFromPreliminaryValues( From df8e36ba616bc2e25e0fac9a955c6396b5ee8862 Mon Sep 17 00:00:00 2001 From: sophiamersmann Date: Thu, 26 Oct 2023 11:15:22 +0000 Subject: [PATCH 2/4] fix(data-table): only compute deltas if the start year is earlier than the end year --- packages/@ourworldindata/grapher/src/dataTable/DataTable.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/@ourworldindata/grapher/src/dataTable/DataTable.tsx b/packages/@ourworldindata/grapher/src/dataTable/DataTable.tsx index f79a41ca9bf..b9c1f10485a 100644 --- a/packages/@ourworldindata/grapher/src/dataTable/DataTable.tsx +++ b/packages/@ourworldindata/grapher/src/dataTable/DataTable.tsx @@ -770,7 +770,8 @@ export class DataTable extends React.Component<{ start !== undefined && end !== undefined && typeof start.value === "number" && - typeof end.value === "number" + typeof end.value === "number" && + start.time <= end.time ) { const deltaValue = end.value - start.value const deltaRatioValue = deltaValue / Math.abs(start.value) From 53fa95cc7ade2906c00b134ff63e660f09e52854 Mon Sep 17 00:00:00 2001 From: sophiamersmann Date: Thu, 26 Oct 2023 11:23:46 +0000 Subject: [PATCH 3/4] fix(data-table): fix type error --- packages/@ourworldindata/grapher/src/dataTable/DataTable.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/@ourworldindata/grapher/src/dataTable/DataTable.tsx b/packages/@ourworldindata/grapher/src/dataTable/DataTable.tsx index b9c1f10485a..821854dfa6c 100644 --- a/packages/@ourworldindata/grapher/src/dataTable/DataTable.tsx +++ b/packages/@ourworldindata/grapher/src/dataTable/DataTable.tsx @@ -771,6 +771,9 @@ export class DataTable extends React.Component<{ end !== undefined && typeof start.value === "number" && typeof end.value === "number" && + // sanity check: start time should always be <= end time + start.time !== undefined && + end.time !== undefined && start.time <= end.time ) { const deltaValue = end.value - start.value From e3dc1a3a5393f1186becea61810bc4091c485a34 Mon Sep 17 00:00:00 2001 From: sophiamersmann Date: Thu, 26 Oct 2023 11:29:27 +0000 Subject: [PATCH 4/4] chore: make eslint happy --- packages/@ourworldindata/grapher/src/dataTable/DataTable.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/@ourworldindata/grapher/src/dataTable/DataTable.tsx b/packages/@ourworldindata/grapher/src/dataTable/DataTable.tsx index 821854dfa6c..50d7577fb92 100644 --- a/packages/@ourworldindata/grapher/src/dataTable/DataTable.tsx +++ b/packages/@ourworldindata/grapher/src/dataTable/DataTable.tsx @@ -23,8 +23,6 @@ import { upperFirst, valuesByEntityAtTimes, es6mapValues, - valuesByEntityWithinTimes, - getStartEndValues, sortBy, countBy, union,