Layout dependencies in tree graph (similar to gitk)
I have a bunch of nodes that may have dependencies, for example A, B, C, with connections A <- B, and B <-C. I would like to lay them out in a list (listview/treeview in a gui), and draw a nice diagram showing the relations in one column. I am thinking of something like what some git tools give you.
(See this thread for more examples).
I managed to sketch my own algorithm for this, but I'm not sure I got all corner cases. This seems to be a Solved Problem, so I thought I'd ask here for any standard algorithm. My requirements are:
- Lines can leave and arrive at each row.
- Lines may pass by a row.
- The rows have a natural order. For now, the dependencies only go in one direction (later lines may depend on previous ones), but I'd like to drop that requirement if possible. (My made up algorithm doesn't allow that.)
- I don't need the lines to merge as in the above image. If several lines arrive at or leave from the same point, they may merge for cosmetic reasons. I don't want to merge a passing with an arrival though, as in line 3 in above image. (So there would be two passings, and one end point there.)
- Again, for cosmetic reasons, the algorithm may "compactify" the tree, and bend the lines to save space. But it would also suffice if it only had straight lines.
- I want to start with the list of dependencies, and get out instructions what to draw in each cell to create the tree.
Any references / code examples for such an algorithm? Of course there's the source of various git clients, but they do things slightly differently to what I'm looking for (I have no merges).