Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Layered layout : How to create rounded links (Read 2563 times)
Surya
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 2
Joined: Jul 10th, 2015
Layered layout : How to create rounded links
Jul 10th, 2015 at 5:15am
Print Post  
Hi,

Please explain how to create rounded links in layered layout.
The 'rounded' property does not seem to effect it.

Thanks,
Surya
  

forum_png_1.png ( 36 KB | 126 Downloads )
forum_png_1.png
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Layered layout : How to create rounded links
Reply #1 - Jul 10th, 2015 at 10:59am
Print Post  
Hi,

Links bend only when crossing a layer. If a link is between nodes in adjacent layers, it will remain straight line. If you need to add artificial bends to make the link more curvy, you could switch to Bezier style and add control points with some offset from the straight line:

Code
Select All
layeredLayout.Arrange(diagram);

foreach (var link in diagram.Links)
{
	var points = link.ControlPoints.Clone();

	// insert Bezier control points for each segment of polyline link
	for (int i = points.Count - 1; i > 0; i--)
	{
		var segmentStart = points[i - 1];
		var segmentEnd = points[i];
		var vector = new Vector(segmentStart, segmentEnd);

		var cp1 = segmentStart + vector / 3;
		var cp2 = segmentStart + 2 * vector / 3;

		var dx = vector.X;
		if (dx == 0)
		{
			cp1.X -= 2;
			cp2.X += 4;
		}
		else
		{
			cp1.X += dx / 6;
			cp2.X += dx / 6;
		}

		points.Insert(i, cp1);
		points.Insert(i + 1, cp2);
	}

	for (int i = 3; i < points.Count - 1; i += 4)
	{
		var pp = points[i - 1];
		pp.X = points[i].X;
		points[i - 1] = pp;
		var pn = points[i + 1];
		pn.X = points[i].X;
		points[i + 1] = pn;
	}

	link.Shape = LinkShape.Bezier;
	link.ControlPoints.Clear();
	link.ControlPoints.AddRange(points);
	link.UpdateFromPoints(false, true);
} 





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