From ef7f60179a95ab3b6c6d9b390075e7c20a59283a Mon Sep 17 00:00:00 2001 From: Nils Schneider Date: Thu, 16 Apr 2015 20:35:42 +0200 Subject: [PATCH] forcegraph: limit framerate --- lib/forcegraph.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) 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() {