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