diff --git a/html/admin/js/graphViewer/graph/communityNode.js b/html/admin/js/graphViewer/graph/communityNode.js
index 3c021e043a..4900da1523 100644
--- a/html/admin/js/graphViewer/graph/communityNode.js
+++ b/html/admin/js/graphViewer/graph/communityNode.js
@@ -32,6 +32,8 @@
function CommunityNode(initial) {
"use strict";
+ initial = initial || [];
+
var
////////////////////////////////////
@@ -39,8 +41,9 @@ function CommunityNode(initial) {
////////////////////////////////////
self = this,
nodes = {},
- edges = {},
-
+ internal = {},
+ inbound = {},
+ outbound = {},
////////////////////////////////////
// Private functions //
////////////////////////////////////
@@ -70,14 +73,36 @@ function CommunityNode(initial) {
self._size++;
},
- insertEdge = function(e) {
- edges[e._id] = e;
+ insertInboundEdge = function(e) {
+ e.target = self;
+ if (outbound[e._id]) {
+ delete outbound[e._id];
+ internal[e._id] = e;
+ return true;
+ }
+ inbound[e._id] = e;
+ return false;
+ },
+
+ insertOutboundEdge = function(e) {
+ e.source = self;
+ if (inbound[e._id]) {
+ delete inbound[e._id];
+ internal[e._id] = e;
+ return true;
+ }
+ outbound[e._id] = e;
+ return false;
},
dissolve = function() {
return {
nodes: toArray(nodes),
- edges: toArray(edges)
+ edges: {
+ both: toArray(internal),
+ inbound: toArray(inbound),
+ outbound: toArray(outbound)
+ }
};
};
@@ -90,8 +115,8 @@ function CommunityNode(initial) {
////////////////////////////////////
this._id = "*community_" + Math.floor(Math.random()* 1000000);
if (initial.length > 0) {
- this.x = initial[0].position.x;
- this.y = initial[0].position.y;
+ this.x = initial[0].x;
+ this.y = initial[0].y;
} else {
this.x = 0;
this.y = 0;
@@ -110,10 +135,7 @@ function CommunityNode(initial) {
this.getNodes = getNodes;
this.getNode = getNode;
this.insertNode = insertNode;
- this.insertEdge = insertEdge;
+ this.insertInboundEdge = insertInboundEdge;
+ this.insertOutboundEdge = insertOutboundEdge;
this.dissolve = dissolve;
-
-
-
-
}
diff --git a/html/admin/js/graphViewer/jasmine_test/specCommunityNode/communityNodeSpec.js b/html/admin/js/graphViewer/jasmine_test/specCommunityNode/communityNodeSpec.js
index c497840962..0c1769c7e8 100644
--- a/html/admin/js/graphViewer/jasmine_test/specCommunityNode/communityNodeSpec.js
+++ b/html/admin/js/graphViewer/jasmine_test/specCommunityNode/communityNodeSpec.js
@@ -87,8 +87,12 @@
expect(testee).toHaveFunction("insertNode", 1);
});
- it('should offer a function to insert an additional edge', function() {
- expect(testee).toHaveFunction("insertEdge", 1);
+ it('should offer a function to insert an incomming edge', function() {
+ expect(testee).toHaveFunction("insertInboundEdge", 1);
+ });
+
+ it('should offer a function to insert an outgoing edge', function() {
+ expect(testee).toHaveFunction("insertOutboundEdge", 1);
});
it('should offer a function to dissolve the community', function() {
@@ -183,6 +187,9 @@
_id: "foxx",
_inboundCounter: 0,
_outboundCounter: 0,
+ x: x,
+ y: y,
+ z: 1,
position: {
x: x,
y: y,
@@ -199,24 +206,101 @@
expect(c._id).toMatch(/^\*community_\d{1,7}$/);
});
+ it('should return true if an inserted edge is internal', function() {
+ var c = new CommunityNode(),
+ e1 = {
+ _id: "1-2",
+ _data: {
+ _from: "1",
+ _to: "2"
+ },
+ source: nodes[1],
+ target: nodes[2]
+ },
+ e2 = {
+ _id: "2-1",
+ _data: {
+ _from: "2",
+ _to: "1"
+ },
+ source: nodes[2],
+ target: nodes[1]
+ };
+ c.insertInboundEdge(e1);
+ expect(c.insertOutboundEdge(e1)).toBeTruthy();
+ c.insertOutboundEdge(e2);
+ expect(c.insertInboundEdge(e2)).toBeTruthy();
+ });
+
+ it('should return false if an inserted edge is not internal', function() {
+ var c = new CommunityNode(),
+ e1 = {
+ _id: "1-2",
+ _data: {
+ _from: "1",
+ _to: "2"
+ },
+ source: nodes[1],
+ target: nodes[2]
+ },
+ e2 = {
+ _id: "2-1",
+ _data: {
+ _from: "2",
+ _to: "1"
+ },
+ source: nodes[2],
+ target: nodes[1]
+ };
+ expect(c.insertInboundEdge(e1)).toBeFalsy();
+ expect(c.insertOutboundEdge(e2)).toBeFalsy();
+ });
+
it('should be able to resolve the community', function() {
var c = new CommunityNode(nodes.slice(3, 13)),
e1 = {
_id: "3-4",
- _from: "3",
- _to: "4"
+ _data: {
+ _from: "3",
+ _to: "4"
+ },
+ source: nodes[3],
+ target: nodes[4]
},
e2 = {
- _id: "5-7",
- _from: "5",
- _to: "7"
+ _id: "1-7",
+ _data: {
+ _from: "1",
+ _to: "7"
+ },
+ source: nodes[1],
+ target: nodes[7]
+ },
+ e3 = {
+ _id: "8-25",
+ _data: {
+ _from: "8",
+ _to: "25"
+ },
+ source: nodes[8],
+ target: nodes[25]
};
- c.insertEdge(e1);
- c.insertEdge(e2);
+ c.insertInboundEdge(e1);
+ c.insertOutboundEdge(e1);
+ c.insertInboundEdge(e2);
+ c.insertOutboundEdge(e3);
expect(c.dissolve()).toEqual({
nodes: nodes.slice(3, 13),
- edges: [e1, e2]
+ edges: {
+ both: [e1],
+ inbound: [e2],
+ outbound: [e3]
+ }
});
+ expect(e1.source).toEqual(c);
+ expect(e1.target).toEqual(c);
+ expect(e2.target).toEqual(c);
+ expect(e3.source).toEqual(c);
});
});