mirror of https://gitee.com/bigwinds/arangodb
GraphViewer: Added first basic functions for the community node
This commit is contained in:
parent
a190fa58e6
commit
20e41e48ca
|
@ -1,4 +1,5 @@
|
|||
/*jslint indent: 2, nomen: true, maxlen: 100, white: true plusplus: true */
|
||||
/*global _ */
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Graph functionality
|
||||
///
|
||||
|
@ -31,4 +32,66 @@
|
|||
function CommunityNode(initial) {
|
||||
"use strict";
|
||||
|
||||
var
|
||||
|
||||
////////////////////////////////////
|
||||
// Private variables //
|
||||
////////////////////////////////////
|
||||
|
||||
nodes = {},
|
||||
|
||||
////////////////////////////////////
|
||||
// Private functions //
|
||||
////////////////////////////////////
|
||||
|
||||
toArray = function(obj) {
|
||||
var res = [];
|
||||
_.each(obj, function(v) {
|
||||
res.push(v);
|
||||
});
|
||||
return res;
|
||||
},
|
||||
|
||||
hasNode = function(id) {
|
||||
return !!nodes[id];
|
||||
},
|
||||
|
||||
getNodes = function() {
|
||||
return toArray(nodes);
|
||||
},
|
||||
|
||||
getNode = function(id) {
|
||||
return nodes[id];
|
||||
},
|
||||
|
||||
insertNode = function(n) {
|
||||
nodes[n._id] = n;
|
||||
},
|
||||
|
||||
insertEdge = function(e) {
|
||||
|
||||
},
|
||||
|
||||
dissolve = function() {
|
||||
|
||||
};
|
||||
|
||||
////////////////////////////////////
|
||||
// Setup //
|
||||
////////////////////////////////////
|
||||
|
||||
_.each(initial, function(n) {
|
||||
insertNode(n);
|
||||
});
|
||||
|
||||
////////////////////////////////////
|
||||
// Public functions //
|
||||
////////////////////////////////////
|
||||
|
||||
this.hasNode = hasNode;
|
||||
this.getNodes = getNodes;
|
||||
this.getNode = getNode;
|
||||
this.insertNode = insertNode;
|
||||
this.insertEdge = insertEdge;
|
||||
this.dissolve = dissolve;
|
||||
}
|
||||
|
|
|
@ -75,16 +75,65 @@
|
|||
expect(testee).toHaveFunction("getNodes", 0);
|
||||
});
|
||||
|
||||
it('should offer a function to check if node is included', function() {
|
||||
it('should offer a function to check if a node is included', function() {
|
||||
expect(testee).toHaveFunction("hasNode", 1);
|
||||
});
|
||||
|
||||
it('should offer a function to get a node if it is included', function() {
|
||||
expect(testee).toHaveFunction("getNode", 1);
|
||||
});
|
||||
|
||||
it('should offer a function to insert an additional node', function() {
|
||||
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 dissolve the community', function() {
|
||||
expect(testee).toHaveFunction("dissolve", 0);
|
||||
});
|
||||
});
|
||||
|
||||
it('should create a communityNode containing the given nodes', function() {
|
||||
var c = new CommunityNode(nodes.slice(3, 13));
|
||||
expect(c.getNodes()).toEqual(nodes.slice(3, 13));
|
||||
});
|
||||
|
||||
|
||||
it('should be able to insert a new node', function() {
|
||||
var c = new CommunityNode(nodes.slice(3, 13)),
|
||||
n = {
|
||||
_id: "fuxx",
|
||||
_inboundCounter: 0,
|
||||
_outboundCounter: 0,
|
||||
position: {
|
||||
x: 1,
|
||||
y: 1,
|
||||
z: 1
|
||||
}
|
||||
};
|
||||
c.insertNode(n);
|
||||
expect(c.getNodes()).toEqual(nodes.slice(3, 13).concat([n]));
|
||||
});
|
||||
|
||||
it('should be able to check if a node is included', function() {
|
||||
var n = {
|
||||
_id: "fuxx",
|
||||
_inboundCounter: 0,
|
||||
_outboundCounter: 0,
|
||||
position: {
|
||||
x: 1,
|
||||
y: 1,
|
||||
z: 1
|
||||
}
|
||||
},
|
||||
c = new CommunityNode([n]);
|
||||
|
||||
expect(c.hasNode("fuxx")).toBeTruthy();
|
||||
expect(c.hasNode("1")).toBeFalsy();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
}());
|
||||
|
|
Loading…
Reference in New Issue