mirror of https://gitee.com/bigwinds/arangodb
GraphViewer: Edges are bound to community nodes correctly
This commit is contained in:
parent
f196496bd8
commit
65c959e9d6
|
@ -53,6 +53,7 @@ function ArangoAdapter(nodes, edges, config) {
|
|||
api = {},
|
||||
queries = {},
|
||||
cachedCommunities = {},
|
||||
joinedInCommunities = {},
|
||||
nodeCollection,
|
||||
edgeCollection,
|
||||
limit,
|
||||
|
@ -96,9 +97,10 @@ function ArangoAdapter(nodes, edges, config) {
|
|||
},
|
||||
|
||||
findNode = function(id) {
|
||||
var res = $.grep(nodes, function(e){
|
||||
return e._id === id;
|
||||
});
|
||||
var intId = joinedInCommunities[id] || id,
|
||||
res = $.grep(nodes, function(e){
|
||||
return e._id === intId;
|
||||
});
|
||||
if (res.length === 0) {
|
||||
return false;
|
||||
}
|
||||
|
@ -145,7 +147,8 @@ function ArangoAdapter(nodes, edges, config) {
|
|||
_data: data,
|
||||
_id: data._id
|
||||
},
|
||||
e = findEdge(edge._id);
|
||||
e = findEdge(edge._id),
|
||||
edgeToPush;
|
||||
if (e) {
|
||||
return e;
|
||||
}
|
||||
|
@ -162,6 +165,24 @@ function ArangoAdapter(nodes, edges, config) {
|
|||
edges.push(edge);
|
||||
source._outboundCounter++;
|
||||
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;
|
||||
},
|
||||
|
||||
|
@ -317,8 +338,10 @@ function ArangoAdapter(nodes, edges, config) {
|
|||
cachedCommunities[commId] = {};
|
||||
cachedCommunities[commId].nodes = nodesToRemove;
|
||||
cachedCommunities[commId].edges = [];
|
||||
|
||||
combineCommunityEdges(nodesToRemove, commNode);
|
||||
_.each(nodesToRemove, function(n) {
|
||||
joinedInCommunities[n._id] = commId;
|
||||
removeNode(n);
|
||||
});
|
||||
nodes.push(commNode);
|
||||
|
@ -335,6 +358,7 @@ function ArangoAdapter(nodes, edges, config) {
|
|||
collapseCommunity(com);
|
||||
}
|
||||
_.each(nodesToAdd, function(n) {
|
||||
delete joinedInCommunities[n._id];
|
||||
nodes.push(n);
|
||||
});
|
||||
_.each(edgesToChange, function(e) {
|
||||
|
|
|
@ -978,31 +978,35 @@
|
|||
});
|
||||
|
||||
describe('expanding after a while', function() {
|
||||
|
||||
it('should connect edges of internal nodes accordingly', function() {
|
||||
|
||||
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() {
|
||||
var v = "vertices",
|
||||
e = "edges",
|
||||
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);
|
||||
e = "edges";
|
||||
nodes.length = 0;
|
||||
edges.length = 0;
|
||||
v0 = insertNode(v, 0);
|
||||
v1 = insertNode(v, 1);
|
||||
v2 = insertNode(v, 2);
|
||||
v3 = insertNode(v, 3);
|
||||
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;
|
||||
counterCallback = function() {
|
||||
called++;
|
||||
};
|
||||
spyOn(this, "fakeReducerRequest").andCallFake(function() {
|
||||
return [c0, c1, c2, c3];
|
||||
return [v1, v3, v4];
|
||||
});
|
||||
adapter.setNodeLimit(3);
|
||||
|
||||
|
@ -1018,7 +1022,7 @@
|
|||
|
||||
runs(function() {
|
||||
adapter.loadNode(v2, counterCallback);
|
||||
commNode = getCommunityNodesIds()[0];
|
||||
commNode = getCommunityNodes()[0];
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
|
@ -1026,14 +1030,15 @@
|
|||
});
|
||||
|
||||
runs(function() {
|
||||
var commId = commNode._id;
|
||||
// Check start condition
|
||||
existNodes([commNode, v0, v2]);
|
||||
existNodes([commId, v0, v2]);
|
||||
expect(nodes.length).toEqual(3);
|
||||
|
||||
existEdge(v0, v2);
|
||||
existEdge(v0, commNode);
|
||||
existEdge(v2, commNode);
|
||||
expect(edges.length).toEqual(3);
|
||||
existEdge(v0, commId);
|
||||
existEdge(v2, commId);
|
||||
expect(edges.length).toEqual(4);
|
||||
|
||||
adapter.setNodeLimit(20);
|
||||
adapter.expandCommunity(commNode, counterCallback);
|
||||
|
|
Loading…
Reference in New Issue