From eb735c8c52967bb2db84620fd127d24e1c167e99 Mon Sep 17 00:00:00 2001 From: Nils Schneider Date: Fri, 10 Apr 2015 15:19:42 +0200 Subject: [PATCH] forcegraph: calculate linksDict/nodesDict indepently of d3 --- lib/forcegraph.js | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/lib/forcegraph.js b/lib/forcegraph.js index 8a825b7..92bd467 100644 --- a/lib/forcegraph.js +++ b/lib/forcegraph.js @@ -343,13 +343,22 @@ define(["d3"], function (d3) { return e }) + linksDict = {} + nodesDict = {} + intNodes.forEach(function (d) { d.neighbours = {} + + if (d.o.node) + nodesDict[d.o.node.nodeinfo.node_id] = d }) intLinks.forEach(function (d) { d.source.neighbours[d.target.o.id] = d.target d.target.neighbours[d.source.o.id] = d.source + + if (d.o.source.node && d.o.target.node) + linksDict[d.o.id] = d }) intNodes.forEach(function (d) { @@ -362,20 +371,6 @@ define(["d3"], function (d3) { node = updateNodes(visNodes, intNodes) label = updateLabels(visLabels, intNodes) - linksDict = {} - - link.each( function (d) { - if (d.o.source.node && d.o.target.node) - linksDict[d.o.id] = d - }) - - nodesDict = {} - - node.each( function (d) { - if (d.o.node) - nodesDict[d.o.node.nodeinfo.node_id] = d - }) - if (localStorageTest()) { var save = JSON.parse(localStorage.getItem("graph/nodeposition"))