From 4a2f89b3b045fe21ae1ff8e4723008e23145e67e Mon Sep 17 00:00:00 2001 From: Sophia Mersmann Date: Wed, 8 Jan 2025 14:07:43 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=89=20support=20disconnecting=20lines?= =?UTF-8?q?=20in=20explorers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../explorer/src/ColumnGrammar.ts | 9 +++++++- .../explorer/src/ExplorerProgram.ts | 22 +++++++++++++------ .../src/gridLang/GridLangConstants.ts | 4 ++++ 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/packages/@ourworldindata/explorer/src/ColumnGrammar.ts b/packages/@ourworldindata/explorer/src/ColumnGrammar.ts index 1130cce7e49..3645f3a6137 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 fecb5b2e4b6..6fb381e44c2 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 2dbc3d3909e..efd835c63d6 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[]