GarethAyres
GarethAyres

Reputation: 106

Make a fixed node in d3.js un-fixed

How can i make d3.js force-layout nodes that have fixed:true become unfixed?

If i set them to d.fixed=false this does not work.

I have code similar to http://bl.ocks.org/norrs/2883411 working. So it sets d.fixed=true on drag.

evaluating d.fixed as Boolean doesnt appear to work either.

But i would like to be able to unfix the nodes too.

Either on drag or via some other function.

Im trying this:

if (d.fixed==false) {
        d.fixed=true;
        d3.select(this).classed("fixed", true);
}
else
{
        d.fixed = false;
        d3.select(this).classed("fixed", false);
}

The bad results can be seen on this fiddle: http://jsfiddle.net/2u5KB/2/

Thanks, Gareth.

Upvotes: 1

Views: 1866

Answers (1)

GarethAyres
GarethAyres

Reputation: 106

OK i worked out my problem.

I was doing the check and change on d.fixed in the dragstart method.

Moving the code to the dragend method resolved the problem.

I guess dragstart has some different behavior that i expected

Upvotes: 1

Related Questions