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) {