Tree Diagram Nodes separation control


I want to represent the following layout when the port is opened (+/- signs)
The problem is that the situation I get is:
I use the GraphLinksModel with TreeLayout
Angle 0, Alingments=start, LayerSpacing=100, NodeSpacing=400, NodeIndent=10, Sorting=Forwards, Compaction=Block, LayerSpacingOverlap=10

TreeLayout routes the links without consideration that there might be multiple ports on each node. I think you want to customize your TreeLayout.

First, I think you need to sort all of the “children” coming out of a node, to avoid links that might cross over each other. If you already have a defined vertical ordering of the nodes, this gets more complicated. But if you don’t, I think you just need to sort them by the Y value of the first Point of the link route coming from the “parent” node. You can implement this by setting the TreeLayout.Comparer property and TreeLayout.Sorting=“Ascending”.

I think you also want to override the TreeLayout.LayoutLinks method. Call the base method and then iterate over the nodes and if there is more than one port with links connected to it, collect those links and modify the link routes going out of the node to avoid the undesired route segment overlaps.

Presumably you do want to keep overlapping segments when they all issue from the same port, yes? I think that’s what most people would want. You just want to avoid overlaps on links from different ports. That also keeps the diagram looking simpler. But if you really want to have all links avoid all segment overlaps, that’s possible too.

Orthogonal link routes normally have 6 points in them. You’ll want to adjust the X coordinate of points 2 and 3. Sort the links coming out of each port by the Y value of the last Point of the route. You’ll need to decide what spacing there should be between the links.

Hmmm, actually you’ll need to split up the collection of links into two lists: ones going “up” and ones going “down”.

Some day we may do this automatically for you. LayeredDigraphLayout tries to do this, for example. But we never got around doing this for TreeLayout because few trees use multiple ports. (Yes, I know about the Decision Tree sample.)