# Anybody know of any tree/graph drawing software that can link edges?

**URL:** <https://boards.straightdope.com/t/anybody-know-of-any-tree-graph-drawing-software-that-can-link-edges/441174>\
**Category:** Factual Questions\
**Created:** [March 12, 2008, 11:22pm UTC](https://boards.straightdope.com/t/anybody-know-of-any-tree-graph-drawing-software-that-can-link-edges/441174 "2008-03-12T23:22:17Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![chorpler](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/chorpler/32/2888_2.png) [@chorpler](https://boards.straightdope.com/u/chorpler)\
**Post date:** [March 12, 2008, 11:22pm UTC](https://boards.straightdope.com/t/anybody-know-of-any-tree-graph-drawing-software-that-can-link-edges/441174/1 "2008-03-12T23:22:17Z")

</div>

In my artificial intelligence class, we draw a lot of trees and graphs to represent states and searches and the like. Some of them, such as graphs or trees\* for games using the MINIMAX algorithm or alpha-beta pruning, have some subtrees where the branches need to be AND-ed together; the resulting subtrees are called AND-subtrees, and the entire data structure is then referred to, logically enough, as an AND/OR tree.

My professor draws the AND-subtrees with arcs linking all of the edges to the nodes that should be AND-ed together. See [this screenshot](http://www.hplx.net/and-or_tree.png) for an example; this is for a hypothetical game, and the AND and ORs work in a straightforward manner: in order for node B to represent a win, nodes E, F, and G must all be wins (since they have to be ANDed together), but the root node A is a win if any of nodes B, C, or D are a winner (one or more, in other words – since they’re ORed together).

So far, I haven’t been able to find any kind of tree or graph drawing software that lets me link subtree edges with the arcs (or straight lines, or anything at all) that represent that this particular subtree is an AND-subtree. So far I’ve just been copying the trees over to Word and drawing the arcs in manually, but that’s very time consuming and annoying.

So … does anybody know of any tree/graph drawing software that will let me link edges together like that? I’ve tried a couple of freeware programs such as [uDraw](http://www.informatik.uni-bremen.de/uDrawGraph/en/index.html) (formerly known as daVinci) and [TreeForm](http://www.ece.ubc.ca/~donaldd/treeform.htm), but I can’t find anything that will join edges.

Any help is greatly appreciated!

- I’m going to just say “trees” from now on, but I need something that can draw graphs too … although I guess a tree is just a particular kind of graph, so maybe I should say graph instead. Hmmm … no, I’ll stick with saying trees.

---

<div class="post-metadata">

**Author:** ![friedo](https://avatars.discourse-cdn.com/v4/letter/f/8edcca/32.png) [@friedo](https://boards.straightdope.com/u/friedo)\
**Post date:** [March 12, 2008, 11:31pm UTC](https://boards.straightdope.com/t/anybody-know-of-any-tree-graph-drawing-software-that-can-link-edges/441174/2 "2008-03-12T23:31:09Z")

</div>

[GraphViz](http://www.graphviz.org/) is the shiznit for drawing directed and undirected graphs. You just provide a list of nodes, edges and labels in the proper syntax, and GraphViz will spit out an image.

There are various front-end programs that provide a nicer interface to generate the GraphViz code, but I’ve never used them.

ETA: I’m unsure if GraphViz has a feature for linking edges like you describe, but there are a lot of options which I’ve never explored.

---

<div class="post-metadata">

**Author:** ![chorpler](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/chorpler/32/2888_2.png) [@chorpler](https://boards.straightdope.com/u/chorpler)\
**Post date:** [March 12, 2008, 11:38pm UTC](https://boards.straightdope.com/t/anybody-know-of-any-tree-graph-drawing-software-that-can-link-edges/441174/3 "2008-03-12T23:38:54Z")

</div>

[QUOTE=friedo]  
[GraphViz](http://www.graphviz.org/) is the shiznit for drawing directed and undirected graphs. You just provide a list of nodes, edges and labels in the proper syntax, and GraphViz will spit out an image.

There are various front-end programs that provide a nicer interface to generate the GraphViz code, but I’ve never used them.  
[/QUOTE]

Oh yeah – I was going to mention that one too. I just downloaded it five minutes before I posted my question, but I quickly abandoned it when I realized it wasn’t a quick-and-easy GUI but a “supply the list of nodes and edges and labels in the proper syntax” thing. (Which is very handy, if I can just get a decent GUI frontend for it for long enough to learn the proper syntax, because then I wouldn’t have to go through all the trouble of drawing out the graph every time – eventually I’d be able to slam out a few lines and have it automatically generate the graph. But at the moment, I need something quick and easy.)

But anyway … do you know if it can link edges like I mentioned? I briefly looked through the documentation, but I can’t tell on the site at the moment – some of the links on the documentation pages are giving me errors instead of … you know … actual documentation, at the moment.

---

<div class="post-metadata">

**Author:** ![Capt.Ridley\_s\_Shooting\_Party](https://avatars.discourse-cdn.com/v4/letter/c/cc9497/32.png) [@Capt.Ridley\_s\_Shooting\_Party](https://boards.straightdope.com/u/Capt.Ridley_s_Shooting_Party)\
**Post date:** [March 12, 2008, 11:49pm UTC](https://boards.straightdope.com/t/anybody-know-of-any-tree-graph-drawing-software-that-can-link-edges/441174/4 "2008-03-12T23:49:43Z")

</div>

You want [Dia](http://www.gnome.org/projects/dia/). I just downloaded it and tested, and it has the functionality you want. You can also anchor lines to nodes so they stay connected when rearranging the graph.

---

<div class="post-metadata">

**Author:** ![ultrafilter](https://avatars.discourse-cdn.com/v4/letter/u/3d9bf3/32.png) [@ultrafilter](https://boards.straightdope.com/u/ultrafilter)\
**Post date:** [March 13, 2008, 1:27am UTC](https://boards.straightdope.com/t/anybody-know-of-any-tree-graph-drawing-software-that-can-link-edges/441174/5 "2008-03-13T01:27:59Z")

</div>

There’s a gallery on the graphviz site that has a lot of examples of the different sorts of graphs it can draw. I usually just grab the one that looks the most like what I want and modify it for what I need.

One of the most annoying things about it is that it can’t apply any formatting to the labels–so no underlines for the primary keys in your database, no subscripts for the state labels in your DFA, and so on and so forth. I’ll check out dia and see if it’s any nicer in that respect.

---

<div class="post-metadata">

**Author:** ![chorpler](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/chorpler/32/2888_2.png) [@chorpler](https://boards.straightdope.com/u/chorpler)\
**Post date:** [March 13, 2008, 5:29am UTC](https://boards.straightdope.com/t/anybody-know-of-any-tree-graph-drawing-software-that-can-link-edges/441174/6 "2008-03-13T05:29:24Z")

</div>

[QUOTE=Dominic Mulligan]  
You want [Dia](http://www.gnome.org/projects/dia/). I just downloaded it and tested, and it has the functionality you want. You can also anchor lines to nodes so they stay connected when rearranging the graph.  
[/QUOTE]

Thanks **Dominic**. Okay, I tried Dia. It’s pretty cool, but it seems to be more of a general diagramming tool (like Microsoft Visio) than a graph/tree drawing tool.

With TreeForm or uDraw or the like, I can add new nodes and have it automatically link to an existing node, thus making the new node a child/successor/neighbor of that existing node automatically and automatically moving around all the other nodes on that level (if it’s a tree) to make room for the new one, while maintaining the existing edges.

Whereas, as far as I can tell, with Dia I have to draw the nodes and position them by hand, so if I add another node to a particular level I have to reposition everything by hand. Is there a better way to use it that I’ve missed?

---

<div class="post-metadata">

**Author:** ![Digital\_Stimulus](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@Digital\_Stimulus](https://boards.straightdope.com/u/Digital_Stimulus)\
**Post date:** [March 13, 2008, 2:32pm UTC](https://boards.straightdope.com/t/anybody-know-of-any-tree-graph-drawing-software-that-can-link-edges/441174/7 "2008-03-13T14:32:44Z")

</div>

I was going to suggest using either Dia or Dot (a subpackage of graphviz; perhaps there’s a utility listed on the [Wikipedia](http://en.wikipedia.org/wiki/DOT_language) page that would be useful?). The only thing I have to add, since both have already been suggested, is that Dia can export Dot files. So you might draw them by hand in Dia, export, and then manipulate the .dot file.

But I’m interested in taking a gander at any other suggestions also…

---

<div class="post-metadata">

**Author:** ![chorpler](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/chorpler/32/2888_2.png) [@chorpler](https://boards.straightdope.com/u/chorpler)\
**Post date:** [March 15, 2008, 4:28am UTC](https://boards.straightdope.com/t/anybody-know-of-any-tree-graph-drawing-software-that-can-link-edges/441174/8 "2008-03-15T04:28:26Z")

</div>

[QUOTE=Digital Stimulus]  
I was going to suggest using either Dia or Dot (a subpackage of graphviz; perhaps there’s a utility listed on the [Wikipedia](http://en.wikipedia.org/wiki/DOT_language) page that would be useful?). The only thing I have to add, since both have already been suggested, is that Dia can export Dot files. So you might draw them by hand in Dia, export, and then manipulate the .dot file.

But I’m interested in taking a gander at any other suggestions also…  
[/QUOTE]

I didn’t notice that Dia could do that. Thanks for pointing it out, that might be helpful. But ideally I’d like something that can automatically add nodes as children of other nodes, and the like …

TreeForm, for instance, lets you draw trees very quickly and does all the formatting as soon as you add the node. All you have to do is drag an up- or down-node from the menu onto an existing node, and then move the mouse left or right of any existing nodes to tell it where to put the new node.

So I guess my ideal package would be something that would let me draw trees/graphs quite simply like that, but would also have the flexibility of Dia to let me customize the tree/graph after the basic structure is done. It doesn’t sound like there’s anything quite right for me out there, though… although I still need to investigate GraphViz in detail.

Thanks for your help, everybody. And, of course, if anybody has any further suggestions, please share!
