forcegraph: limit framerate

This commit is contained in:
Nils Schneider 2015-04-16 20:35:42 +02:00
parent a3f473a6df
commit ef7f60179a

View File

@ -236,7 +236,18 @@ define(["d3"], function (d3) {
d.y + margin > screenRect.top && d.y - margin < screenRect.bottom 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 translate = zoomBehavior.translate()
var scale = zoomBehavior.scale() var scale = zoomBehavior.scale()
var links = intLinks.filter(visibleLinks) var links = intLinks.filter(visibleLinks)
@ -374,7 +385,7 @@ define(["d3"], function (d3) {
} }
function tickEvent() { function tickEvent() {
redraw() requestAnimationFrame(redraw)
} }
function resizeCanvas() { function resizeCanvas() {