Hi,
I have employed several techniques that you have provided over the past year and they have all been very helpful.
One such method that I have adapted for my use seems to be causing a problem.
Have a look at the attached screenshots.
The only difference between the 2 diagrams is that the 2nd one (BAD) has links to some nodes in a second swim lane.
Why this would cause the overall diagram to be wider is a mystery to me. I've been looking at this for too long. It's time to get your help
Here's the code that attempts to align the nodes in the 2nd swim lane with their parent in the 1st lane.
It appears to do just what I want (thanks for that), except with the undesirable increase in the diagram width.
protected void AlignNodeTo(DiagramNode node, DiagramNode relatedNode, Diagram diagram)
{
// Code provided by Mindfusion (Stoyan) on 05Jul2013 (with some minor modifications)
// It ensures that IP and Data shapes are aligned under their parent task
node.Move(relatedNode.Bounds.X + ((relatedNode.Bounds.Width - node.Bounds.Width) / 2), node.Bounds.Y);
// find all nodes in the same lane as the aligned one
var nodesInLane = new List<DiagramNode>();
foreach (DiagramNode n in diagram.Nodes)
{
if (n.LayoutTraits[SwimlaneLayoutTraits.Lane] != null)
if (n.LayoutTraits[SwimlaneLayoutTraits.Lane].Equals(node.LayoutTraits[SwimlaneLayoutTraits.Lane]))
nodesInLane.Add(n);
}
// if a node intersects the aligned one, move it to the right of it
foreach (DiagramNode n in nodesInLane)
{
if (n != node && n.Intersects(node))
n.Move(node.Bounds.Right + 5, n.Bounds.Y);
}
// Sort the nodes based on their X (left) coordinate
nodesInLane.Sort((n1, n2) =>
n1.Bounds.X.CompareTo(n2.Bounds.X));
// shift remaining nodes to the right to remove overlaps
for (int i = 1; i < nodesInLane.Count; i++)
{
var n1 = nodesInLane[i - 1];
var n2 = nodesInLane[i];
if (n2.Bounds.Left <= n1.Bounds.Right)
{
n2.Move(n1.Bounds.Right + 5, n2.Bounds.Y);
}
}
}
Here's a bit more code that puts the above in perspective.
The above method is called from alignShapesWithTasks which just loops thru all nodes on the diagram that have one of the shapes in the 2nd swim lane linked to it.
Header colHeader = grid.FindColumn(colTitle);
if (colHeader.Width < 225) // Ensure a minimum width
colHeader.Width = 225;
// The following code will try to ensure that Data, IP and Annotation shapes are positioned directly below the task to which they are related
alignShapesWithTasks(diagram);
System.Diagnostics.Debug.WriteLine("---> diagram.GetContentBounds after alignShapesWithTasks = " + diagram.GetContentBounds(false, false));
SortRoutedLinksTaskRight(diagram); // helps to reduce overlapping connectors coming out of the right side of a task
SortRoutedLinksTaskLeft(diagram); // helps to reduce overlapping connectors coming into the left side of a task ** New code from MF - 29Dec2013 **
SortRoutedLinksTaskBottom(diagram);
diagram.RouteAllLinks(); // Moved after the above link sorting functions - 27Dec2013
RectangleF columnHeaderBounds = diagram.LaneGrid.GetColumnHeaderBounds();
RectangleF rowHeaderBounds = diagram.LaneGrid.GetRowHeaderBounds();
RectangleF laneGridBounds = RectangleF.Union(columnHeaderBounds, rowHeaderBounds);
RectangleF itemsBounds = diagram.GetContentBounds(false, false);
diagram.Bounds = RectangleF.Union(itemsBounds, laneGridBounds);
diagram.Bounds = new RectangleF(0F, 0F, diagram.Bounds.Width + 2F, diagram.Bounds.Height + 5F);
// The following ensures a minimum width diagram
if (diagram.Bounds.Width < 225)
diagram.Bounds = new RectangleF(0F, 0F, 225, diagram.Bounds.Height);
Any suggestions?
Thanks
Jim