How to change "linkdistance" while force directed layout is running?

1,234 views
Skip to first unread message

cenk

unread,
Nov 30, 2011, 6:45:28 AM11/30/11
to d3-js
Is there a way to lengthen / shorten edges while the layout is
running?

I tried stopping, updating linkdistance and resuming, no hope...

Thanks.

Mike Bostock

unread,
Nov 30, 2011, 11:56:33 AM11/30/11
to d3...@googlegroups.com
> Is there a way to lengthen / shorten edges while the layout is
> running? I tried stopping, updating linkdistance and resuming,

The link distances and strengths are cached on the link objects, so
you need to call start() when these parameters change rather than
resume().

Mike

cenk

unread,
Nov 30, 2011, 1:57:34 PM11/30/11
to d3-js
Trying this but can't seem to get it working:

force.stop();
force.linkDistance = anotherVal;
force.start();

Thanks :)

Cenk

Mike Bostock

unread,
Nov 30, 2011, 1:59:33 PM11/30/11
to d3...@googlegroups.com
>  force.linkDistance = anotherVal;

That's not how you call a function. Take a look at the documentation:

http://github.com/mbostock/d3/wiki/Force-Layout

Mike

cenk

unread,
Dec 1, 2011, 1:35:22 AM12/1/11
to d3-js
Thank you, I placed a function inside linkDistance and it works :)

Here's the starters code if anyone will be interested:

var linkDistanceVariable = 50;

force = d3.layout.force()
.linkDistance( function() { return linkDistanceVariable; } )
.size([w, h])
.start();

// Stop the layout

force.stop();

// Set the new linkDistance val

linkDistanceVariable = 150; // new

// Start the layout

force.start();

Pria Ahuja

unread,
Oct 12, 2015, 7:40:29 AM10/12/15
to d3-js
Reply all
Reply to author
Forward
0 new messages