1
0
Fork 0

GraphViewer: Simple expansion of Communities now possible

This commit is contained in:
Michael Hackstein 2013-05-21 13:22:12 +02:00
parent bf749438f0
commit f43f0568f7
2 changed files with 65 additions and 9 deletions

View File

@ -118,7 +118,7 @@ function ArangoAdapter(nodes, edges, config) {
if (res.length === 1) {
return res[0];
}
throw "Too many nodes with the same ID, should never happen";
throw "Too many edges with the same ID, should never happen";
},
insertNode = function(data) {
@ -203,22 +203,48 @@ function ArangoAdapter(nodes, edges, config) {
},
combineCommunityEdges = function (nodes, commNode) {
var i, j, s, t;
var i, j, s, t,
cachedCommEdges = cachedCommunities[commNode._id].edges,
edgeToPush;
for (i = 0; i < edges.length; i++ ) {
edgeToPush = {};
// 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]) {
if (edgeToPush.type !== undefined) {
edges[i].target = edgeToPush.target;
delete edgeToPush.target;
edgeToPush.type = "b";
edgeToPush.edge = edges[i];
edges.splice( i, 1 );
i--;
break;
}
edges[i].source = commNode;
edgeToPush.type = "s";
edgeToPush.id = edges[i]._id;
edgeToPush.source = s;
}
if (t === nodes[j]) {
if (edgeToPush.type !== undefined) {
edges[i].source = edgeToPush.source;
delete edgeToPush.source;
edgeToPush.type = "b";
edgeToPush.edge = edges[i];
edges.splice( i, 1 );
i--;
break;
}
edges[i].target = commNode;
edgeToPush.type = "t";
edgeToPush.id = edges[i]._id;
edgeToPush.target = t;
}
}
if (edges[i].source === commNode && edges[i].target === commNode) {
edges.splice( i, 1 );
i--;
if (edgeToPush.type !== undefined) {
cachedCommEdges.push(edgeToPush);
}
}
},
@ -288,7 +314,9 @@ function ArangoAdapter(nodes, edges, config) {
});
commNode.x = nodesToRemove[0].x;
commNode.y = nodesToRemove[0].y;
cachedCommunities[commId] = nodesToRemove;
cachedCommunities[commId] = {};
cachedCommunities[commId].nodes = nodesToRemove;
cachedCommunities[commId].edges = [];
combineCommunityEdges(nodesToRemove, commNode);
_.each(nodesToRemove, function(n) {
removeNode(n);
@ -296,6 +324,33 @@ function ArangoAdapter(nodes, edges, config) {
nodes.push(commNode);
},
expandCommunity = function (commNode) {
var commId = commNode._id,
nodesToAdd = cachedCommunities[commId].nodes,
edgesToChange = cachedCommunities[commId].edges;
removeNode(commNode);
_.each(nodesToAdd, function(n) {
nodes.push(n);
});
_.each(edgesToChange, function(e) {
var edge;
switch(e.type) {
case "t":
edge = findEdge(e.id);
edge.target = e.target;
break;
case "s":
edge = findEdge(e.id);
edge.source = e.source;
break;
case "b":
edges.push(e.edge);
break;
}
});
delete cachedCommunities[commId];
},
parseResultOfTraversal = function (result, callback) {
result = result[0];
_.each(result, function(visited) {
@ -594,6 +649,7 @@ function ArangoAdapter(nodes, edges, config) {
};
self.expandCommunity = function (commNode, callback) {
expandCommunity(commNode);
if (callback !== undefined) {
callback();
}

View File

@ -939,8 +939,7 @@
expect(nodes.length).toEqual(3);
existEdge(commId, c3);
existEdge(commId, c4);
expect(edges.length).toEqual(2);
expect(called).toBeTruthy();
expect(edges.length).toEqual(2);
});
});
@ -998,7 +997,7 @@
});
});
it('should expand a community if enough space is available', function() {
it('should expand a community if enough space is available', function() {
runs(function() {
adapter.setNodeLimit(10);
callbackCheck = false;
@ -1011,6 +1010,7 @@
runs(function() {
expect(getCommunityNodes().length).toEqual(0);
console.log(edges);
existNodes([c0, c1, c2, c3, c4, c5, c6, c7]);
existEdge(c0, c1);
existEdge(c0, c2);