(Visual) C++ world. I have a tree structure, want to visualize it. More specifically:
I have a tree data. I want the library that processes this data and computes coordinates (in any logical coordinate space, say 2000×2000 logical pixels) for each nodes, AND for each lines connecting them. Line connecting the two nodes might not be a simple straight line, it might be curve or some sort of path consisting of straight line segments. Ideally I’d like the line defining path to be calculated for the given tree nodes’ coordinates as well, in case the user will drag and rearrange the nodes.
Shortly, I need the library that will compute all the necessary geometrical coordinates for me, for the given graph. Then I’ll use these coordinates to draw the graph as I wish, using GDI.
I’ve heard of Graphviz, dot-language, and such. But I’m not sure whether it (or its alternatives like OGDF or igraph) can do what I want. The idea I want to accomplish is to render the graph myself, but need the assistance in generating coordinates. Also user must be able to reposition the nodes, so the re-computation of line path that connects rearranged nodes must be possible, so that e.g. lines do not cross any existing nodes.
Yes, graphviz can do this.
Layout a directed graph
Let’s say you have the following graph in
tree.gv:dotcan lay out this graph:dot tree.gvwhich results inAll the coordinates can be found in the output. If you need even more details on how to draw the graph, you may try using the
xdotformat:dot -Txdot tree.gvDetailed information about this format can be found on the graphviz web site.
Layout only edges / recompute edges
You may use one of the above outputs, modify positions of any nodes, and use it as input for the following command:
This will recompute only the edges (more information on neato dot and neato options can be found on their manual pages).
Below you can see an example of an unmodified and a modified layout – I changed positions for the b and g nodes.
Automatic layout:
Modified layout: