forcegraph: redraw using requestAnimationFrame

This commit is contained in:
Nils Schneider 2015-04-16 20:19:31 +02:00
parent 70d78e3742
commit a3f473a6df

View file

@ -124,9 +124,6 @@ define(["d3"], function (d3) {
panzoomReal(translate, scale) panzoomReal(translate, scale)
translateP = translate
scaleP = scale
} }
function panzoomReal(translate, scale) { function panzoomReal(translate, scale) {
@ -134,7 +131,7 @@ define(["d3"], function (d3) {
right: (canvas.width - translate[0]) / scale, right: (canvas.width - translate[0]) / scale,
bottom: (canvas.height - translate[1]) / scale} bottom: (canvas.height - translate[1]) / scale}
redraw() requestAnimationFrame(redraw)
} }
function getSize() { function getSize() {
@ -266,6 +263,10 @@ define(["d3"], function (d3) {
xExtent[1] - xExtent[0] + 2 * margin, xExtent[1] - xExtent[0] + 2 * margin,
yExtent[1] - yExtent[0] + 2 * margin) yExtent[1] - yExtent[0] + 2 * margin)
// Remeber last translate/scale state
translateP = translate
scaleP = scale
ctx.beginPath() ctx.beginPath()
nodes.filter(visibleNodes).forEach(function (d) { nodes.filter(visibleNodes).forEach(function (d) {
var clients = d.o.node.statistics.clients var clients = d.o.node.statistics.clients
@ -384,7 +385,7 @@ define(["d3"], function (d3) {
canvas.style.height = el.offsetHeight + "px" canvas.style.height = el.offsetHeight + "px"
ctx.resetTransform() ctx.resetTransform()
ctx.scale(r, r) ctx.scale(r, r)
redraw() requestAnimationFrame(redraw)
} }
function distance(a, b) { function distance(a, b) {