Hi,
Assuming it's a tree, you could arrange it recursively like this:
float FitChildren(DiagramNode root, float minWidth, float padding)
{
float total = 0;
foreach (DiagramNode child in root.Query("outlinks/destination"))
total += FitChildren(child, minWidth, padding) + padding;
total = Math.Max(total - padding, minWidth);
RectangleF r = root.Bounds;
r.Width = total;
root.Bounds = r;
return total;
}
void Arrange(DiagramNode root, float levelHeight, float padding)
{
float x = root.Bounds.Left;
foreach (DiagramNode child in root.Query("outlinks/destination"))
{
child.Move(x, root.Bounds.Top + levelHeight);
x = child.Bounds.Right + padding;
Arrange(child, levelHeight, padding);
StraightenLink(child.IncomingLinks[0]);
}
}
void StraightenLink(DiagramLink link)
{
RectangleF r = link.Destination.Bounds;
float x = r.Left + r.Width / 2;
link.Style = LinkStyle.Polyline;
link.SegmentCount = 1;
link.ControlPoints[0] = new PointF(x, link.ControlPoints[0].Y);
link.ControlPoints[1] = new PointF(x, link.ControlPoints[1].Y);
}
private void btnTestLayout_Click(object sender, EventArgs e)
{
DiagramNode root = diagram.ActiveItem as DiagramNode;
if (root != null)
{
FitChildren(root, 32, 8);
Arrange(root, 32, 8);
}
}
If you need to straighten links drawn by the user, without moving nodes, check the SequenceDiagram example.
I hope that helps,
Stoyan