From 97a00b6925e3f428ecd53c388fa596b4544d4803 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milan=20P=C3=A4ssler?= Date: Sat, 27 Feb 2016 14:43:27 +0100 Subject: [PATCH] forcegraph: show links with unknown nodes --- lib/filters/nodefilter.js | 2 +- lib/forcegraph.js | 2 +- lib/infobox/link.js | 11 +++++++---- lib/infobox/node.js | 10 ++++++---- lib/linklist.js | 2 +- lib/main.js | 31 +++++++++++++++++++------------ lib/title.js | 2 +- 7 files changed, 36 insertions(+), 24 deletions(-) diff --git a/lib/filters/nodefilter.js b/lib/filters/nodefilter.js index e4e979d..920352d 100644 --- a/lib/filters/nodefilter.js +++ b/lib/filters/nodefilter.js @@ -24,7 +24,7 @@ define([], function () { }) n.graph.links = data.graph.links.filter( function (d) { - return filteredIds.has(d.source.id) && filteredIds.has(d.target.id) + return !d.sourceid || (filteredIds.has(d.source.id) && filteredIds.has(d.target.id)) }) return n diff --git a/lib/forcegraph.js b/lib/forcegraph.js index 2cf49f3..995fd8a 100644 --- a/lib/forcegraph.js +++ b/lib/forcegraph.js @@ -685,7 +685,7 @@ define(["d3"], function (d3) { d.source.neighbours[d.target.o.id] = {node: d.target, link: d} d.target.neighbours[d.source.o.id] = {node: d.source, link: d} - if (d.o.source.node && d.o.target.node) + if (d.o.source && d.o.target) linksDict[d.o.id] = d }) diff --git a/lib/infobox/link.js b/lib/infobox/link.js index acbb432..df91163 100644 --- a/lib/infobox/link.js +++ b/lib/infobox/link.js @@ -1,10 +1,13 @@ define(function () { return function (config, el, router, d) { + var unknown = !(d.source.node) var h2 = document.createElement("h2") var a1 = document.createElement("a") - a1.href = "#" - a1.onclick = router.node(d.source.node) - a1.textContent = d.source.node.nodeinfo.hostname + if (!unknown) { + a1.href = "#" + a1.onclick = router.node(d.source.node) + } + a1.textContent = unknown ? d.source.id : d.source.node.nodeinfo.hostname h2.appendChild(a1) h2.appendChild(document.createTextNode(" → ")) var a2 = document.createElement("a") @@ -20,7 +23,7 @@ define(function () { attributeEntry(attributes, "TQ", showTq(d)) attributeEntry(attributes, "Entfernung", showDistance(d)) attributeEntry(attributes, "Typ", d.type) - var hw1 = dictGet(d.source.node.nodeinfo, ["hardware", "model"]) + var hw1 = unknown ? null : dictGet(d.source.node.nodeinfo, ["hardware", "model"]) var hw2 = dictGet(d.target.node.nodeinfo, ["hardware", "model"]) attributeEntry(attributes, "Hardware", (hw1 != null ? hw1 : "unbekannt") + " – " + (hw2 != null ? hw2 : "unbekannt")) diff --git a/lib/infobox/node.js b/lib/infobox/node.js index 90b00d8..39b8183 100644 --- a/lib/infobox/node.js +++ b/lib/infobox/node.js @@ -326,6 +326,7 @@ define(["moment", "numeral", "tablesort", "tablesort.numeric"], var tbody = document.createElement("tbody") d.neighbours.forEach( function (d) { + var unknown = !(d.node) var tr = document.createElement("tr") var td1 = document.createElement("td") @@ -335,12 +336,13 @@ define(["moment", "numeral", "tablesort", "tablesort.numeric"], var td2 = document.createElement("td") var a1 = document.createElement("a") a1.classList.add("hostname") - a1.textContent = d.node.nodeinfo.hostname - a1.href = "#" - a1.onclick = router.node(d.node) + a1.textContent = unknown ? d.id : d.node.nodeinfo.hostname + if (!unknown) + a1.href = "#" + a1.onclick = router.node(d.node) td2.appendChild(a1) - if (has_location(d.node)) { + if (!unknown && has_location(d.node)) { var span = document.createElement("span") span.classList.add("icon") span.classList.add("ion-location") diff --git a/lib/linklist.js b/lib/linklist.js index e195dde..1fc8574 100644 --- a/lib/linklist.js +++ b/lib/linklist.js @@ -1,6 +1,6 @@ define(["sorttable", "virtual-dom"], function (SortTable, V) { function linkName(d) { - return d.source.node.nodeinfo.hostname + " – " + d.target.node.nodeinfo.hostname + return (d.source.node ? d.source.node.nodeinfo.hostname : d.source.id) + " – " + d.target.node.nodeinfo.hostname } var headings = [{ name: "Knoten", diff --git a/lib/main.js b/lib/main.js index e12cd92..38f85e3 100644 --- a/lib/main.js +++ b/lib/main.js @@ -66,10 +66,7 @@ function (moment, Router, L, GUI, numeral) { }) graph.links.forEach( function (d) { - if (graph.nodes[d.source].node) - d.source = graph.nodes[d.source] - else - d.source = undefined + d.source = graph.nodes[d.source] if (graph.nodes[d.target].node) d.target = graph.nodes[d.target] @@ -78,14 +75,19 @@ function (moment, Router, L, GUI, numeral) { }) var links = graph.links.filter( function (d) { - return d.source !== undefined && d.target !== undefined + return d.target !== undefined }) links.forEach( function (d) { - var ids = [d.source.node.nodeinfo.node_id, d.target.node.nodeinfo.node_id] - d.id = ids.sort().join("-") + var unknown = (d.source.node === undefined) + var ids + if (unknown) + ids = [d.source.id.replace(/:/g, ""), d.target.node.nodeinfo.node_id] + else + ids = [d.source.node.nodeinfo.node_id, d.target.node.nodeinfo.node_id] + d.id = ids.join("-") - if (!("location" in d.source.node.nodeinfo && "location" in d.target.node.nodeinfo)) + if (unknown || !("location" in d.source.node.nodeinfo && "location" in d.target.node.nodeinfo)) return d.latlngs = [] @@ -100,10 +102,6 @@ function (moment, Router, L, GUI, numeral) { }) links.forEach( function (d) { - d.source.node.neighbours.push({ node: d.target.node, link: d, incoming: false }) - d.target.node.neighbours.push({ node: d.source.node, link: d, incoming: true }) - if (d.type !== "tunnel") - d.source.node.meshlinks = d.source.node.meshlinks ? d.source.node.meshlinks + 1 : 1 if (d.type === "tunnel") d.type = "VPN" else if (d.type === "wireless") @@ -112,6 +110,15 @@ function (moment, Router, L, GUI, numeral) { d.type = "Kabel" else d.type = "N/A" + var unknown = (d.source.node === undefined) + if (unknown) { + d.target.node.neighbours.push({ id: d.source.id, link: d, incoming: true }) + return + } + d.source.node.neighbours.push({ node: d.target.node, link: d, incoming: false }) + d.target.node.neighbours.push({ node: d.source.node, link: d, incoming: true }) + if (d.type !== "VPN") + d.source.node.meshlinks = d.source.node.meshlinks ? d.source.node.meshlinks + 1 : 1 }) links.sort( function (a, b) { diff --git a/lib/title.js b/lib/title.js index 372dd75..e9377a4 100644 --- a/lib/title.js +++ b/lib/title.js @@ -20,7 +20,7 @@ define(function () { this.gotoLink = function (d) { if (d) - setTitle(d.source.node.nodeinfo.hostname + " – " + d.target.node.nodeinfo.hostname) + setTitle((d.source.node ? d.source.node.nodeinfo.hostname : d.source.id) + " – " + d.target.node.nodeinfo.hostname) } this.gotoLocation = function() {