8

I'm using the force layout to represent a directed unweighted network. My inspiration comes from the following example: http://bl.ocks.org/mbostock/1153292

enter image description here

Since my own data are really a mess, I'd like to stop the layout and move nodes by dragging them manually. I'd also like that the movement of a node doesn't change the position of others. And it's necessary that links become longer, to reach the node which has been moved.

Is there a simple way to do this?

4
  • You can call force.stop() to stop the simulation. May 15, 2013 at 15:21
  • Then the movement of the nodes should stop. May 15, 2013 at 16:29
  • 1
    My problem is that when I drag a node it starts again...let's say I would it stop forever... May 15, 2013 at 17:07
  • 3
    Unfortunately you can't disable this. You could however add a custom drag behaviour instead of calling force.drag. May 15, 2013 at 17:25

2 Answers 2

6

At the end I found this related question which implements a solution which I'll adopt.

D3 force directed graph with drag and drop support to make selected node position fixed when dropped

http://bl.ocks.org/norrs/2883411

1
  • Better than a stop/start button! Thanks a lot!
    – Henry
    Aug 6, 2015 at 13:46
0
function nameOfFunction () {
    d3.selectAll(".classOfYourNodes").each(
        function(d) {
            d.fixed = true;
        }
    )
}

The method .each calls the anonymous function, which in this case sets the "fixed" attribute to true for every node within the selection.

Edit: The above is in regards to your comment about wanting to stop all of the nodes and not have the force simulation continue when you drag a node, as calling force.stop() does.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.