D3-force forceCollide update radius after graph initialization

This question is a continuation of the previous version entitled "D3-Force update options after initializing the graph" ( D3-Force update options after graph initialization ) and what @altocumulus answered.

I am trying to update simulation simulations after changing the radius of some nodes. However, when I call forceCollideto account for changes, it does not work.

The graph is first triggered correctly using forceCollide, and the function, so that the force corresponds to the radius:

var forceCollide = d3.forceCollide()
.radius(function(d){return d.radius;})
.iterations(2)
.strength(0.95);

var simulation = d3.forceSimulation()
.velocityDecay(velocityDecay)
.force("collide", forceCollide);

Then I modify the object d.radiusand want it to forceCollidereflect the changes. However, when I call again forceCollide, it does not work:

forceCollide.radius(function(d){
d.radius;})

Any thoughts on why this is happening?

+4
1

. , , , . , , .

. initializeDistance():

force.distance = function(_) {
  return arguments.length ? (distance = typeof _ === "function" ? _ : constant(+_), initializeDistance(), force) : distance;
};

.

collide, , :

force.radius = function(_) {
  return arguments.length ? (radius = typeof _ === "function" ? _ : constant(+_), force) : radius;
};

, forceCollide.radius().

forceCollide.initialize(simulation.nodes());

.

+5

Source: https://habr.com/ru/post/1651816/


All Articles