diff --git a/explorer/GrapherGrammar.ts b/explorer/GrapherGrammar.ts index ecc953d3779..1397ee4c328 100644 --- a/explorer/GrapherGrammar.ts +++ b/explorer/GrapherGrammar.ts @@ -15,7 +15,6 @@ import { EnumCellDef, Grammar, IntegerCellDef, - NumericCellDef, SlugDeclarationCellDef, SlugsDeclarationCellDef, StringCellDef, @@ -23,6 +22,7 @@ import { IndicatorIdsOrEtlPathsCellDef, IndicatorIdOrEtlPathCellDef, GrapherCellDef, + NumericOrAutoCellDef, } from "../gridLang/GridLangConstants.js" const toTerminalOptions = (keywords: string[]): CellDef[] => { @@ -176,7 +176,7 @@ export const GrapherGrammar: Grammar = { toGrapherObject: (value) => ({ yAxis: { canChangeScaleType: value } }), }, yAxisMin: { - ...NumericCellDef, + ...NumericOrAutoCellDef, keyword: "yAxisMin", description: "Set the minimum value for the yAxis", toGrapherObject: (value) => ({ yAxis: { min: value } }), diff --git a/gridLang/GridLangConstants.ts b/gridLang/GridLangConstants.ts index 9259535b7cc..75ba1e15a2e 100644 --- a/gridLang/GridLangConstants.ts +++ b/gridLang/GridLangConstants.ts @@ -102,6 +102,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",