Skip to content

Instantly share code, notes, and snippets.

@bvarberg
Created October 16, 2024 03:21
Show Gist options
  • Save bvarberg/f5adb11efd09848f0edec44df947cf0f to your computer and use it in GitHub Desktop.
Save bvarberg/f5adb11efd09848f0edec44df947cf0f to your computer and use it in GitHub Desktop.
Render dot/graphviz within a Deno Jupyter notebook
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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