Skip to content

Instantly share code, notes, and snippets.

@cmoog
Last active May 25, 2023 22:49
Show Gist options
  • Save cmoog/9ce7a9e297592f7762659d9ee86a7159 to your computer and use it in GitHub Desktop.
Save cmoog/9ce7a9e297592f7762659d9ee86a7159 to your computer and use it in GitHub Desktop.
Deno wrapper for using @observablehq/plot to generate SVG charts server-side
import { parseHTML } from "https://esm.sh/linkedom@0.14.25";
import * as ObservablePlot from "https://esm.sh/@observablehq/plot@0.6.7";
// @ts-ignore: bad type
const { document } = parseHTML(`<!DOCTYPE html><html lang="en"></html>`);
export const Plot: typeof ObservablePlot = {
...ObservablePlot,
plot: (options?: ObservablePlot.PlotOptions) => {
const elt = ObservablePlot.plot({ document, ...options });
elt.setAttribute("xmlns", "http://www.w3.org/2000/svg");
elt.setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
return elt.toString();
},
};
@cmoog
Copy link
Author

cmoog commented May 25, 2023

import { Plot } from "https://gist.githubusercontent.com/cmoog/9ce7a9e297592f7762659d9ee86a7159/raw/09e1e9f8356e25b7d86b5e65df9ae92bf15bfa43/denoplot.ts"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment