diff --git a/lib/forcegraph.js b/lib/forcegraph.js index ba15722..506b0b1 100644 --- a/lib/forcegraph.js +++ b/lib/forcegraph.js @@ -236,7 +236,18 @@ define(["d3"], function (d3) { d.y + margin > screenRect.top && d.y - margin < screenRect.bottom } - function redraw() { + var oldTime = 0 + + function redraw(time) { + var deltaTime = time - oldTime + + if (deltaTime < 20) { + requestAnimationFrame(redraw) + return + } + + oldTime = time + var translate = zoomBehavior.translate() var scale = zoomBehavior.scale() var links = intLinks.filter(visibleLinks) @@ -374,7 +385,7 @@ define(["d3"], function (d3) { } function tickEvent() { - redraw() + requestAnimationFrame(redraw) } function resizeCanvas() {