Rather than storing separate state for the nodes’ fixed positions, just use the
fx and fy properties on the nodes themselves. This is more similar to the 3.x
API which used node.fixed (and node.px, node.py to store the previous position).
This eliminates the need to expose additional APIs for getting, setting,
clearing and iterating over the fixed positions.
Fixes#35.
Related #30. Rather than normalize the total force applied per node, have the
default link strength be inversely proportional to the number of links for the
source and the target. This way, if the source or target is heavily connected,
the strength of the link is reduced. However, we still bias the application of
the link such that the less-connected of the two nodes is moved more.
This feels a bit cleaner since you don’t need to track the name of the fixing
force externally. It also enforces that fixing happens after the application of
any forces.
This lets you set the “desired” alpha for the simulation, and have the
simulation smoothly interpolate towards the desired value. By default, the
target value is zero, such that the simulation cools. However, by setting it to
a non-zero value, such as during a drag interaction, you can also use it to have
the simulation heat. Fixes#26.
This commit also changes simulation.restart so that it no longer resets the
alpha to one, and changes the meaning of simulation.alphaDecay. The new default
alphaDecay now cause the simulation to end after 300 ticks, instead of 345.
It’s tempting to do them independently (in parallel), but this makes convergence
much slower. We’re now moving nodes while they’re in the quadtree, which means
we could miss a few collisions; but since the tree is rebuilt on each iteration
that should probably be fine.
This reverts part of 95354e8470, though it retains
the area-biased resolution and the performance improvements.
Fix#25. We now resolve collisions for all nodes independently, rather than
moving one node at a time. And since we’re not mutating the quadtree while
resolving, the quadtree can now store the maximum radius for each quadrant,
accelerating search! We can also optimize resolution a little bit since now
resolutions are always symmetric.
Collision resolutions are now biased so that the acceleration is inversely
proportional to the circle’s area, such that larger circles (which are more
likely to overlap many small circles) are more stable.
Also: only jiggle if two circles are overlapping.
Fixes#23. This doesn’t catch all degenerate configurations, such as when x = y,
but it at least handles a common case for geometric constraints. As an added
bonus, this commit avoids extraneous jiggling in the many-body force when
visiting testing the target node’s quadtree cell.
This changes simulation.tick to always advance the simulation one step,
regardless of the current value of alpha and alphaMin. If alpha is less than
alphaMin after this step, simulation.tick returns true, indicating that the
simulation can be safely ended.
Furthermore, simulation.tick no longer dispatches a tick event; the tick event
is only dispatched by the simulation’s internal timer. This is now consistent
with simulation.stop, which likewise does not dispatch an end event; the end
event is only dispatched when the simulation’s internal timer stops.
Rather than initialize the node positions randomly, use a phyllotaxis. This is
just as good, and means the resulting behavior will be deterministic as long as
no nodes are exactly coincident.
Calling simulation.stop no longer resets the alpha, so a subsequent call to
simulation.start now resumes the simulation, and you can call simulation.tick to
run the simulation manually.
This commit also removes the start event. There’s not much of a point to the
start event since it’s impossible to listen for it in the normal case: the event
is dispatched during the construction of the simulation before any listeners can
be registered. Even in other cases, the simulation is always restarted manually,
so you could always notify a listener manually at the same time. Furthermore,
supporting a start event would require us to track whether the timer is running,
so it’s simpler to just leave it out. (And lastly, eliminating the start event
avoids some confusion about the relationship between simulation.stop and the end
event, which are unrelated!)
Lastly, simplify the recalculation of the current iteration when changing the
alpha decay rate constant.