Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic change setLinkShape in existing diagram doesn't work (Read 1766 times)
hans
Junior Member
**
Offline


I Love MindFusion!

Posts: 81
Location: Netherlands
Joined: Mar 17th, 2012
change setLinkShape in existing diagram doesn't work
Jan 30th, 2016 at 11:30pm
Print Post  
I use this code to change the Linkshape of all existing links in my diagram, but the links do not change to bezier.
Also creating a new link after this code always creates cascading links.

It used to work when linksShape was named LinkStyle

function setLinkStyle(a) {
    diagram1.setLinkShape(a);//2 = cascading, 0 = bezier, 1 = poly+-
    if (a === 0) {
        activePattern = anchorpattern0;
    }
    else {
        activePattern = anchorpattern2;
    }
    diagram1.nodes.forEach(function (node) {
        node.setAnchorPattern(activePattern);
    });

    diagram1.links.forEach(function (link) {
        link.setShape(a);
    });
    diagram1.routeAllLinks();
}

using netdiagram 5.5 (dec 8 2015)
Should I call some refresh-function ?
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: change setLinkShape in existing diagram doesn't work
Reply #1 - Feb 1st, 2016 at 10:10am
Print Post  
Hi,

It seems the router does not handle Bezier links but just assigns the cascading-like point coordinates it finds to the link.points array. You can add some curvature after routing by offsetting each segment's internal control points -

Code
Select All
...
diagram1.routeAllLinks();

if (a == 0)
{
	diagram1.links.forEach(function (link)
	{
		var pts = link.points;
		var s = link.getSegmentCount();
		for (var c = 0; c < s; c++)
		{
			var fp = pts[c * 3];
			var dx = pts[c * 3 + 3].x - fp.x;
			var dy = pts[c * 3 + 3].y - fp.y;
			pts[c * 3 + 1] = fp.newWithOffset(dx * 1 / 3, dy * 1 / 3);
			pts[c * 3 + 2] = fp.newWithOffset(dx * 2 / 3, dy * 2 / 3);
		}
		for (var c = 0; c < s - 1; c++)
		{
			var i = c * 3 + 3;
			pts[i].x = (pts[i - 1].x + pts[i + 1].x) / 2;
			pts[i].y = (pts[i - 1].y + pts[i + 1].y) / 2;
		}
		link.updateFromPoints();
	});
} 



We'll add this to the router for next release.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint