1
0
Fork 0

GraphViewer: CommunityNodes now tell about the reason why they are joined if they know it

This commit is contained in:
Michael Hackstein 2013-07-15 13:51:13 +02:00
parent 3f12250c73
commit fe2afc1883
2 changed files with 67 additions and 2 deletions

View File

@ -309,7 +309,7 @@ function AbstractAdapter(nodes, edges, descendant, config) {
}
},
collapseCommunity = function (community) {
collapseCommunity = function (community, reason) {
if (!community || community.length === 0) {
return;
}
@ -324,6 +324,9 @@ function AbstractAdapter(nodes, edges, descendant, config) {
commNode.x = nodesToRemove[0].x;
commNode.y = nodesToRemove[0].y;
commNode._size = community.length;
if (reason) {
commNode._reason = reason;
}
cachedCommunities[commId] = {};
cachedCommunities[commId].nodes = nodesToRemove;
cachedCommunities[commId].edges = [];
@ -421,7 +424,7 @@ function AbstractAdapter(nodes, edges, descendant, config) {
var ids = _.map(b.nodes, function(n) {
return n._id;
});
collapseCommunity(ids);
collapseCommunity(ids, b.reason);
}
});
}

View File

@ -1707,6 +1707,68 @@
existNodes(["1", "2"]);
});
it('should display the reason why a community has been joined', function() {
var n1, n2, n3, n4, n5,
com1, com2,
inserted = [],
limit = 3;
spyOn(mockReducer, "bucketNodes").andCallFake(function() {
return [
{
reason: {
type: "similar",
example: n1
},
nodes: [n1, n2]
},
{
reason: {
key: "type",
value: "example"
},
nodes: [n3, n4, n5]
}
];
});
adapter.setChildLimit(limit);
n1 = adapter.insertNode({_id: "1" });
n2 = adapter.insertNode({_id: "2" });
n3 = adapter.insertNode({_id: "3" });
n4 = adapter.insertNode({_id: "4" });
n5 = adapter.insertNode({_id: "5" });
_.each(nodes, function(n) {
inserted.push(n);
});
adapter.checkSizeOfInserted(inserted);
expect(mockReducer.bucketNodes).wasCalledWith(inserted, limit);
expect(nodes.length).toEqual(2);
expect(getCommunityNodes().length).toEqual(2);
notExistNodes(["1", "2", "3", "4", "5"]);
_.each(getCommunityNodes(), function(c) {
if (c._size === 2) {
com1 = c;
return;
}
if (c._size === 3) {
com2 = c;
return;
}
// Should never be reached
expect(true).toBeFalsy();
});
expect(com1._reason).toEqual({
type: "similar",
example: n1
});
expect(com2._reason).toEqual({
key: "type",
value: "example"
});
});
});
});