Skip to content

Commit

Permalink
🐛 (slope) fix tabs for line chart that turned into discrete bar
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann committed Nov 22, 2024
1 parent 9750e7f commit c5a7ff0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export interface CaptionedChartManager
isOnMapTab?: boolean
isOnTableTab?: boolean
activeChartType?: GrapherChartType
isLineChartThatTurnedIntoDiscreteBar?: boolean
isLineChartThatTurnedIntoDiscreteBarActive?: boolean
showEntitySelectionToggle?: boolean
isExportingForSocialMedia?: boolean

Expand Down Expand Up @@ -197,7 +197,7 @@ export class CaptionedChart extends React.Component<CaptionedChartProps> {
if (manager.isOnTableTab) return undefined
if (manager.isOnMapTab) return GRAPHER_MAP_TYPE
if (manager.isOnChartTab) {
return manager.isLineChartThatTurnedIntoDiscreteBar
return manager.isLineChartThatTurnedIntoDiscreteBarActive
? GRAPHER_CHART_TYPES.DiscreteBar
: manager.activeChartType
}
Expand Down
16 changes: 12 additions & 4 deletions packages/@ourworldindata/grapher/src/controls/ContentSwitchers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,11 @@ function TabIcon({
case GRAPHER_TAB_NAMES.WorldMap:
return <FontAwesomeIcon icon={faEarthAmericas} />
default:
const chartIcon = isLineChartThatTurnedIntoDiscreteBar
? chartIcons[GRAPHER_CHART_TYPES.DiscreteBar]
: chartIcons[tab]
const chartIcon =
tab === GRAPHER_TAB_NAMES.LineChart &&
isLineChartThatTurnedIntoDiscreteBar
? chartIcons[GRAPHER_CHART_TYPES.DiscreteBar]
: chartIcons[tab]
return chartIcon
}
}
Expand All @@ -192,9 +194,15 @@ function makeTabLabelText(
if (tab === GRAPHER_TAB_NAMES.WorldMap) return "Map"
if (!options.hasMultipleChartTypes) return "Chart"

if (
tab === GRAPHER_TAB_NAMES.LineChart &&
options.isLineChartThatTurnedIntoDiscreteBar
)
return "Bar"

switch (tab) {
case GRAPHER_TAB_NAMES.LineChart:
return options.isLineChartThatTurnedIntoDiscreteBar ? "Bar" : "Line"
return "Line"
case GRAPHER_TAB_NAMES.SlopeChart:
return "Slope"

Expand Down
8 changes: 7 additions & 1 deletion packages/@ourworldindata/grapher/src/core/Grapher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1943,7 +1943,7 @@ export class Grapher

@computed
get typeExceptWhenLineChartAndSingleTimeThenWillBeBarChart(): GrapherChartType {
return this.isLineChartThatTurnedIntoDiscreteBar
return this.isLineChartThatTurnedIntoDiscreteBarActive
? GRAPHER_CHART_TYPES.DiscreteBar
: this.activeChartType ?? GRAPHER_CHART_TYPES.LineChart
}
Expand Down Expand Up @@ -2002,6 +2002,12 @@ export class Grapher
return closestMinTime !== undefined && closestMinTime === closestMaxTime
}

@computed get isLineChartThatTurnedIntoDiscreteBarActive(): boolean {
return (
this.isOnLineChartTab && this.isLineChartThatTurnedIntoDiscreteBar
)
}

@computed get isOnLineChartTab(): boolean {
return this.activeChartType === GRAPHER_CHART_TYPES.LineChart
}
Expand Down

0 comments on commit c5a7ff0

Please sign in to comment.