forcegraph: restore last panzoom on resetview

This commit is contained in:
Nils Schneider 2015-04-19 16:29:22 +02:00
parent 3a6d4855a9
commit 72dccaa51c

View file

@ -18,6 +18,7 @@ define(["d3"], function (d3) {
var highlightedLinks = [] var highlightedLinks = []
var nodes = [] var nodes = []
var unknownNodes = [] var unknownNodes = []
var savedPanZoom
var draggedNode var draggedNode
@ -118,6 +119,12 @@ define(["d3"], function (d3) {
var translateP, scaleP var translateP, scaleP
function onPanZoom() {
savedPanZoom = {translate: zoomBehavior.translate(),
scale: zoomBehavior.scale()}
panzoom()
}
function panzoom() { function panzoom() {
var translate = zoomBehavior.translate() var translate = zoomBehavior.translate()
var scale = zoomBehavior.scale() var scale = zoomBehavior.scale()
@ -196,7 +203,10 @@ define(["d3"], function (d3) {
} }
if (!nopanzoom) if (!nopanzoom)
if (!savedPanZoom)
panzoomTo([0, 0], force.size()) panzoomTo([0, 0], force.size())
else
animatePanzoom(savedPanZoom.translate, savedPanZoom.scale)
} }
function drawLabel(d) { function drawLabel(d) {
@ -465,7 +475,7 @@ define(["d3"], function (d3) {
zoomBehavior = d3.behavior.zoom() zoomBehavior = d3.behavior.zoom()
.scaleExtent([1 / 3, 3]) .scaleExtent([1 / 3, 3])
.on("zoom", panzoom) .on("zoom", onPanZoom)
.translate([sidebar.getWidth(), 0]) .translate([sidebar.getWidth(), 0])
canvas = d3.select(el) canvas = d3.select(el)