Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Layered layout - ordering of sub elements (Read 3868 times)
dku
YaBB Newbies
*
Offline



Posts: 41
Joined: Jun 5th, 2008
Layered layout - ordering of sub elements
Jul 24th, 2008 at 5:02pm
Print Post  
Hello,

I'm using layered layout for a 'near' tree diagram (my element can have several parents, so, not really a tree).

It is working well, but gives it any possibility to sort the elements. When layout n sub-elements for an element, it will be fine if I can determine the order of the sub-elements in the layer (or at least direct it ...)

Do you see any possibilities to do that ?

Thanks
Didier
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Layered layout - ordering of sub elements
Reply #1 - Jul 25th, 2008 at 10:33am
Print Post  
Hi,

Unfortunately, you cannot control in what order LayeredLayout arranges child nodes. However, you could sort them yourself after applying the layout:

Code
Select All
LayeredLayout ll = new LayeredLayout();
ll.Arrange(diagram);
diagram.ResizeToFitItems(10);

foreach (DiagramNode node in diagram.Nodes)
{
	DiagramNodeCollection childNodes = new DiagramNodeCollection();
	foreach (DiagramLink link in node.OutgoingLinks)
	{
		DiagramNode dest = link.Destination;
		if (Math.Abs(node.Bounds.Bottom + ll.LayerDistance - (dest.Bounds.Y)) < 0.1)
			childNodes.Add(dest);
	}

	ArrayList sortedByX = new ArrayList(childNodes);
	sortedByX.Sort(new XComparer());
	RectangleF[] sortedRects = new RectangleF[childNodes.Count];
	for (int i = 0; i < childNodes.Count; ++i)
		sortedRects[i] = ((DiagramNode)sortedByX[i]).Bounds;
	for (int i = 0; i < childNodes.Count; ++i)
		childNodes[i].Bounds = sortedRects[i];
}

public class XComparer : IComparer
{
	public int Compare(object x, object y)
	{
		DiagramNode n1 = x as DiagramNode;
		DiagramNode n2 = y as DiagramNode;

		if (n1.Bounds.X < n2.Bounds.X) return -1;
		if (n1.Bounds.X > n2.Bounds.X) return 1;
		return 0;
	}
}
 



That code assumes all nodes have the same height. It will probably create more link crossings, and you might have to provide for more comlex situations, e.g. sorting also by the "grandchild" positions.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
dku
YaBB Newbies
*
Offline



Posts: 41
Joined: Jun 5th, 2008
Re: Layered layout - ordering of sub elements
Reply #2 - Aug 11th, 2008 at 12:48pm
Print Post  
Hello,

Thanks. It works, I can sort the nodes.

It gives node crossing with the same parent object. It means that in the Arrange method from layout, you gives a position at the origin of the link.

Gives it a way to tell the diagram to redraw links or a way that they all take the same origin point ?

Below : parent with 3 subnodes sorted



I imagined that the link is bound to th center of the node, so swapping subnode should redraw correctly.

Thanks
Didier
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Online


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: Layered layout - ordering of sub elements
Reply #3 - Aug 11th, 2008 at 1:02pm
Print Post  
Hi,

Call DiagramLink.ReassignAnchorPoints for all links after the layout, or set DiagramLink.ControlPoints[0] to the middle point of the related node side.

g.
  
Back to top
 
IP Logged
 
dku
YaBB Newbies
*
Offline



Posts: 41
Joined: Jun 5th, 2008
Re: Layered layout - ordering of sub elements
Reply #4 - Aug 11th, 2008 at 3:56pm
Print Post  
Thanks a lot.
It works perfectly.
Didier
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint