From 35fd75e4f6bb76edf021c52f7bac9b8e624d9bf1 Mon Sep 17 00:00:00 2001 From: Geno Date: Sun, 29 Oct 2017 11:21:55 +0100 Subject: [PATCH] [BUGFIX] forcegraph show only online nodes --- lib/forcegraph.js | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/lib/forcegraph.js b/lib/forcegraph.js index dd49757..76955f7 100644 --- a/lib/forcegraph.js +++ b/lib/forcegraph.js @@ -1,5 +1,5 @@ -define(['d3-selection', 'd3-force', 'd3-zoom', 'd3-drag', 'd3-timer', 'd3-ease', 'd3-interpolate', 'utils/math', 'forcegraph/draw'], - function (d3Selection, d3Force, d3Zoom, d3Drag, d3Timer, d3Ease, d3Interpolate, math, draw) { +define(['d3-selection', 'd3-force', 'd3-zoom', 'd3-drag', 'd3-timer', 'd3-ease', 'd3-interpolate', 'helper', 'utils/math', 'forcegraph/draw'], + function (d3Selection, d3Force, d3Zoom, d3Drag, d3Timer, d3Ease, d3Interpolate, helper, math, draw) { 'use strict'; return function (config, linkScale, sidebar, router) { @@ -197,11 +197,9 @@ define(['d3-selection', 'd3-force', 'd3-zoom', 'd3-drag', 'd3-timer', 'd3-ease', }); self.setData = function setData(data) { - intNodes = data.nodes.all.map(function (d) { - var e; - if (d.node_id in dictNodes) { - e = dictNodes[d.node_id]; - } else { + intNodes = data.nodes.all.filter(helper.online).map(function (d) { + var e = dictNodes[d.node_id]; + if (!e) { e = {}; dictNodes[d.node_id] = e; } @@ -211,15 +209,16 @@ define(['d3-selection', 'd3-force', 'd3-zoom', 'd3-drag', 'd3-timer', 'd3-ease', return e; }); - intLinks = data.links.map(function (d) { - var e = {}; - e.o = d; - e.source = dictNodes[d.source.node_id]; - e.target = dictNodes[d.target.node_id]; - e.color = linkScale(d.source_tq); - e.color_to = linkScale(d.target_tq); - - return e; + intLinks = data.links.filter(function (d) { + return dictNodes[d.source.node_id] && dictNodes[d.target.node_id]; + }).map(function (d) { + return { + o: d, + source: dictNodes[d.source.node_id], + target: dictNodes[d.target.node_id], + color: linkScale(d.source_tq), + color_to: linkScale(d.target_tq) + }; }); force.nodes(intNodes);