prepare router, forcegraph, map for destroy/reload

This commit is contained in:
Nils Schneider 2015-03-31 23:24:24 +02:00
parent 625e7ba880
commit 473734f2bb
3 changed files with 40 additions and 8 deletions

View File

@ -1,7 +1,7 @@
define(["d3"], function (d3) {
return function (linkScale, sidebar, router) {
var self = this
var vis, link, node, label
var svg, vis, link, node, label
var nodesDict, linksDict
var zoomBehavior
var force
@ -72,8 +72,6 @@ define(["d3"], function (d3) {
var height = el.offsetHeight
force.size([width, height])
force.start()
panzoom()
}
function tickEvent() {
@ -99,11 +97,13 @@ define(["d3"], function (d3) {
zoomBehavior = d3.behavior.zoom()
.scaleExtent([1 / 3, 3])
.on("zoom", panzoom)
.translate([sidebar.getWidth(), 0])
vis = d3.select(el).append("svg")
.attr("pointer-events", "all")
.call(zoomBehavior)
.append("g")
svg = d3.select(el).append("svg")
.attr("pointer-events", "all")
.call(zoomBehavior)
vis = svg.append("g")
vis.append("g").attr("class", "links")
vis.append("g").attr("class", "nodes")
@ -115,6 +115,8 @@ define(["d3"], function (d3) {
.linkDistance(70)
.on("tick", tickEvent)
panzoom()
var draggableNode = d3.behavior.drag()
.on("dragstart", dragstart)
.on("drag", dragmove)
@ -263,6 +265,21 @@ define(["d3"], function (d3) {
}
}
self.destroy = function () {
window.removeEventListener("resize", resize)
force.stop()
node.remove()
link.remove()
svg.remove()
force = null
svg = null
vis = null
link = null
node = null
label = null
}
return self
}
})

View File

@ -182,6 +182,10 @@ define(["leaflet", "moment", "leaflet.label"], function (L, moment) {
resetView()
}
self.destroy = function () {
map.remove()
}
return self
}
})

View File

@ -1,8 +1,9 @@
define(function () {
return function () {
var self = this
var objects = { nodes: {}, links: {} }
var targets = []
var self = this
var running = false
function saveState(d) {
var s = "#!"
@ -79,6 +80,8 @@ define(function () {
}
self.start = function () {
running = true
if (!loadState(window.location.hash))
resetView(false)
@ -134,6 +137,14 @@ define(function () {
})
}
self.reload = function () {
if (!running)
return
if (!loadState(window.history.state))
resetView(false)
}
return self
}
})