Skip to content

Commit

Permalink
🎉 (admin) add slope chart toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann committed Nov 26, 2024
1 parent 200c379 commit 7a8e3d9
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions adminSiteClient/EditorBasicTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
StackMode,
ALL_GRAPHER_CHART_TYPES,
GrapherChartType,
GRAPHER_CHART_TYPES,
} from "@ourworldindata/types"
import {
DimensionSlot,
Expand Down Expand Up @@ -367,6 +368,10 @@ export class EditorBasicTab<
? []
: [value as GrapherChartType]

if (grapher.isLineChart) {
this.addSlopeChart()
}

if (grapher.isMarimekko) {
grapher.hideRelativeToggle = false
grapher.stackMode = StackMode.relative
Expand Down Expand Up @@ -414,6 +419,32 @@ export class EditorBasicTab<
]
}

private addSlopeChart(): void {
const { grapher } = this.props.editor
if (grapher.hasSlopeChart) return
grapher.chartTypes = [
...grapher.chartTypes,
GRAPHER_CHART_TYPES.SlopeChart,
]
}

private removeSlopeChart(): void {
const { grapher } = this.props.editor
grapher.chartTypes = grapher.chartTypes.filter(
(type) => type !== GRAPHER_CHART_TYPES.SlopeChart
)
}

@action.bound toggleSecondarySlopeChart(
shouldHaveSlopeChart: boolean
): void {
if (shouldHaveSlopeChart) {
this.addSlopeChart()
} else {
this.removeSlopeChart()
}
}

render() {
const { editor } = this.props
const { grapher } = editor
Expand All @@ -438,6 +469,13 @@ export class EditorBasicTab<
(grapher.hasMapTab = shouldHaveMapTab)
}
/>
{grapher.isLineChart && (
<Toggle
label="Slope chart"
value={grapher.hasSlopeChart}
onValue={this.toggleSecondarySlopeChart}
/>
)}
</FieldsRow>
</Section>
{!isIndicatorChart && (
Expand Down

0 comments on commit 7a8e3d9

Please sign in to comment.