From 48147eb417e5daab6b718f9e7facfec602c77f07 Mon Sep 17 00:00:00 2001 From: Nils Schneider Date: Tue, 31 Mar 2015 21:29:47 +0200 Subject: [PATCH] forcegraph: reset zoom on resetView --- lib/forcegraph.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/forcegraph.js b/lib/forcegraph.js index 50a3b22..1a87808 100644 --- a/lib/forcegraph.js +++ b/lib/forcegraph.js @@ -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) {