1
0
Fork 0

GraphViewer: Edges are bound to community nodes correctly

This commit is contained in:
Michael Hackstein 2013-05-23 10:30:03 +02:00
parent f196496bd8
commit 65c959e9d6
2 changed files with 47 additions and 18 deletions

View File

@ -53,6 +53,7 @@ function ArangoAdapter(nodes, edges, config) {
api = {}, api = {},
queries = {}, queries = {},
cachedCommunities = {}, cachedCommunities = {},
joinedInCommunities = {},
nodeCollection, nodeCollection,
edgeCollection, edgeCollection,
limit, limit,
@ -96,9 +97,10 @@ function ArangoAdapter(nodes, edges, config) {
}, },
findNode = function(id) { findNode = function(id) {
var res = $.grep(nodes, function(e){ var intId = joinedInCommunities[id] || id,
return e._id === id; res = $.grep(nodes, function(e){
}); return e._id === intId;
});
if (res.length === 0) { if (res.length === 0) {
return false; return false;
} }
@ -145,7 +147,8 @@ function ArangoAdapter(nodes, edges, config) {
_data: data, _data: data,
_id: data._id _id: data._id
}, },
e = findEdge(edge._id); e = findEdge(edge._id),
edgeToPush;
if (e) { if (e) {
return e; return e;
} }
@ -162,6 +165,24 @@ function ArangoAdapter(nodes, edges, config) {
edges.push(edge); edges.push(edge);
source._outboundCounter++; source._outboundCounter++;
target._inboundCounter++; target._inboundCounter++;
if (cachedCommunities[source._id] !== undefined) {
edgeToPush = {};
edgeToPush.type = "s";
edgeToPush.id = edge._id;
edgeToPush.source = $.grep(cachedCommunities[source._id].nodes, function(e){
return e._id === data._from;
})[0];
cachedCommunities[source._id].edges.push(edgeToPush);
}
if (cachedCommunities[target._id] !== undefined) {
edgeToPush = {};
edgeToPush.type = "t";
edgeToPush.id = edge._id;
edgeToPush.target = $.grep(cachedCommunities[target._id].nodes, function(e){
return e._id === data._to;
})[0];
cachedCommunities[target._id].edges.push(edgeToPush);
}
return edge; return edge;
}, },
@ -317,8 +338,10 @@ function ArangoAdapter(nodes, edges, config) {
cachedCommunities[commId] = {}; cachedCommunities[commId] = {};
cachedCommunities[commId].nodes = nodesToRemove; cachedCommunities[commId].nodes = nodesToRemove;
cachedCommunities[commId].edges = []; cachedCommunities[commId].edges = [];
combineCommunityEdges(nodesToRemove, commNode); combineCommunityEdges(nodesToRemove, commNode);
_.each(nodesToRemove, function(n) { _.each(nodesToRemove, function(n) {
joinedInCommunities[n._id] = commId;
removeNode(n); removeNode(n);
}); });
nodes.push(commNode); nodes.push(commNode);
@ -335,6 +358,7 @@ function ArangoAdapter(nodes, edges, config) {
collapseCommunity(com); collapseCommunity(com);
} }
_.each(nodesToAdd, function(n) { _.each(nodesToAdd, function(n) {
delete joinedInCommunities[n._id];
nodes.push(n); nodes.push(n);
}); });
_.each(edgesToChange, function(e) { _.each(edgesToChange, function(e) {

View File

@ -978,31 +978,35 @@
}); });
describe('expanding after a while', function() { describe('expanding after a while', function() {
it('should connect edges of internal nodes accordingly', function() { it('should connect edges of internal nodes accordingly', function() {
var commNode, called, counterCallback, var commNode, called, counterCallback,
v0, v1, v2, v3, v4; v0, v1, v2, v3, v4,
e0_1, e0_2, e1_3, e1_4, e2_3, e2_4;
runs(function() { runs(function() {
var v = "vertices", var v = "vertices",
e = "edges", e = "edges";
e0_1 = insertEdge(e, v0, v1), nodes.length = 0;
e0_2 = insertEdge(e, v0, v2), edges.length = 0;
e1_3 = insertEdge(e, v1, v3),
e1_4 = insertEdge(e, v1, v4),
e2_3 = insertEdge(e, v2, v3),
e2_4 = insertEdge(e, v2, v4);
v0 = insertNode(v, 0); v0 = insertNode(v, 0);
v1 = insertNode(v, 1); v1 = insertNode(v, 1);
v2 = insertNode(v, 2); v2 = insertNode(v, 2);
v3 = insertNode(v, 3); v3 = insertNode(v, 3);
v4 = insertNode(v, 4); v4 = insertNode(v, 4);
e0_1 = insertEdge(e, v0, v1);
e0_2 = insertEdge(e, v0, v2);
e1_3 = insertEdge(e, v1, v3);
e1_4 = insertEdge(e, v1, v4);
e2_3 = insertEdge(e, v2, v3);
e2_4 = insertEdge(e, v2, v4);
called = 0; called = 0;
counterCallback = function() { counterCallback = function() {
called++; called++;
}; };
spyOn(this, "fakeReducerRequest").andCallFake(function() { spyOn(this, "fakeReducerRequest").andCallFake(function() {
return [c0, c1, c2, c3]; return [v1, v3, v4];
}); });
adapter.setNodeLimit(3); adapter.setNodeLimit(3);
@ -1018,7 +1022,7 @@
runs(function() { runs(function() {
adapter.loadNode(v2, counterCallback); adapter.loadNode(v2, counterCallback);
commNode = getCommunityNodesIds()[0]; commNode = getCommunityNodes()[0];
}); });
waitsFor(function() { waitsFor(function() {
@ -1026,14 +1030,15 @@
}); });
runs(function() { runs(function() {
var commId = commNode._id;
// Check start condition // Check start condition
existNodes([commNode, v0, v2]); existNodes([commId, v0, v2]);
expect(nodes.length).toEqual(3); expect(nodes.length).toEqual(3);
existEdge(v0, v2); existEdge(v0, v2);
existEdge(v0, commNode); existEdge(v0, commId);
existEdge(v2, commNode); existEdge(v2, commId);
expect(edges.length).toEqual(3); expect(edges.length).toEqual(4);
adapter.setNodeLimit(20); adapter.setNodeLimit(20);
adapter.expandCommunity(commNode, counterCallback); adapter.expandCommunity(commNode, counterCallback);