Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Remove the link lines overlap (Read 9129 times)
hhko
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 20
Joined: Feb 9th, 2010
Remove the link lines overlap
Feb 17th, 2010 at 6:28am
Print Post  
Hi.  Grin
When two or more link lines between same shapes, the lines overlap.
But, I wish it would not overlap the link lines.

How do I implement?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Remove the link lines overlap
Reply #1 - Feb 17th, 2010 at 9:31am
Print Post  
  
Back to top
 
IP Logged
 
hhko
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 20
Joined: Feb 9th, 2010
Re: Remove the link lines overlap
Reply #2 - Feb 18th, 2010 at 6:29am
Print Post  
Hi. thank you.

all examples source code using LinkStyle.Bezier.
but. I want to use LinkStyle.Polyline.
so, I wish to change only start and end position.
  
Back to top
 
IP Logged
 
hhko
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 20
Joined: Feb 9th, 2010
Re: Remove the link lines overlap
Reply #3 - Feb 18th, 2010 at 6:56am
Print Post  
How to attach image file here?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Remove the link lines overlap
Reply #4 - Feb 18th, 2010 at 8:46am
Print Post  
In such case try this:

Code
Select All
private void diagram_LinkCreated(object sender, LinkEventArgs e)
{
	DiagramLink link = e.Link;
	DiagramLinkCollection links = GetCommonLinks(link.Origin, link.Destination);
	PointF firstPoint = link.ControlPoints[0];
	PointF lastPoint = link.ControlPoints[link.ControlPoints.Count - 1];

	if (firstPoint.Y == link.Origin.Bounds.Top ||
		firstPoint.Y == link.Origin.Bounds.Bottom)
		DistributeHorizontally(links, link.Origin, firstPoint.Y);
	else
		DistributeVertically(links, link.Origin, firstPoint.X);

	if (lastPoint.Y == link.Destination.Bounds.Top ||
		lastPoint.Y == link.Destination.Bounds.Bottom)
		DistributeHorizontally(links, link.Destination, lastPoint.Y);
	else
		DistributeVertically(links, link.Destination, lastPoint.X);
}

private void DistributeHorizontally(DiagramLinkCollection links, DiagramNode node, float y)
{
	float d = node.Bounds.Width / (links.Count + 1);
	float x = node.Bounds.Left + d;
	foreach (DiagramLink link in links)
	{
		int index = link.Origin == node ? 0 : link.ControlPoints.Count - 1;
		link.ControlPoints[index] = new PointF(x, y);
		link.UpdateFromPoints(true, false);
		x += d;
	}
}

private void DistributeVertically(DiagramLinkCollection links, DiagramNode node, float y)
{
	// same as above but replace width/height, left/top, etc
} 



You can't upload files here; instead upload the image on your server or e.g. flickr and paste a link.

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


I love YaBB 1G - SP1!

Posts: 20
Joined: Feb 9th, 2010
Re: Remove the link lines overlap
Reply #5 - Feb 18th, 2010 at 4:20pm
Print Post  
http://cfile25.uf.tistory.com/original/163721214B7D60F14CAF23

I think that diagram_LinkCreated and DistributeHorizontally/DistributeVertically are some problem.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Remove the link lines overlap
Reply #6 - Feb 18th, 2010 at 5:42pm
Print Post  
problem 2: Comparing the link's end point position with node Top/Left/Bottom/Right will work only if the node's Shape is Rectangle. Replace those equality comparisons in LinkCreated with less than and greater than comparison of the link point's X/Y with the node's center point X/Y.

problem 1: The Distribute methods work correctly only for rectangles too. If using other shapes, try calling the node.GetIntersection() method specifying the end points found for a rectangle to get a point lying on the shape boundary.
  
Back to top
 
IP Logged
 
hhko
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 20
Joined: Feb 9th, 2010
Re: Remove the link lines overlap
Reply #7 - Feb 21st, 2010 at 4:35am
Print Post  
Hi. very thank you.

I have some problem.
http://cfile29.uf.tistory.com/original/144732154B80B7043EE77F

