vasturiano/force-graph

Graph rerenders when showing particles using `linkDirectionalParticles`

mgonline opened this issue · 1 comments

Describe the bug
DEMO: https://codesandbox.io/s/force-graph-enable-particles-dynamic-bjz8pg

I want to show particles for specific edges dynamically. The dynamicity comes from a state variable, so I have to pass an accessor function to .linkDirectionalParticles(...). That didn't work, probably because graph doesn't know when my state variable changed. So I did the following after changing the state variable:

graph.linkDirectionalParticles(graph.linkDirectionalParticles())

...and it worked! HOWEVER...

The problem seems to be an interference with some of the forces - specifically collide and radial. This is because if I remove the forces, it works well. Similarly, if I remove the above line that forcefully sets linkDirectionalParticles, it works too (different story it doesn't show particles).

As you can see in the demo, I haven't used anything extraordinary. I'm confused if this is an issue with force-graph, d3-force, or my own code. Highly appreciate any help making this work. Thanks!

To Reproduce
See DEMO

Expected behavior
Graph shouldn't rerender when enabling particles.

Desktop (please complete the following information):

  • OS: WIn/Mac
  • Browser: Chrome
  • Version: latest

Additional context
Add any other context about the problem here.

Thanks for reporting @mgonline. I've just pushed an update that should fix this. The force simulation engine was unnecessarily being reheated on changes to the links particle counts.