-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing how d3 and plot are loaded in saveChart
- Loading branch information
Showing
1 changed file
with
5 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ import { chromium } from "playwright-chromium"; | |
import type { Data } from "@observablehq/plot"; | ||
import { readFileSync, writeFileSync } from "node:fs"; | ||
import { fileURLToPath } from "node:url"; | ||
import { dirname } from "node:path"; | ||
import { dirname, resolve } from "node:path"; | ||
|
||
/** | ||
* Saves an [Observable Plot](https://github.com/observablehq/plot) chart as an image file (`.png` or `.jpeg`). You can also save a SVG file (`.svg`), but only the main SVG element will be saved, not the other HTML elements (legend, title, etc.). | ||
|
@@ -48,16 +48,18 @@ export default async function saveChart( | |
|
||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = dirname(__filename); | ||
const d3Path = resolve(__dirname, "./imports/[email protected]"); | ||
const plotPath = resolve(__dirname, "./imports/[email protected]"); | ||
|
||
await page.addScriptTag({ | ||
content: readFileSync( | ||
`${__dirname}/imports/[email protected]`, | ||
d3Path, | ||
"utf-8", | ||
), | ||
}); | ||
await page.addScriptTag({ | ||
content: readFileSync( | ||
`${__dirname}/imports/[email protected]`, | ||
plotPath, | ||
"utf-8", | ||
), | ||
}); | ||
|