refactor router

This commit is contained in:
Nils Schneider 2015-03-25 20:55:49 +01:00
parent 26f6936d39
commit 1e6e868bfb
2 changed files with 27 additions and 25 deletions

View File

@ -10,7 +10,7 @@ define(function () {
m.setStyle(iconFunc(d)) m.setStyle(iconFunc(d))
} }
m.on('click', router.node(d, false)) m.on('click', router.node(d))
m.bindLabel(d.nodeinfo.hostname) m.bindLabel(d.nodeinfo.hostname)
dict[d.nodeinfo.node_id] = m dict[d.nodeinfo.node_id] = m
@ -38,7 +38,7 @@ define(function () {
} }
line.bindLabel(d.source.node.nodeinfo.hostname + " " + d.target.node.nodeinfo.hostname + "<br><strong>" + showDistance(d) + " / " + showTq(d) + "</strong>") line.bindLabel(d.source.node.nodeinfo.hostname + " " + d.target.node.nodeinfo.hostname + "<br><strong>" + showDistance(d) + " / " + showTq(d) + "</strong>")
line.on('click', router.link(d, false)) line.on('click', router.link(d))
dict[linkId(d)] = line dict[linkId(d)] = line

View File

@ -15,32 +15,16 @@ define(function () {
saveState() saveState()
} }
function gotoNode(d, showMap, push) { function gotoNode(d) {
showMap = trueDefault(showMap)
push = trueDefault(push)
targets.forEach( function (t) { targets.forEach( function (t) {
t.gotoNode(d) t.gotoNode(d)
}) })
if (push)
saveState( { node: d })
return false
} }
function gotoLink(d, showMap, push) { function gotoLink(d) {
showMap = trueDefault(showMap)
push = trueDefault(push)
targets.forEach( function (t) { targets.forEach( function (t) {
t.gotoLink(d) t.gotoLink(d)
}) })
if (push)
saveState( { link: d })
return false
} }
function saveState(d) { function saveState(d) {
@ -73,20 +57,38 @@ define(function () {
var id = args[1] var id = args[1]
if (id in objects.nodes) if (id in objects.nodes)
gotoNode(objects.nodes[id], true, false) gotoNode(objects.nodes[id])
} }
if (args[0] === "l") { if (args[0] === "l") {
var id = args[1] var id = args[1]
if (id in objects.links) if (id in objects.links)
gotoLink(objects.links[id], true, false) gotoLink(objects.links[id])
} }
} }
self.node = function (d, m, p) { return function () { return gotoNode(d, m, p) }} self.node = function (d) {
self.link = function (d, m, p) { return function () { return gotoLink(d, m, p) }} return function () {
self.reset = resetView gotoNode(d)
saveState({ node: d })
return false
}
}
self.link = function (d) {
return function () {
gotoLink(d)
saveState({ link: d })
return false
}
}
self.reset = function () {
resetView()
saveState()
}
self.addMarkers = function (d) { self.addMarkers = function (d) {
markers = d markers = d
} }