Check out this thread which has a lot of good info relating to this topic.
One suggestion from that thread that you might try to implement is to call force.tick()
several times within a single requestAnimationFrame
callback, then update the node and link positions, and then loop until force.alpha
reaches 0 (or whatever you want your alpha threshold to be). Try something like this:
var ticksPerRender = 3;
requestAnimationFrame(function render() {
for (var i = 0; i < ticksPerRender; i++) {
force.tick();
}
// UPDATE NODE AND LINK POSITIONS HERE
if (force.alpha() > 0) {
requestAnimationFrame(render);
}
});
That would render once for every 3 ticks, or 3x speed. Adjust the ticksPerRender
value as needed.
HERE is a simple demo. In this case, I've used the force.on('start', callback)
to call the rendering logic described above. This means it will automatically be called again when beginning a drag interaction.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…