From 2ac844a213d5bdc8e9f3fa758f5a8489207d9e79 Mon Sep 17 00:00:00 2001 From: Nils Schneider Date: Fri, 20 Mar 2015 15:03:39 +0100 Subject: [PATCH] history: show links --- history.js | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/history.js b/history.js index 7768b57..2e96f62 100644 --- a/history.js +++ b/history.js @@ -116,11 +116,36 @@ function handle_data(map) { addToList(document.getElementById("newnodes"), "firstseen", newnodes) addToList(document.getElementById("lostnodes"), "lastseen", lostnodes) - mkmap(map, newnodes, lostnodes, onlinenodes) + var graph = data[1].batadv + var nodes = data[0].nodes + + graph.nodes.forEach( function (d) { + if (d.node_id in nodes && "location" in nodes[d.node_id].nodeinfo) + d.node = nodes[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 + }) + + graph = graph.links.filter( function (d) { + var ok = d.source !== undefined && d.target !== undefined + return ok + }) + + mkmap(map, newnodes, lostnodes, onlinenodes, graph) } } -function mkmap(map, newnodes, lostnodes, onlinenodes) { +function mkmap(map, newnodes, lostnodes, onlinenodes, graph) { L.control.zoom({ position: "topright" }).addTo(map) L.tileLayer("http://otile{s}.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.jpg", { @@ -130,6 +155,8 @@ function mkmap(map, newnodes, lostnodes, onlinenodes) { maxZoom: 18 }).addTo(map) + addLinksToMap(map, graph) + var nodes = newnodes.concat(lostnodes).filter( function (d) { return "location" in d.nodeinfo }) @@ -168,6 +195,26 @@ function mkmap(map, newnodes, lostnodes, onlinenodes) { map.fitBounds(group.getBounds()) } +function addLinksToMap(map, graph) { + var scale = chroma.scale(['green', 'orange', 'red']).domain([1, 10]) + + var lines = graph.map( function (d) { + var latlngs = [] + latlngs.push(L.latLng(d.source.node.nodeinfo.location.latitude, d.source.node.nodeinfo.location.longitude)) + latlngs.push(L.latLng(d.target.node.nodeinfo.location.latitude, d.target.node.nodeinfo.location.longitude)) + + var opts = { color: scale(d.tq).hex(), + weight: 3 + } + + var line = L.polyline(latlngs, opts) + + return line + }) + + var group = L.featureGroup(lines).addTo(map) +} + function addToList(el, tf, list) { list.forEach( function (d) { var time = moment(d[tf]).fromNow()