summaryrefslogtreecommitdiff
path: root/js/preprocess.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/preprocess.js')
-rw-r--r--js/preprocess.js16
1 files changed, 8 insertions, 8 deletions
diff --git a/js/preprocess.js b/js/preprocess.js
index 65d27c3..8a3e34c 100644
--- a/js/preprocess.js
+++ b/js/preprocess.js
@@ -80,19 +80,19 @@ function preprocess(data, options) {
console.log('Nodes count (after dropping loners):', data.nodes.length);
}
- // prepare data for force layout: map user IDs to indices
- var userIds_indices = {};
+ // link edges with nodes
+ var users = {};
data.nodes.forEach(function (user, i) {
- userIds_indices[user.userid] = i;
+ users[user.userid] = user;
});
- console.log('UserID to index map:', userIds_indices);
// change userID of relation edges to indices
data.edges.map(function (link) {
- link.source = userIds_indices[link.source];
- link.target = userIds_indices[link.target];
+ // replace source/target user IDs by their respective (user) nodes
+ link.source = users[link.source];
+ link.target = users[link.target];
// for faster lookup, store neighboring nodes per node
- data.nodes[link.source].relatedTo.push(link.target);
- data.nodes[link.target].relatedFrom.push(link.source);
+ link.source.relatedTo.push(link.target.userid);
+ link.target.relatedFrom.push(link.source.userid);
});
}