From 88d8c31029713d4e3a20cb97cfa8397e65202d69 Mon Sep 17 00:00:00 2001 From: Michael Hackstein Date: Tue, 21 May 2013 10:24:04 +0200 Subject: [PATCH] GraphViewer: Finished implementation of community joining, display and reverse action to be implemented --- .../js/graphViewer/graph/arangoAdapter.js | 31 ++++++++++++++++--- .../specAdapter/arangoAdapterSpec.js | 19 ++++++++---- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/html/admin/js/graphViewer/graph/arangoAdapter.js b/html/admin/js/graphViewer/graph/arangoAdapter.js index 93c5cc3501..1c242c6298 100644 --- a/html/admin/js/graphViewer/graph/arangoAdapter.js +++ b/html/admin/js/graphViewer/graph/arangoAdapter.js @@ -187,7 +187,7 @@ function ArangoAdapter(nodes, edges, config) { removeEdgesForNode = function (node) { var i; - for ( i = 0; i < edges.length; i++ ) { + for (i = 0; i < edges.length; i++ ) { if (edges[i].source === node) { node._outboundCounter--; 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 removeOutboundEdgesFromNode = function ( node ) { if (node._outboundCounter > 0) { @@ -260,17 +281,17 @@ function ArangoAdapter(nodes, edges, config) { var commId = "community_1", commNode = { _id: commId, - x: 1, - y: 1 + edges: [] }, nodesToRemove = _.map(community, function(id) { return findNode(id); }); + commNode.x = nodesToRemove[0].x; + commNode.y = nodesToRemove[0].y; cachedCommunities[commId] = nodesToRemove; - + combineCommunityEdges(nodesToRemove, commNode); _.each(nodesToRemove, function(n) { removeNode(n); - removeEdgesForNode(n); }); nodes.push(commNode); }, diff --git a/html/admin/js/graphViewer/jasmine_test/specAdapter/arangoAdapterSpec.js b/html/admin/js/graphViewer/jasmine_test/specAdapter/arangoAdapterSpec.js index bf3c65f866..fe9c106020 100644 --- a/html/admin/js/graphViewer/jasmine_test/specAdapter/arangoAdapterSpec.js +++ b/html/admin/js/graphViewer/jasmine_test/specAdapter/arangoAdapterSpec.js @@ -877,21 +877,27 @@ runs(function() { adapter.setNodeLimit(6); - spyOn(this, "fakeReducerRequest"); + spyOn(this, "fakeReducerRequest").andCallFake(function() { + return [c0]; + }); adapter.loadNodeFromTreeById(c1, checkCallbackFunction); expect(this.fakeReducerRequest).toHaveBeenCalledWith(6, nodeWithID(c1)); }); }); 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); expect(this.fakeReducerRequest).not.toHaveBeenCalled(); }); 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); expect(this.fakeReducerRequest).toHaveBeenCalledWith(2); }); @@ -911,10 +917,11 @@ notExistNodes([c0, c1, c2]); existNode("community_1"); - existNodes([c3]); - expect(nodes.length).toEqual(2); + existNodes([c3, c4]); + expect(nodes.length).toEqual(3); existEdge("community_1", c3); - expect(edges.length).toEqual(1); + existEdge("community_1", c4); + expect(edges.length).toEqual(2); expect(called).toBeTruthy(); });