From a3f473a6df312b4674ceea7f8f1412839f7f8e27 Mon Sep 17 00:00:00 2001 From: Nils Schneider Date: Thu, 16 Apr 2015 20:19:31 +0200 Subject: [PATCH] forcegraph: redraw using requestAnimationFrame --- lib/forcegraph.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/forcegraph.js b/lib/forcegraph.js index 6189ff9..ba15722 100644 --- a/lib/forcegraph.js +++ b/lib/forcegraph.js @@ -124,9 +124,6 @@ define(["d3"], function (d3) { panzoomReal(translate, scale) - - translateP = translate - scaleP = scale } function panzoomReal(translate, scale) { @@ -134,7 +131,7 @@ define(["d3"], function (d3) { right: (canvas.width - translate[0]) / scale, bottom: (canvas.height - translate[1]) / scale} - redraw() + requestAnimationFrame(redraw) } function getSize() { @@ -266,6 +263,10 @@ define(["d3"], function (d3) { xExtent[1] - xExtent[0] + 2 * margin, yExtent[1] - yExtent[0] + 2 * margin) + // Remeber last translate/scale state + translateP = translate + scaleP = scale + ctx.beginPath() nodes.filter(visibleNodes).forEach(function (d) { var clients = d.o.node.statistics.clients @@ -384,7 +385,7 @@ define(["d3"], function (d3) { canvas.style.height = el.offsetHeight + "px" ctx.resetTransform() ctx.scale(r, r) - redraw() + requestAnimationFrame(redraw) } function distance(a, b) {