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%") 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) */ /* Infobox stuff (XXX: move to module) */
function attributeEntry(el, label, value) { function attributeEntry(el, label, value) {

View File

@ -162,7 +162,7 @@ define(["d3"], function (d3) {
link = vis.select("g.links") link = vis.select("g.links")
.selectAll("g.link") .selectAll("g.link")
.data(links, linkId) .data(links, function (d) { return d.id })
var linkEnter = link.enter().append("g") var linkEnter = link.enter().append("g")
.attr("class", "link") .attr("class", "link")
@ -183,18 +183,14 @@ define(["d3"], function (d3) {
link.each( function (d) { link.each( function (d) {
if (d.source.node && d.target.node) if (d.source.node && d.target.node)
linksDict[linkId(d)] = d linksDict[d.id] = d
}) })
nodes = data.graph.nodes nodes = data.graph.nodes
node = vis.select("g.nodes") node = vis.select("g.nodes")
.selectAll(".node") .selectAll(".node")
.data(nodes, .data(nodes, function(d) { return d.id })
function(d) {
return d.id
}
)
var nodeEnter = node.enter().append("circle") var nodeEnter = node.enter().append("circle")
.attr("r", 8) .attr("r", 8)
@ -266,7 +262,7 @@ define(["d3"], function (d3) {
return e === d && d !== undefined return e === d && d !== undefined
}) })
var l = linksDict[linkId(d)] var l = linksDict[d.id]
if (l) { if (l) {
var x = d3.extent([l.source, l.target], function (d) { return d.x }) 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) { 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)) if (!("location" in d.source.node.nodeinfo && "location" in d.target.node.nodeinfo))
return 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.bindLabel(d.source.node.nodeinfo.hostname + " " + d.target.node.nodeinfo.hostname + "<br><strong>" + showDistance(d) + " / " + showTq(d) + "</strong>")
line.on("click", router.link(d)) line.on("click", router.link(d))
dict[linkId(d)] = line dict[d.id] = line
return line return line
}) })
@ -178,7 +178,7 @@ define(["d3", "leaflet", "moment", "leaflet.label"], function (d3, L, moment) {
self.gotoLink = function (d) { self.gotoLink = function (d) {
resetMarkerStyles(nodeDict, linkDict) resetMarkerStyles(nodeDict, linkDict)
var m = goto(linkDict, linkId(d)) var m = goto(linkDict, d.id)
if (m) if (m)
m.setStyle({ weight: 7, opacity: 1, dashArray: "10, 10" }) 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) s += "n:" + encodeURIComponent(d.node.nodeinfo.node_id)
if ("link" in d) if ("link" in d)
s += "l:" + encodeURIComponent(linkId(d.link)) s += "l:" + encodeURIComponent(d.link.id)
} }
window.history.pushState(s, undefined, s) window.history.pushState(s, undefined, s)
@ -133,7 +133,7 @@ define(function () {
}) })
data.graph.links.forEach( function (d) { data.graph.links.forEach( function (d) {
objects.links[linkId(d)] = d objects.links[d.id] = d
}) })
} }

View File

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