Is there a standard way to read and parse DOT graph files in javascript, ideally in way that will work nicely in d3?
Currently, the only thing I can think of doing is reading plain text and doing my own parsing. Hopefully this'd be reinventing the wheel though.
d3.text("graph.dot", function(error, dotGraph) {
....
)};
Same example, using latest version of graphlib-dot and dagre-d3.
Late to the party, but if you're still interested, here's a way to do it with the new d3-graphviz plug-in that I just released:
The question asks for a possibility to visualise
.dot
files einther injavascript
orD3js
. I think the solution from the highest rated answer will work for most of you.I was unhappy because of these 3 reasons:
lowdash
,dagre
andgraphlib
additionally toD3js
and is heavyweight.D3js
"friedly" data-structure.That's why I created an adapter which will basically allow you to use
.dot
files with any of thousands ofD3js
samples by changing just one statement. If you have someD3js
visualisation working on following data-structure:Just include following script and call
d3.dot
:instead of:
GitHub repository with code and examples
To get Graphviz DOT files rendered in Javascript, combine the graphlib-dot and dagre-d3 libraries.
The
graphlibDot.parse()
method takes a graph or digraph definition in DOT syntax and produces a graph object. ThedagreD3.Renderer.run()
method can then output this graph object to SVG.You can then use additional D3 methods to add functionality to the graph, retrieving additional node and edge attributes from the graphlib graph object as needed.
A trivial self-contained example is: