Skip to content

Commit

Permalink
🎉 make line/slope switching available to authors / TAS-720 (#4207)
Browse files Browse the repository at this point in the history
Make line/slope chart switching available to authors by:
- adding a Slope chart toggle in the admin
- adding 'LineChart SlopeChart' as an option for the `type` column

I considered renaming the `type` column in explorers to `chartTypes` but other than consistency there is little benefit.
  • Loading branch information
sophiamersmann authored Dec 11, 2024
1 parent b59dbca commit db3e296
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
34 changes: 34 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 @@ -414,6 +415,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 +465,13 @@ export class EditorBasicTab<
(grapher.hasMapTab = shouldHaveMapTab)
}
/>
{grapher.isLineChart && (
<Toggle
label="Slope chart"
value={grapher.hasSlopeChart}
onValue={this.toggleSecondarySlopeChart}
/>
)}
</FieldsRow>
</Section>
{!isIndicatorChart && (
Expand Down
2 changes: 1 addition & 1 deletion packages/@ourworldindata/explorer/src/ExplorerProgram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ interface ExplorerGrapherInterface extends GrapherInterface {
relatedQuestionText?: string
relatedQuestionUrl?: string
mapTargetTime?: number
type?: GrapherChartType | "None"
type?: GrapherChartType | "LineChart SlopeChart" | "None"
}

const ExplorerRootDef: CellDef = {
Expand Down
4 changes: 3 additions & 1 deletion packages/@ourworldindata/explorer/src/GrapherGrammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
ColorSchemeName,
FacetAxisDomain,
FacetStrategy,
GRAPHER_CHART_TYPES,
GRAPHER_TAB_OPTIONS,
MissingDataStrategy,
StackMode,
Expand Down Expand Up @@ -66,10 +67,11 @@ export const GrapherGrammar: Grammar<GrapherCellDef> = {
description: `The type of chart to show such as LineChart or ScatterPlot. If set to None, then the chart tab is hidden.`,
terminalOptions: toTerminalOptions([
...ALL_GRAPHER_CHART_TYPES,
`${GRAPHER_CHART_TYPES.LineChart} ${GRAPHER_CHART_TYPES.SlopeChart}`,
"None",
]),
toGrapherObject: (value) => ({
chartTypes: value === "None" ? [] : [value],
chartTypes: value === "None" ? [] : value.split(" "),
}),
},
grapherId: {
Expand Down

0 comments on commit db3e296

Please sign in to comment.