Mike Daines

I recently released a new package as part of my Viz.js project. Viz.js wraps a WebAssembly build of Graphviz so you can use it in a web browser or with Node.js.

This package is called @viz-js/dot2svg, and it exports a single function that handles just the main use case of Viz.js, which is visualizing graphs written in the DOT language as SVG images.

Example usage:

import { dot2svg } from "@viz-js/dot2svg";

const svg = await dot2svg("digraph { a -> b }");

This is what svg looks like:

a a b b a->b

The dot2svg function is async because it needs to instantiate a WebAssembly module to use Graphviz, but it reuses the same module on subsequent calls. If you need more control over this or want to render other formats, it’s better to use the @viz-js/viz package.