From 72dccaa51ca36f29940322f332e84940d171a7e0 Mon Sep 17 00:00:00 2001 From: Nils Schneider Date: Sun, 19 Apr 2015 16:29:22 +0200 Subject: [PATCH] forcegraph: restore last panzoom on resetview --- lib/forcegraph.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/forcegraph.js b/lib/forcegraph.js index 10fd665..4a7132c 100644 --- a/lib/forcegraph.js +++ b/lib/forcegraph.js @@ -18,6 +18,7 @@ define(["d3"], function (d3) { var highlightedLinks = [] var nodes = [] var unknownNodes = [] + var savedPanZoom var draggedNode @@ -118,6 +119,12 @@ define(["d3"], function (d3) { var translateP, scaleP + function onPanZoom() { + savedPanZoom = {translate: zoomBehavior.translate(), + scale: zoomBehavior.scale()} + panzoom() + } + function panzoom() { var translate = zoomBehavior.translate() var scale = zoomBehavior.scale() @@ -196,7 +203,10 @@ define(["d3"], function (d3) { } if (!nopanzoom) - panzoomTo([0, 0], force.size()) + if (!savedPanZoom) + panzoomTo([0, 0], force.size()) + else + animatePanzoom(savedPanZoom.translate, savedPanZoom.scale) } function drawLabel(d) { @@ -465,7 +475,7 @@ define(["d3"], function (d3) { zoomBehavior = d3.behavior.zoom() .scaleExtent([1 / 3, 3]) - .on("zoom", panzoom) + .on("zoom", onPanZoom) .translate([sidebar.getWidth(), 0]) canvas = d3.select(el)