Skip to content

Commit

Permalink
🐛 (stacked bar/area) show timeline on table tab
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann committed May 6, 2024
1 parent 7d5fb2c commit 667805c
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions packages/@ourworldindata/grapher/src/core/Grapher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 667805c

Please sign in to comment.