From e3281fc72fbd619d1ea46e8f1f6b099ceb2ad083 Mon Sep 17 00:00:00 2001 From: sophiamersmann Date: Mon, 8 Apr 2024 10:52:15 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20(stacked=20bar/area)=20show=20ti?= =?UTF-8?q?meline=20on=20table=20tab?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../grapher/src/core/Grapher.tsx | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/packages/@ourworldindata/grapher/src/core/Grapher.tsx b/packages/@ourworldindata/grapher/src/core/Grapher.tsx index 74633e78ab2..3a369dae371 100644 --- a/packages/@ourworldindata/grapher/src/core/Grapher.tsx +++ b/packages/@ourworldindata/grapher/src/core/Grapher.tsx @@ -1030,6 +1030,13 @@ export class Grapher ) } + /** + * Plots time on the x-axis. + */ + @computed private get hasTimeDimension(): boolean { + return this.isStackedBar || this.isStackedArea || this.isLineChart + } + @computed get startHandleTimeBound(): TimeBound { if (this.onlySingleTimeSelectionPossible) return this.endHandleTimeBound return this.timelineHandleTimeBounds[0] @@ -1178,6 +1185,19 @@ export class Grapher const time = maxTimeBoundFromJSONOrPositiveInfinity(this.map.time) return [time, time] } + + // If the timeline is hidden on the chart tab but displayed on the table tab + // (which is the case for charts that plot time on the x-axis), + // we always want to use the authored `minTime` and `maxTime` for the chart, + // 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 + return [ + minTimeBoundFromJSONOrNegativeInfinity(minTime), + maxTimeBoundFromJSONOrPositiveInfinity(maxTime), + ] + } + return [ // Handle `undefined` values in minTime/maxTime minTimeBoundFromJSONOrNegativeInfinity(this.minTime), @@ -1422,11 +1442,16 @@ export class Grapher case GrapherTabOption.map: return !this.map.hideTimeline - // use the chart-level `hideTimeline` option for the table, too - case GrapherTabOption.table: + // use the chart-level `hideTimeline` option case GrapherTabOption.chart: return !this.hideTimeline + // use the chart-level `hideTimeline` option for the table, with some exceptions + case GrapherTabOption.table: + // always show the timeline for charts that plot time on the x-axis + if (this.hasTimeDimension) return true + return !this.hideTimeline + default: return false }