This question is a follow-up on a previous one titled \"D3-Force updating parameters after initializing graph\" (D3-Force updating parameters after initializing graph) and t
This will not actually update the radius. You are just re-setting the callback used to determine the radius, which doesn't even change compared to what it was before. Even if it did change, this would not trigger your update, because the radii won't be re-evaluated based on your updated data.
When updating the distance callback of the link force, the force itself will get initialized. A look at the source shows a call to initializeDistance()
:
force.distance = function(_) {
return arguments.length ? (distance = typeof _ === "function" ? _ : constant(+_), initializeDistance(), force) : distance;
};
The same holds true for many other updates of other forces' parameters.
Looking at the source of the collide force, however, one notices that there is no initialization invoked:
force.radius = function(_) {
return arguments.length ? (radius = typeof _ === "function" ? _ : constant(+_), force) : radius;
};
Since your callback doesn't change you won't need to call forceCollide.radius()
again. Instead you need to call
forceCollide.initialize(simulation.nodes());
This will re-evaluate the radii based on your updated data.