Skip to content

Commit

Permalink
add numeric or auto cell def
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann committed Oct 31, 2024
1 parent ba6ab35 commit 34a35c4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions explorer/GrapherGrammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import {
EnumCellDef,
Grammar,
IntegerCellDef,
NumericCellDef,
SlugDeclarationCellDef,
SlugsDeclarationCellDef,
StringCellDef,
UrlCellDef,
IndicatorIdsOrEtlPathsCellDef,
IndicatorIdOrEtlPathCellDef,
GrapherCellDef,
NumericOrAutoCellDef,
} from "../gridLang/GridLangConstants.js"

const toTerminalOptions = (keywords: string[]): CellDef[] => {
Expand Down Expand Up @@ -176,7 +176,7 @@ export const GrapherGrammar: Grammar<GrapherCellDef> = {
toGrapherObject: (value) => ({ yAxis: { canChangeScaleType: value } }),
},
yAxisMin: {
...NumericCellDef,
...NumericOrAutoCellDef,
keyword: "yAxisMin",
description: "Set the minimum value for the yAxis",
toGrapherObject: (value) => ({ yAxis: { min: value } }),
Expand Down
13 changes: 13 additions & 0 deletions gridLang/GridLangConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 34a35c4

Please sign in to comment.