Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic How to force links to not follow same path (Read 5524 times)
Gaurav Dubey
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 9
Joined: Sep 28th, 2016
How to force links to not follow same path
Jan 17th, 2017 at 3:38pm
Print Post  
Hi,
We are using mind fusion API to develop a screen where user can draw components and links, However if there are many in/out links, it is very difficult for user to understand which link is for which components unless he select the link because links are following already drawn path.

Is it possible for each link to use different path by providing some padding or something? It will be really helpful if any snippet can be provided for the same.

I have seen the examples in forum posted however they works only if overlapping happens between the component, In my case I have to show 2 types of links so i am using Bezier and Polygon. But with polygon, it is difficult to understand source and destination even there is no duplicate links between the component( Please see image for reference).


Thanks a lot
  

sampleScenario.png ( 8 KB | 194 Downloads )
sampleScenario.png
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3146
Joined: Oct 19th, 2005
Re: How to force links to not follow same path
Reply #1 - Jan 17th, 2017 at 6:00pm
Print Post  
The paths should be easier to follow if you enable RoundedLinks property - the bends will be drawn as arcs then and it should be clear if a link turns at a crossing point. If you prefer not to use that, you could pull links apart like this (showing case for horizontal links only) -

Code
Select All
void pullLinksApart(Diagram diagram)
{
	// group links by coordinates of their first control point
	HashMap<String, ArrayList<DiagramLink>> linksByStartPoint = new HashMap<>();
	for (DiagramLink link : diagram.getLinks())
	{
		String key = link.getStartPoint().toString();
		ArrayList<DiagramLink> links = linksByStartPoint.get(key);
		if (links == null)
		{
			links = new ArrayList<DiagramLink>();
			linksByStartPoint.put(key, links);
		}
		links.add(link);
	}

	// for each group with two or more links
	for (ArrayList<DiagramLink> links : linksByStartPoint.values())
	{
		if (links.size() < 2)
			continue;

		DiagramLink firstLink = links.get(0);
		Rectangle2D.Float nodeRect = firstLink.getOrigin().getBounds();
		Point2D.Float point = firstLink.getStartPoint();
		if (point.x == nodeRect.x || point.x == nodeRect.x + nodeRect.width)
		{
			// sort the links by position of their end points
			Collections.sort(links, new Comparator<DiagramLink>()
			{
				@Override
				public int compare(DiagramLink l1, DiagramLink l2)
				{
					float y1 = l1.getStartPoint().y;
					float y2 = l2.getStartPoint().y;
					if (y1 < y2) return -1;
					if (y1 > y2) return 1;
					return 0;
				}
			});

			float d = nodeRect.height / (links.size() + 1);
			float y = nodeRect.y + d;
			for (DiagramLink link : links)
			{
				Point2D.Float p1 = link.getStartPoint();
				Point2D.Float p2 = link.getControlPoints().get(1);
				if (link.getShape() == LinkShape.Cascading && p2.y == p1.y)
					p2.y = y;
				p1.y = y;
				link.updateFromPoints();
				y += d;
			}
		}
	}
} 



Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Gaurav Dubey
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 9
Joined: Sep 28th, 2016
Re: How to force links to not follow same path
Reply #2 - Jan 19th, 2017 at 12:16pm
Print Post  
Hi Slavcho,

This is only pulling links from start and end points, however we need separate path of each link, i tried OrthogonalRouter but somehow it is changing link start and end point to some other components.

I have sent the mail along with attached screenshots to support email address as well.

Please suggest the solution
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3146
Joined: Oct 19th, 2005
Re: How to force links to not follow same path
Reply #3 - Jan 19th, 2017 at 5:38pm
Print Post  
Hi,

Try setting OrthogonalRouter's Anchoring property to Keep and it should use the end points you assign from pullApart method. Alternatively try the diagram.routeAllLinks method with RoutingOptions.Anchoring set to Keep as well.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Gaurav Dubey
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 9
Joined: Sep 28th, 2016
Re: How to force links to not follow same path
Reply #4 - Jan 26th, 2017 at 3:45pm
Print Post  
Thanks a lot, it solved the problem. Smiley
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint