refactor setData

This commit is contained in:
Nils Schneider 2015-03-29 17:48:25 +02:00
commit a031ac336d
7 changed files with 47 additions and 35 deletions

View file

@ -18,8 +18,8 @@ function (config, moment, chroma, Router, Map, Sidebar, Tabs, Container, Meshsta
document.body.insertBefore(map.div, document.body.firstChild)
meshstats = new Meshstats()
newnodeslist = new SimpleNodelist(config, "firstseen", router, "Neue Knoten")
lostnodeslist = new SimpleNodelist(config, "lastseen", router, "Verschwundene Knoten")
newnodeslist = new SimpleNodelist(config, "new", "firstseen", router, "Neue Knoten")
lostnodeslist = new SimpleNodelist(config, "lost", "lastseen", router, "Verschwundene Knoten")
nodelist = new Nodelist(router)
linklist = new Linklist(linkScale, router)
@ -37,8 +37,7 @@ function (config, moment, chroma, Router, Map, Sidebar, Tabs, Container, Meshsta
}
function handleData(data) {
var nodedict = data[0]
var nodes = Object.keys(nodedict.nodes).map(function (key) { return nodedict.nodes[key] })
var nodes = Object.keys(data[0].nodes).map(function (key) { return data[0].nodes[key] })
nodes = nodes.filter( function (d) {
return "firstseen" in d && "lastseen" in d
@ -99,13 +98,15 @@ function (config, moment, chroma, Router, Map, Sidebar, Tabs, Container, Meshsta
d.target.node.neighbours.push({ node: d.source.node, link: d })
})
map.setData(now, nodes, links, newnodes, lostnodes)
meshstats.setData(nodes)
nodelist.setData(now, nodes)
linklist.setData(links)
newnodeslist.setData(newnodes)
lostnodeslist.setData(lostnodes)
router.setData(nodes, links)
return { now: now,
timestamp: data[0].timestamp,
nodes: {
all: nodes,
new: newnodes,
lost: lostnodes
},
links: links
}
}
var urls = [ config.dataPath + "nodes.json",
@ -118,6 +119,15 @@ function (config, moment, chroma, Router, Map, Sidebar, Tabs, Container, Meshsta
return d
})
.then(handleData)
.then(function (d) {
map.setData(d)
meshstats.setData(d)
nodelist.setData(d)
linklist.setData(d)
newnodeslist.setData(d)
lostnodeslist.setData(d)
router.setData(d)
})
.then(function () { router.start() })
}