Skip to content

Commit

Permalink
Fixing how d3 and plot are loaded in saveChart
Browse files Browse the repository at this point in the history
  • Loading branch information
nshiab committed Dec 13, 2024
1 parent 251426e commit a828ab7
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/dataviz/saveChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.).
Expand Down Expand Up @@ -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",
),
});
Expand Down

0 comments on commit a828ab7

Please sign in to comment.