Kaynağa Gözat

forcegraph: do not animate pan/zoom on first router event

Nils Schneider 9 yıl önce
ebeveyn
işleme
0780a83dd2
1 değiştirilmiş dosya ile 14 ekleme ve 3 silme
  1. 14 3
      lib/forcegraph.js

+ 14 - 3
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 () {