make linkId a property (id) of link

This commit is contained in:
Nils Schneider 2015-04-06 23:10:37 +02:00
parent 315484625b
commit 389291e585
6 changed files with 11 additions and 19 deletions

View file

@ -112,12 +112,6 @@ function showTq(d) {
return numeral(1/d.tq).format("0%")
}
function linkId(d) {
var ids = [d.source.node.nodeinfo.node_id, d.target.node.nodeinfo.node_id]
return ids.sort().join("-")
}
/* Infobox stuff (XXX: move to module) */
function attributeEntry(el, label, value) {

View file

@ -162,7 +162,7 @@ define(["d3"], function (d3) {
link = vis.select("g.links")
.selectAll("g.link")
.data(links, linkId)
.data(links, function (d) { return d.id })
var linkEnter = link.enter().append("g")
.attr("class", "link")
@ -183,18 +183,14 @@ define(["d3"], function (d3) {
link.each( function (d) {
if (d.source.node && d.target.node)
linksDict[linkId(d)] = d
linksDict[d.id] = d
})
nodes = data.graph.nodes
node = vis.select("g.nodes")
.selectAll(".node")
.data(nodes,
function(d) {
return d.id
}
)
.data(nodes, function(d) { return d.id })
var nodeEnter = node.enter().append("circle")
.attr("r", 8)
@ -266,7 +262,7 @@ define(["d3"], function (d3) {
return e === d && d !== undefined
})
var l = linksDict[linkId(d)]
var l = linksDict[d.id]
if (l) {
var x = d3.extent([l.source, l.target], function (d) { return d.x })

View file

@ -44,6 +44,9 @@ function (config, moment, Router, L, GUI, numeral) {
})
links.forEach( function (d) {
var ids = [d.source.node.nodeinfo.node_id, d.target.node.nodeinfo.node_id]
d.id = ids.sort().join("-")
if (!("location" in d.source.node.nodeinfo && "location" in d.target.node.nodeinfo))
return

View file

@ -40,7 +40,7 @@ define(["d3", "leaflet", "moment", "leaflet.label"], function (d3, L, moment) {
line.bindLabel(d.source.node.nodeinfo.hostname + " " + d.target.node.nodeinfo.hostname + "<br><strong>" + showDistance(d) + " / " + showTq(d) + "</strong>")
line.on("click", router.link(d))
dict[linkId(d)] = line
dict[d.id] = line
return line
})
@ -178,7 +178,7 @@ define(["d3", "leaflet", "moment", "leaflet.label"], function (d3, L, moment) {
self.gotoLink = function (d) {
resetMarkerStyles(nodeDict, linkDict)
var m = goto(linkDict, linkId(d))
var m = goto(linkDict, d.id)
if (m)
m.setStyle({ weight: 7, opacity: 1, dashArray: "10, 10" })

View file

@ -13,7 +13,7 @@ define(function () {
s += "n:" + encodeURIComponent(d.node.nodeinfo.node_id)
if ("link" in d)
s += "l:" + encodeURIComponent(linkId(d.link))
s += "l:" + encodeURIComponent(d.link.id)
}
window.history.pushState(s, undefined, s)
@ -133,7 +133,7 @@ define(function () {
})
data.graph.links.forEach( function (d) {
objects.links[linkId(d)] = d
objects.links[d.id] = d
})
}

View file

@ -29,7 +29,6 @@
"getJSON": false,
"has_location": false,
"limit": false,
"linkId": false,
"localStorageTest": false,
"offline": false,
"one": false,