diff --git a/lib/forcegraph.js b/lib/forcegraph.js index 2ef1cf4..8b555b2 100644 --- a/lib/forcegraph.js +++ b/lib/forcegraph.js @@ -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 } }) diff --git a/lib/map.js b/lib/map.js index 73e18ea..b389a79 100644 --- a/lib/map.js +++ b/lib/map.js @@ -182,6 +182,10 @@ define(["leaflet", "moment", "leaflet.label"], function (L, moment) { resetView() } + self.destroy = function () { + map.remove() + } + return self } }) diff --git a/lib/router.js b/lib/router.js index 998a1df..01a7472 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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 } })