Skip to content

Commit

Permalink
✨ (explorer) allow to pass "auto" as yAxisMin (#4102)
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann authored Nov 1, 2024
1 parent 0db4524 commit 6567b91
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
4 changes: 3 additions & 1 deletion explorer/Explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
GrapherInterface,
GrapherQueryParams,
GrapherTabOption,
AxisMinMaxValueStr,
} from "@ourworldindata/types"
import {
OwidTable,
Expand Down Expand Up @@ -459,7 +460,8 @@ export class Explorer
} = this.explorerProgram.grapherConfig

grapher.yAxis.canChangeScaleType = yScaleToggle
grapher.yAxis.min = yAxisMin
grapher.yAxis.min =
yAxisMin === AxisMinMaxValueStr.auto ? Infinity : yAxisMin
if (facetYDomain) {
grapher.yAxis.facetDomain = facetYDomain
}
Expand Down
3 changes: 2 additions & 1 deletion explorer/ExplorerProgram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
SubNavId,
FacetAxisDomain,
GrapherInterface,
AxisMinMaxValueStr,
} from "@ourworldindata/types"
import {
CoreTable,
Expand Down Expand Up @@ -56,7 +57,7 @@ interface ExplorerGrapherInterface extends GrapherInterface {
colorVariableId?: string
sizeVariableId?: string
yScaleToggle?: boolean
yAxisMin?: number
yAxisMin?: number | AxisMinMaxValueStr.auto
facetYDomain?: FacetAxisDomain
relatedQuestionText?: string
relatedQuestionUrl?: string
Expand Down
4 changes: 2 additions & 2 deletions explorer/GrapherGrammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
EnumCellDef,
Grammar,
IntegerCellDef,
NumericCellDef,
NumericOrAutoCellDef,
SlugDeclarationCellDef,
SlugsDeclarationCellDef,
StringCellDef,
Expand Down Expand Up @@ -149,7 +149,7 @@ export const GrapherGrammar: Grammar = {
description: "Set to 'true' if the user can change the yAxis",
},
yAxisMin: {
...NumericCellDef,
...NumericOrAutoCellDef,
keyword: "yAxisMin",
description: "Set the minimum value for the yAxis",
},
Expand Down
13 changes: 13 additions & 0 deletions gridLang/GridLangConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ export const NumericCellDef: CellDef = {
parse: (value: any) => parseFloat(value),
}

export const NumericOrAutoCellDef: CellDef = {
keyword: "",
cssClass: "NumericCellDef",
description: "",
regex: /^(-?\d+\.?\d*|auto)$/,
requirementsDescription: `Must be a number or "auto"`,
valuePlaceholder: "98.6",
parse: (value: any) => {
if (value === "auto") return "auto"
return parseFloat(value)
},
}

export const IntegerCellDef: CellDef = {
keyword: "",
cssClass: "IntegerCellDef",
Expand Down

0 comments on commit 6567b91

Please sign in to comment.