Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Overlapping multiple links (Read 7962 times)
bknaylor
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 4
Joined: Aug 27th, 2008
Overlapping multiple links
Nov 19th, 2008 at 4:17pm
Print Post  
We have a situation where we have more than one link between two nodes. The links overlap when we arrange the layout and the link on bottom is inaccessible. Is there a way to force the links not to overlap?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Overlapping multiple links
Reply #1 - Nov 19th, 2008 at 4:38pm
Print Post  
This older thread shows one way to do this:
http://mindfusion.eu/Forum/YaBB.pl?board=fcnet_disc;action=display;num=115436435...

and here is the code ported to the Flowchart.NET 5 API:

Code
Select All
private void diagram_LinkCreated(object sender, LinkEventArgs e)
{
	DiagramLinkCollection commonLinks = GetCommonLinks(e.Link.Origin, e.Link.Destination);

	PointF pt1 = e.Link.ControlPoints[0];
	PointF pt2 = e.Link.ControlPoints[e.Link.ControlPoints.Count - 1];

	if (commonLinks.Count > 1)
	{
		for (int c = 0; c < commonLinks.Count; ++c)
		{
			DiagramLink link = commonLinks[c];
			link.Style = LinkStyle.Bezier;
			link.SegmentCount = 1;

			PointF cp1 = new PointF(pt1.X + 1 * (pt2.X - pt1.X) / 3, pt1.Y + 1 * (pt2.Y - pt1.Y) / 3);
			PointF cp2 = new PointF(pt1.X + 2 * (pt2.X - pt1.X) / 3, pt1.Y + 2 * (pt2.Y - pt1.Y) / 3);

			float angle = 0, radius = 0;
			CartesianToPolar(pt1, pt2, ref angle, ref radius);

			int pairOffset = (c / 2 + 1) * 5;
			if (commonLinks.Count % 2 == 0)
			{
				PolarToCartesian(cp1, c % 2 == 0 ? angle - 90 : angle + 90, pairOffset, ref cp1);
				PolarToCartesian(cp2, c % 2 == 0 ? angle - 90 : angle + 90, pairOffset, ref cp2);

				if (link.ControlPoints[0] == pt1)
				{
					link.ControlPoints[1] = cp1;
					link.ControlPoints[2] = cp2;
				}
				else
				{
					link.ControlPoints[1] = cp2;
					link.ControlPoints[2] = cp1;
				}

				link.UpdateFromPoints();
			}
		}
	}
}

DiagramLinkCollection GetCommonLinks(DiagramNode node1, DiagramNode node2)
{
	DiagramLinkCollection commonLinks = new DiagramLinkCollection();

	foreach (DiagramLink link in node1.OutgoingLinks)
		if (link.Destination == node2)
			commonLinks.Add(link);

	foreach (DiagramLink link in node1.IncomingLinks)
		if (link.Origin == node2)
			commonLinks.Add(link);

	return commonLinks;
}

void PolarToCartesian(PointF coordCenter, float a, float r, ref PointF cartesian)
{
	if (r == 0)
	{
		cartesian = coordCenter;
		return;
	}

	cartesian.X = (float)(coordCenter.X + Math.Cos(a * Math.PI / 180) * r);
	cartesian.Y = (float)(coordCenter.Y - Math.Sin(a * Math.PI / 180) * r);
}

void CartesianToPolar(PointF coordCenter, PointF cartesian, ref float a, ref float r)
{
	if (coordCenter == cartesian)
	{
		a = 0;
		r = 0;
		return;
	}

	float dx = cartesian.X - coordCenter.X;
	float dy = cartesian.Y - coordCenter.Y;
	r = (float)(Math.Sqrt(Math.Pow(dx, 2) + Math.Pow(dy, 2)));

	a = (float)(Math.Atan(-dy / dx) * 180 / Math.PI);
	if (dx < 0) a += 180;
}
 



You could copy the LinkCreated code to a helper method and call it for each pair of nodes with more than one link between them.

I hope that helps,
Stoyan
« Last Edit: May 31st, 2021 at 1:19pm by Slavcho »  
Back to top
 
IP Logged
 
bknaylor
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 4
Joined: Aug 27th, 2008
Re: Overlapping multiple links
Reply #2 - Nov 19th, 2008 at 5:08pm
Print Post  
Thanks, I will try it.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint