Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Links in TreeLayout / OrthogonalLayout (Read 2895 times)
Rich Cassell
Junior Member
**
Offline


I Love MindFusion!

Posts: 63
Joined: Sep 19th, 2012
Links in TreeLayout / OrthogonalLayout
Jul 24th, 2013 at 10:25am
Print Post  
Hey!

I've been using TreeLayout for a while now and am generally very happy with the way it lays out the nodes and the links for my purpose. It's very neat and clear, and also allows us to give the user a choice of link type (Curved, Cascading, etc).

We do, however, have one issue with the way it finds the most efficient path, in that links are very likely to actual "run" down the same path, particularly if it's 2 links with the same origin and destination. This makes the link text etc very difficult to read and also the paths very difficult to follow.

After searching the forums i've found a few people with this problem and more often than not the OrthogonalLayout is suggested to be run against the links. This does, i agree, stop the links from overlapping and solves the original problem, however, it does have it's own quirks. The links are now far less neat than the original layout and seem to have no order, with outgoing links swapping positions if the layout deems it necessary. It also seems to only support the cascading layout, so has removed our "preferences" ability.

Essentially, i need something that sits neatly between the TreeLayout and the OrthogonalLayout. Any ideas? Another option, if possible, is if you could tell me the pseudo algorithm for how OrthognalLayout sorts the links, then i might be able to create my own layout method to acheive what i need.

Any help will be appreciated.

Best regards,

Rich Smiley
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Links in TreeLayout / OrthogonalLayout
Reply #1 - Jul 24th, 2013 at 1:41pm
Print Post  
Hi,

You should use TreeLayout only for trees, otherwise try LayeredLayout or FlowchartLayout.

You could apply different layout classes selectively based on the diagram type. E.g. check if the current diagram is a tree (root's IncomingLinks.Count == 0, for all other nodes IncomingLinks.Count == 1) and in that case run TreeLayout, otherwise LayeredLayout. After calling Arrange, run this method to pull links between same origin and destination apart:

Code
Select All
void PullLinksApart(float padding)
{
	diagram.UpdateRuntimeIndices();

	// find repeating links
	var repeatingLinks = new Dictionary<int, List<DiagramLink>>();
	foreach (DiagramLink link in diagram.Links)
	{
		int k1 = Math.Min(link.Origin.RuntimeIndex, link.Destination.RuntimeIndex);
		int k2 = Math.Max(link.Origin.RuntimeIndex, link.Destination.RuntimeIndex);
		int key = diagram.Items.Count * k1 + k2;
		if (!repeatingLinks.ContainsKey(key))
			repeatingLinks[key] = new List<DiagramLink>();
		repeatingLinks[key].Add(link);
	}

	// pull them apart
	foreach (KeyValuePair<int, List<DiagramLink>> linkList in repeatingLinks)
	{
		int c = 0, numLinks = linkList.Value.Count;
		if (numLinks < 2)
			continue;
		foreach (DiagramLink link in linkList.Value)
		{
			for (int p = 0; p < link.ControlPoints.Count; ++p)
			{
				PointF point = link.ControlPoints[p];
				point.X += padding * c - padding * (numLinks - 1) / 2;
				link.ControlPoints[p] = point;
				link.UpdateFromPoints();
			}
			c++;
		}
	}
} 



For layouts with rounded links, you could use the method shown here instead:
http://mindfusion.eu/Forum/YaBB.pl?num=1227111424/1#1

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Rich Cassell
Junior Member
**
Offline


I Love MindFusion!

Posts: 63
Joined: Sep 19th, 2012
Re: Links in TreeLayout / OrthogonalLayout
Reply #2 - Jul 25th, 2013 at 10:19am
Print Post  
Hi Stoyan,

That method has improved it no end, so thanks for that.

In 99% of cases our diagrams do fit the mould of a treeLayout, i.e. the root having no incoming nodes and all and all other nodes having a single incoming link... However, we do have small occasions where, rather than repeating large sections of the tree, we allow the user to put 2 incoming links to a node... Is this likely to be what's causing our occasional link problems?

I think the other key part to it is the fact we always use a "Stop" node, like a workflow, but on the tree, that causes issues too... Perhaps another look at LayeredLayouts will be beneficial.

Thanks for your help,
Rich
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Links in TreeLayout / OrthogonalLayout
Reply #3 - Jul 25th, 2013 at 10:49am
Print Post  
Hi,

Quote:
However, we do have small occasions where, rather than repeating large sections of the tree, we allow the user to put 2 incoming links to a node... Is this likely to be what's causing our occasional link problems?


Yes, TreeLayout processes only the first incoming link and ignores the other ones. After calling Arrange, you could loop over all nodes with IncomingLinks.Count >= 2 and call link.Route() for them, to make sure the ignored links don't intersect nodes in the diagram.

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