Skip to content

Commit

Permalink
Merge pull request #3882 from owid/fix-svg-export-grapher-url
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelgerber authored Aug 19, 2024
2 parents bc9ba63 + 8906be9 commit d29f58f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions baker/GrapherBaker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from "@ourworldindata/utils"
import fs from "fs-extra"
import * as lodash from "lodash"
import { bakeGraphersToPngs } from "./GrapherImageBaker.js"
import { bakeGrapherToSvgAndPng } from "./GrapherImageBaker.js"
import {
OPTIMIZE_SVG_EXPORTS,
BAKED_BASE_URL,
Expand Down Expand Up @@ -397,7 +397,7 @@ const bakeGrapherPageAndVariablesPngAndSVGIfChanged = async (
const variableDataMedadataMap = new Map(
variableDataMetadata.map((item) => [item.metadata.id, item])
)
await bakeGraphersToPngs(
await bakeGrapherToSvgAndPng(
`${bakedSiteDir}/grapher/exports`,
grapher,
variableDataMedadataMap,
Expand Down
8 changes: 4 additions & 4 deletions baker/GrapherImageBaker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
grapherUrlToSlugAndQueryStr,
} from "./GrapherBakingUtils.js"
import pMap from "p-map"
import { BAKED_GRAPHER_URL } from "../settings/clientSettings.js"

interface SvgFilenameFragments {
slug: string
Expand All @@ -25,15 +26,13 @@ interface SvgFilenameFragments {
queryStr?: string
}

export async function bakeGraphersToPngs(
export async function bakeGrapherToSvgAndPng(
outDir: string,
jsonConfig: GrapherInterface,
vardata: MultipleOwidVariableDataDimensionsMap,
optimizeSvgs = false
) {
const grapher = new Grapher({ ...jsonConfig, manuallyProvideData: true })
grapher.isExportingToSvgOrPng = true
grapher.shouldIncludeDetailsInStaticExport = false
const grapher = initGrapherForSvgExport(jsonConfig)
grapher.receiveOwidData(vardata)
const outPath = path.join(outDir, grapher.slug as string)

Expand Down Expand Up @@ -132,6 +131,7 @@ export function initGrapherForSvgExport(
queryStr: string = ""
) {
const grapher = new Grapher({
bakedGrapherURL: BAKED_GRAPHER_URL,
...jsonConfig,
manuallyProvideData: true,
queryStr,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,8 @@ export class StaticCaptionedChart extends CaptionedChart {
@computed private get fonts(): React.ReactElement {
let origin = ""
try {
origin = new URL(this.manager.bakedGrapherURL!).origin
if (this.manager.bakedGrapherURL)
origin = new URL(this.manager.bakedGrapherURL).origin
} catch (e) {}
const css = `@import url(${origin}/fonts.css)`
return (
Expand Down

0 comments on commit d29f58f

Please sign in to comment.