From 74e640f89958d625d48da1b755acc1216619011e Mon Sep 17 00:00:00 2001 From: Nils Schneider Date: Wed, 8 Apr 2015 01:21:52 +0200 Subject: [PATCH] forcegraph: fix links losing nodes --- lib/forcegraph.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/forcegraph.js b/lib/forcegraph.js index 5a8fa3e..0a97e44 100644 --- a/lib/forcegraph.js +++ b/lib/forcegraph.js @@ -8,6 +8,7 @@ define(["d3"], function (d3) { var el var doAnimation = false var intNodes = [] + var intLinks = [] var highlight var LINK_DISTANCE = 70 @@ -212,13 +213,26 @@ define(["d3"], function (d3) { newNodesDict[d.o.id] = d }) - var intLinks = data.graph.links.filter( function (d) { + var oldLinks = {} + + intLinks.forEach( function (d) { + oldLinks[d.o.id] = d + }) + + intLinks = data.graph.links.filter( function (d) { return !d.vpn }).map( function (d) { - var source = newNodesDict[d.source.id] - var target = newNodesDict[d.target.id] + var e + if (d.id in oldLinks) + e = oldLinks[d.id] + else + e = {} - return {o: d, source: source, target: target} + e.o = d + e.source = newNodesDict[d.source.id] + e.target = newNodesDict[d.target.id] + + return e }) link = vis.select("g.links")