2015-03-25 20:25:41 +01:00
|
|
|
require(["router", "map", "sidebar", "meshstats", "linklist", "simplenodelist", "infobox/main"],
|
|
|
|
function (Router, Map, Sidebar, Meshstats, Linklist, SimpleNodelist, Infobox) {
|
2015-03-25 21:11:15 +01:00
|
|
|
getJSON("config.json").then(main)
|
2015-03-25 00:54:00 +01:00
|
|
|
|
2015-03-25 21:11:15 +01:00
|
|
|
function main(config) {
|
2015-03-25 21:19:52 +01:00
|
|
|
var linklist, lostnodeslist, map, meshstats, newnodeslist, router
|
2015-03-25 00:54:00 +01:00
|
|
|
|
2015-03-25 21:19:52 +01:00
|
|
|
function createGUI() {
|
|
|
|
moment.locale("de")
|
2015-03-25 00:54:00 +01:00
|
|
|
|
2015-03-25 21:19:52 +01:00
|
|
|
router = new Router(config)
|
2015-03-25 01:16:15 +01:00
|
|
|
|
2015-03-25 21:19:52 +01:00
|
|
|
var linkScale = chroma.scale(chroma.interpolate.bezier(['green', 'yellow', 'red'])).domain([1, 5])
|
|
|
|
var sidebar = new Sidebar(document.body)
|
|
|
|
var infobox = new Infobox(config, sidebar, router)
|
2015-03-25 11:21:09 +01:00
|
|
|
|
2015-03-25 21:19:52 +01:00
|
|
|
map = new Map(linkScale, sidebar, router)
|
|
|
|
document.body.insertBefore(map.div, document.body.firstChild)
|
2015-03-25 11:21:09 +01:00
|
|
|
|
2015-03-25 21:19:52 +01:00
|
|
|
meshstats = new Meshstats()
|
|
|
|
newnodeslist = new SimpleNodelist(config, "firstseen", router, "Neue Knoten")
|
|
|
|
lostnodeslist = new SimpleNodelist(config, "lastseen", router, "Verschwundene Knoten")
|
|
|
|
linklist = new Linklist(linkScale, router)
|
|
|
|
|
|
|
|
sidebar.add(meshstats)
|
|
|
|
sidebar.add(newnodeslist)
|
|
|
|
sidebar.add(lostnodeslist)
|
|
|
|
sidebar.add(linklist)
|
|
|
|
|
|
|
|
router.addTarget(infobox)
|
|
|
|
router.addTarget(map)
|
|
|
|
}
|
2015-03-25 00:54:00 +01:00
|
|
|
|
2015-03-25 21:11:15 +01:00
|
|
|
var urls = [ config.dataPath + 'nodes.json',
|
|
|
|
config.dataPath + 'graph.json'
|
|
|
|
]
|
2015-03-25 00:54:00 +01:00
|
|
|
|
2015-03-25 21:11:15 +01:00
|
|
|
Promise.all(urls.map(getJSON))
|
2015-03-25 21:19:52 +01:00
|
|
|
.then(function (d) { createGUI(); return d })
|
2015-03-25 21:11:15 +01:00
|
|
|
.then(handle_data)
|
|
|
|
.then(function () { router.loadState(window.location.hash) })
|
2015-03-25 16:28:36 +01:00
|
|
|
|
2015-03-25 21:11:15 +01:00
|
|
|
function handle_data(data) {
|
2015-03-25 00:54:00 +01:00
|
|
|
var nodedict = data[0]
|
|
|
|
var nodes = Object.keys(nodedict.nodes).map(function (key) { return nodedict.nodes[key] })
|
|
|
|
|
|
|
|
nodes = nodes.filter( function (d) {
|
|
|
|
return "firstseen" in d && "lastseen" in d
|
|
|
|
})
|
|
|
|
|
|
|
|
nodes.forEach( function(node) {
|
|
|
|
node.firstseen = moment.utc(node.firstseen)
|
|
|
|
node.lastseen = moment.utc(node.lastseen)
|
|
|
|
})
|
|
|
|
|
|
|
|
var now = moment()
|
|
|
|
var age = moment(now).subtract(14, 'days')
|
|
|
|
|
|
|
|
var newnodes = limit("firstseen", age, sortByKey("firstseen", nodes).filter(online))
|
|
|
|
var lostnodes = limit("lastseen", age, sortByKey("lastseen", nodes).filter(offline))
|
|
|
|
|
|
|
|
var onlinenodes = nodes.filter(online)
|
|
|
|
|
|
|
|
var graph = data[1].batadv
|
|
|
|
var graphnodes = data[0].nodes
|
|
|
|
|
|
|
|
graph.nodes.forEach( function (d) {
|
|
|
|
if (d.node_id in graphnodes)
|
|
|
|
d.node = graphnodes[d.node_id]
|
|
|
|
})
|
|
|
|
|
|
|
|
graph.links.forEach( function (d) {
|
|
|
|
if (graph.nodes[d.source].node)
|
|
|
|
d.source = graph.nodes[d.source]
|
|
|
|
else
|
|
|
|
d.source = undefined
|
|
|
|
|
|
|
|
if (graph.nodes[d.target].node)
|
|
|
|
d.target = graph.nodes[d.target]
|
|
|
|
else
|
|
|
|
d.target = undefined
|
|
|
|
})
|
|
|
|
|
|
|
|
var links = graph.links.filter( function (d) {
|
|
|
|
return d.source !== undefined && d.target !== undefined
|
|
|
|
})
|
|
|
|
|
|
|
|
links.forEach( function (d) {
|
|
|
|
if (!("location" in d.source.node.nodeinfo && "location" in d.target.node.nodeinfo))
|
|
|
|
return
|
|
|
|
|
|
|
|
d.latlngs = []
|
|
|
|
d.latlngs.push(L.latLng(d.source.node.nodeinfo.location.latitude, d.source.node.nodeinfo.location.longitude))
|
|
|
|
d.latlngs.push(L.latLng(d.target.node.nodeinfo.location.latitude, d.target.node.nodeinfo.location.longitude))
|
|
|
|
|
|
|
|
d.distance = d.latlngs[0].distanceTo(d.latlngs[1])
|
|
|
|
})
|
|
|
|
|
|
|
|
nodes.forEach( function (d) {
|
|
|
|
d.neighbours = []
|
|
|
|
})
|
|
|
|
|
|
|
|
links.forEach( function (d) {
|
|
|
|
d.source.node.neighbours.push({ node: d.target.node, link: d })
|
|
|
|
d.target.node.neighbours.push({ node: d.source.node, link: d })
|
|
|
|
})
|
|
|
|
|
2015-03-25 16:36:24 +01:00
|
|
|
map.setData(now, newnodes, lostnodes, onlinenodes, links)
|
2015-03-25 15:33:36 +01:00
|
|
|
meshstats.setData(nodes)
|
2015-03-25 16:04:23 +01:00
|
|
|
linklist.setData(links)
|
2015-03-25 16:28:36 +01:00
|
|
|
newnodeslist.setData(newnodes)
|
|
|
|
lostnodeslist.setData(lostnodes)
|
2015-03-25 20:25:41 +01:00
|
|
|
router.setData(nodes, links)
|
2015-03-25 00:54:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|