Code
Select All
private void OverlapLinkCreated(object sender, LinkEventArgs e)
{
    DiagramLink link = e.Link;
    DiagramLinkCollection links = GetCommonLinks(link.Origin, link.Destination);
    PointF firstPoint = link.ControlPoints[0];
    PointF lastPoint = link.ControlPoints[link.ControlPoints.Count - 1];

    ShapeNode origin = link.Origin as ShapeNode;
    ShapeNode destination = link.Destination as ShapeNode;
    PointF originIntersectionPoint = origin.GetIntersection(firstPoint, lastPoint);
    if (originIntersectionPoint.Y <= link.Origin.Bounds.Top ||
	  originIntersectionPoint.Y >= link.Origin.Bounds.Bottom)
	  DistributeHorizontally(links, origin, firstPoint.Y);
    else
	  DistributeVertically(links, origin, firstPoint.X);

    PointF destinationIntersectionPoint = link.Destination.GetIntersection(firstPoint, lastPoint);
    if (destinationIntersectionPoint.Y <= link.Destination.Bounds.Top ||
	  destinationIntersectionPoint.Y >= link.Destination.Bounds.Bottom)
	  DistributeHorizontally(links, destination, lastPoint.Y);
    else
	  DistributeVertically(links, destination, lastPoint.X);
}

private void DistributeHorizontally(DiagramLinkCollection links, ShapeNode node, float y)
{
    float d = node.Bounds.Width / (links.Count + 1);
    int x = 1;

    foreach (DiagramLink link in links)
    {
	  int index = link.Origin == node ? 0 : link.ControlPoints.Count - 1;
	  PointF endPointF = node.GetIntersection(link.ControlPoints[0], link.ControlPoints[link.ControlPoints.Count - 1]);
	  endPointF.X = node.Bounds.Left + (d * x);
	  endPointF.Y = y;

	  link.ControlPoints[index] = endPointF;
	  link.UpdateFromPoints(true, false);
	  x++;
    }
}

private void DistributeVertically(DiagramLinkCollection links, ShapeNode node, float x)
{
    float d = node.Bounds.Height / (links.Count + 1);
    int y = 1;

    foreach (DiagramLink link in links)
    {
	  int index = link.Origin == node ? 0 : link.ControlPoints.Count - 1;
	  PointF endPointF = node.GetIntersection(link.ControlPoints[0], link.ControlPoints[link.ControlPoints.Count - 1]);
	  endPointF.X = x;
	  endPointF.Y = node.Bounds.Top  + (d * y);

	  link.ControlPoints[index] = endPointF;
	  link.UpdateFromPoints(true, false);
	  y++;
    }
}
 



problem 1. I called node.GetIntersection() function. but why overlap?

problem 2. How can I improve code ?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Remove the link lines overlap
Reply #8 - Feb 21st, 2010 at 1:22pm
Print Post  
Try this:

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

	PointF firstPoint = link.ControlPoints[0];
	PointF lastPoint = link.ControlPoints[link.ControlPoints.Count - 1];

	PointF oc = link.Origin.GetCenter();
	float ocdx = Math.Abs(firstPoint.X - oc.X);
	float ocdy = Math.Abs(firstPoint.Y - oc.Y);
	if (ocdx < ocdy)
		DistributeHorizontally(links, link.Origin, firstPoint.Y);
	else
		DistributeVertically(links, link.Origin, firstPoint.X);

	PointF dc = link.Destination.GetCenter();
	float dcdx = Math.Abs(lastPoint.X - dc.X);
	float dcdy = Math.Abs(lastPoint.Y - dc.Y);
	if (dcdx < dcdy)
		DistributeHorizontally(links, link.Destination, lastPoint.Y);
	else
		DistributeVertically(links, link.Destination, lastPoint.X);
}

private void DistributeHorizontally(DiagramLinkCollection links, DiagramNode node, float y)
{
	float d = node.Bounds.Width / (links.Count + 1);
	float x = node.Bounds.Left + d;
	foreach (DiagramLink link in links)
	{
		int index = link.Origin == node ? 0 : link.ControlPoints.Count - 1;
		PointF c = node.GetCenter();
		float h = node.Bounds.Height;
		PointF p1 = new PointF(x, y + (c.Y > y ? - h: +h));
		PointF p2 = new PointF(x, c.Y);
		PointF p = node.GetIntersection(p1, p2);
		link.ControlPoints[index] = p;
		link.UpdateFromPoints(true, false);
		x += d;
	}
}

private void DistributeVertically(DiagramLinkCollection links, DiagramNode node, float x)
{
	float d = node.Bounds.Height / (links.Count + 1);
	float y = node.Bounds.Top + d;
	foreach (DiagramLink link in links)
	{
		int index = link.Origin == node ? 0 : link.ControlPoints.Count - 1;
		PointF c = node.GetCenter();
		float w = node.Bounds.Width;
		PointF p1 = new PointF(x + (c.X > x ? -w : +w), y);
		PointF p2 = new PointF(c.X, y);
		PointF p = node.GetIntersection(p1, p2);
		link.ControlPoints[index] = p;
		link.UpdateFromPoints(true, false);
		y += d;
	}
} 



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