diff --git a/explorer/Explorer.tsx b/explorer/Explorer.tsx index 73cccbedd14..d79e638478d 100644 --- a/explorer/Explorer.tsx +++ b/explorer/Explorer.tsx @@ -9,6 +9,7 @@ import { GrapherInterface, GrapherQueryParams, GrapherTabOption, + AxisMinMaxValueStr, } from "@ourworldindata/types" import { OwidTable, @@ -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 } diff --git a/explorer/ExplorerProgram.ts b/explorer/ExplorerProgram.ts index 8a73ffa4cfb..c86e788378e 100644 --- a/explorer/ExplorerProgram.ts +++ b/explorer/ExplorerProgram.ts @@ -7,6 +7,7 @@ import { SubNavId, FacetAxisDomain, GrapherInterface, + AxisMinMaxValueStr, } from "@ourworldindata/types" import { CoreTable, @@ -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 diff --git a/explorer/GrapherGrammar.ts b/explorer/GrapherGrammar.ts index c9f51a291e8..e1027608e43 100644 --- a/explorer/GrapherGrammar.ts +++ b/explorer/GrapherGrammar.ts @@ -15,7 +15,7 @@ import { EnumCellDef, Grammar, IntegerCellDef, - NumericCellDef, + NumericOrAutoCellDef, SlugDeclarationCellDef, SlugsDeclarationCellDef, StringCellDef, @@ -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", }, diff --git a/gridLang/GridLangConstants.ts b/gridLang/GridLangConstants.ts index 1fa69f782ab..62a461d7966 100644 --- a/gridLang/GridLangConstants.ts +++ b/gridLang/GridLangConstants.ts @@ -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",