mirror of https://gitee.com/bigwinds/arangodb
GraphViewer: Slightly changed interface of ArangoAdapter. It now defaults to the domains.host if none is given
This commit is contained in:
parent
77344be842
commit
04ae758746
|
@ -1,5 +1,5 @@
|
||||||
/*jslint indent: 2, nomen: true, maxlen: 100, white: true plusplus: true */
|
/*jslint indent: 2, nomen: true, maxlen: 100, white: true plusplus: true */
|
||||||
/*global $, d3, _, console*/
|
/*global $, d3, _, console, document*/
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief Graph functionality
|
/// @brief Graph functionality
|
||||||
///
|
///
|
||||||
|
@ -27,14 +27,70 @@
|
||||||
/// @author Copyright 2011-2013, triAGENS GmbH, Cologne, Germany
|
/// @author Copyright 2011-2013, triAGENS GmbH, Cologne, Germany
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
function ArangoAdapter(arangodb, nodes, edges, nodeCollection, edgeCollection, width, height) {
|
//function ArangoAdapter(arangodb, nodes, edges, nodeCollection, edgeCollection, width, height) {
|
||||||
|
function ArangoAdapter(nodes, edges, config) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
if (nodes === undefined) {
|
||||||
|
throw "The nodes have to be given.";
|
||||||
|
}
|
||||||
|
if (edges === undefined) {
|
||||||
|
throw "The edges have to be given.";
|
||||||
|
}
|
||||||
|
if (config === undefined) {
|
||||||
|
throw "A configuration with node- and edgeCollection has to be given.";
|
||||||
|
}
|
||||||
|
if (config.nodeCollection === undefined) {
|
||||||
|
throw "The nodeCollection has to be given.";
|
||||||
|
}
|
||||||
|
if (config.edgeCollection === undefined) {
|
||||||
|
throw "The edgeCollection has to be given.";
|
||||||
|
}
|
||||||
|
|
||||||
var self = this,
|
var self = this,
|
||||||
initialX = {},
|
initialX = {},
|
||||||
initialY = {},
|
initialY = {},
|
||||||
api = {},
|
api = {},
|
||||||
queries = {},
|
queries = {},
|
||||||
|
nodeCollection,
|
||||||
|
edgeCollection,
|
||||||
|
arangodb,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
|
||||||
|
setWidth = function(w) {
|
||||||
|
initialX.range = width / 2;
|
||||||
|
initialX.start = width / 4;
|
||||||
|
initialX.getStart = function () {
|
||||||
|
return this.start + Math.random() * this.range;
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
setHeight = function(h) {
|
||||||
|
initialY.range = height / 2;
|
||||||
|
initialY.start = height / 4;
|
||||||
|
initialY.getStart = function () {
|
||||||
|
return this.start + Math.random() * this.range;
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
parseConfig = function(config) {
|
||||||
|
initialX.getStart = function() {return 0;};
|
||||||
|
initialY.getStart = function() {return 0;};
|
||||||
|
nodeCollection = config.nodeCollection;
|
||||||
|
edgeCollection = config.edgeCollection;
|
||||||
|
if (config.host === undefined) {
|
||||||
|
arangodb = "http://" + document.location.host;
|
||||||
|
} else {
|
||||||
|
arangodb = config.host;
|
||||||
|
}
|
||||||
|
if (config.width !== undefined) {
|
||||||
|
setWidth(config.width);
|
||||||
|
}
|
||||||
|
if (config.height !== undefined) {
|
||||||
|
setHeight(config.height);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
findNode = function(id) {
|
findNode = function(id) {
|
||||||
var res = $.grep(nodes, function(e){
|
var res = $.grep(nodes, function(e){
|
||||||
|
@ -249,6 +305,8 @@ function ArangoAdapter(arangodb, nodes, edges, nodeCollection, edgeCollection, w
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
parseConfig(config);
|
||||||
|
|
||||||
api.base = arangodb.lastIndexOf("http://", 0) === 0
|
api.base = arangodb.lastIndexOf("http://", 0) === 0
|
||||||
? arangodb + "/_api/"
|
? arangodb + "/_api/"
|
||||||
: "http://" + arangodb + "/_api/";
|
: "http://" + arangodb + "/_api/";
|
||||||
|
@ -303,18 +361,6 @@ function ArangoAdapter(arangodb, nodes, edges, nodeCollection, edgeCollection, w
|
||||||
+ " || e._from == @id"
|
+ " || e._from == @id"
|
||||||
+ " RETURN e";
|
+ " RETURN e";
|
||||||
|
|
||||||
initialX.range = width / 2;
|
|
||||||
initialX.start = width / 4;
|
|
||||||
initialX.getStart = function () {
|
|
||||||
return this.start + Math.random() * this.range;
|
|
||||||
};
|
|
||||||
|
|
||||||
initialY.range = height / 2;
|
|
||||||
initialY.start = height / 4;
|
|
||||||
initialY.getStart = function () {
|
|
||||||
return this.start + Math.random() * this.range;
|
|
||||||
};
|
|
||||||
|
|
||||||
self.oldLoadNodeFromTreeById = function(nodeId, callback) {
|
self.oldLoadNodeFromTreeById = function(nodeId, callback) {
|
||||||
sendQuery(queries.nodeById, {
|
sendQuery(queries.nodeById, {
|
||||||
id: nodeId
|
id: nodeId
|
||||||
|
|
|
@ -97,14 +97,12 @@ function GraphViewer(svg, width, height,
|
||||||
|
|
||||||
switch (adapterConfig.type.toLowerCase()) {
|
switch (adapterConfig.type.toLowerCase()) {
|
||||||
case "arango":
|
case "arango":
|
||||||
|
adapterConfig.width = width;
|
||||||
|
adapterConfig.height = height;
|
||||||
self.adapter = new ArangoAdapter(
|
self.adapter = new ArangoAdapter(
|
||||||
adapterConfig.host,
|
|
||||||
nodes,
|
nodes,
|
||||||
edges,
|
edges,
|
||||||
adapterConfig.nodeCollection,
|
adapterConfig
|
||||||
adapterConfig.edgeCollection,
|
|
||||||
width,
|
|
||||||
height
|
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case "json":
|
case "json":
|
||||||
|
|
|
@ -39,13 +39,16 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
describe('Arango Adapter', function () {
|
describe('Arango Adapter', function () {
|
||||||
|
/*
|
||||||
describeInterface(new ArangoAdapter("", [], [], "", "", 1, 1));
|
describeInterface(new ArangoAdapter([], [], {
|
||||||
|
nodeCollection: "",
|
||||||
|
edgeCollection: ""
|
||||||
|
}));
|
||||||
|
*/
|
||||||
var adapter,
|
var adapter,
|
||||||
nodes,
|
nodes,
|
||||||
edges,
|
edges,
|
||||||
arangodb,
|
arangodb = "http://localhost:8529",
|
||||||
nodesCollection,
|
nodesCollection,
|
||||||
nodesCollId,
|
nodesCollId,
|
||||||
altNodesCollection,
|
altNodesCollection,
|
||||||
|
@ -210,26 +213,78 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
|
|
||||||
arangodb = "http://localhost:8529";
|
|
||||||
setupArangoContent();
|
setupArangoContent();
|
||||||
nodes = [];
|
nodes = [];
|
||||||
edges = [];
|
edges = [];
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error if no nodes are given', function() {
|
||||||
|
expect(
|
||||||
|
function() {
|
||||||
|
var t = new ArangoAdapter();
|
||||||
|
}
|
||||||
|
).toThrow("The nodes have to be given.");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error if no edges are given', function() {
|
||||||
|
expect(
|
||||||
|
function() {
|
||||||
|
var t = new ArangoAdapter([]);
|
||||||
|
}
|
||||||
|
).toThrow("The edges have to be given.");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error if no nodeCollection is given', function() {
|
||||||
|
expect(
|
||||||
|
function() {
|
||||||
|
var t = new ArangoAdapter([], [], {
|
||||||
|
edgeCollection: ""
|
||||||
|
});
|
||||||
|
}
|
||||||
|
).toThrow("The nodeCollection has to be given.");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error if no edgeCollection is given', function() {
|
||||||
|
expect(
|
||||||
|
function() {
|
||||||
|
var t = new ArangoAdapter([], [], {
|
||||||
|
nodeCollection: ""
|
||||||
|
});
|
||||||
|
}
|
||||||
|
).toThrow("The edgeCollection has to be given.");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not throw an error if everything is given', function() {
|
||||||
|
expect(
|
||||||
|
function() {
|
||||||
|
var t = new ArangoAdapter([], [], {
|
||||||
|
nodeCollection: "",
|
||||||
|
edgeCollection: ""
|
||||||
|
});
|
||||||
|
}
|
||||||
|
).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should automatically determine the host of not given', function() {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('setup correctly', function() {
|
||||||
|
beforeEach(function() {
|
||||||
adapter = new ArangoAdapter(
|
adapter = new ArangoAdapter(
|
||||||
arangodb,
|
|
||||||
nodes,
|
nodes,
|
||||||
edges,
|
edges,
|
||||||
nodesCollection,
|
{
|
||||||
edgesCollection,
|
nodeCollection: nodesCollection,
|
||||||
100,
|
edgeCollection: edgesCollection,
|
||||||
40);
|
width: 100,
|
||||||
|
height: 40
|
||||||
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function() {
|
it('should be able to load a tree node from '
|
||||||
|
+ 'ArangoDB by internal _id attribute', function() {
|
||||||
});
|
|
||||||
|
|
||||||
it('should be able to load a tree node from ArangoDB by internal _id attribute', function() {
|
|
||||||
|
|
||||||
var c0, c1, c2, c3, c4;
|
var c0, c1, c2, c3, c4;
|
||||||
|
|
||||||
|
@ -434,6 +489,8 @@
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
describe('that has already loaded one graph', function() {
|
describe('that has already loaded one graph', function() {
|
||||||
var c0, c1, c2, c3, c4, c5, c6, c7;
|
var c0, c1, c2, c3, c4, c5, c6, c7;
|
||||||
|
|
||||||
|
@ -833,6 +890,7 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
describe("Graph Viewer", function() {
|
describe("Graph Viewer", function() {
|
||||||
"use strict";
|
"use strict";
|
||||||
var viewer,
|
var viewer,
|
||||||
waittime = 100,
|
waittime = 200,
|
||||||
svg,
|
svg,
|
||||||
docSVG;
|
docSVG;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue