Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Sorting/Ordering Nodes (Read 1108 times)
MF
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 1
Joined: Jul 12th, 2010
Sorting/Ordering Nodes
Jul 12th, 2010 at 4:32pm
Print Post  
Is there a way to sort/order shape objects and their location will not change during the routing/rendering process? Example. Shapes will be ordered/layered top to bottom by their color, all reds on one row, all blues on one row, etc. but the routing/rendering process will not change their location and yet will still draw all their links.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Sorting/Ordering Nodes
Reply #1 - Jul 12th, 2010 at 4:53pm
Print Post  
You can call the RouteAllLinks method to route links without changing the position of nodes. Sorting could be done by collecting nodes in a hashtable according to their color and then iterating it to set the nodes' Bounds:

Code
Select All
// group the nodes
Dictionary<Color, List<DiagramNode>> sortedNodes = new Dictionary<Color, List<DiagramNode>>();
foreach (DiagramNode node in diagram.Nodes)
{
	Color key = ((SolidBrush)node.Brush).Color;
	if (!sortedNodes.ContainsKey(key))
		sortedNodes[key] = new List<DiagramNode>();
	sortedNodes[key].Add(node);
}

// arrange in rows
float dist = 20;
float y = 10;
foreach (Color key in sortedNodes.Keys)
{
	float x = 10;
	float rowHeight = 0;
	foreach (DiagramNode node in sortedNodes[key])
	{
		RectangleF r = node.Bounds;
		r.Location = new PointF(x, y);
		node.Bounds = r;
		x += r.Width + dist;
		rowHeight = Math.Max(rowHeight, r.Height);
	}
	y += rowHeight + dist;
}

diagram.RouteAllLinks(); 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint