Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Aligning shapes in different swim lanes (Read 3030 times)
jlj30
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 183
Joined: Sep 4th, 2011
Aligning shapes in different swim lanes
Jul 4th, 2013 at 2:51pm
Print Post  
Hi,

What approach would you suggest that would ensure a particular shape in one swim lane is vertically aligned with a shape in a different lane?

Could I use the Move and AttachTo methods even though the parent node is in another lane?

And at what sequence in my code what I perform such an action?

Suggestions appreciated.

Thanks as always.

Jim
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Aligning shapes in different swim lanes
Reply #1 - Jul 5th, 2013 at 1:31pm
Print Post  
Hi,

You can call Move to align a node to another one's Bounds. However that could make it overlap another node at that position, so you might also need to move the remaining nodes from the lane to the right to remove overlaps:

Code
Select All
void AlignNodeTo(DiagramNode node, DiagramNode to)
{
	node.Move(to.Bounds.X, node.Bounds.Y);

	// find all nodes in the same lane as the aligned one
	var nodesInLane = new List<DiagramNode>();
	foreach (var n in diagram.Nodes)
	{
		if (n.LayoutTraits[SwimlaneLayoutTraits.Lane].Equals(
			node.LayoutTraits[SwimlaneLayoutTraits.Lane]))
			nodesInLane.Add(n);
	}

	// if a node intersect the aligned one, move it to the right of it
	foreach (var n in nodesInLane)
		if (n != node && n.Intersects(node))
			n.Move(node.Bounds.Right, n.Bounds.Y);

	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); 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
jlj30
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 183
Joined: Sep 4th, 2011
Re: Aligning shapes in different swim lanes
Reply #2 - Jul 7th, 2013 at 5:40pm
Print Post  
Thanks Stoyan for the great response.
I'll give it a try and let you know how it goes.
Jim
  
Back to top
 
IP Logged
 
jlj30
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 183
Joined: Sep 4th, 2011
Re: Aligning shapes in different swim lanes
Reply #3 - Jul 10th, 2013 at 2:39pm
Print Post  
Hi again,

I've just got around to looking into this again and have a question.
Where would I be inserting the code that you provided?
For example, should it be after swimLayout.Arrange, but before diagram.RouteAllLinks() ?  Or someplace else?

Please advise and thanks for the help.

Jim
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Aligning shapes in different swim lanes
Reply #4 - Jul 11th, 2013 at 11:28am
Print Post  
Hi,

Yes, call it after layout.Arrange and before routing links.

Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint