Created
October 16, 2024 03:21
-
-
Save bvarberg/f5adb11efd09848f0edec44df947cf0f to your computer and use it in GitHub Desktop.
Render dot/graphviz within a Deno Jupyter notebook
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 { toStream } from "npm:ts-graphviz/adapter"; | |
import { toText } from "jsr:@std/streams"; | |
/** | |
* Creates an object from `dot` input that can be displayed in a Jupyter | |
* notebook as an SVG. | |
*/ | |
export class Graph { | |
dot: string; | |
constructor(dot: string) { | |
this.dot = dot; | |
} | |
async [Deno.jupyter.$display]() { | |
const svg = await toStream(this.dot).then(toText); | |
return { | |
"text/plain": this.dot, | |
"image/svg+xml": svg, | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment