Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Anchors & Routing (Read 5057 times)
Jasef
YaBB Newbies
*
Offline



Posts: 26
Joined: Jul 17th, 2011
Anchors & Routing
Dec 19th, 2016 at 7:31pm
Print Post  
Hi,

I'm trying to route a bunch of links in a tree layout format where a single node has multiple children pointing to it.

I have defined n number of incoming anchor points to the top or bottom of the node (Depending on direction of graph). Is it possible to route x (where x is less than n, but could be greater) number of links to be more evenly spread across these anchor points, while still keeping no overlapping links. The links are straight lines.

I'm generally seeing either 2 or 3 of the anchor points being used, sometimes one near the center and then one near the very far left and right of the node.


Cheers,
Jasef.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Anchors & Routing
Reply #1 - Dec 20th, 2016 at 12:40pm
Print Post  
Hi,

You can distribute tree links uniformly using this method (for top->down direction) -
Code
Select All
void distributeLinks(DiagramNode node)
{
	DiagramLinkList links = node.getOutgoingLinks();
	int numLinks = links.size();
	if (numLinks == 0)
		return;

	Rectangle2D.Float rect = node.getBounds();
	float available = rect.width;
	float padding = available / (numLinks + 1);
	float currentX = rect.x + padding;
	for (int l = 0; l < numLinks; l++)
	{
		DiagramLink link = links.get(l);
		Point2D.Float point = link.getStartPoint();
		point.x = currentX;
		point.y = (float)rect.getMaxY();
		currentX += padding;
		link.updateFromPoints();
	}
}

void distributeLinks()
{
	for (DiagramNode node : diagram.getNodes())
		distributeLinks(node);
}

Rectangle2D defBounds = new Rectangle2D.Float(10, 10, 30, 20);

void treeLayout()
{
	diagram.clearAll();
	DiagramNode root = diagram.getFactory().createShapeNode(defBounds);
	buildTree(root, 3);

	TreeLayout layout = new TreeLayout();
	layout.setLevelDistance(30);
	layout.arrange(diagram);

	distributeLinks();
}

void buildTree(DiagramNode parent, int depth)
{
	for (int i = 0; i < 3; i++)
	{
		DiagramNode child = diagram.getFactory().createShapeNode(defBounds);
		diagram.getFactory().createDiagramLink(parent,  child);
		if (depth >= 0)
			buildTree(child, depth - 1);
	}
} 



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



Posts: 26
Joined: Jul 17th, 2011
Re: Anchors & Routing
Reply #2 - Dec 20th, 2016 at 8:23pm
Print Post  
Hi Slavcho,

that works.
But is there no way for the router to do this itself?


Regards,
Jason.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Anchors & Routing
Reply #3 - Dec 22nd, 2016 at 10:00am
Print Post  
Hi Jason,

At this time auto-routing only selects nearest pair of anchor points when you use the Reassign option. We could probably split that into separate options for nearest points and distributed points.

Regards,
Slavcho
  
Back to top
 
IP Logged
 
Jasef
YaBB Newbies
*
Offline



Posts: 26
Joined: Jul 17th, 2011
Re: Anchors & Routing
Reply #4 - Dec 22nd, 2016 at 6:58pm
Print Post  
Hi Slavcho,

okay cool! Good to know.


Cheers,
Jasef.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint