anvaka / ngraph.physics.simulator

Physics library for ngraph
MIT License
23 stars 7 forks source link

Dynamically update Spring Length #2

Open enki opened 8 years ago

enki commented 8 years ago

I have dynamically changing connectionStrength (as per customLinkLength demo), and need to propagate the change to the physics engine. Spring Transform seems to only set the length initially.

Is there a preferred way to update the spring lengths dynamically?

anvaka commented 8 years ago

There are three options.

  1. If you have access to forcelayout object, you can call getSpring() method, and then adjust its length there - this would set individual spring length
  2. If you want to change it on global level (affects every spring), just call layout.simulator.springLength(newLength)
  3. You can also get all individual springs registered within simulator by calling layout.simulator.springs - this will return array of all springs. Be careful with this method, since simulator can change an array if new links are added.