diff --git a/packages/@ourworldindata/explorer/src/ColumnGrammar.ts b/packages/@ourworldindata/explorer/src/ColumnGrammar.ts index 1130cce7e4..3645f3a613 100644 --- a/packages/@ourworldindata/explorer/src/ColumnGrammar.ts +++ b/packages/@ourworldindata/explorer/src/ColumnGrammar.ts @@ -7,6 +7,7 @@ import { import { ToleranceStrategy } from "@ourworldindata/utils" import { BooleanCellDef, + ColumnCellDef, EnumCellDef, EtlPathCellDef, Grammar, @@ -17,7 +18,7 @@ import { UrlCellDef, } from "./gridLang/GridLangConstants.js" -export const ColumnGrammar: Grammar = { +export const ColumnGrammar: Grammar = { variableId: { ...IntegerCellDef, keyword: "variableId", @@ -206,4 +207,10 @@ export const ColumnGrammar: Grammar = { " Example: one,#ccc,uno; two,,dos", ].join("\n"), }, + plotMarkersOnlyInLineChart: { + ...BooleanCellDef, + keyword: "plotMarkersOnlyInLineChart", + description: "Should data points be connected by a line?", + display: true, + }, } as const diff --git a/packages/@ourworldindata/explorer/src/ExplorerProgram.ts b/packages/@ourworldindata/explorer/src/ExplorerProgram.ts index fecb5b2e4b..6fb381e44c 100644 --- a/packages/@ourworldindata/explorer/src/ExplorerProgram.ts +++ b/packages/@ourworldindata/explorer/src/ExplorerProgram.ts @@ -533,13 +533,21 @@ const parseColumnDefs = (block: string[][]): OwidColumnDef[] => { "Keep only column defs with a slug or variable id" ) return columnsTable.rows.map((row) => { - // ignore slug if variable id is given - if ( - row.owidVariableId && - isNotErrorValue(row.owidVariableId) && - row.slug - ) - delete row.slug + // ignore slug if a variable id is given + const hasValidVariableId = + row.owidVariableId && isNotErrorValue(row.owidVariableId) + if (hasValidVariableId && row.slug) delete row.slug + + for (const field in row) { + const cellDef = ColumnGrammar[field] + if (cellDef?.display) { + // move field into 'display' object + row.display = row.display || {} + row.display[field] = row[field] + delete row[field] + } + } + return trimAndParseObject(row, ColumnGrammar) }) } diff --git a/packages/@ourworldindata/explorer/src/gridLang/GridLangConstants.ts b/packages/@ourworldindata/explorer/src/gridLang/GridLangConstants.ts index 2dbc3d3909..efd835c63d 100644 --- a/packages/@ourworldindata/explorer/src/gridLang/GridLangConstants.ts +++ b/packages/@ourworldindata/explorer/src/gridLang/GridLangConstants.ts @@ -38,6 +38,10 @@ export interface GrapherCellDef extends CellDef { toGrapherObject: (value: any) => GrapherInterface // map to a partial config that is a valid GrapherInterface } +export interface ColumnCellDef extends CellDef { + display?: boolean +} + export interface ParsedCell { errorMessage?: string cssClasses?: string[]