I am trying to create a tree structure with graphviz. I am open to either writing the graphviz code by hand or using the ruby-graphviz gem for ruby. Given the below picture can anyone provide any insight on the necessary code? Ignore that the lines are not straight…they should be when graphviz builds the graph. I am open to having dots/points when lines intersect as well.
I have played with ruby-graphviz and the family tree class…this is getting me part of the way there but I really need all lines to be straight and intersect at right angles and the out-of-the-box code doesn’t seem to do that.
The code should be generic enough to allow for the “C” box to have children as well and for there also to be more children under “A”.
The colors are irrelevant…the examples can exclude any coloring.
http://docs.google.com/drawings/pub?id=1lUTfgKP_LN0x7C3ItbsFjfLBuDTL84AtmoaW7YFn32Y&w=1036&h=713
As far as I know this requires a little work-around; I will only do it in Graphviz DOT language. I give you the solution first, then provide some explanations of how you can extend it.
This is the resulting figure:
This is the Graphviz code producing the figure:
If you put it in a file named
inputfile.dotyou can get the resulting image file by using the commandneato -Tpng inputfile.dot > outfile.png.Now a couple of comments on how it works: The code building the tree with
A, B, C, D, E, Item1, Item2, Item3is straightforward (the attributes merely set the colors and box styles). The trick to get the lines straight and orthogonal consists of 1) adding invisible nodes with zero size to the graph, and 2) positioning all objects in absolute coordinates on the canvas. The auxiliary nodesD1, D2, D3, D4, D5, D6, D7are needed for step 1) and thepos="x,y!"options are needed for step 2). Note, that you need the!sign at the end of theposcommand since otherwise the positions would not be considered final and the layout would still get changed.You can add additional nodes by first positioning a new node (by using the code for the nodes
A ... Item3as a template), adding an invisible, auxiliary node (withpossuch that all connections to and from it are orthogonal) and then adding the connection to the graph via<StartingNode> -- <AuxiliaryNode> -- <NewNode>.