Layed Digraph so Close


Our product needs an automatic layout very similar to what is shown in the Org Chart demo (which I know uses the Layerd Digraph Layout). The only difference between what it does and what we need is that sometimes (but not always) with an even number of child nodes, the parent node appears directly over one of the children rather then centered evenly above the child nodes. With an odd number of child nodes, so far it has always been OK.
I played with several settings and couldn’t figure out how to accomplish that effect using the properties available. After reading the documentation, I’m thinking that something’s going on with “artificial” nodes or that perhaps I need to change they way layers are assigned. But I’m having difficulty understanding the documentation on the Digraph layout. If somone could point me in the right direction, it would be greatly appreciated.


In case that didn’t make sense, perhaps some artwork is needed.
The way it currently works:

The way we need it to work:


You’re right that there might be some way of fiddling with the algorithm to do what you want, but it isn’t clear to me it’s worth it.
Your requirement, “centered evenly above the child nodes” isn’t clear to me. Does that mean the parent’s midpoint is at the midpoint of the children’s midpoints, or at the midpoint of the children’s total width? There’s a difference, of course, when the nodes have different widths.
In either case, it might be easiest for you to just do a regular layout and then fix it up afterwards, adjusting any positions recursively starting with the bottom of the tree, according to whatever your criteria are.


“centered evenly above the child nodes” isn’t clear to me
By “centered evenly above the child nodes” I mean, the parents midpoint should = ((firstchild.left + lastchild.right) / 2).
it might be easiest for you to just do a regular layout and then fix it up afterwards
I’m not so sure that would be easy to do. If I understand you correctly, then you’re telling me to start with the Digraph and then go back through the document from the end nodes and work my way to the top node adjusting as needed right? I think I would just end up spending as much time trying to ‘fix’ the digraph layout as I would writing my own, because it’s not just the parent node that is inherintly the problem. I believe the parents position is the root cause, but it causes other problems in the layout.
Let me provide another illustration:

Notice how when we get nested child nodes with only two siblings, the chart starts to double back on itself? This isn’t the way an org chart is supposed to look. It makes it more difficult to read.
Check out the way MS Powerpoint does org charts:

Notice how two-child nodes are spaced evenly within the document. The difference between the GoDiagram Org Chart example and the PowerPoint example explains the problem we have with the layout. I hope that clears it up.
So would you still suggest I start with an existing layout and work my way backwards, or is this a totally new layout?
Thanks again.


Actually, we provide a simple tree layout algorithm in two different sample applications: Classier and FamilyTree. You could adopt that code, which just takes up a paragraph or two. I think that would be simpler than trying to modify the behavior of the layered-digraph algorithm, which is designed for much more complex cases than yours.
Providing a tree-only layout algorithm with lots of tree-specific options is on our list of things to do someday.