Hi, I’m the maintainer of Viz.js, a project that builds Graphviz with Emscripten and provides a wrapper for using it in JavaScript. The project was inactive for a while, but I started working on it again this year.
Viz.js will render graphs written in DOT syntax, but that’s often inconvenient if you want to render something based on model objects in your program, since you need to build a string and worry about quoting, etc. Generally wrapper libraries offer a richer interface, so you can create a graph object, add nodes and edges, and then render it. I’d like to provide similar functionality, but I don’t want Viz.js to return a graph object that has to be manually closed by a user of the library.
The direction I’ve taken so far is to accept plain JavaScript objects (which could be serialized as JSON) as input for rendering. I’m curious to know what people think of the schema I’ve come up with.
Commit that adds this to Viz.js
Here’s an example of what it looks like in code:
viz.render({
defaultAttributes: {
node: { shape: "circle" }
},
nodes: [
{
name: "a",
attributes: { label: "A", color: "red" }
}
],
edges: [
{ tail: "a", head: "b" }
],
subgraphs: [
{
name: "cluster_1",
nodes: [
{
name: "b",
attributes: { label: "B", color: "blue" }
}
]
}
]
});
Which should be equivalent to this in DOT:
digraph {
node [shape=circle];
a [label=A, color=red];
a -> b;
subgraph cluster_1 {
b [label=B, color=blue];
}
}