From 7ff9e9f8541f7117c1bb77f73f0219a6397c7bf3 Mon Sep 17 00:00:00 2001 From: sophiamersmann Date: Mon, 13 May 2024 13:27:18 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20don't=20switch=20to=20discrete?= =?UTF-8?q?=20bar=20chart=20when=20timeline=20is=20hidden?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/@ourworldindata/grapher/src/core/Grapher.tsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/@ourworldindata/grapher/src/core/Grapher.tsx b/packages/@ourworldindata/grapher/src/core/Grapher.tsx index 6040a912e34..1f8efd936f4 100644 --- a/packages/@ourworldindata/grapher/src/core/Grapher.tsx +++ b/packages/@ourworldindata/grapher/src/core/Grapher.tsx @@ -1192,6 +1192,7 @@ export class Grapher // irrespective of the time range the user might have selected on the table tab if (this.isOnChartTab && this.hideTimeline && this.hasTimeDimension) { const { minTime, maxTime } = this.authorsVersion + console.log("minTime", minTime, "maxTime", maxTime) return [ minTimeBoundFromJSONOrNegativeInfinity(minTime), maxTimeBoundFromJSONOrPositiveInfinity(maxTime), @@ -1749,17 +1750,19 @@ export class Grapher @computed get isLineChartThatTurnedIntoDiscreteBar(): boolean { if (!this.isLineChart) return false + const [minTime, maxTime] = this.timelineHandleTimeBounds + // This is the easy case: minTime and maxTime are the same, no need to do // more fancy checks - if (this.minTime === this.maxTime) return true + if (minTime === maxTime) return true // We can have cases where minTime = Infinity and/or maxTime = -Infinity, // but still only a single year is selected. // To check for that we need to look at the times array. const times = this.tableAfterAuthorTimelineFilter.timeColumn.uniqValues - const minTime = findClosestTime(times, this.minTime ?? -Infinity) - const maxTime = findClosestTime(times, this.maxTime ?? Infinity) - return minTime !== undefined && minTime === maxTime + const closestMinTime = findClosestTime(times, minTime) + const closestMaxTime = findClosestTime(times, maxTime) + return closestMinTime !== undefined && closestMinTime === closestMaxTime } @computed get supportsMultipleYColumns(): boolean {