Skip to content

Commit

Permalink
enhance: centralize columnsToIgnore
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelgerber authored and danyx23 committed Oct 10, 2024
1 parent 0615d5d commit 6195555
Showing 1 changed file with 13 additions and 22 deletions.
35 changes: 13 additions & 22 deletions functions/_common/grapherRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ async function initGrapher(
return grapher
}

function assembleMetadata(grapher: Grapher, searchParams: URLSearchParams) {
const getColumnsForMetadata = (grapher: Grapher) => {
const columnsToIgnore = new Set(
[
OwidTableSlugs.entityId,
Expand All @@ -330,12 +330,19 @@ function assembleMetadata(grapher: Grapher, searchParams: URLSearchParams) {
].map((slug) => slug.toString())
)

const columnsToGet = grapher.inputTable.columnSlugs.filter(
const colsToGet = grapher.inputTable.columnSlugs.filter(
(col) => !columnsToIgnore.has(col)
)

return grapher.inputTable.getColumns(colsToGet)
}

function assembleMetadata(grapher: Grapher, searchParams: URLSearchParams) {
const useShortNames = searchParams.get("useColumnShortNames") === "true"
console.log("useShortNames", useShortNames)

const metadataCols = getColumnsForMetadata(grapher)

const columns: [
string,
{
Expand Down Expand Up @@ -366,7 +373,7 @@ function assembleMetadata(grapher: Grapher, searchParams: URLSearchParams) {
>[]
shortName: string
},
][] = grapher.inputTable.getColumns(columnsToGet).map((col) => {
][] = metadataCols.map((col) => {
console.log("mapping col", col.name)
const {
descriptionShort,
Expand Down Expand Up @@ -630,26 +637,10 @@ export async function fetchReadmeForGrapher(
}

function assembleReadme(grapher: Grapher): string {
const columnsToIgnore = new Set(
[
OwidTableSlugs.entityId,
OwidTableSlugs.time,
OwidTableSlugs.entityColor,
OwidTableSlugs.entityName,
OwidTableSlugs.entityCode,
OwidTableSlugs.year,
OwidTableSlugs.day,
].map((slug) => slug.toString())
)

const columnsToGet = grapher.inputTable.columnSlugs.filter(
(col) => !columnsToIgnore.has(col)
)

const columns = grapher.inputTable.getColumns(columnsToGet)

return constructReadme(grapher, columns)
const metadataCols = getColumnsForMetadata(grapher)
return constructReadme(grapher, metadataCols)
}

async function fetchAndRenderGrapherToSvg(
identifier: GrapherIdentifier,
options: ImageOptions,
Expand Down

0 comments on commit 6195555

Please sign in to comment.