From 0780a83dd24c131ef87c65c0602109ecd7c80650 Mon Sep 17 00:00:00 2001 From: Nils Schneider Date: Tue, 31 Mar 2015 23:45:32 +0200 Subject: [PATCH] forcegraph: do not animate pan/zoom on first router event --- lib/forcegraph.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/forcegraph.js b/lib/forcegraph.js index 8b555b2..0a95e09 100644 --- a/lib/forcegraph.js +++ b/lib/forcegraph.js @@ -6,6 +6,7 @@ define(["d3"], function (d3) { var zoomBehavior var force var el + var doAnimation = false function nodeName(d) { if (d.node && d.node.nodeinfo) @@ -34,9 +35,13 @@ define(["d3"], function (d3) { zoomBehavior.scale(scale) zoomBehavior.translate(translate) - vis.transition().duration(500) - .attr("transform", "translate(" + translate + ") " + - "scale(" + scale + ")") + var el = vis + + if (doAnimation) + el = el.transition().duration(500) + + el.attr("transform", "translate(" + translate + ") " + + "scale(" + scale + ")") } function panzoom() { @@ -236,6 +241,8 @@ define(["d3"], function (d3) { link.classed("highlight", false) animatePanzoom([sidebar.getWidth(), 0], 1) + + doAnimation = true } self.gotoNode = function (d) { @@ -248,6 +255,8 @@ define(["d3"], function (d3) { if (n) panzoomTo([n.x, n.y], [n.x, n.y]) + + doAnimation = true } self.gotoLink = function (d) { @@ -263,6 +272,8 @@ define(["d3"], function (d3) { var y = d3.extent([l.source, l.target], function (d) { return d.y }) panzoomTo([x[0], y[0]], [x[1], y[1]]) } + + doAnimation = true } self.destroy = function () {