summaryrefslogtreecommitdiff
path: root/bubble.js
diff options
context:
space:
mode:
Diffstat (limited to 'bubble.js')
-rw-r--r--bubble.js56
1 files changed, 28 insertions, 28 deletions
diff --git a/bubble.js b/bubble.js
index 8d957b6..773e481 100644
--- a/bubble.js
+++ b/bubble.js
@@ -207,7 +207,8 @@ function processData(data) {
// ... and also update neighboring nodes
contents.selectAll('.node')
.classed('neighbor', function (node) {
- return node.related.indexOf(d.index) >= 0;
+ return node.relatedTo.indexOf(d.index) >= 0 ||
+ node.relatedFrom.indexOf(d.index) >= 0;
});
})
.on('mouseout', function (d) {
@@ -234,35 +235,33 @@ function processData(data) {
userInfo.select('.spam-status')
.text(d.isSpam ? 'SPAM' : 'ham');
- var selfId = d.index;
- var links = [];
- force.links().forEach(function (edge) {
- // insert related elements, assuming no self-references
- if (edge.source.index === selfId) {
- links.push({
- direction: 'to',
- node: edge.target
+ var nodes = {
+ 'from': force.nodes().filter(function (edge) {
+ return edge.relatedFrom.indexOf(d.index) >= 0;
+ }),
+ 'to': force.nodes().filter(function (edge) {
+ return edge.relatedTo.indexOf(d.index) >= 0;
+ })
+ };
+ Object.keys(nodes).forEach(function (dir) {
+ var related = nodes[dir];
+ related.sort(function sort_by_name(a, b) {
+ return a.name.localeCompare(b.name);
+ });
+ userInfo.select('.relations-' + dir + '-count')
+ .text(related.length);
+ var relations = userInfo.select('.relations-' + dir)
+ .selectAll('li')
+ .data(related, function key_func_links(d) {
+ // unique keys to group by node (index)
+ return d.index;
});
- } else if (edge.target.index === selfId) {
- links.push({
- direction: 'from',
- node: edge.source
+ relations.enter().append('li')
+ .text(function (d) {
+ return dir + ' ' + d.name;
});
- }
+ relations.exit().remove();
});
- userInfo.select('.relations-count')
- .text(links.length);
- var relations = userInfo.select('.relations')
- .selectAll('li')
- .data(links, function (d) {
- // unique keys to group by direction and node (index)
- return d.direction + ' ' + d.node.index;
- });
- relations.enter().append('li')
- .text(function (d) {
- return d.direction + ' ' + d.node.name;
- });
- relations.exit().remove();
}
force.on('tick', function() {
@@ -338,7 +337,8 @@ function run() {
tweetCount: d.tweetcount,
radius: Math.sqrt(d.tweetcount),
isSpam: +d.isspam,
- related: [] // nodes that link to this
+ // indices of nodes that link to this one
+ relatedTo: [], relatedFrom: [],
};
}),
// source,target,value