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 */
|
||||
/*global $, d3, _, console*/
|
||||
/*global $, d3, _, console, document*/
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Graph functionality
|
||||
///
|
||||
|
@ -27,14 +27,70 @@
|
|||
/// @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";
|
||||
|
||||
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,
|
||||
initialX = {},
|
||||
initialY = {},
|
||||
api = {},
|
||||
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) {
|
||||
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
|
||||
? arangodb + "/_api/"
|
||||
: "http://" + arangodb + "/_api/";
|
||||
|
@ -303,18 +361,6 @@ function ArangoAdapter(arangodb, nodes, edges, nodeCollection, edgeCollection, w
|
|||
+ " || e._from == @id"
|
||||
+ " 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) {
|
||||
sendQuery(queries.nodeById, {
|
||||
id: nodeId
|
||||
|
|
|
@ -97,14 +97,12 @@ function GraphViewer(svg, width, height,
|
|||
|
||||
switch (adapterConfig.type.toLowerCase()) {
|
||||
case "arango":
|
||||
adapterConfig.width = width;
|
||||
adapterConfig.height = height;
|
||||
self.adapter = new ArangoAdapter(
|
||||
adapterConfig.host,
|
||||
nodes,
|
||||
edges,
|
||||
adapterConfig.nodeCollection,
|
||||
adapterConfig.edgeCollection,
|
||||
width,
|
||||
height
|
||||
adapterConfig
|
||||
);
|
||||
break;
|
||||
case "json":
|
||||
|
|
|
@ -39,13 +39,16 @@
|
|||
"use strict";
|
||||
|
||||
describe('Arango Adapter', function () {
|
||||
|
||||
describeInterface(new ArangoAdapter("", [], [], "", "", 1, 1));
|
||||
|
||||
/*
|
||||
describeInterface(new ArangoAdapter([], [], {
|
||||
nodeCollection: "",
|
||||
edgeCollection: ""
|
||||
}));
|
||||
*/
|
||||
var adapter,
|
||||
nodes,
|
||||
edges,
|
||||
arangodb,
|
||||
arangodb = "http://localhost:8529",
|
||||
nodesCollection,
|
||||
nodesCollId,
|
||||
altNodesCollection,
|
||||
|
@ -210,26 +213,78 @@
|
|||
};
|
||||
|
||||
beforeEach(function() {
|
||||
|
||||
arangodb = "http://localhost:8529";
|
||||
setupArangoContent();
|
||||
nodes = [];
|
||||
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(
|
||||
arangodb,
|
||||
nodes,
|
||||
edges,
|
||||
nodesCollection,
|
||||
edgesCollection,
|
||||
100,
|
||||
40);
|
||||
{
|
||||
nodeCollection: nodesCollection,
|
||||
edgeCollection: edgesCollection,
|
||||
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;
|
||||
|
||||
|
@ -434,6 +489,8 @@
|
|||
|
||||
});
|
||||
|
||||
|
||||
|
||||
describe('that has already loaded one graph', function() {
|
||||
var c0, c1, c2, c3, c4, c5, c6, c7;
|
||||
|
||||
|
@ -833,6 +890,7 @@
|
|||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
describe("Graph Viewer", function() {
|
||||
"use strict";
|
||||
var viewer,
|
||||
waittime = 100,
|
||||
waittime = 200,
|
||||
svg,
|
||||
docSVG;
|
||||
|
||||
|
|
Loading…
Reference in New Issue