diff --git a/frontend/js/graphViewer/graph/eventLibrary.js b/frontend/js/graphViewer/graph/eventLibrary.js
index f358e826f3..178adbab72 100644
--- a/frontend/js/graphViewer/graph/eventLibrary.js
+++ b/frontend/js/graphViewer/graph/eventLibrary.js
@@ -1,4 +1,5 @@
/*jslint indent: 2, nomen: true, maxlen: 100, sloppy: true, vars: true, white: true, plusplus: true */
+/*global _*/
/* global eventLibrary */
////////////////////////////////////////////////////////////////////////////////
@@ -28,7 +29,9 @@
/// @author Copyright 2011-2012, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
-// Example onclick = new eventLibrary.Expand(edges, nodes, start, adapter.loadNode, nodeShaper.reshapeNode)
+// Example onclick = new eventLibrary.Expand(
+// edges, nodes, start,
+// adapter.loadNode, nodeShaper.reshapeNode)
function EventLibrary() {
this.Expand = function (edges, nodes, startCallback, loadNode, reshapeNode) {
if (edges === undefined) {
@@ -64,8 +67,8 @@ function EventLibrary() {
// Helper function to easily remove all outbound edges for one node
removeOutboundEdgesFromNode = function ( node ) {
if (node._outboundCounter > 0) {
- var subNodes = [];
- var i;
+ var subNodes = [],
+ i;
for ( i = 0; i < edges.length; i++ ) {
if ( edges[i].source === node ) {
subNodes.push(edges[i].target);
diff --git a/frontend/js/graphViewer/jasmine_test/jasmineTestLinks.html b/frontend/js/graphViewer/jasmine_test/jasmineTestLinks.html
index 0222884bb2..362a8f0628 100644
--- a/frontend/js/graphViewer/jasmine_test/jasmineTestLinks.html
+++ b/frontend/js/graphViewer/jasmine_test/jasmineTestLinks.html
@@ -3,12 +3,13 @@
diff --git a/frontend/js/graphViewer/jasmine_test/runnerAll.html b/frontend/js/graphViewer/jasmine_test/runnerAll.html
index 413b00a3b0..b848f1c633 100644
--- a/frontend/js/graphViewer/jasmine_test/runnerAll.html
+++ b/frontend/js/graphViewer/jasmine_test/runnerAll.html
@@ -15,12 +15,13 @@
-
+
+
@@ -29,7 +30,7 @@
-
+
diff --git a/frontend/js/graphViewer/jasmine_test/runnerEventLibrary.html b/frontend/js/graphViewer/jasmine_test/runnerEventLibrary.html
new file mode 100644
index 0000000000..6020462f4d
--- /dev/null
+++ b/frontend/js/graphViewer/jasmine_test/runnerEventLibrary.html
@@ -0,0 +1,63 @@
+
+
+
+ Jasmine Test Arango Adapter
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/frontend/js/graphViewer/jasmine_test/specEventLibrary/eventLibrarySpec.js b/frontend/js/graphViewer/jasmine_test/specEventLibrary/eventLibrarySpec.js
index 5e8b5537a0..dbe3106628 100644
--- a/frontend/js/graphViewer/jasmine_test/specEventLibrary/eventLibrarySpec.js
+++ b/frontend/js/graphViewer/jasmine_test/specEventLibrary/eventLibrarySpec.js
@@ -3,7 +3,6 @@
/*global describe, it, expect */
/*global runs, spyOn, waitsFor */
/*global window, eb, loadFixtures, document */
-/*global $, _, d3*/
/*global EventLibrary*/
////////////////////////////////////////////////////////////////////////////////
@@ -39,395 +38,142 @@
describe('Event Library', function () {
- describe('Node Expander', function() {
-
- beforeEach(function() {
- var
- nodes = [],
- edges = [],
-
-
- var expandEvent =
- $('#foo').on('click', function() {
- alert($(this).text());
- });
- $('#foo').trigger('click');
- });
-
-
- });
-
- var layouter,
- nodes,
- width,
- height,
- offset,
- linkDistance,
- gravity,
- standardConfig,
- edgeShaper,
-
- createNodeList = function(amount) {
- var i,
- nodes = [];
- for (i = 0; i < amount; i++) {
- nodes.push({"id": i});
- }
- return nodes;
- },
- timeOutTest = function() {
- var startTime;
-
- runs(function() {
- spyOn(layouter, 'stop').andCallThrough();
- startTime = (new Date()).getTime();
- layouter.start();
- });
-
- waitsFor(function() {
- return layouter.stop.calls.length > 0;
- }, "layouter should have been stopped", 2000);
-
- runs(function() {
- // List test if not time-outed
- var endTime = (new Date()).getTime(),
- duration = endTime - startTime;
- expect(duration).toBeInATimeCategory();
- });
- },
- positioningTest = function() {
- runs(function() {
- spyOn(layouter, 'stop').andCallThrough();
- layouter.start();
- });
-
- waitsFor(function() {
- return layouter.stop.calls.length > 0;
- }, "layouter should have been stopped", 2000);
-
- runs(function() {
- expect(nodes).toNotBeOffScreen();
- });
- },
-
- dummyNodeShaper = {
- "updateNodes": function() {
- var changeDist = 0;
- _.each(nodes, function(d) {
- changeDist += Math.abs(d.px - d.x) + Math.abs(d.py - d.y);
- });
- return changeDist;
- }
- };
-
+ var eventLib;
beforeEach(function() {
- width = 940;
- height = 640;
- offset = 10;
- linkDistance = 100;
- gravity = 0.5;
-
- standardConfig = {
- "nodes": [],
- "links": [],
- "width": width,
- "height": height,
- "gravity": gravity,
- "distance": linkDistance
- };
-
- this.addMatchers({
- toBeInATimeCategory: function() {
- var duration = this.actual;
- this.message = function(){
- layouter.stop();
- if (duration < 100) {
- return "terminates super fast (0.1 s)";
- }
- if (duration < 1000) {
- return "terminates fast (1 s)";
- }
- if (duration < 2000) {
- return "terminates quite fast (2 s)";
- }
- if (duration < 5000) {
- return "terminates in reasonable time (5 s)";
- }
- if (duration < 10000) {
- return "terminates in acceptable time (10 s)";
- }
- return "does not terminate in acceptable time";
- };
- return duration < 10000;
- },
-
- toBeCloseToNode: function (n2, threshold) {
- var n1 = this.actual,
- xdis = n1.x - n2.x,
- ydis = n1.y - n2.y,
- distance = Math.sqrt(xdis*xdis + ydis*ydis);
- this.message = function() {
- return "Node " + n1.id
- + " should be close to Node " + n2.id
- + " but distance is " + distance;
- };
- threshold = threshold || 100;
- return Math.abs(distance) < threshold;
- },
-
- toBeDistantToNode: function (n2, threshold) {
- var n1 = this.actual,
- xdis = n1.x - n2.x,
- ydis = n1.y - n2.y,
- distance = Math.sqrt(xdis*xdis + ydis*ydis);
- this.message = function() {
- if (distance - linkDistance < 0) {
- return "Node " + n1.id
- + " should be distant from Node " + n2.id
- + " but distance is to short (" + distance + ")";
- }
- return "Node " + n1.id
- + " should be distant from Node " + n2.id
- + " but distance is to long (" + distance + ")";
-
- };
- threshold = threshold || 100;
- return Math.abs(distance - linkDistance) < threshold;
- },
-
- toNotBeOffScreen: function () {
- var minx = Number.MAX_VALUE,
- miny = Number.MAX_VALUE,
- maxx = Number.MIN_VALUE,
- maxy = Number.MIN_VALUE,
- nodes = this.actual;
- _.each(nodes, function(node) {
- minx = Math.min(minx, node.x);
- miny = Math.min(miny, node.y);
- maxx = Math.max(maxx, node.x);
- maxy = Math.max(maxy, node.y);
- });
- this.message = function () {
- var msg = "Errors: \n";
- if (minx < offset) {
- msg += "Minimal x: " + minx + " < " + offset + ", ";
- }
- if (maxx > width - offset) {
- msg += "Maximal x: " + maxx + " > " + (width - offset) + ", ";
- }
- if (miny > offset) {
- msg += "Minimal y: " + miny + " < " + offset + " ,";
- }
- if (maxy > height - offset) {
- msg += "Maximal y: " + maxy + " > " + (height - offset);
- }
- return msg;
- };
- return minx > offset
- && maxx < width - offset
- && miny > offset
- && maxy < height - offset;
- }
- });
-
+ eventLib = new EventLibrary();
});
-
- it('should position the first node in the centre', function() {
- runs(function() {
- standardConfig.nodes = createNodeList(1);
- nodes = standardConfig.nodes;
- edgeShaper = {"updateEdges": function(){}};
- layouter = new ForceLayouter(standardConfig);
- layouter.setCombinedUpdateFunction(dummyNodeShaper, edgeShaper);
- spyOn(layouter, 'stop').andCallThrough();
- layouter.start();
+
+ describe('Expand', function() {
+
+ var loaded,
+ reshaped,
+ nodes,
+ edges,
+ loadedNodes,
+ reshapedNodes,
+ started,
+ loadNodeCallback = function(node) {
+ loaded++;
+ loadedNodes.push(node);
+ },
+ reshapeNodeCallback = function(node) {
+ reshaped++;
+ reshapedNodes.push(node);
+ },
+ startCallback = function() {
+ started++;
+ },
+ testee;
+
+ beforeEach(function() {
+ loaded = 0;
+ reshaped = 0;
+ started = 0;
+
+ nodes = [];
+ edges = [];
+ loadedNodes = [];
+ reshapedNodes = [];
});
- waitsFor(function() {
- return layouter.stop.calls.length > 0;
- }, "force should have been stopped", 10000);
-
- runs(function() {
- var center = {
- "id": "center",
- "x": width/2,
- "y": height/2
+ it('should expand a collapsed node', function() {
+ var node = {
+ id: 0,
+ _outboundCounter: 0,
+ _inboundCounter: 0
};
- expect(nodes[0]).toBeCloseToNode(center);
- });
- });
-
- it('should position not linked nodes close to each other', function() {
- runs(function() {
- nodes = createNodeList(4);
- standardConfig.nodes = nodes;
- edgeShaper = {"updateEdges": function(){}};
- layouter = new ForceLayouter(standardConfig);
- layouter.setCombinedUpdateFunction(dummyNodeShaper, edgeShaper);
- spyOn(layouter, 'stop').andCallThrough();
- layouter.start();
- });
-
- waitsFor(function() {
- return layouter.stop.calls.length > 0;
- }, "force should have been stopped", 10000);
+ nodes.push(node);
+ testee = eventLib.Expand(
+ edges,
+ nodes,
+ startCallback,
+ loadNodeCallback,
+ reshapeNodeCallback
+ );
+ testee(node);
- runs(function() {
- expect(nodes[0]).toBeCloseToNode(nodes[1]);
- expect(nodes[0]).toBeCloseToNode(nodes[2]);
- expect(nodes[0]).toBeCloseToNode(nodes[3]);
- expect(nodes[1]).toBeCloseToNode(nodes[2]);
- expect(nodes[1]).toBeCloseToNode(nodes[3]);
- expect(nodes[2]).toBeCloseToNode(nodes[3]);
- });
-
- });
-
- it('should keep distance between linked nodes', function() {
- runs(function() {
- nodes = createNodeList(4);
- standardConfig.nodes = nodes;
- standardConfig.links = [
- {"source": nodes[0], "target": nodes[1]},
- {"source": nodes[0], "target": nodes[2]},
- {"source": nodes[0], "target": nodes[3]},
- {"source": nodes[1], "target": nodes[3]},
- {"source": nodes[2], "target": nodes[3]}
- ];
- edgeShaper = {"updateEdges": function(){}};
- layouter = new ForceLayouter(standardConfig);
- layouter.setCombinedUpdateFunction(dummyNodeShaper, edgeShaper);
- spyOn(layouter, 'stop').andCallThrough();
- layouter.start();
- });
-
- waitsFor(function() {
- return layouter.stop.calls.length > 0;
- }, "force should have been stopped", 10000);
-
- runs(function() {
- expect(nodes[0]).toBeDistantToNode(nodes[1]);
- expect(nodes[0]).toBeDistantToNode(nodes[2]);
- expect(nodes[0]).toBeDistantToNode(nodes[3]);
- expect(nodes[1]).toBeDistantToNode(nodes[3]);
- expect(nodes[2]).toBeDistantToNode(nodes[3]);
- });
-
- });
-
- it('should throw an error if nodes are not defined', function() {
- expect(function() {
- var tmp = new ForceLayouter({"links": []});
- }).toThrow("No nodes defined");
- expect(function() {
- var tmp = new ForceLayouter({"nodes": [],"links": []});
- }).not.toThrow("No nodes defined");
- });
-
- it('should throw an error if links are not defined', function() {
- expect(function() {
- var tmp = new ForceLayouter({"nodes": []});
- }).toThrow("No links defined");
- expect(function() {
- var tmp = new ForceLayouter({"nodes": [],"links": []});
- }).not.toThrow("No links defined");
- });
-
-
- describe('tested under normal conditions (50 nodes)', function() {
- beforeEach(function() {
- nodes = createNodeList(50);
- standardConfig.nodes = nodes;
- edgeShaper = {"updateEdges": function(){}};
- layouter = new ForceLayouter(standardConfig);
- layouter.setCombinedUpdateFunction(dummyNodeShaper, edgeShaper);
+ expect(node._expanded).toBeTruthy();
+ expect(started).toEqual(1);
+ expect(reshaped).toEqual(1);
+ expect(loaded).toEqual(1);
+ expect(reshapedNodes.length).toEqual(1);
+ expect(reshapedNodes[0]).toEqual(node);
+ expect(loadedNodes.length).toEqual(1);
+ expect(loadedNodes[0]).toEqual(node.id);
});
-
- it('should not position a node offscreen', function() {
- positioningTest();
- });
-
- it('should terminate', function() {
- timeOutTest();
- });
-
- });
-
- describe('tested under heavy weight conditions (500 nodes)', function() {
-
- beforeEach(function() {
- nodes = createNodeList(500);
- standardConfig.nodes = nodes;
- edgeShaper = {"updateEdges": function(){}};
- layouter = new ForceLayouter(standardConfig);
- layouter.setCombinedUpdateFunction(dummyNodeShaper, edgeShaper);
+ it('should collapse an expanded node', function() {
+ var node = {
+ id: 0,
+ _expanded: true,
+ _outboundCounter: 0,
+ _inboundCounter: 0
+ };
+ nodes.push(node);
+ testee = eventLib.Expand(
+ edges,
+ nodes,
+ startCallback,
+ loadNodeCallback,
+ reshapeNodeCallback
+ );
+ testee(node);
+ expect(node._expanded).toBeFalsy();
+ expect(started).toEqual(1);
+ expect(reshaped).toEqual(1);
+ expect(loaded).toEqual(0);
+ expect(reshapedNodes.length).toEqual(1);
+ expect(reshapedNodes[0]).toEqual(node);
});
-
- it('should not position a node offscreen', function() {
- positioningTest();
- });
-
-
- it('should terminate', function() {
- timeOutTest();
- });
-
- });
- /*
- describe('tested under evil stress (5000 nodes)', function() {
-
- beforeEach(function() {
- nodes = createNodeList(5000);
- standardConfig.nodes = nodes;
- edgeShaper = {"updateEdges": function(){}};
- layouter = new ForceLayouter(standardConfig);
- layouter.setCombinedUpdateFunction(dummyNodeShaper, edgeShaper);
+ it('should collapse a tree', function() {
+ var root = {
+ id: 0,
+ _expanded: true,
+ _outboundCounter: 2,
+ _inboundCounter: 0
+ },
+ c1 = {
+ id: 1,
+ _outboundCounter: 0,
+ _inboundCounter: 1
+ },
+ c2 = {
+ id: 2,
+ _outboundCounter: 0,
+ _inboundCounter: 1
+ };
- });
-
-
- it('should not position a node offscreen', function() {
- positioningTest();
- });
-
-
- it('should terminate', function() {
- timeOutTest();
- });
-
-
- });
-
- */
- /*
- describe('tested by the devil himself (50000 nodes)', function() {
-
- beforeEach(function() {
- nodes = createNodeList(50000);
- standardConfig.nodes = nodes;
- edgeShaper = {"updateEdges": function(){}};
- layouter = new ForceLayouter(standardConfig);
- layouter.setCombinedUpdateFunction(dummyNodeShaper, edgeShaper);
+ nodes.push(root);
+ nodes.push(c1);
+ nodes.push(c2);
+ edges.push({source: root, target: c1});
+ edges.push({source: root, target: c2});
- });
-
-
- it('should not position a node offscreen', function() {
- positioningTest();
- });
-
-
- it('should terminate', function() {
- timeOutTest();
+ testee = eventLib.Expand(
+ edges,
+ nodes,
+ startCallback,
+ loadNodeCallback,
+ reshapeNodeCallback
+ );
+ testee(root);
+
+ expect(root._expanded).toBeFalsy();
+ expect(started).toEqual(1);
+ expect(reshaped).toEqual(1);
+ expect(loaded).toEqual(0);
+ expect(nodes.length).toEqual(1);
+ expect(edges.length).toEqual(0);
+ expect(reshapedNodes.length).toEqual(1);
+ expect(reshapedNodes[0]).toEqual(root);
});
});
- */
+
});
}());
\ No newline at end of file
diff --git a/frontend/js/graphViewer/jasmine_test/specGraphViewer/graphViewerSpec.js b/frontend/js/graphViewer/jasmine_test/specGraphViewer/graphViewerSpec.js
index 357d3cbba2..7888318a7e 100644
--- a/frontend/js/graphViewer/jasmine_test/specGraphViewer/graphViewerSpec.js
+++ b/frontend/js/graphViewer/jasmine_test/specGraphViewer/graphViewerSpec.js
@@ -4,7 +4,7 @@
/*global waitsFor, runs */
/*global window, eb, loadFixtures, document */
/*global $, _, d3*/
-/*global ClickExpander*/
+/*global GraphViewer*/
////////////////////////////////////////////////////////////////////////////////
/// @brief Graph functionality
@@ -34,12 +34,12 @@
////////////////////////////////////////////////////////////////////////////////
-describe("click Expander", function() {
+describe("Graph Viewer", function() {
"use strict";
- var expander,
+ var viewer,
svg,
docSVG,
-
+ /*
nodeWithID = function(id) {
return $.grep(expander.nodes, function(e){
return e.id === id;
@@ -84,7 +84,7 @@ describe("click Expander", function() {
notExistNodes = function(ids) {
_.each(ids, notExistNode);
},
-
+ */
displayNode = function(id) {
expect($("svg #" + id)[0]).toBeDefined();
},
@@ -122,6 +122,9 @@ describe("click Expander", function() {
docSVG = document.createElement("svg");
document.body.appendChild(docSVG);
svg = d3.select("svg");
+
+
+
expander = new ClickExpander("../generated_1000/", svg, 980, 640, 1);
});
diff --git a/frontend/js/graphViewer/jasmine_test/specJSONAdapter/jsonAdapterSpec.js b/frontend/js/graphViewer/jasmine_test/specJSONAdapter/jsonAdapterSpec.js
index 7f21109aa9..2243ac4b4d 100644
--- a/frontend/js/graphViewer/jasmine_test/specJSONAdapter/jsonAdapterSpec.js
+++ b/frontend/js/graphViewer/jasmine_test/specJSONAdapter/jsonAdapterSpec.js
@@ -75,7 +75,7 @@
edges.insertEdge = function(source, target) {
this.push({source: source, target: target});
};
- startNode = 477;
+ startNode = 0;
adapter = new JSONAdapter(jsonPath, nodes, edges);
});
@@ -94,7 +94,7 @@
});
runs(function() {
- existNodes([477, 29, 159, 213, 339]);
+ existNodes([0, 1, 2, 3, 4]);
expect(nodes.length).toEqual(5);
});
});