Spoiler: UseĀ Vizdom.devĀ to render DAGs written in the DOT language
As a software dev, Iāve occasionally worked with DAGs ā most of which involve visualizing them. In many cases, I found it difficult to get a quick rendering and found myself looking for tooling.
Fortunately, thereās the trustyĀ
Exceptā¦
- It doesnāt work well on the web*
- I need to install it
- It doesnāt manage DOT/GV files online
Considerations
*Okay,Ā technicallyĀ Graphviz can be compiled to WebAssembly, and a few talented folks managed to build a few neat projects such as dreampufāsĀ
For example, I want to store my graph inĀ
I could useĀ
Unfortunately, I have to translate DOT into the flavor of markdown that Mermaid requires. For smaller textual representations, I can use ChatGPT to convert them for me, but it frequently makes grammatical mistakes, and the graph will refuse to render ā making it unreliable as a source of automation.
Then there isĀ
The Problem
- I want to renderĀ programmaticallyĀ generated DOT outputs ā none of the tooling seems to help me achieve that goal.
- I want to embed links that render graphs.
- I want to store the rendering online for updates or to visually compare it with other graphs.
The Solution
Yup ā I built anĀ
ā¦And itās built entirely in Rust š¦ with many thanks toĀ
tl;drĀ ā a simple, purpose-built app to render DAGs online, fast
Minimizing edge crossings in graph generation, a recognized NP-hard challenge is key to creating visually appealing graphs. The team at Terrastruct has published an outstandingĀ
This version is particularly effective for rendering hierarchical graphs, leveraging the intricate complexities of this problem.
Rendering large DAGs (500+ nodes/edges) tends to be somewhat sluggish with Graphviz. Dagre + D3 (
I believe it is a good compromise for the kinds of attributes programmatically generated DOT will consume.
Vizdom Features
- š Blazing fast rendering
- š¾ Store graphs in links
- 0ļøā£ Zero dependencies and no installation required
Rendering Speed
Well, itās an apples-to-oranges comparison. Graphviz still producesĀ greatĀ visualizations and supports moreĀ
Yes, I know itās terrible to compare years of experience and tooling around the 30+ year streak that is Graphviz, but for my narrow use-case, it is crazy fast. Here are some wall times on my M1 Macbook Pro for renderingĀ
- Native Graphviz: ~30 seconds
- Chrome (WASM) Graphviz: crashes*
- Chrome (Javascript) DagreJS: ~10 seconds
- Chrome (WASM)Ā
Vizdom :Ā ~1 second
Check out the link here which will render the graph in your browser. Otherwise, this is what youād expect to see:
* It crashes because the emscripten flag, ALLOW_MEMORY_GROWTH=1
, is not set, therefore limiting the total memory to 16MB. This can be fixed, but I have not found an online project that can handle the graph in question.
Store Graphs in Links
Youāll notice when you make any changes to the DOT file, the URL immediately updates a few query parameters to store the graph and layout options, allowing you to always reference a copy of your data just by storing the link!
There is a catch ā large-ish graphs tend to make the URI too large for AWS (whereĀ
Iām currently working on a solution to handle larger graphs, but in the meantime, Iāve included a few ways to persist and store graphs:
- Copy an embeddable link that automatically renders a view that maximizes the graph.
- Copy an iframe snippet to embed in any application that supports rendering them.
- Or simply download the rendered SVG.
Hereās an example of what the editor view looks like of theĀ
Diff View
Occasionally, I found myself trying to compare two graphs that Iāve generated, so while I was at it, I added aĀ
Color Legend:
- Red: Deleted
- Orange: Modified
- Green: Added
Hereās a few snaps:
Click me: changing a node ID from āeā to āfā
Click me: adding ācluster=trueā
Future Direction
[1]: E. R. Gansner, E. Koutsofios, S. C. North and K. . -P. Vo, āA technique for drawing directed graphs,ā in IEEE Transactions on Software Engineering, vol. 19, no. 3, pp. 214ā230, March 1993, doi: 10.1109/32.221135.
Also published here