forcegraph: reset zoom on resetView

This commit is contained in:
Nils Schneider 2015-03-31 21:29:47 +02:00
parent d2fe76f736
commit 48147eb417

View file

@ -53,6 +53,10 @@ define(["d3"], function (d3) {
var y = -centroid[1] * scale + size[1] / 2
var translate = [x + sidebarWidth, y]
animatePanzoom(translate, scale)
}
function animatePanzoom(translate, scale) {
zoomBehavior.scale(scale)
zoomBehavior.translate(translate)
@ -61,17 +65,11 @@ define(["d3"], function (d3) {
"scale(" + scale + ")")
}
function resize(initial) {
function resize() {
var sidebarWidth = sidebar.getWidth()
var width = el.offsetWidth - sidebarWidth
var height = el.offsetHeight
if (initial === true) {
var translate = zoomBehavior.translate()
translate[0] += sidebarWidth
zoomBehavior.translate(translate)
}
force.size([width, height])
force.start()
panzoom()
@ -225,7 +223,7 @@ define(["d3"], function (d3) {
force.nodes(nodes)
.links(links)
resize(true)
resize()
force.start()
}
@ -233,6 +231,10 @@ define(["d3"], function (d3) {
self.resetView = function () {
node.classed("highlight", false)
link.classed("highlight", false)
var size = force.size()
animatePanzoom([sidebar.getWidth(), 0], 1)
}
self.gotoNode = function (d) {