Last active
May 25, 2023 22:49
-
-
Save cmoog/9ce7a9e297592f7762659d9ee86a7159 to your computer and use it in GitHub Desktop.
Deno wrapper for using @observablehq/plot to generate SVG charts server-side
This file contains hidden or 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
import { parseHTML } from "https://esm.sh/[email protected]"; | |
import * as ObservablePlot from "https://esm.sh/@observablehq/[email protected]"; | |
// @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(); | |
}, | |
}; |
Author
cmoog
commented
May 25, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment