forcegraph: show links with unknown nodes

This commit is contained in:
Milan Pässler 2016-02-27 14:43:27 +01:00
parent 9f48cb1f3b
commit 97a00b6925
7 changed files with 36 additions and 24 deletions

View File

@ -24,7 +24,7 @@ define([], function () {
}) })
n.graph.links = data.graph.links.filter( function (d) { 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 return n

View File

@ -685,7 +685,7 @@ define(["d3"], function (d3) {
d.source.neighbours[d.target.o.id] = {node: d.target, link: d} d.source.neighbours[d.target.o.id] = {node: d.target, link: d}
d.target.neighbours[d.source.o.id] = {node: d.source, 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 linksDict[d.o.id] = d
}) })

View File

@ -1,10 +1,13 @@
define(function () { define(function () {
return function (config, el, router, d) { return function (config, el, router, d) {
var unknown = !(d.source.node)
var h2 = document.createElement("h2") var h2 = document.createElement("h2")
var a1 = document.createElement("a") var a1 = document.createElement("a")
a1.href = "#" if (!unknown) {
a1.onclick = router.node(d.source.node) a1.href = "#"
a1.textContent = d.source.node.nodeinfo.hostname a1.onclick = router.node(d.source.node)
}
a1.textContent = unknown ? d.source.id : d.source.node.nodeinfo.hostname
h2.appendChild(a1) h2.appendChild(a1)
h2.appendChild(document.createTextNode(" → ")) h2.appendChild(document.createTextNode(" → "))
var a2 = document.createElement("a") var a2 = document.createElement("a")
@ -20,7 +23,7 @@ define(function () {
attributeEntry(attributes, "TQ", showTq(d)) attributeEntry(attributes, "TQ", showTq(d))
attributeEntry(attributes, "Entfernung", showDistance(d)) attributeEntry(attributes, "Entfernung", showDistance(d))
attributeEntry(attributes, "Typ", d.type) 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"]) var hw2 = dictGet(d.target.node.nodeinfo, ["hardware", "model"])
attributeEntry(attributes, "Hardware", (hw1 != null ? hw1 : "unbekannt") + " " + (hw2 != null ? hw2 : "unbekannt")) attributeEntry(attributes, "Hardware", (hw1 != null ? hw1 : "unbekannt") + " " + (hw2 != null ? hw2 : "unbekannt"))

View File

@ -326,6 +326,7 @@ define(["moment", "numeral", "tablesort", "tablesort.numeric"],
var tbody = document.createElement("tbody") var tbody = document.createElement("tbody")
d.neighbours.forEach( function (d) { d.neighbours.forEach( function (d) {
var unknown = !(d.node)
var tr = document.createElement("tr") var tr = document.createElement("tr")
var td1 = document.createElement("td") var td1 = document.createElement("td")
@ -335,12 +336,13 @@ define(["moment", "numeral", "tablesort", "tablesort.numeric"],
var td2 = document.createElement("td") var td2 = document.createElement("td")
var a1 = document.createElement("a") var a1 = document.createElement("a")
a1.classList.add("hostname") a1.classList.add("hostname")
a1.textContent = d.node.nodeinfo.hostname a1.textContent = unknown ? d.id : d.node.nodeinfo.hostname
a1.href = "#" if (!unknown)
a1.onclick = router.node(d.node) a1.href = "#"
a1.onclick = router.node(d.node)
td2.appendChild(a1) td2.appendChild(a1)
if (has_location(d.node)) { if (!unknown && has_location(d.node)) {
var span = document.createElement("span") var span = document.createElement("span")
span.classList.add("icon") span.classList.add("icon")
span.classList.add("ion-location") span.classList.add("ion-location")

View File

@ -1,6 +1,6 @@
define(["sorttable", "virtual-dom"], function (SortTable, V) { define(["sorttable", "virtual-dom"], function (SortTable, V) {
function linkName(d) { 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", var headings = [{ name: "Knoten",

View File

@ -66,10 +66,7 @@ function (moment, Router, L, GUI, numeral) {
}) })
graph.links.forEach( function (d) { graph.links.forEach( function (d) {
if (graph.nodes[d.source].node) d.source = graph.nodes[d.source]
d.source = graph.nodes[d.source]
else
d.source = undefined
if (graph.nodes[d.target].node) if (graph.nodes[d.target].node)
d.target = graph.nodes[d.target] d.target = graph.nodes[d.target]
@ -78,14 +75,19 @@ function (moment, Router, L, GUI, numeral) {
}) })
var links = graph.links.filter( function (d) { var links = graph.links.filter( function (d) {
return d.source !== undefined && d.target !== undefined return d.target !== undefined
}) })
links.forEach( function (d) { links.forEach( function (d) {
var ids = [d.source.node.nodeinfo.node_id, d.target.node.nodeinfo.node_id] var unknown = (d.source.node === undefined)
d.id = ids.sort().join("-") 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 return
d.latlngs = [] d.latlngs = []
@ -100,10 +102,6 @@ function (moment, Router, L, GUI, numeral) {
}) })
links.forEach( function (d) { 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") if (d.type === "tunnel")
d.type = "VPN" d.type = "VPN"
else if (d.type === "wireless") else if (d.type === "wireless")
@ -112,6 +110,15 @@ function (moment, Router, L, GUI, numeral) {
d.type = "Kabel" d.type = "Kabel"
else else
d.type = "N/A" 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) { links.sort( function (a, b) {

View File

@ -20,7 +20,7 @@ define(function () {
this.gotoLink = function (d) { this.gotoLink = function (d) {
if (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() { this.gotoLocation = function() {