Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ (explorer) allow to pass "auto" as yAxisMin #4102

Merged
merged 1 commit into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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