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) {
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

View file

@ -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
})

View file

@ -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")
if (!unknown) {
a1.href = "#"
a1.onclick = router.node(d.source.node)
a1.textContent = d.source.node.nodeinfo.hostname
}
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"))

View file

@ -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.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")

View file

@ -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",

View file

@ -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
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) {

View file

@ -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() {