1
0
Fork 0

GraphViewer: Finished implementation of community joining, display and reverse action to be implemented

This commit is contained in:
Michael Hackstein 2013-05-21 10:24:04 +02:00
parent 6bf1d00d18
commit 88d8c31029
2 changed files with 39 additions and 11 deletions

View File

@ -187,7 +187,7 @@ function ArangoAdapter(nodes, edges, config) {
removeEdgesForNode = function (node) { removeEdgesForNode = function (node) {
var i; var i;
for ( i = 0; i < edges.length; i++ ) { for (i = 0; i < edges.length; i++ ) {
if (edges[i].source === node) { if (edges[i].source === node) {
node._outboundCounter--; node._outboundCounter--;
edges[i].target._inboundCounter--; edges[i].target._inboundCounter--;
@ -202,6 +202,27 @@ function ArangoAdapter(nodes, edges, config) {
} }
}, },
combineCommunityEdges = function (nodes, commNode) {
var i, j, s, t;
for (i = 0; i < edges.length; i++ ) {
// s and t keep old values yay!
s = edges[i].source;
t = edges[i].target;
for (j = 0; j < nodes.length; j++) {
if (s === nodes[j]) {
edges[i].source = commNode;
}
if (t === nodes[j]) {
edges[i].target = commNode;
}
}
if (edges[i].source === commNode && edges[i].target === commNode) {
edges.splice( i, 1 );
i--;
}
}
},
// Helper function to easily remove all outbound edges for one node // Helper function to easily remove all outbound edges for one node
removeOutboundEdgesFromNode = function ( node ) { removeOutboundEdgesFromNode = function ( node ) {
if (node._outboundCounter > 0) { if (node._outboundCounter > 0) {
@ -260,17 +281,17 @@ function ArangoAdapter(nodes, edges, config) {
var commId = "community_1", var commId = "community_1",
commNode = { commNode = {
_id: commId, _id: commId,
x: 1, edges: []
y: 1
}, },
nodesToRemove = _.map(community, function(id) { nodesToRemove = _.map(community, function(id) {
return findNode(id); return findNode(id);
}); });
commNode.x = nodesToRemove[0].x;
commNode.y = nodesToRemove[0].y;
cachedCommunities[commId] = nodesToRemove; cachedCommunities[commId] = nodesToRemove;
combineCommunityEdges(nodesToRemove, commNode);
_.each(nodesToRemove, function(n) { _.each(nodesToRemove, function(n) {
removeNode(n); removeNode(n);
removeEdgesForNode(n);
}); });
nodes.push(commNode); nodes.push(commNode);
}, },

View File

@ -877,21 +877,27 @@
runs(function() { runs(function() {
adapter.setNodeLimit(6); adapter.setNodeLimit(6);
spyOn(this, "fakeReducerRequest"); spyOn(this, "fakeReducerRequest").andCallFake(function() {
return [c0];
});
adapter.loadNodeFromTreeById(c1, checkCallbackFunction); adapter.loadNodeFromTreeById(c1, checkCallbackFunction);
expect(this.fakeReducerRequest).toHaveBeenCalledWith(6, nodeWithID(c1)); expect(this.fakeReducerRequest).toHaveBeenCalledWith(6, nodeWithID(c1));
}); });
}); });
it('should not trigger the reducer if the limit is set large enough', function() { it('should not trigger the reducer if the limit is set large enough', function() {
spyOn(this, "fakeReducerRequest"); spyOn(this, "fakeReducerRequest").andCallFake(function() {
return [c0];
});
adapter.setNodeLimit(10); adapter.setNodeLimit(10);
expect(this.fakeReducerRequest).not.toHaveBeenCalled(); expect(this.fakeReducerRequest).not.toHaveBeenCalled();
}); });
it('should trigger the reducer if the limit is set too small', function() { it('should trigger the reducer if the limit is set too small', function() {
spyOn(this, "fakeReducerRequest"); spyOn(this, "fakeReducerRequest").andCallFake(function() {
return [c0];
});
adapter.setNodeLimit(2); adapter.setNodeLimit(2);
expect(this.fakeReducerRequest).toHaveBeenCalledWith(2); expect(this.fakeReducerRequest).toHaveBeenCalledWith(2);
}); });
@ -911,10 +917,11 @@
notExistNodes([c0, c1, c2]); notExistNodes([c0, c1, c2]);
existNode("community_1"); existNode("community_1");
existNodes([c3]); existNodes([c3, c4]);
expect(nodes.length).toEqual(2); expect(nodes.length).toEqual(3);
existEdge("community_1", c3); existEdge("community_1", c3);
expect(edges.length).toEqual(1); existEdge("community_1", c4);
expect(edges.length).toEqual(2);
expect(called).toBeTruthy(); expect(called).toBeTruthy();
}); });