Skip to content

Commit

Permalink
🎉 support disconnecting lines in explorers
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann committed Jan 9, 2025
1 parent 8ae80bd commit 4a2f89b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
9 changes: 8 additions & 1 deletion packages/@ourworldindata/explorer/src/ColumnGrammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import { ToleranceStrategy } from "@ourworldindata/utils"
import {
BooleanCellDef,
ColumnCellDef,
EnumCellDef,
EtlPathCellDef,
Grammar,
Expand All @@ -17,7 +18,7 @@ import {
UrlCellDef,
} from "./gridLang/GridLangConstants.js"

export const ColumnGrammar: Grammar = {
export const ColumnGrammar: Grammar<ColumnCellDef> = {
variableId: {
...IntegerCellDef,
keyword: "variableId",
Expand Down Expand Up @@ -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
22 changes: 15 additions & 7 deletions packages/@ourworldindata/explorer/src/ExplorerProgram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down

0 comments on commit 4a2f89b

Please sign in to comment.