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

This commit is contained in:
Nils Schneider 2015-03-31 23:45:32 +02:00
parent 473734f2bb
commit 0780a83dd2

View file

@ -6,6 +6,7 @@ define(["d3"], function (d3) {
var zoomBehavior var zoomBehavior
var force var force
var el var el
var doAnimation = false
function nodeName(d) { function nodeName(d) {
if (d.node && d.node.nodeinfo) if (d.node && d.node.nodeinfo)
@ -34,8 +35,12 @@ define(["d3"], function (d3) {
zoomBehavior.scale(scale) zoomBehavior.scale(scale)
zoomBehavior.translate(translate) zoomBehavior.translate(translate)
vis.transition().duration(500) var el = vis
.attr("transform", "translate(" + translate + ") " +
if (doAnimation)
el = el.transition().duration(500)
el.attr("transform", "translate(" + translate + ") " +
"scale(" + scale + ")") "scale(" + scale + ")")
} }
@ -236,6 +241,8 @@ define(["d3"], function (d3) {
link.classed("highlight", false) link.classed("highlight", false)
animatePanzoom([sidebar.getWidth(), 0], 1) animatePanzoom([sidebar.getWidth(), 0], 1)
doAnimation = true
} }
self.gotoNode = function (d) { self.gotoNode = function (d) {
@ -248,6 +255,8 @@ define(["d3"], function (d3) {
if (n) if (n)
panzoomTo([n.x, n.y], [n.x, n.y]) panzoomTo([n.x, n.y], [n.x, n.y])
doAnimation = true
} }
self.gotoLink = function (d) { 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 }) var y = d3.extent([l.source, l.target], function (d) { return d.y })
panzoomTo([x[0], y[0]], [x[1], y[1]]) panzoomTo([x[0], y[0]], [x[1], y[1]])
} }
doAnimation = true
} }
self.destroy = function () { self.destroy = function () {