From 389291e5853a0ef40f5404cbe2b5367adf8718b5 Mon Sep 17 00:00:00 2001 From: Nils Schneider Date: Mon, 6 Apr 2015 23:10:37 +0200 Subject: [PATCH] make linkId a property (id) of link --- helper.js | 6 ------ lib/forcegraph.js | 12 ++++-------- lib/main.js | 3 +++ lib/map.js | 4 ++-- lib/router.js | 4 ++-- package.json | 1 - 6 files changed, 11 insertions(+), 19 deletions(-) diff --git a/helper.js b/helper.js index 7450d79..a4d29fa 100644 --- a/helper.js +++ b/helper.js @@ -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) { diff --git a/lib/forcegraph.js b/lib/forcegraph.js index 4e621cf..c6d8b03 100644 --- a/lib/forcegraph.js +++ b/lib/forcegraph.js @@ -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 }) diff --git a/lib/main.js b/lib/main.js index d9a2121..83411e4 100644 --- a/lib/main.js +++ b/lib/main.js @@ -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 diff --git a/lib/map.js b/lib/map.js index 69b9f1a..25feaef 100644 --- a/lib/map.js +++ b/lib/map.js @@ -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 + "
" + showDistance(d) + " / " + showTq(d) + "") 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" }) diff --git a/lib/router.js b/lib/router.js index 01a7472..95c5072 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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 }) } diff --git a/package.json b/package.json index ef2558f..9a662d7 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,6 @@ "getJSON": false, "has_location": false, "limit": false, - "linkId": false, "localStorageTest": false, "offline": false, "one": false,