Skip to content

Commit

Permalink
🔨 incorporate PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
danyx23 committed Oct 24, 2024
1 parent b22a10f commit 19e2195
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 41 deletions.
1 change: 1 addition & 0 deletions functions/_common/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ export const extensions = {
readme: ".readme.md",
zip: ".zip",
}
export type Etag = string
2 changes: 1 addition & 1 deletion functions/_common/fetchMetadataForGrapher.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Grapher } from "@ourworldindata/grapher"
import { OwidColumnDef } from "@ourworldindata/types"
import { StatusError } from "itty-router"
import { createZip } from "littlezipper"
import { createZip, File } from "littlezipper"
import { assembleMetadata, getColumnsForMetadata } from "./metadataTools.js"
import { Env } from "./env.js"
import { GrapherIdentifier, initGrapher } from "./grapherTools.js"
Expand Down
3 changes: 0 additions & 3 deletions functions/_common/grapherRenderer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { svg2png, initialize as initializeSvg2Png } from "svg2png-wasm"
import { TimeLogger } from "./timeLogger"
import { png } from "itty-router"
import { File } from "littlezipper"

import svg2png_wasm from "../../node_modules/svg2png-wasm/svg2png_wasm_bg.wasm"

Expand All @@ -19,8 +18,6 @@ declare global {
var window: any
}

export type Etag = string

export const grapherBaseUrl = "https://ourworldindata.org/grapher"

// Lots of defaults; these are mostly the same as they are in owid-grapher.
Expand Down
48 changes: 17 additions & 31 deletions functions/_common/metadataTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ import {
getCitationLong,
} from "@ourworldindata/utils"

interface MetadataColumn {
titleShort: string
titleLong: string
descriptionShort: string
descriptionKey: string[]
descriptionProcessing: string
shortUnit: string
unit: string
timespan: string
tolerance: number
type: string
conversionFactor: number
owidVariableId: number
shortName: string
}

export const getColumnsForMetadata = (grapher: Grapher) => {
const columnsToIgnore = new Set(
[
Expand Down Expand Up @@ -40,37 +56,7 @@ export function assembleMetadata(

const metadataCols = getColumnsForMetadata(grapher)

const columns: [
string,
{
title: string
titleProducer: string
titleVariant: string
descriptionShort: string
descriptionFromProducer: string
descriptionKey: string[]
descriptionProcessing: string
shortUnit: string
unit: string
timespan: string
tolerance: number
type: string
conversionFactor: number
owidVariableId: number
catalogPath: string
sources: Partial<
Pick<
OwidOrigin,
| "attribution"
| "attributionShort"
| "description"
| "urlDownload"
| "urlMain"
>
>[]
shortName: string
},
][] = metadataCols.map((col) => {
const columns: [string, MetadataColumn][] = metadataCols.map((col) => {
console.log("mapping col", col.name)
const {
descriptionShort,
Expand Down
4 changes: 2 additions & 2 deletions functions/_common/reusableHandlers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Env } from "./env.js"
import { Etag, fetchAndRenderGrapher } from "./grapherRenderer.js"
import { Env, Etag } from "./env.js"
import { fetchAndRenderGrapher } from "./grapherRenderer.js"
import { GrapherIdentifier } from "./grapherTools.js"

export async function handleThumbnailRequest(
Expand Down
3 changes: 1 addition & 2 deletions functions/grapher/[slug].ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Env, extensions } from "../_common/env.js"
import { Etag } from "../_common/grapherRenderer.js"
import { Env, extensions, Etag } from "../_common/env.js"
import {
fetchCsvForGrapher,
fetchMetadataForGrapher,
Expand Down
3 changes: 1 addition & 2 deletions functions/grapher/by-uuid/[uuid].ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Env } from "../../_common/env.js"
import { extensions } from "../../_common/env.js"
import { Env, extensions } from "../../_common/env.js"
import { fetchGrapherConfig } from "../../_common/grapherTools.js"
import { IRequestStrict, Router, error, StatusError } from "itty-router"
import { handleThumbnailRequest } from "../../_common/reusableHandlers.js"
Expand Down

0 comments on commit 19e2195

Please sign in to comment.