Thanks for the hint - connections will be drawn by our users in no definite order, so I ended up sorting them before arranging the tree. Hopefully this will be useful to somebody:
class SortByOAP : IComparer
{
public int Compare(object x, object y)
{
DiagramLink l1 = (DiagramLink)x;
DiagramLink l2 = (DiagramLink)y;
return l1.OriginAnchor.CompareTo(l2.OriginAnchor);
}
}
void OnTreeLayout(object sender, EventArgs e)
{
foreach (DiagramNode n in diagram.Nodes)
{
ArrayList l = new ArrayList(n.OutgoingLinks);
l.Sort(new SortByOAP());
n.OutgoingLinks.Clear();
foreach (DiagramLink dl in l)
n.OutgoingLinks.Add(dl);
}
TreeLayout tl = new TreeLayout();
tl.Type = TreeLayoutType.Centered;
tl.Direction = TreeLayoutDirections.LeftToRight;
tl.LinkStyle = TreeLayoutLinkType.Rounded;
tl.Anchoring = Anchoring.Keep;
tl.Arrange(diagram);
}
It would be great to have this as a built-in sort option in TreeLayout
May I also suggest you guys add methods to implement some common operations on the Diagram, for example SelectAll, InvertSelection, AlignSelection. They weren't too hard to code myself, but it should make a nice impression to your future evaluators
- Jacob