From d6b84eba22ced96e37a0de22f522f9ebf847198f Mon Sep 17 00:00:00 2001 From: Geno Date: Sun, 29 Oct 2017 20:14:09 +0100 Subject: [PATCH] [BUGFIX] Filter links by node + perfomance using dict/map --- lib/filters/nodefilter.js | 22 ++-------------------- lib/infobox/node.js | 4 ++-- lib/main.js | 13 ++----------- 3 files changed, 6 insertions(+), 33 deletions(-) diff --git a/lib/filters/nodefilter.js b/lib/filters/nodefilter.js index 0cf7fd0..b8e24a8 100644 --- a/lib/filters/nodefilter.js +++ b/lib/filters/nodefilter.js @@ -12,26 +12,8 @@ define(function () { } } - var filteredIds = new Set(); - - n.graph = {}; - n.graph.nodes = data.graph.nodes.filter(function (d) { - var r; - if (d.node) { - r = filter(d.node); - } else { - r = filter({}); - } - - if (r) { - filteredIds.add(d.id); - } - - return r; - }); - - n.graph.links = data.graph.links.filter(function (d) { - return filteredIds.has(d.source.id) && filteredIds.has(d.target.id); + n.links = data.links.filter(function (d) { + return filter(d.source) && filter(d.target); }); return n; diff --git a/lib/infobox/node.js b/lib/infobox/node.js index 98c8b10..04f0f2e 100644 --- a/lib/infobox/node.js +++ b/lib/infobox/node.js @@ -229,9 +229,9 @@ define(['sorttable', 'snabbdom', 'd3-interpolate', 'moment', 'helper'], } function renderNeighbourRow(n) { - var icons = []; + var icons = ''; if (helper.hasLocation(n.node)) { - icons.push(V.h('span', { props: { className: 'ion-location' } })); + icons = V.h('span', { props: { className: 'ion-location' } }); } var td1 = V.h('td', icons); diff --git a/lib/main.js b/lib/main.js index bf74dda..1003216 100644 --- a/lib/main.js +++ b/lib/main.js @@ -32,13 +32,8 @@ define(['moment', 'utils/router', 'leaflet', 'gui', 'helper', 'utils/language'], }); links.forEach(function (d) { - d.source = nodes.find(function (a) { - return a.node_id === d.source; - }); - - d.target = nodes.find(function (a) { - return a.node_id === d.target; - }); + d.source = nodeDict[d.source]; + d.target = nodeDict[d.target]; d.id = [d.source.node_id, d.target.node_id].join('-'); d.source.neighbours.push({ node: d.target, link: d }); @@ -68,10 +63,6 @@ define(['moment', 'utils/router', 'leaflet', 'gui', 'helper', 'utils/language'], lost: lostnodes }, links: links, - graph: { - links: [], - nodes: [] - }, nodeDict: nodeDict }; }