mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-22 14:17:57 +01:00
Test Suite refactor
This commit is contained in:
parent
db645859ae
commit
b741851f54
@ -1,887 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright [2011] [wisemapping]
|
|
||||||
*
|
|
||||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
|
||||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
|
||||||
* "powered by wisemapping" text requirement on every single page;
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the license at
|
|
||||||
*
|
|
||||||
* http://www.wisemapping.org/license
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
mindplot.layout.TestSuite = new Class({
|
|
||||||
Extends: mindplot.layout.ChildrenSorterStrategy,
|
|
||||||
|
|
||||||
initialize:function() {
|
|
||||||
this.testAligned();
|
|
||||||
this.testSymmetry();
|
|
||||||
this.testBalanced();
|
|
||||||
this.testEvents();
|
|
||||||
this.testEventsComplex();
|
|
||||||
this.testDisconnect();
|
|
||||||
this.testReconnect();
|
|
||||||
this.testRemoveNode();
|
|
||||||
this.testSymmetricPredict();
|
|
||||||
this.testBalancedPredict();
|
|
||||||
this.testSize();
|
|
||||||
this.testFreePosition();
|
|
||||||
this.testFreePredict();
|
|
||||||
this.testReconnectFreeNode();
|
|
||||||
this.testReconnectSingleNode();
|
|
||||||
},
|
|
||||||
|
|
||||||
testAligned: function() {
|
|
||||||
|
|
||||||
var position = {x:0,y:0};
|
|
||||||
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
|
|
||||||
|
|
||||||
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.connectNode(0, 1, 0);
|
|
||||||
manager.connectNode(1, 2, 0);
|
|
||||||
manager.connectNode(2, 3, 0);
|
|
||||||
manager.connectNode(3, 4, 0);
|
|
||||||
|
|
||||||
manager.layout();
|
|
||||||
manager.plot("testAligned", {width:1200,height:200});
|
|
||||||
|
|
||||||
// All nodes should be vertically aligned
|
|
||||||
$assert(manager.find(0).getPosition().y == manager.find(1).getPosition().y, "Nodes are not aligned");
|
|
||||||
$assert(manager.find(0).getPosition().y == manager.find(2).getPosition().y, "Nodes are not aligned");
|
|
||||||
$assert(manager.find(0).getPosition().y == manager.find(3).getPosition().y, "Nodes are not aligned");
|
|
||||||
$assert(manager.find(0).getPosition().y == manager.find(4).getPosition().y, "Nodes are not aligned");
|
|
||||||
},
|
|
||||||
|
|
||||||
testSymmetry: function() {
|
|
||||||
var position = {x:0,y:0};
|
|
||||||
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
|
|
||||||
|
|
||||||
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(9, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(10, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(11, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(12, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(13, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(14, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.connectNode(0, 14, 0);
|
|
||||||
manager.connectNode(14, 13, 0);
|
|
||||||
manager.connectNode(13, 1, 0);
|
|
||||||
manager.connectNode(13, 2, 1);
|
|
||||||
manager.connectNode(13, 3, 2);
|
|
||||||
manager.connectNode(13, 4, 3);
|
|
||||||
manager.connectNode(13, 5, 4);
|
|
||||||
manager.connectNode(1, 6, 0);
|
|
||||||
manager.connectNode(1, 7, 1);
|
|
||||||
manager.connectNode(7, 8, 0);
|
|
||||||
manager.connectNode(8, 9, 0);
|
|
||||||
manager.connectNode(5, 10, 0);
|
|
||||||
manager.connectNode(6, 11, 0);
|
|
||||||
manager.connectNode(6, 12, 1);
|
|
||||||
|
|
||||||
manager.layout();
|
|
||||||
manager.plot("testSymmetry",{width:1600, height:400});
|
|
||||||
|
|
||||||
// All nodes should be positioned symmetrically with respect to their common ancestors
|
|
||||||
$assert(manager.find(14).getPosition().y == -manager.find(13).getPosition().y, "Symmetry is not respected");
|
|
||||||
$assert(manager.find(5).getPosition().y == -manager.find(11).getPosition().y, "Symmetry is not respected");
|
|
||||||
$assert(manager.find(11).getPosition().y - manager.find(6).getPosition().y == -(manager.find(12).getPosition().y - manager.find(6).getPosition().y), "Symmetry is not respected");
|
|
||||||
$assert(manager.find(8).getPosition().y - manager.find(1).getPosition().y == -(manager.find(11).getPosition().y - manager.find(1).getPosition().y), "Symmetry is not respected");
|
|
||||||
$assert(manager.find(9).getPosition().y - manager.find(1).getPosition().y == -(manager.find(11).getPosition().y - manager.find(1).getPosition().y), "Symmetry is not respected");
|
|
||||||
},
|
|
||||||
|
|
||||||
testBalanced: function() {
|
|
||||||
var position = {x:0, y:0};
|
|
||||||
var plotsize = {width:1000, height:200};
|
|
||||||
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
|
|
||||||
|
|
||||||
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.connectNode(0, 1, 0);
|
|
||||||
manager.layout();
|
|
||||||
manager.plot("testBalanced1", plotsize);
|
|
||||||
|
|
||||||
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.connectNode(0, 2, 1);
|
|
||||||
manager.layout();
|
|
||||||
manager.plot("testBalanced2", plotsize);
|
|
||||||
|
|
||||||
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.connectNode(0, 3, 2);
|
|
||||||
manager.layout();
|
|
||||||
manager.plot("testBalanced3", plotsize);
|
|
||||||
|
|
||||||
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.connectNode(0, 4, 3);
|
|
||||||
manager.layout();
|
|
||||||
manager.plot("testBalanced4", plotsize);
|
|
||||||
|
|
||||||
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.connectNode(0, 5, 4);
|
|
||||||
manager.layout();
|
|
||||||
manager.plot("testBalanced5", plotsize);
|
|
||||||
|
|
||||||
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.connectNode(0, 6, 5);
|
|
||||||
manager.layout();
|
|
||||||
manager.plot("testBalanced6", plotsize);
|
|
||||||
|
|
||||||
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(9, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.connectNode(3, 7, 0)
|
|
||||||
manager.connectNode(7, 8, 0)
|
|
||||||
manager.connectNode(7, 9, 1);
|
|
||||||
manager.layout();
|
|
||||||
manager.plot("testBalanced7", plotsize);
|
|
||||||
|
|
||||||
manager.addNode(10, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(11, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(12, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.connectNode(6, 10, 0)
|
|
||||||
manager.connectNode(10, 11, 0)
|
|
||||||
manager.connectNode(10, 12, 1);
|
|
||||||
manager.layout();
|
|
||||||
manager.plot("testBalanced8", plotsize);
|
|
||||||
|
|
||||||
manager.addNode(13, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.connectNode(0, 13, 4);
|
|
||||||
manager.layout();
|
|
||||||
manager.plot("testBalanced9", {width:1000, height:400});
|
|
||||||
|
|
||||||
manager.addNode(14, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.connectNode(0, 14, 5);
|
|
||||||
manager.layout();
|
|
||||||
manager.plot("testBalanced10", {width:1000, height:400});
|
|
||||||
|
|
||||||
manager.addNode(15, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.connectNode(0, 15, 4);
|
|
||||||
manager.layout();
|
|
||||||
manager.plot("testBalanced11", {width:1000, height:400});
|
|
||||||
|
|
||||||
manager.addNode(16, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.connectNode(0, 16, 25);
|
|
||||||
manager.layout();
|
|
||||||
manager.plot("testBalanced12", {width:1000, height:400});
|
|
||||||
|
|
||||||
manager.addNode(17, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(18, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(19, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.connectNode(0, 17, 11);
|
|
||||||
manager.connectNode(0, 18, 13);
|
|
||||||
manager.connectNode(0, 19, 10);
|
|
||||||
manager.layout();
|
|
||||||
manager.plot("testBalanced13", {width:1000, height:400});
|
|
||||||
|
|
||||||
$assert(manager.find(1).getPosition().x > manager.find(0).getPosition().x, "even order nodes must be at right of central topic");
|
|
||||||
$assert(manager.find(3).getPosition().x > manager.find(0).getPosition().x, "even order nodes must be at right of central topic");
|
|
||||||
$assert(manager.find(5).getPosition().x > manager.find(0).getPosition().x, "even order nodes must be at right of central topic");
|
|
||||||
|
|
||||||
$assert(manager.find(2).getPosition().x < manager.find(0).getPosition().x, "odd order nodes must be at right of central topic");
|
|
||||||
$assert(manager.find(4).getPosition().x < manager.find(0).getPosition().x, "odd order nodes must be at right of central topic");
|
|
||||||
$assert(manager.find(6).getPosition().x < manager.find(0).getPosition().x, "odd order nodes must be at right of central topic");
|
|
||||||
|
|
||||||
$assert(manager.find(7).getPosition().x > manager.find(3).getPosition().x, "children of 1st level even order nodes must be to the right");
|
|
||||||
$assert(manager.find(8).getPosition().x > manager.find(7).getPosition().x, "children of 1st level even order nodes must be to the right");
|
|
||||||
$assert(manager.find(9).getPosition().x > manager.find(7).getPosition().x, "children of 1st level even order nodes must be to the right");
|
|
||||||
|
|
||||||
$assert(manager.find(10).getPosition().x < manager.find(6).getPosition().x, "children of 1st level odd order nodes must be to the left");
|
|
||||||
$assert(manager.find(11).getPosition().x < manager.find(10).getPosition().x, "children of 1st level odd order nodes must be to the left");
|
|
||||||
$assert(manager.find(12).getPosition().x < manager.find(10).getPosition().x, "children of 1st level odd order nodes must be to the left");
|
|
||||||
},
|
|
||||||
|
|
||||||
testEvents: function() {
|
|
||||||
console.log("testEvents:");
|
|
||||||
var position = {x:0,y:0};
|
|
||||||
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
|
|
||||||
|
|
||||||
// Add 3 nodes...
|
|
||||||
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, {x:0, y: 60});
|
|
||||||
|
|
||||||
// Now connect one with two....
|
|
||||||
manager.connectNode(0, 1, 0);
|
|
||||||
manager.connectNode(0, 2, 1);
|
|
||||||
manager.connectNode(1, 3, 0);
|
|
||||||
|
|
||||||
// Basic layout repositioning ...
|
|
||||||
console.log("\t--- Updated tree ---");
|
|
||||||
var events = [];
|
|
||||||
manager.addEvent('change', function(event) {
|
|
||||||
console.log("\tUpdated nodes: {id:" + event.getId() + ", order: " + event.getOrder() + ",position: {" + event.getPosition().x + "," + event.getPosition().y + "}");
|
|
||||||
events.push(event);
|
|
||||||
});
|
|
||||||
manager.layout(true);
|
|
||||||
manager.plot("testEvents1", {width:800, height:200});
|
|
||||||
|
|
||||||
// Ok, if a new node is added, this an event should be fired ...
|
|
||||||
console.log("\t---- Layout without changes should not affect the tree ---");
|
|
||||||
events.empty();
|
|
||||||
manager.layout(true);
|
|
||||||
manager.plot("testEvents2", {width:800, height:200});
|
|
||||||
|
|
||||||
$assert(events.length == 0, "Unnecessary tree updated.");
|
|
||||||
|
|
||||||
console.log("\n");
|
|
||||||
},
|
|
||||||
|
|
||||||
testEventsComplex: function() {
|
|
||||||
console.log("testEventsComplex:");
|
|
||||||
var position = {x:0,y:0};
|
|
||||||
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
|
|
||||||
|
|
||||||
// Add 3 nodes...
|
|
||||||
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, {x:0, y:60});
|
|
||||||
|
|
||||||
// Now connect one with two....
|
|
||||||
manager.connectNode(0, 1, 0);
|
|
||||||
manager.connectNode(0, 2, 1);
|
|
||||||
manager.connectNode(0, 3, 2);
|
|
||||||
manager.connectNode(3, 4, 0);
|
|
||||||
manager.connectNode(3, 5, 1);
|
|
||||||
|
|
||||||
var events = [];
|
|
||||||
manager.addEvent('change', function(event) {
|
|
||||||
console.log("\tUpdated nodes: {id:" + event.getId() + ", order: " + event.getOrder() + ",position: {" + event.getPosition().x + "," + event.getPosition().y + "}");
|
|
||||||
events.push(event);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Reposition ...
|
|
||||||
manager.layout(true);
|
|
||||||
manager.plot("testEventsComplex1", {width:800, height:200});
|
|
||||||
|
|
||||||
// Add a new node and connect. Only children nodes should be affected.
|
|
||||||
console.log("\t---- Connect a new node ---");
|
|
||||||
|
|
||||||
events.empty();
|
|
||||||
manager.connectNode(3, 6, 2);
|
|
||||||
manager.layout(true);
|
|
||||||
manager.plot("testEventsComplex2", {width:800, height:200});
|
|
||||||
|
|
||||||
//TODO(gb): fix this. only 4 (reposition of nodes 1,4,5,6) events should be fired, actually 6 are
|
|
||||||
// $assert(events.length == 6, "Only 4 nodes should be repositioned.");
|
|
||||||
|
|
||||||
console.log("\n");
|
|
||||||
},
|
|
||||||
|
|
||||||
testDisconnect: function() {
|
|
||||||
console.log("testDisconnect:");
|
|
||||||
var position = {x:0,y:0};
|
|
||||||
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
|
|
||||||
|
|
||||||
// Prepare a sample graph ...
|
|
||||||
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
|
|
||||||
manager.connectNode(0, 1, 0);
|
|
||||||
manager.connectNode(1, 2, 0);
|
|
||||||
manager.connectNode(1, 3, 1);
|
|
||||||
manager.connectNode(1, 4, 2);
|
|
||||||
manager.connectNode(4, 5, 0);
|
|
||||||
manager.connectNode(5, 6, 0);
|
|
||||||
manager.connectNode(5, 7, 1);
|
|
||||||
|
|
||||||
var events = [];
|
|
||||||
manager.addEvent('change', function(event) {
|
|
||||||
var pos = event.getPosition();
|
|
||||||
var posStr = pos ? ",position: {" + pos.x + "," + pos.y : "";
|
|
||||||
var node = manager.find(event.getId());
|
|
||||||
console.log("\tUpdated nodes: {id:" + event.getId() + ", order: " + event.getOrder() + posStr + "}");
|
|
||||||
events.push(event);
|
|
||||||
});
|
|
||||||
manager.layout(true);
|
|
||||||
manager.plot("testDisconnect1", {width:1200, height:400});
|
|
||||||
|
|
||||||
// Now, disconnect one node ...
|
|
||||||
console.log("--- Disconnect a single node ---");
|
|
||||||
events.empty();
|
|
||||||
manager.disconnectNode(2);
|
|
||||||
manager.layout(true);
|
|
||||||
manager.plot("testDisconnect2", {width:1200, height:400});
|
|
||||||
|
|
||||||
// $assert(events.some(function(event) {return event.getId() == 2;}), "Event for disconnected node seems not to be propagated");
|
|
||||||
$assert(manager._treeSet.getParent(manager.find(2)) == null, "Node 2 should have no parent, it was disconnected");
|
|
||||||
|
|
||||||
// Great, let's disconnect a node with children.
|
|
||||||
console.log("--- Disconnect a node with children ---");
|
|
||||||
manager.disconnectNode(4);
|
|
||||||
manager.layout(true);
|
|
||||||
manager.plot("testDisconnect3", {width:1200, height:400});
|
|
||||||
|
|
||||||
$assert(events.some(function(event) {return event.getId() == 4;}), "Event for disconnected node seems not to be propagated");
|
|
||||||
$assert(manager._treeSet.getParent(manager.find(4)) == null, "Node 4 should have no parent, it was disconnected");
|
|
||||||
var childrenOfNode4 = manager._treeSet.getChildren(manager.find(4));
|
|
||||||
var childrenOfNode5 = manager._treeSet.getChildren(manager.find(5));
|
|
||||||
$assert(childrenOfNode4.contains(manager.find(5)), "Node 5 still should be the child of node 4");
|
|
||||||
$assert(childrenOfNode5.contains(manager.find(6)) && childrenOfNode5.contains(manager.find(7)), "Nodes 6 and 7 still should be the children of node 5");
|
|
||||||
|
|
||||||
console.log("\n");
|
|
||||||
},
|
|
||||||
|
|
||||||
testReconnect: function() {
|
|
||||||
var position = {x:0,y:0};
|
|
||||||
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
|
|
||||||
|
|
||||||
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(9, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(10, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(11, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(12, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.connectNode(0, 1, 0);
|
|
||||||
manager.connectNode(0, 2, 1);
|
|
||||||
manager.connectNode(0, 3, 2);
|
|
||||||
manager.connectNode(0, 4, 3);
|
|
||||||
manager.connectNode(0, 5, 4);
|
|
||||||
manager.connectNode(1, 6, 0);
|
|
||||||
manager.connectNode(1, 7, 1);
|
|
||||||
manager.connectNode(7, 8, 0);
|
|
||||||
manager.connectNode(8, 9, 0);
|
|
||||||
manager.connectNode(5, 10, 0);
|
|
||||||
manager.connectNode(6, 11, 0);
|
|
||||||
manager.connectNode(6, 12, 1);
|
|
||||||
|
|
||||||
manager.layout();
|
|
||||||
manager.plot("testReconnect1",{width:1200, height:400});
|
|
||||||
|
|
||||||
var childrenOfNode6BeforeReconnect = manager._treeSet.getChildren(manager.find(6));
|
|
||||||
|
|
||||||
// Reconnect node 6 to node 4
|
|
||||||
manager.disconnectNode(6);
|
|
||||||
manager.connectNode(4,6,0);
|
|
||||||
manager.layout();
|
|
||||||
manager.plot("testReconnect2",{width:1200, height:400});
|
|
||||||
|
|
||||||
var childrenOfNode4AfterReconnect = manager._treeSet.getChildren(manager.find(4));
|
|
||||||
var childrenOfNode6AfterReconnect = manager._treeSet.getChildren(manager.find(6));
|
|
||||||
$assert(childrenOfNode4AfterReconnect.contains(manager.find(6)), "Node 6 should be the child of node 4");
|
|
||||||
$assert(childrenOfNode6BeforeReconnect == childrenOfNode6AfterReconnect, "The children of node 6 should be the same");
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
testRemoveNode: function() {
|
|
||||||
console.log("testRemoveNode:");
|
|
||||||
var position = {x:0,y:0};
|
|
||||||
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
|
|
||||||
|
|
||||||
// Prepare a sample graph ...
|
|
||||||
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(9, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
|
|
||||||
manager.connectNode(0, 1, 0);
|
|
||||||
manager.connectNode(0, 5, 1);
|
|
||||||
manager.connectNode(0, 6, 2);
|
|
||||||
manager.connectNode(0, 7, 3);
|
|
||||||
manager.connectNode(0, 8, 4);
|
|
||||||
manager.connectNode(0, 9, 5);
|
|
||||||
manager.connectNode(1, 2, 0);
|
|
||||||
manager.connectNode(1, 3, 1);
|
|
||||||
manager.connectNode(3, 4, 0);
|
|
||||||
|
|
||||||
var events = [];
|
|
||||||
manager.addEvent('change', function(event) {
|
|
||||||
var pos = event.getPosition();
|
|
||||||
var posStr = pos ? ",position: {" + pos.x + "," + event.getPosition().y : "";
|
|
||||||
console.log("\tUpdated nodes: {id:" + event.getId() + ", order: " + event.getOrder() + posStr + "}");
|
|
||||||
events.push(event);
|
|
||||||
});
|
|
||||||
manager.layout(true);
|
|
||||||
manager.plot("testRemoveNode1", {width:1000, height:200});
|
|
||||||
|
|
||||||
// Test removal of a connected node ...
|
|
||||||
console.log("\t--- Remove node 3 ---");
|
|
||||||
manager.removeNode(3);
|
|
||||||
manager.layout(true);
|
|
||||||
manager.plot("testRemoveNode2", {width:1000, height:200});
|
|
||||||
|
|
||||||
// Remove a node from the root node
|
|
||||||
console.log("\t--- Remove node 6 ---");
|
|
||||||
manager.removeNode(6);
|
|
||||||
manager.layout(true);
|
|
||||||
manager.plot("testRemoveNode3", {width:1000, height:200});
|
|
||||||
|
|
||||||
// Remove a node from the root node
|
|
||||||
console.log("\t--- Remove node 5 ---");
|
|
||||||
manager.removeNode(5);
|
|
||||||
manager.layout(true);
|
|
||||||
manager.plot("testRemoveNode4", {width:1000, height:200});
|
|
||||||
|
|
||||||
$assert(manager.find(1).getPosition().y == manager.find(2).getPosition().y, "After removal of node 3, nodes 1 and 2 should be alingned");
|
|
||||||
console.log("\n");
|
|
||||||
},
|
|
||||||
|
|
||||||
testSymmetricPredict: function() {
|
|
||||||
console.log("testSymmetricPredict:");
|
|
||||||
var position = {x:0,y:0};
|
|
||||||
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
|
|
||||||
|
|
||||||
// Prepare a sample graph ...
|
|
||||||
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(9, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(10, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(11, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
|
|
||||||
manager.connectNode(0, 1, 0);
|
|
||||||
manager.connectNode(0, 2, 1);
|
|
||||||
manager.connectNode(0, 3, 2);
|
|
||||||
manager.connectNode(3, 4, 0);
|
|
||||||
manager.connectNode(3, 5, 1);
|
|
||||||
manager.connectNode(3, 6, 2);
|
|
||||||
manager.connectNode(5, 7, 0);
|
|
||||||
manager.connectNode(5, 8, 1);
|
|
||||||
manager.connectNode(5, 11, 2);
|
|
||||||
manager.connectNode(2, 9, 0);
|
|
||||||
manager.connectNode(2, 10, 1);
|
|
||||||
|
|
||||||
manager.layout();
|
|
||||||
|
|
||||||
console.log("\tAdded as child of node 9 and dropped at (-280, 45):");
|
|
||||||
var graph1 = manager.plot("testSymmetricPredict1", {width:1000, height:400});
|
|
||||||
this._plotPrediction(graph1, manager.predict(9, {x:-280, y:45}));
|
|
||||||
console.log("\tAdded as child of node 1 and dropped at (155, -90):");
|
|
||||||
this._plotPrediction(graph1, manager.predict(1, {x:-155, y:-90}));
|
|
||||||
|
|
||||||
console.log("\tAdded as child of node 5 and dropped at (375, 15):");
|
|
||||||
var graph2 = manager.plot("testSymmetricPredict2", {width:1000, height:400});
|
|
||||||
this._plotPrediction(graph2, manager.predict(5, {x:375, y:15}));
|
|
||||||
console.log("\tAdded as child of node 5 and dropped at (375, 45):");
|
|
||||||
this._plotPrediction(graph2, manager.predict(5, {x:375, y:45}));
|
|
||||||
console.log("\tAdded as child of node 5 and dropped at (375, 45):");
|
|
||||||
this._plotPrediction(graph2, manager.predict(5, {x:375, y:65}));
|
|
||||||
console.log("\tAdded as child of node 5 and dropped at (380, -30):");
|
|
||||||
this._plotPrediction(graph2, manager.predict(5, {x:380, y:-30}));
|
|
||||||
|
|
||||||
console.log("\tAdded as child of node 3 and dropped at (280, 45):");
|
|
||||||
var graph3 = manager.plot("testSymmetricPredict3", {width:1000, height:400});
|
|
||||||
this._plotPrediction(graph3, manager.predict(3, {x:280, y:45}));
|
|
||||||
console.log("\tAdded as child of node 3 and dropped at (255, 110):");
|
|
||||||
this._plotPrediction(graph3, manager.predict(3, {x:255, y:110}));
|
|
||||||
console.log("\tAdded as child of node 2 and dropped at (-260, 0):");
|
|
||||||
|
|
||||||
var graph4 = manager.plot("testSymmetricPredict4", {width:1000, height:400});
|
|
||||||
this._plotPrediction(graph4, manager.predict(2, {x:-260, y:0}));
|
|
||||||
|
|
||||||
console.log("\tPredict nodes added with no position:");
|
|
||||||
var graph5 = manager.plot("testSymmetricPredict5", {width:1000, height:400});
|
|
||||||
this._plotPrediction(graph5, manager.predict(1, null));
|
|
||||||
this._plotPrediction(graph5, manager.predict(2, null));
|
|
||||||
this._plotPrediction(graph5, manager.predict(3, null));
|
|
||||||
this._plotPrediction(graph5, manager.predict(10, null));
|
|
||||||
},
|
|
||||||
|
|
||||||
testBalancedPredict: function() {
|
|
||||||
console.log("testBalancedPredict");
|
|
||||||
var position = {x:0, y:0};
|
|
||||||
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
|
|
||||||
|
|
||||||
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(9, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(10, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(11, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
|
|
||||||
manager.connectNode(0,1,0);
|
|
||||||
manager.connectNode(0,2,1);
|
|
||||||
manager.connectNode(0,3,2);
|
|
||||||
manager.connectNode(0,4,3);
|
|
||||||
manager.connectNode(0,5,4);
|
|
||||||
manager.connectNode(4,7,0);
|
|
||||||
manager.connectNode(4,8,1);
|
|
||||||
manager.connectNode(8,9,0);
|
|
||||||
manager.connectNode(3,10,0);
|
|
||||||
manager.connectNode(3,11,1);
|
|
||||||
|
|
||||||
manager.layout();
|
|
||||||
|
|
||||||
console.log("\tAdded as child of node 0 and dropped at (165, -70):");
|
|
||||||
var graph1 = manager.plot("testBalancedPredict1", {width:1000, height:400});
|
|
||||||
this._plotPrediction(graph1, manager.predict(0, {x:165, y:-70}));
|
|
||||||
console.log("\tAdded as child of node 0 and dropped at (165, -10):");
|
|
||||||
this._plotPrediction(graph1, manager.predict(0, {x:165, y:-10}));
|
|
||||||
console.log("\tAdded as child of node 0 and dropped at (145, 15):");
|
|
||||||
this._plotPrediction(graph1, manager.predict(0, {x:145, y:15}));
|
|
||||||
console.log("\tAdded as child of node 0 and dropped at (145, 70):");
|
|
||||||
this._plotPrediction(graph1, manager.predict(0, {x:145, y:70}));
|
|
||||||
|
|
||||||
console.log("\tAdded as child of node 0 and dropped at (-145, -50):");
|
|
||||||
var graph2 = manager.plot("testBalancedPredict2", {width:1000, height:400});
|
|
||||||
this._plotPrediction(graph2, manager.predict(0, {x:-145, y:-50}));
|
|
||||||
console.log("\tAdded as child of node 0 and dropped at (-145, -10):");
|
|
||||||
this._plotPrediction(graph2, manager.predict(0, {x:-145, y:-10}));
|
|
||||||
console.log("\tAdded as child of node 0 and dropped at (-145, 40):");
|
|
||||||
this._plotPrediction(graph2, manager.predict(0, {x:-145, y:400}));
|
|
||||||
|
|
||||||
console.log("\tAdded as child of node 0 and dropped at (0, 40):");
|
|
||||||
var graph3 = manager.plot("testBalancedPredict3", {width:1000, height:400});
|
|
||||||
this._plotPrediction(graph3, manager.predict(0, {x:0, y:40}));
|
|
||||||
console.log("\tAdded as child of node 0 and dropped at (0, 0):");
|
|
||||||
this._plotPrediction(graph3, manager.predict(0, {x:0, y:0}));
|
|
||||||
|
|
||||||
console.log("\tPredict nodes added with no position:");
|
|
||||||
var graph4 = manager.plot("testBalancedPredict4", {width:1000, height:400});
|
|
||||||
this._plotPrediction(graph4, manager.predict(0, null));
|
|
||||||
|
|
||||||
console.log("\tPredict nodes added with no position:");
|
|
||||||
var graph5 = manager.plot("testBalancedPredict5", {width:1000, height:400});
|
|
||||||
this._plotPrediction(graph5, manager.predict(0, null));
|
|
||||||
|
|
||||||
console.log("\tPredict nodes added only a root node:");
|
|
||||||
manager.removeNode(1).removeNode(2).removeNode(3).removeNode(4).removeNode(5);
|
|
||||||
manager.layout();
|
|
||||||
var graph6 = manager.plot("testBalancedPredict6", {width:1000, height:400});
|
|
||||||
this._plotPrediction(graph6, manager.predict(0, null));
|
|
||||||
this._plotPrediction(graph6, manager.predict(0, {x: 40, y: 100}));
|
|
||||||
},
|
|
||||||
|
|
||||||
_plotPrediction: function(canvas, prediction) {
|
|
||||||
var position = prediction.position;
|
|
||||||
var order = prediction.order;
|
|
||||||
console.log("\t\tprediction {order:" + order + ", position: (" + position.x + "," + position.y + ")}");
|
|
||||||
var cx = position.x + canvas.width / 2 - mindplot.layout.TestSuite.NODE_SIZE.width / 2;
|
|
||||||
var cy = position.y + canvas.height / 2 - mindplot.layout.TestSuite.NODE_SIZE.height / 2;
|
|
||||||
canvas.rect(cx, cy, mindplot.layout.TestSuite.NODE_SIZE.width, mindplot.layout.TestSuite.NODE_SIZE.height);
|
|
||||||
},
|
|
||||||
|
|
||||||
testSize: function() {
|
|
||||||
var position = {x:0, y:0};
|
|
||||||
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
|
|
||||||
|
|
||||||
manager.addNode(1, {width: 60, height: 60}, position);
|
|
||||||
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(3, {width: 260, height: 30}, position);
|
|
||||||
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(7, {width: 80, height: 80}, position);
|
|
||||||
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(9, {width: 30, height: 30}, position);
|
|
||||||
manager.addNode(10, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(11, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(12, {width: 100, height: 70}, position);
|
|
||||||
manager.addNode(13, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(14, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(15, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(16, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(17, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
|
|
||||||
manager.connectNode(0,1,0);
|
|
||||||
manager.connectNode(1,16,0);
|
|
||||||
manager.connectNode(0,2,1);
|
|
||||||
manager.connectNode(0,3,2);
|
|
||||||
manager.connectNode(0,4,3);
|
|
||||||
manager.connectNode(0,5,4);
|
|
||||||
manager.connectNode(4,7,0);
|
|
||||||
manager.connectNode(7,15,0);
|
|
||||||
manager.connectNode(7,17,1);
|
|
||||||
manager.connectNode(4,8,1);
|
|
||||||
manager.connectNode(8,9,0);
|
|
||||||
manager.connectNode(3,10,0);
|
|
||||||
manager.connectNode(3,11,1);
|
|
||||||
manager.connectNode(9,12,0);
|
|
||||||
manager.connectNode(9,13,1);
|
|
||||||
manager.connectNode(13,14,0);
|
|
||||||
|
|
||||||
manager.layout();
|
|
||||||
manager.plot("testSize1", {width: 1400, height: 400});
|
|
||||||
|
|
||||||
var graph2 = manager.plot("testSize2", {width: 1400, height: 400});
|
|
||||||
this._plotPrediction(graph2, manager.predict(0, {x:-145, y:400}));
|
|
||||||
this._plotPrediction(graph2, manager.predict(9, {x:-330, y:70}));
|
|
||||||
this._plotPrediction(graph2, manager.predict(9, {x:-330, y:120}));
|
|
||||||
this._plotPrediction(graph2, manager.predict(0, {x:15, y:20}));
|
|
||||||
|
|
||||||
var graph3 = manager.plot("testSize3", {width: 1400, height: 400});
|
|
||||||
this._plotPrediction(graph3, manager.predict(0, null));
|
|
||||||
this._plotPrediction(graph3, manager.predict(9, null));
|
|
||||||
this._plotPrediction(graph3, manager.predict(3, null));
|
|
||||||
this._plotPrediction(graph3, manager.predict(1, null));
|
|
||||||
|
|
||||||
manager.updateNodeSize(7, {width:80, height:120});
|
|
||||||
manager.layout();
|
|
||||||
manager.plot("testSize4", {width: 1400, height: 400});
|
|
||||||
|
|
||||||
manager.updateNodeSize(7, {width:200, height:30});
|
|
||||||
manager.layout();
|
|
||||||
manager.plot("testSize5", {width: 1400, height: 400});
|
|
||||||
},
|
|
||||||
|
|
||||||
testFreePosition: function() {
|
|
||||||
console.log("testFreePosition:");
|
|
||||||
var position = {x:0,y:0};
|
|
||||||
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
|
|
||||||
|
|
||||||
// Prepare a sample graph ...
|
|
||||||
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(9, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(10, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(11, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(12, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(13, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(14, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(15, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(16, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(17, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(18, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(19, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(20, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(21, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(22, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
|
|
||||||
manager.connectNode(0,1,0).connectNode(0,2,1).connectNode(0,3,2).connectNode(0,4,3);
|
|
||||||
manager.connectNode(4,21,0).connectNode(4,22,0);
|
|
||||||
manager.connectNode(1,5,0);
|
|
||||||
manager.connectNode(5,6,0).connectNode(6,8,0).connectNode(8,9,0);
|
|
||||||
manager.connectNode(5,7,1).connectNode(7,10,0);
|
|
||||||
manager.connectNode(3,11,0).connectNode(11,14,0).connectNode(14,18,0).connectNode(14,19,1).connectNode(14,20,2);
|
|
||||||
manager.connectNode(3,12,1).connectNode(12,15,0).connectNode(12,16,1).connectNode(12,17,2);
|
|
||||||
manager.connectNode(3,13,2);
|
|
||||||
|
|
||||||
manager.layout();
|
|
||||||
manager.plot("testFreePosition1", {width:1400, height:600});
|
|
||||||
|
|
||||||
console.log("move node 12 to (300,30)");
|
|
||||||
manager.moveNode(12, {x:300, y:30});
|
|
||||||
manager.layout();
|
|
||||||
manager.plot("testFreePosition2", {width:1400, height:600});
|
|
||||||
|
|
||||||
console.log("move node 13 to (340,180)");
|
|
||||||
manager.moveNode(13, {x:340, y:180});
|
|
||||||
manager.layout(true);
|
|
||||||
manager.plot("testFreePosition3", {width:1400, height:600});
|
|
||||||
|
|
||||||
console.log("move node 11 to (250,-50)");
|
|
||||||
manager.moveNode(11, {x:250, y:-50});
|
|
||||||
manager.layout(true);
|
|
||||||
manager.plot("testFreePosition4", {width:1400, height:600});
|
|
||||||
|
|
||||||
console.log("move node 7 to (350,-190)");
|
|
||||||
manager.moveNode(7, {x:350, y:-190});
|
|
||||||
manager.layout(true);
|
|
||||||
manager.plot("testFreePosition5", {width:1400, height:600});
|
|
||||||
|
|
||||||
console.log("add node 23 to 12:");
|
|
||||||
manager.addNode(23, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.connectNode(12,23,3);
|
|
||||||
manager.layout(true);
|
|
||||||
manager.plot("testFreePosition6", {width:1400, height:600});
|
|
||||||
|
|
||||||
console.log("move node 4 to (-300, 190)");
|
|
||||||
manager.moveNode(4, {x:-300, y:190});
|
|
||||||
manager.layout(true);
|
|
||||||
manager.plot("testFreePosition7", {width:1400, height:600});
|
|
||||||
|
|
||||||
console.log("add node 24 to 3:");
|
|
||||||
manager.addNode(24, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.connectNode(3,24,3);
|
|
||||||
manager.layout(true);
|
|
||||||
manager.plot("testFreePosition8", {width:1400, height:600});
|
|
||||||
|
|
||||||
console.log("add node 25 to 17:");
|
|
||||||
manager.addNode(25, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.connectNode(17,25,0);
|
|
||||||
manager.layout(true);
|
|
||||||
manager.plot("testFreePosition9", {width:1400, height:600});
|
|
||||||
},
|
|
||||||
|
|
||||||
testFreePredict: function() {
|
|
||||||
console.log("testFreePredict:");
|
|
||||||
var position = {x:0,y:0};
|
|
||||||
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
|
|
||||||
|
|
||||||
// Prepare a sample graph ...
|
|
||||||
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(9, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(10, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(11, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
|
|
||||||
manager.connectNode(0, 1, 0);
|
|
||||||
manager.connectNode(0, 2, 1);
|
|
||||||
manager.connectNode(0, 3, 2);
|
|
||||||
manager.connectNode(3, 4, 0);
|
|
||||||
manager.connectNode(3, 5, 1);
|
|
||||||
manager.connectNode(3, 6, 2);
|
|
||||||
manager.connectNode(5, 7, 0);
|
|
||||||
manager.connectNode(5, 8, 1);
|
|
||||||
manager.connectNode(5, 11, 2);
|
|
||||||
manager.connectNode(2, 9, 0);
|
|
||||||
manager.connectNode(2, 10, 1);
|
|
||||||
|
|
||||||
manager.layout();
|
|
||||||
var graph = manager.plot("testFreePredict1", {width:1000, height:400});
|
|
||||||
|
|
||||||
var pos1 = {x: 370, y:80};
|
|
||||||
var predict1 = manager.predict(11, pos1, true);
|
|
||||||
$assert(predict1.position.x == pos1.x && predict1.position.y == pos1.y, "free predict should return the same position");
|
|
||||||
|
|
||||||
var pos2 = {x: -200, y:80};
|
|
||||||
var predict2 = manager.predict(2, pos2, true);
|
|
||||||
$assert(predict2.position.x == pos2.x && predict2.position.y == pos2.y, "free predict should return the same position");
|
|
||||||
|
|
||||||
var pos3 = {x: 200, y:30};
|
|
||||||
var node5 = manager.find(5);
|
|
||||||
var predict3 = manager.predict(5, pos3, true);
|
|
||||||
$assert(predict3.position.x == node5.getPosition().x && predict3.position.y == pos3.y, "free predict should return the x-coordinate of the node");
|
|
||||||
|
|
||||||
var pos4 = {x: -100, y:45};
|
|
||||||
var node10 = manager.find(10);
|
|
||||||
var predict4 = manager.predict(10, pos4, true);
|
|
||||||
$assert(predict4.position.x == node10.getPosition().x && predict4.position.y == pos4.y, "free predict should return the x-coordinate of the node");
|
|
||||||
|
|
||||||
this._plotPrediction(graph, predict1);
|
|
||||||
this._plotPrediction(graph, predict2);
|
|
||||||
this._plotPrediction(graph, predict3);
|
|
||||||
this._plotPrediction(graph, predict4);
|
|
||||||
},
|
|
||||||
|
|
||||||
testReconnectFreeNode: function() {
|
|
||||||
console.log("testReconnectFreeNode:");
|
|
||||||
var position = {x:0,y:0};
|
|
||||||
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
|
|
||||||
|
|
||||||
// Prepare a sample graph ...
|
|
||||||
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(9, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(10, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.addNode(11, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
|
|
||||||
manager.connectNode(0, 1, 0);
|
|
||||||
manager.connectNode(0, 2, 1);
|
|
||||||
manager.connectNode(0, 3, 2);
|
|
||||||
manager.connectNode(3, 4, 0);
|
|
||||||
manager.connectNode(3, 5, 1);
|
|
||||||
manager.connectNode(3, 6, 2);
|
|
||||||
manager.connectNode(5, 7, 0);
|
|
||||||
manager.connectNode(5, 8, 1);
|
|
||||||
manager.connectNode(5, 11, 2);
|
|
||||||
manager.connectNode(2, 9, 0);
|
|
||||||
manager.connectNode(2, 10, 1);
|
|
||||||
|
|
||||||
manager.layout();
|
|
||||||
manager.plot("testReconnectFreeNode1", {width:1000, height:400});
|
|
||||||
|
|
||||||
console.log("move node 5");
|
|
||||||
manager.moveNode(5, {x:250, y:30});
|
|
||||||
manager.layout();
|
|
||||||
manager.plot("testReconnectFreeNode2", {width:1000, height:400});
|
|
||||||
|
|
||||||
console.log("reconnect node 5 to node 2");
|
|
||||||
manager.disconnectNode(5);
|
|
||||||
manager.connectNode(2,5,2);
|
|
||||||
manager.layout();
|
|
||||||
manager.plot("testReconnectFreeNode3", {width:1000, height:400});
|
|
||||||
|
|
||||||
console.log("move node 8");
|
|
||||||
manager.moveNode(8, {x:-370, y:60});
|
|
||||||
manager.layout();
|
|
||||||
manager.plot("testReconnectFreeNode4", {width:1000, height:400});
|
|
||||||
|
|
||||||
//TODO(gb): fix this. node 11 is not positioned correctly
|
|
||||||
console.log("reconnect node 5 to node 10");
|
|
||||||
manager.disconnectNode(5);
|
|
||||||
manager.connectNode(10,5,0);
|
|
||||||
manager.layout();
|
|
||||||
manager.plot("testReconnectFreeNode5", {width:1000, height:400});
|
|
||||||
|
|
||||||
// console.log("reconnect node 5 to node 3");
|
|
||||||
// manager.disconnectNode(5);
|
|
||||||
// manager.connectNode(3,5,2);
|
|
||||||
// manager.layout();
|
|
||||||
// manager.plot("testReconnectFreeNode6", {width:1000, height:400});
|
|
||||||
|
|
||||||
// manager.moveNode(8, {x:370, y:30});
|
|
||||||
// manager.layout();
|
|
||||||
// manager.plot("testReconnectFreeNode2", {width:1000, height:400});
|
|
||||||
},
|
|
||||||
|
|
||||||
testReconnectSingleNode: function() {
|
|
||||||
console.log("testReconnectSingleNode:");
|
|
||||||
var position = {x:0,y:0};
|
|
||||||
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
|
|
||||||
|
|
||||||
// Prepare a sample graph ...
|
|
||||||
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position);
|
|
||||||
manager.connectNode(0, 1, 0);
|
|
||||||
manager.layout();
|
|
||||||
var graph = manager.plot("testReconnectSingleNode1", {width:1000, height:400});
|
|
||||||
this._plotPrediction(graph, manager.predict(0, {x:-50, y:0}));
|
|
||||||
|
|
||||||
|
|
||||||
manager.disconnectNode(1);
|
|
||||||
manager.connectNode(0,1,1);
|
|
||||||
manager.layout();
|
|
||||||
manager.plot("testReconnectSingleNode2", {width:1000, height:400});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
mindplot.layout.TestSuite.NODE_SIZE = {width:80, height:30},
|
|
||||||
mindplot.layout.TestSuite.ROOT_NODE_SIZE = {width:120, height:40}
|
|
@ -5,7 +5,6 @@
|
|||||||
<script type='text/javascript' src='../../../main/javascript/libraries/mootools/mootools-core-1.3.2-full-compress.js'></script>
|
<script type='text/javascript' src='../../../main/javascript/libraries/mootools/mootools-core-1.3.2-full-compress.js'></script>
|
||||||
<script type='text/javascript' src='../../../../../core-js/target/classes/core.js'></script>
|
<script type='text/javascript' src='../../../../../core-js/target/classes/core.js'></script>
|
||||||
|
|
||||||
|
|
||||||
<script type='text/javascript' src='../../../main/javascript/header.js'></script>
|
<script type='text/javascript' src='../../../main/javascript/header.js'></script>
|
||||||
<script type='text/javascript' src='../../../main/javascript/layout/Node.js'></script>
|
<script type='text/javascript' src='../../../main/javascript/layout/Node.js'></script>
|
||||||
<script type='text/javascript' src='../../../main/javascript/layout/RootedTreeSet.js'></script>
|
<script type='text/javascript' src='../../../main/javascript/layout/RootedTreeSet.js'></script>
|
||||||
@ -19,15 +18,20 @@
|
|||||||
<script type='text/javascript' src='../../../main/javascript/layout/OriginalLayout.js'></script>
|
<script type='text/javascript' src='../../../main/javascript/layout/OriginalLayout.js'></script>
|
||||||
<script type='text/javascript' src='../../../main/javascript/layout/ChangeEvent.js'></script>
|
<script type='text/javascript' src='../../../main/javascript/layout/ChangeEvent.js'></script>
|
||||||
|
|
||||||
<script type="text/javascript" src="raphael-min.js"></script>
|
<script type="text/javascript" src="test/raphael-min.js"></script>
|
||||||
<script type="text/javascript" src="raphael-plugins.js"></script>
|
<script type="text/javascript" src="test/raphael-plugins.js"></script>
|
||||||
|
|
||||||
<script type='text/javascript' src='TestSuite.js'></script>
|
|
||||||
|
|
||||||
|
<script type='text/javascript' src='test/TestSuite.js'></script>
|
||||||
|
<script type='text/javascript' src='test/BalancedTestSuite.js'></script>
|
||||||
|
<script type='text/javascript' src='test/SymmetricTestSuite.js'></script>
|
||||||
|
<script type='text/javascript' src='test/FreeTestSuite.js'></script>
|
||||||
|
|
||||||
<script type='text/javascript'>
|
<script type='text/javascript'>
|
||||||
window.addEvent('domready', function() {
|
window.addEvent('domready', function() {
|
||||||
var test = new mindplot.layout.TestSuite();
|
// var basicTest = new mindplot.layout.TestSuite();
|
||||||
|
// var balancedTest = new mindplot.layout.BalancedTestSuite();
|
||||||
|
// var symmetricTest = new mindplot.layout.SymmetricTestSuite();
|
||||||
|
var freeTest = new mindplot.layout.FreeTestSuite();
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -44,97 +48,113 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h2>testAligned:</h2>
|
|
||||||
<div id="testAligned"></div>
|
|
||||||
|
|
||||||
<h2>testSymmetry:</h2>
|
<div id="basicTest" style="display: none;">
|
||||||
<div id="testSymmetry"></div>
|
<h1>Basic Tests</h1>
|
||||||
|
|
||||||
<h2>testBalanced:</h2>
|
<h3>testAligned:</h3>
|
||||||
<div id="testBalanced1" class="col"></div>
|
<div id="testAligned"></div>
|
||||||
<div id="testBalanced2" class="col"></div>
|
|
||||||
<div id="testBalanced3" class="col last"></div>
|
|
||||||
<div id="testBalanced4" class="col"></div>
|
|
||||||
<div id="testBalanced5" class="col"></div>
|
|
||||||
<div id="testBalanced6" class="col last"></div>
|
|
||||||
<div id="testBalanced7" class="col"></div>
|
|
||||||
<div id="testBalanced8" class="col last"></div>
|
|
||||||
<div id="testBalanced9" class="col last"></div>
|
|
||||||
<div id="testBalanced10" class="col last"></div>
|
|
||||||
<div id="testBalanced11" class="col last"></div>
|
|
||||||
<div id="testBalanced12" class="col last"></div>
|
|
||||||
<div id="testBalanced13" class="col last"></div>
|
|
||||||
|
|
||||||
<h2>testEvents:</h2>
|
<h3>testEvents:</h3>
|
||||||
<div id="testEvents1" class="col"></div>
|
<div id="testEvents1" class="col"></div>
|
||||||
<div id="testEvents2" class="col last"></div>
|
<div id="testEvents2" class="col last"></div>
|
||||||
|
|
||||||
<h2>testEventsComplex:</h2>
|
<h3>testEventsComplex:</h3>
|
||||||
<div id="testEventsComplex1" class="col"></div>
|
<div id="testEventsComplex1" class="col"></div>
|
||||||
<div id="testEventsComplex2" class="col last"></div>
|
<div id="testEventsComplex2" class="col last"></div>
|
||||||
|
|
||||||
<h2>testDisconnect:</h2>
|
<h3>testDisconnect:</h3>
|
||||||
<div id="testDisconnect1" class="col"></div>
|
<div id="testDisconnect1" class="col"></div>
|
||||||
<div id="testDisconnect2" class="col"></div>
|
<div id="testDisconnect2" class="col"></div>
|
||||||
<div id="testDisconnect3" class="col last"></div>
|
<div id="testDisconnect3" class="col last"></div>
|
||||||
|
|
||||||
<h2>testReconnect:</h2>
|
<h3>testReconnect:</h3>
|
||||||
<div id="testReconnect1" class="col"></div>
|
<div id="testReconnect1" class="col"></div>
|
||||||
<div id="testReconnect2" class="col last"></div>
|
<div id="testReconnect2" class="col last"></div>
|
||||||
|
|
||||||
<h2>testRemoveNode:</h2>
|
<h3>testRemoveNode:</h3>
|
||||||
<div id="testRemoveNode1" class="col"></div>
|
<div id="testRemoveNode1" class="col"></div>
|
||||||
<div id="testRemoveNode2" class="col last"></div>
|
<div id="testRemoveNode2" class="col last"></div>
|
||||||
<div id="testRemoveNode3" class="col last"></div>
|
<div id="testRemoveNode3" class="col last"></div>
|
||||||
<div id="testRemoveNode4" class="col last"></div>
|
<div id="testRemoveNode4" class="col last"></div>
|
||||||
|
|
||||||
<h2>testSymmetricPredict:</h2>
|
<h3>testSize:</h3>
|
||||||
<div id="testSymmetricPredict1"></div>
|
<div id="testSize1" class="col"></div>
|
||||||
<div id="testSymmetricPredict2"></div>
|
<div id="testSize2" class="col last"></div>
|
||||||
<div id="testSymmetricPredict3"></div>
|
<div id="testSize3" class="col last"></div>
|
||||||
<div id="testSymmetricPredict4"></div>
|
<div id="testSize4" class="col last"></div>
|
||||||
<div id="testSymmetricPredict5"></div>
|
<div id="testSize5" class="col last"></div>
|
||||||
|
|
||||||
<h2>testBalancedPredict:</h2>
|
<h3>testReconnectSingleNode:</h3>
|
||||||
<div id="testBalancedPredict1"></div>
|
<div id="testReconnectSingleNode1" class="col"></div>
|
||||||
<div id="testBalancedPredict2"></div>
|
<div id="testReconnectSingleNode2" class="col"></div>
|
||||||
<div id="testBalancedPredict3"></div>
|
</div>
|
||||||
<div id="testBalancedPredict4"></div>
|
|
||||||
<div id="testBalancedPredict5"></div>
|
|
||||||
<div id="testBalancedPredict6"></div>
|
|
||||||
|
|
||||||
<h2>testSize:</h2>
|
<div id="balancedTest" style="display: none;">
|
||||||
<div id="testSize1" class="col"></div>
|
<h1>Balanced Sorter Tests</h1>
|
||||||
<div id="testSize2" class="col last"></div>
|
|
||||||
<div id="testSize3" class="col last"></div>
|
|
||||||
<div id="testSize4" class="col last"></div>
|
|
||||||
<div id="testSize5" class="col last"></div>
|
|
||||||
|
|
||||||
<h2>testFreePosition:</h2>
|
<h3>testBalanced:</h3>
|
||||||
<div id="testFreePosition1" class="col"></div>
|
<div id="testBalanced1" class="col"></div>
|
||||||
<div id="testFreePosition2" class="col last"></div>
|
<div id="testBalanced2" class="col"></div>
|
||||||
<div id="testFreePosition3" class="col last"></div>
|
<div id="testBalanced3" class="col last"></div>
|
||||||
<div id="testFreePosition4" class="col last"></div>
|
<div id="testBalanced4" class="col"></div>
|
||||||
<div id="testFreePosition5" class="col last"></div>
|
<div id="testBalanced5" class="col"></div>
|
||||||
<div id="testFreePosition6" class="col last"></div>
|
<div id="testBalanced6" class="col last"></div>
|
||||||
<div id="testFreePosition7" class="col last"></div>
|
<div id="testBalanced7" class="col"></div>
|
||||||
<div id="testFreePosition8" class="col last"></div>
|
<div id="testBalanced8" class="col last"></div>
|
||||||
<div id="testFreePosition9" class="col last"></div>
|
<div id="testBalanced9" class="col last"></div>
|
||||||
|
<div id="testBalanced10" class="col last"></div>
|
||||||
|
<div id="testBalanced11" class="col last"></div>
|
||||||
|
<div id="testBalanced12" class="col last"></div>
|
||||||
|
<div id="testBalanced13" class="col last"></div>
|
||||||
|
|
||||||
<h2>testFreePredict:</h2>
|
<h3>testBalancedPredict:</h3>
|
||||||
<div id="testFreePredict1" class="col"></div>
|
<div id="testBalancedPredict1"></div>
|
||||||
|
<div id="testBalancedPredict2"></div>
|
||||||
|
<div id="testBalancedPredict3"></div>
|
||||||
|
<div id="testBalancedPredict4"></div>
|
||||||
|
<div id="testBalancedPredict5"></div>
|
||||||
|
<div id="testBalancedPredict6"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<h2>testReconnectFreeNode:</h2>
|
<div id="symmetricTest" style="display: none;">
|
||||||
<div id="testReconnectFreeNode1" class="col"></div>
|
<h1>Symmetric Sorter Tests</h1>
|
||||||
<div id="testReconnectFreeNode2" class="col"></div>
|
<h3>testSymmetry:</h3>
|
||||||
<div id="testReconnectFreeNode3" class="col"></div>
|
<div id="testSymmetry"></div>
|
||||||
<div id="testReconnectFreeNode4" class="col"></div>
|
|
||||||
<div id="testReconnectFreeNode5" class="col"></div>
|
|
||||||
<div id="testReconnectFreeNode6" class="col"></div>
|
|
||||||
|
|
||||||
<h2>testReconnectSingleNode:</h2>
|
<h3>testSymmetricPredict:</h3>
|
||||||
<div id="testReconnectSingleNode1" class="col"></div>
|
<div id="testSymmetricPredict1"></div>
|
||||||
<div id="testReconnectSingleNode2" class="col"></div>
|
<div id="testSymmetricPredict2"></div>
|
||||||
|
<div id="testSymmetricPredict3"></div>
|
||||||
|
<div id="testSymmetricPredict4"></div>
|
||||||
|
<div id="testSymmetricPredict5"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="freeTest" style="display: none;">
|
||||||
|
<h1>Free Positioning Tests</h1>
|
||||||
|
|
||||||
|
<h3>testFreePosition:</h3>
|
||||||
|
<div id="testFreePosition1" class="col"></div>
|
||||||
|
<div id="testFreePosition2" class="col last"></div>
|
||||||
|
<div id="testFreePosition3" class="col last"></div>
|
||||||
|
<div id="testFreePosition4" class="col last"></div>
|
||||||
|
<div id="testFreePosition5" class="col last"></div>
|
||||||
|
<div id="testFreePosition6" class="col last"></div>
|
||||||
|
<div id="testFreePosition7" class="col last"></div>
|
||||||
|
<div id="testFreePosition8" class="col last"></div>
|
||||||
|
<div id="testFreePosition9" class="col last"></div>
|
||||||
|
|
||||||
|
<h3>testFreePredict:</h3>
|
||||||
|
<div id="testFreePredict1" class="col"></div>
|
||||||
|
|
||||||
|
<h3>testReconnectFreeNode:</h3>
|
||||||
|
<div id="testReconnectFreeNode1" class="col"></div>
|
||||||
|
<div id="testReconnectFreeNode2" class="col"></div>
|
||||||
|
<div id="testReconnectFreeNode3" class="col"></div>
|
||||||
|
<div id="testReconnectFreeNode4" class="col"></div>
|
||||||
|
<div id="testReconnectFreeNode5" class="col"></div>
|
||||||
|
<div id="testReconnectFreeNode6" class="col"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
195
mindplot/src/test/javascript/static/test/BalancedTestSuite.js
Normal file
195
mindplot/src/test/javascript/static/test/BalancedTestSuite.js
Normal file
@ -0,0 +1,195 @@
|
|||||||
|
/*
|
||||||
|
* Copyright [2011] [wisemapping]
|
||||||
|
*
|
||||||
|
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||||
|
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||||
|
* "powered by wisemapping" text requirement on every single page;
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the license at
|
||||||
|
*
|
||||||
|
* http://www.wisemapping.org/license
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
mindplot.layout.BalancedTestSuite = new Class({
|
||||||
|
Extends: mindplot.layout.TestSuite,
|
||||||
|
|
||||||
|
initialize:function() {
|
||||||
|
$("balancedTest").setStyle("display","block");
|
||||||
|
|
||||||
|
this.testBalanced();
|
||||||
|
this.testBalancedPredict();
|
||||||
|
},
|
||||||
|
|
||||||
|
testBalanced: function() {
|
||||||
|
var position = {x:0, y:0};
|
||||||
|
var plotsize = {width:1000, height:200};
|
||||||
|
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
|
||||||
|
|
||||||
|
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.connectNode(0, 1, 0);
|
||||||
|
manager.layout();
|
||||||
|
manager.plot("testBalanced1", plotsize);
|
||||||
|
|
||||||
|
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.connectNode(0, 2, 1);
|
||||||
|
manager.layout();
|
||||||
|
manager.plot("testBalanced2", plotsize);
|
||||||
|
|
||||||
|
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.connectNode(0, 3, 2);
|
||||||
|
manager.layout();
|
||||||
|
manager.plot("testBalanced3", plotsize);
|
||||||
|
|
||||||
|
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.connectNode(0, 4, 3);
|
||||||
|
manager.layout();
|
||||||
|
manager.plot("testBalanced4", plotsize);
|
||||||
|
|
||||||
|
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.connectNode(0, 5, 4);
|
||||||
|
manager.layout();
|
||||||
|
manager.plot("testBalanced5", plotsize);
|
||||||
|
|
||||||
|
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.connectNode(0, 6, 5);
|
||||||
|
manager.layout();
|
||||||
|
manager.plot("testBalanced6", plotsize);
|
||||||
|
|
||||||
|
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(9, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.connectNode(3, 7, 0)
|
||||||
|
manager.connectNode(7, 8, 0)
|
||||||
|
manager.connectNode(7, 9, 1);
|
||||||
|
manager.layout();
|
||||||
|
manager.plot("testBalanced7", plotsize);
|
||||||
|
|
||||||
|
manager.addNode(10, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(11, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(12, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.connectNode(6, 10, 0)
|
||||||
|
manager.connectNode(10, 11, 0)
|
||||||
|
manager.connectNode(10, 12, 1);
|
||||||
|
manager.layout();
|
||||||
|
manager.plot("testBalanced8", plotsize);
|
||||||
|
|
||||||
|
manager.addNode(13, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.connectNode(0, 13, 4);
|
||||||
|
manager.layout();
|
||||||
|
manager.plot("testBalanced9", {width:1000, height:400});
|
||||||
|
|
||||||
|
manager.addNode(14, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.connectNode(0, 14, 5);
|
||||||
|
manager.layout();
|
||||||
|
manager.plot("testBalanced10", {width:1000, height:400});
|
||||||
|
|
||||||
|
manager.addNode(15, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.connectNode(0, 15, 4);
|
||||||
|
manager.layout();
|
||||||
|
manager.plot("testBalanced11", {width:1000, height:400});
|
||||||
|
|
||||||
|
manager.addNode(16, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.connectNode(0, 16, 25);
|
||||||
|
manager.layout();
|
||||||
|
manager.plot("testBalanced12", {width:1000, height:400});
|
||||||
|
|
||||||
|
manager.addNode(17, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(18, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(19, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.connectNode(0, 17, 11);
|
||||||
|
manager.connectNode(0, 18, 13);
|
||||||
|
manager.connectNode(0, 19, 10);
|
||||||
|
manager.layout();
|
||||||
|
manager.plot("testBalanced13", {width:1000, height:400});
|
||||||
|
|
||||||
|
$assert(manager.find(1).getPosition().x > manager.find(0).getPosition().x, "even order nodes must be at right of central topic");
|
||||||
|
$assert(manager.find(3).getPosition().x > manager.find(0).getPosition().x, "even order nodes must be at right of central topic");
|
||||||
|
$assert(manager.find(5).getPosition().x > manager.find(0).getPosition().x, "even order nodes must be at right of central topic");
|
||||||
|
|
||||||
|
$assert(manager.find(2).getPosition().x < manager.find(0).getPosition().x, "odd order nodes must be at right of central topic");
|
||||||
|
$assert(manager.find(4).getPosition().x < manager.find(0).getPosition().x, "odd order nodes must be at right of central topic");
|
||||||
|
$assert(manager.find(6).getPosition().x < manager.find(0).getPosition().x, "odd order nodes must be at right of central topic");
|
||||||
|
|
||||||
|
$assert(manager.find(7).getPosition().x > manager.find(3).getPosition().x, "children of 1st level even order nodes must be to the right");
|
||||||
|
$assert(manager.find(8).getPosition().x > manager.find(7).getPosition().x, "children of 1st level even order nodes must be to the right");
|
||||||
|
$assert(manager.find(9).getPosition().x > manager.find(7).getPosition().x, "children of 1st level even order nodes must be to the right");
|
||||||
|
|
||||||
|
$assert(manager.find(10).getPosition().x < manager.find(6).getPosition().x, "children of 1st level odd order nodes must be to the left");
|
||||||
|
$assert(manager.find(11).getPosition().x < manager.find(10).getPosition().x, "children of 1st level odd order nodes must be to the left");
|
||||||
|
$assert(manager.find(12).getPosition().x < manager.find(10).getPosition().x, "children of 1st level odd order nodes must be to the left");
|
||||||
|
},
|
||||||
|
|
||||||
|
testBalancedPredict: function() {
|
||||||
|
console.log("testBalancedPredict");
|
||||||
|
var position = {x:0, y:0};
|
||||||
|
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
|
||||||
|
|
||||||
|
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(9, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(10, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(11, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
|
||||||
|
manager.connectNode(0,1,0);
|
||||||
|
manager.connectNode(0,2,1);
|
||||||
|
manager.connectNode(0,3,2);
|
||||||
|
manager.connectNode(0,4,3);
|
||||||
|
manager.connectNode(0,5,4);
|
||||||
|
manager.connectNode(4,7,0);
|
||||||
|
manager.connectNode(4,8,1);
|
||||||
|
manager.connectNode(8,9,0);
|
||||||
|
manager.connectNode(3,10,0);
|
||||||
|
manager.connectNode(3,11,1);
|
||||||
|
|
||||||
|
manager.layout();
|
||||||
|
|
||||||
|
console.log("\tAdded as child of node 0 and dropped at (165, -70):");
|
||||||
|
var graph1 = manager.plot("testBalancedPredict1", {width:1000, height:400});
|
||||||
|
this._plotPrediction(graph1, manager.predict(0, {x:165, y:-70}));
|
||||||
|
console.log("\tAdded as child of node 0 and dropped at (165, -10):");
|
||||||
|
this._plotPrediction(graph1, manager.predict(0, {x:165, y:-10}));
|
||||||
|
console.log("\tAdded as child of node 0 and dropped at (145, 15):");
|
||||||
|
this._plotPrediction(graph1, manager.predict(0, {x:145, y:15}));
|
||||||
|
console.log("\tAdded as child of node 0 and dropped at (145, 70):");
|
||||||
|
this._plotPrediction(graph1, manager.predict(0, {x:145, y:70}));
|
||||||
|
|
||||||
|
console.log("\tAdded as child of node 0 and dropped at (-145, -50):");
|
||||||
|
var graph2 = manager.plot("testBalancedPredict2", {width:1000, height:400});
|
||||||
|
this._plotPrediction(graph2, manager.predict(0, {x:-145, y:-50}));
|
||||||
|
console.log("\tAdded as child of node 0 and dropped at (-145, -10):");
|
||||||
|
this._plotPrediction(graph2, manager.predict(0, {x:-145, y:-10}));
|
||||||
|
console.log("\tAdded as child of node 0 and dropped at (-145, 40):");
|
||||||
|
this._plotPrediction(graph2, manager.predict(0, {x:-145, y:400}));
|
||||||
|
|
||||||
|
console.log("\tAdded as child of node 0 and dropped at (0, 40):");
|
||||||
|
var graph3 = manager.plot("testBalancedPredict3", {width:1000, height:400});
|
||||||
|
this._plotPrediction(graph3, manager.predict(0, {x:0, y:40}));
|
||||||
|
console.log("\tAdded as child of node 0 and dropped at (0, 0):");
|
||||||
|
this._plotPrediction(graph3, manager.predict(0, {x:0, y:0}));
|
||||||
|
|
||||||
|
console.log("\tPredict nodes added with no position:");
|
||||||
|
var graph4 = manager.plot("testBalancedPredict4", {width:1000, height:400});
|
||||||
|
this._plotPrediction(graph4, manager.predict(0, null));
|
||||||
|
|
||||||
|
console.log("\tPredict nodes added with no position:");
|
||||||
|
var graph5 = manager.plot("testBalancedPredict5", {width:1000, height:400});
|
||||||
|
this._plotPrediction(graph5, manager.predict(0, null));
|
||||||
|
|
||||||
|
console.log("\tPredict nodes added only a root node:");
|
||||||
|
manager.removeNode(1).removeNode(2).removeNode(3).removeNode(4).removeNode(5);
|
||||||
|
manager.layout();
|
||||||
|
var graph6 = manager.plot("testBalancedPredict6", {width:1000, height:400});
|
||||||
|
this._plotPrediction(graph6, manager.predict(0, null));
|
||||||
|
this._plotPrediction(graph6, manager.predict(0, {x: 40, y: 100}));
|
||||||
|
},
|
||||||
|
});
|
237
mindplot/src/test/javascript/static/test/FreeTestSuite.js
Normal file
237
mindplot/src/test/javascript/static/test/FreeTestSuite.js
Normal file
@ -0,0 +1,237 @@
|
|||||||
|
/*
|
||||||
|
* Copyright [2011] [wisemapping]
|
||||||
|
*
|
||||||
|
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||||
|
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||||
|
* "powered by wisemapping" text requirement on every single page;
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the license at
|
||||||
|
*
|
||||||
|
* http://www.wisemapping.org/license
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
mindplot.layout.FreeTestSuite = new Class({
|
||||||
|
Extends: mindplot.layout.TestSuite,
|
||||||
|
|
||||||
|
initialize:function() {
|
||||||
|
$("freeTest").setStyle("display","block");
|
||||||
|
|
||||||
|
this.testFreePosition();
|
||||||
|
this.testFreePredict();
|
||||||
|
this.testReconnectFreeNode();
|
||||||
|
},
|
||||||
|
|
||||||
|
testFreePosition: function() {
|
||||||
|
console.log("testFreePosition:");
|
||||||
|
var position = {x:0,y:0};
|
||||||
|
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
|
||||||
|
|
||||||
|
// Prepare a sample graph ...
|
||||||
|
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(9, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(10, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(11, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(12, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(13, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(14, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(15, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(16, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(17, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(18, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(19, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(20, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(21, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(22, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
|
||||||
|
manager.connectNode(0,1,0).connectNode(0,2,1).connectNode(0,3,2).connectNode(0,4,3);
|
||||||
|
manager.connectNode(4,21,0).connectNode(4,22,0);
|
||||||
|
manager.connectNode(1,5,0);
|
||||||
|
manager.connectNode(5,6,0).connectNode(6,8,0).connectNode(8,9,0);
|
||||||
|
manager.connectNode(5,7,1).connectNode(7,10,0);
|
||||||
|
manager.connectNode(3,11,0).connectNode(11,14,0).connectNode(14,18,0).connectNode(14,19,1).connectNode(14,20,2);
|
||||||
|
manager.connectNode(3,12,1).connectNode(12,15,0).connectNode(12,16,1).connectNode(12,17,2);
|
||||||
|
manager.connectNode(3,13,2);
|
||||||
|
|
||||||
|
manager.layout();
|
||||||
|
manager.plot("testFreePosition1", {width:1400, height:600});
|
||||||
|
|
||||||
|
console.log("move node 12 to (300,30)");
|
||||||
|
manager.moveNode(12, {x:300, y:30});
|
||||||
|
manager.layout();
|
||||||
|
manager.plot("testFreePosition2", {width:1400, height:600});
|
||||||
|
|
||||||
|
console.log("move node 13 to (340,180)");
|
||||||
|
manager.moveNode(13, {x:340, y:180});
|
||||||
|
manager.layout(true);
|
||||||
|
manager.plot("testFreePosition3", {width:1400, height:600});
|
||||||
|
|
||||||
|
console.log("move node 11 to (250,-50)");
|
||||||
|
manager.moveNode(11, {x:250, y:-50});
|
||||||
|
manager.layout(true);
|
||||||
|
manager.plot("testFreePosition4", {width:1400, height:600});
|
||||||
|
|
||||||
|
console.log("move node 7 to (350,-190)");
|
||||||
|
manager.moveNode(7, {x:350, y:-190});
|
||||||
|
manager.layout(true);
|
||||||
|
manager.plot("testFreePosition5", {width:1400, height:600});
|
||||||
|
|
||||||
|
console.log("add node 23 to 12:");
|
||||||
|
manager.addNode(23, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.connectNode(12,23,3);
|
||||||
|
manager.layout(true);
|
||||||
|
manager.plot("testFreePosition6", {width:1400, height:600});
|
||||||
|
|
||||||
|
console.log("move node 4 to (-300, 190)");
|
||||||
|
manager.moveNode(4, {x:-300, y:190});
|
||||||
|
manager.layout(true);
|
||||||
|
manager.plot("testFreePosition7", {width:1400, height:600});
|
||||||
|
|
||||||
|
console.log("add node 24 to 3:");
|
||||||
|
manager.addNode(24, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.connectNode(3,24,3);
|
||||||
|
manager.layout(true);
|
||||||
|
manager.plot("testFreePosition8", {width:1400, height:600});
|
||||||
|
|
||||||
|
console.log("add node 25 to 17:");
|
||||||
|
manager.addNode(25, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.connectNode(17,25,0);
|
||||||
|
manager.layout(true);
|
||||||
|
manager.plot("testFreePosition9", {width:1400, height:600});
|
||||||
|
},
|
||||||
|
|
||||||
|
testFreePredict: function() {
|
||||||
|
console.log("testFreePredict:");
|
||||||
|
var position = {x:0,y:0};
|
||||||
|
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
|
||||||
|
|
||||||
|
// Prepare a sample graph ...
|
||||||
|
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(9, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(10, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(11, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
|
||||||
|
manager.connectNode(0, 1, 0);
|
||||||
|
manager.connectNode(0, 2, 1);
|
||||||
|
manager.connectNode(0, 3, 2);
|
||||||
|
manager.connectNode(3, 4, 0);
|
||||||
|
manager.connectNode(3, 5, 1);
|
||||||
|
manager.connectNode(3, 6, 2);
|
||||||
|
manager.connectNode(5, 7, 0);
|
||||||
|
manager.connectNode(5, 8, 1);
|
||||||
|
manager.connectNode(5, 11, 2);
|
||||||
|
manager.connectNode(2, 9, 0);
|
||||||
|
manager.connectNode(2, 10, 1);
|
||||||
|
|
||||||
|
manager.layout();
|
||||||
|
var graph = manager.plot("testFreePredict1", {width:1000, height:400});
|
||||||
|
|
||||||
|
var pos1 = {x: 370, y:80};
|
||||||
|
var predict1 = manager.predict(11, pos1, true);
|
||||||
|
$assert(predict1.position.x == pos1.x && predict1.position.y == pos1.y, "free predict should return the same position");
|
||||||
|
|
||||||
|
var pos2 = {x: -200, y:80};
|
||||||
|
var predict2 = manager.predict(2, pos2, true);
|
||||||
|
$assert(predict2.position.x == pos2.x && predict2.position.y == pos2.y, "free predict should return the same position");
|
||||||
|
|
||||||
|
var pos3 = {x: 200, y:30};
|
||||||
|
var node5 = manager.find(5);
|
||||||
|
var predict3 = manager.predict(5, pos3, true);
|
||||||
|
$assert(predict3.position.x == node5.getPosition().x && predict3.position.y == pos3.y, "free predict should return the x-coordinate of the node");
|
||||||
|
|
||||||
|
var pos4 = {x: -100, y:45};
|
||||||
|
var node10 = manager.find(10);
|
||||||
|
var predict4 = manager.predict(10, pos4, true);
|
||||||
|
$assert(predict4.position.x == node10.getPosition().x && predict4.position.y == pos4.y, "free predict should return the x-coordinate of the node");
|
||||||
|
|
||||||
|
this._plotPrediction(graph, predict1);
|
||||||
|
this._plotPrediction(graph, predict2);
|
||||||
|
this._plotPrediction(graph, predict3);
|
||||||
|
this._plotPrediction(graph, predict4);
|
||||||
|
},
|
||||||
|
|
||||||
|
testReconnectFreeNode: function() {
|
||||||
|
console.log("testReconnectFreeNode:");
|
||||||
|
var position = {x:0,y:0};
|
||||||
|
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
|
||||||
|
|
||||||
|
// Prepare a sample graph ...
|
||||||
|
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(9, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(10, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(11, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
|
||||||
|
manager.connectNode(0, 1, 0);
|
||||||
|
manager.connectNode(0, 2, 1);
|
||||||
|
manager.connectNode(0, 3, 2);
|
||||||
|
manager.connectNode(3, 4, 0);
|
||||||
|
manager.connectNode(3, 5, 1);
|
||||||
|
manager.connectNode(3, 6, 2);
|
||||||
|
manager.connectNode(5, 7, 0);
|
||||||
|
manager.connectNode(5, 8, 1);
|
||||||
|
manager.connectNode(5, 11, 2);
|
||||||
|
manager.connectNode(2, 9, 0);
|
||||||
|
manager.connectNode(2, 10, 1);
|
||||||
|
|
||||||
|
manager.layout();
|
||||||
|
manager.plot("testReconnectFreeNode1", {width:1000, height:400});
|
||||||
|
|
||||||
|
console.log("move node 5");
|
||||||
|
manager.moveNode(5, {x:250, y:30});
|
||||||
|
manager.layout();
|
||||||
|
manager.plot("testReconnectFreeNode2", {width:1000, height:400});
|
||||||
|
|
||||||
|
console.log("reconnect node 5 to node 2");
|
||||||
|
manager.disconnectNode(5);
|
||||||
|
manager.connectNode(2,5,2);
|
||||||
|
manager.layout();
|
||||||
|
manager.plot("testReconnectFreeNode3", {width:1000, height:400});
|
||||||
|
|
||||||
|
console.log("move node 8");
|
||||||
|
manager.moveNode(8, {x:-370, y:60});
|
||||||
|
manager.layout();
|
||||||
|
manager.plot("testReconnectFreeNode4", {width:1000, height:400});
|
||||||
|
|
||||||
|
//TODO(gb): fix this. node 11 is not positioned correctly
|
||||||
|
console.log("reconnect node 5 to node 10");
|
||||||
|
manager.disconnectNode(5);
|
||||||
|
manager.connectNode(10,5,0);
|
||||||
|
manager.layout();
|
||||||
|
manager.plot("testReconnectFreeNode5", {width:1000, height:400});
|
||||||
|
|
||||||
|
// console.log("reconnect node 5 to node 3");
|
||||||
|
// manager.disconnectNode(5);
|
||||||
|
// manager.connectNode(3,5,2);
|
||||||
|
// manager.layout();
|
||||||
|
// manager.plot("testReconnectFreeNode6", {width:1000, height:400});
|
||||||
|
|
||||||
|
// manager.moveNode(8, {x:370, y:30});
|
||||||
|
// manager.layout();
|
||||||
|
// manager.plot("testReconnectFreeNode2", {width:1000, height:400});
|
||||||
|
}
|
||||||
|
});
|
137
mindplot/src/test/javascript/static/test/SymmetricTestSuite.js
Normal file
137
mindplot/src/test/javascript/static/test/SymmetricTestSuite.js
Normal file
@ -0,0 +1,137 @@
|
|||||||
|
/*
|
||||||
|
* Copyright [2011] [wisemapping]
|
||||||
|
*
|
||||||
|
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||||
|
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||||
|
* "powered by wisemapping" text requirement on every single page;
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the license at
|
||||||
|
*
|
||||||
|
* http://www.wisemapping.org/license
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
mindplot.layout.SymmetricTestSuite = new Class({
|
||||||
|
Extends: mindplot.layout.TestSuite,
|
||||||
|
|
||||||
|
initialize:function() {
|
||||||
|
$("symmetricTest").setStyle("display","block");
|
||||||
|
|
||||||
|
this.testSymmetry();
|
||||||
|
this.testSymmetricPredict();
|
||||||
|
},
|
||||||
|
|
||||||
|
testSymmetry: function() {
|
||||||
|
var position = {x:0,y:0};
|
||||||
|
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
|
||||||
|
|
||||||
|
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(9, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(10, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(11, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(12, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(13, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(14, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.connectNode(0, 14, 0);
|
||||||
|
manager.connectNode(14, 13, 0);
|
||||||
|
manager.connectNode(13, 1, 0);
|
||||||
|
manager.connectNode(13, 2, 1);
|
||||||
|
manager.connectNode(13, 3, 2);
|
||||||
|
manager.connectNode(13, 4, 3);
|
||||||
|
manager.connectNode(13, 5, 4);
|
||||||
|
manager.connectNode(1, 6, 0);
|
||||||
|
manager.connectNode(1, 7, 1);
|
||||||
|
manager.connectNode(7, 8, 0);
|
||||||
|
manager.connectNode(8, 9, 0);
|
||||||
|
manager.connectNode(5, 10, 0);
|
||||||
|
manager.connectNode(6, 11, 0);
|
||||||
|
manager.connectNode(6, 12, 1);
|
||||||
|
|
||||||
|
manager.layout();
|
||||||
|
manager.plot("testSymmetry",{width:1600, height:400});
|
||||||
|
|
||||||
|
// All nodes should be positioned symmetrically with respect to their common ancestors
|
||||||
|
$assert(manager.find(14).getPosition().y == -manager.find(13).getPosition().y, "Symmetry is not respected");
|
||||||
|
$assert(manager.find(5).getPosition().y == -manager.find(11).getPosition().y, "Symmetry is not respected");
|
||||||
|
$assert(manager.find(11).getPosition().y - manager.find(6).getPosition().y == -(manager.find(12).getPosition().y - manager.find(6).getPosition().y), "Symmetry is not respected");
|
||||||
|
$assert(manager.find(8).getPosition().y - manager.find(1).getPosition().y == -(manager.find(11).getPosition().y - manager.find(1).getPosition().y), "Symmetry is not respected");
|
||||||
|
$assert(manager.find(9).getPosition().y - manager.find(1).getPosition().y == -(manager.find(11).getPosition().y - manager.find(1).getPosition().y), "Symmetry is not respected");
|
||||||
|
},
|
||||||
|
|
||||||
|
testSymmetricPredict: function() {
|
||||||
|
console.log("testSymmetricPredict:");
|
||||||
|
var position = {x:0,y:0};
|
||||||
|
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
|
||||||
|
|
||||||
|
// Prepare a sample graph ...
|
||||||
|
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(9, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(10, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(11, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
|
||||||
|
manager.connectNode(0, 1, 0);
|
||||||
|
manager.connectNode(0, 2, 1);
|
||||||
|
manager.connectNode(0, 3, 2);
|
||||||
|
manager.connectNode(3, 4, 0);
|
||||||
|
manager.connectNode(3, 5, 1);
|
||||||
|
manager.connectNode(3, 6, 2);
|
||||||
|
manager.connectNode(5, 7, 0);
|
||||||
|
manager.connectNode(5, 8, 1);
|
||||||
|
manager.connectNode(5, 11, 2);
|
||||||
|
manager.connectNode(2, 9, 0);
|
||||||
|
manager.connectNode(2, 10, 1);
|
||||||
|
|
||||||
|
manager.layout();
|
||||||
|
|
||||||
|
console.log("\tAdded as child of node 9 and dropped at (-280, 45):");
|
||||||
|
var graph1 = manager.plot("testSymmetricPredict1", {width:1000, height:400});
|
||||||
|
this._plotPrediction(graph1, manager.predict(9, {x:-280, y:45}));
|
||||||
|
console.log("\tAdded as child of node 1 and dropped at (155, -90):");
|
||||||
|
this._plotPrediction(graph1, manager.predict(1, {x:-155, y:-90}));
|
||||||
|
|
||||||
|
console.log("\tAdded as child of node 5 and dropped at (375, 15):");
|
||||||
|
var graph2 = manager.plot("testSymmetricPredict2", {width:1000, height:400});
|
||||||
|
this._plotPrediction(graph2, manager.predict(5, {x:375, y:15}));
|
||||||
|
console.log("\tAdded as child of node 5 and dropped at (375, 45):");
|
||||||
|
this._plotPrediction(graph2, manager.predict(5, {x:375, y:45}));
|
||||||
|
console.log("\tAdded as child of node 5 and dropped at (375, 45):");
|
||||||
|
this._plotPrediction(graph2, manager.predict(5, {x:375, y:65}));
|
||||||
|
console.log("\tAdded as child of node 5 and dropped at (380, -30):");
|
||||||
|
this._plotPrediction(graph2, manager.predict(5, {x:380, y:-30}));
|
||||||
|
|
||||||
|
console.log("\tAdded as child of node 3 and dropped at (280, 45):");
|
||||||
|
var graph3 = manager.plot("testSymmetricPredict3", {width:1000, height:400});
|
||||||
|
this._plotPrediction(graph3, manager.predict(3, {x:280, y:45}));
|
||||||
|
console.log("\tAdded as child of node 3 and dropped at (255, 110):");
|
||||||
|
this._plotPrediction(graph3, manager.predict(3, {x:255, y:110}));
|
||||||
|
console.log("\tAdded as child of node 2 and dropped at (-260, 0):");
|
||||||
|
|
||||||
|
var graph4 = manager.plot("testSymmetricPredict4", {width:1000, height:400});
|
||||||
|
this._plotPrediction(graph4, manager.predict(2, {x:-260, y:0}));
|
||||||
|
|
||||||
|
console.log("\tPredict nodes added with no position:");
|
||||||
|
var graph5 = manager.plot("testSymmetricPredict5", {width:1000, height:400});
|
||||||
|
this._plotPrediction(graph5, manager.predict(1, null));
|
||||||
|
this._plotPrediction(graph5, manager.predict(2, null));
|
||||||
|
this._plotPrediction(graph5, manager.predict(3, null));
|
||||||
|
this._plotPrediction(graph5, manager.predict(10, null));
|
||||||
|
}
|
||||||
|
});
|
395
mindplot/src/test/javascript/static/test/TestSuite.js
Normal file
395
mindplot/src/test/javascript/static/test/TestSuite.js
Normal file
@ -0,0 +1,395 @@
|
|||||||
|
/*
|
||||||
|
* Copyright [2011] [wisemapping]
|
||||||
|
*
|
||||||
|
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||||
|
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||||
|
* "powered by wisemapping" text requirement on every single page;
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the license at
|
||||||
|
*
|
||||||
|
* http://www.wisemapping.org/license
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
mindplot.layout.TestSuite = new Class({
|
||||||
|
Extends: mindplot.layout.ChildrenSorterStrategy,
|
||||||
|
|
||||||
|
initialize:function() {
|
||||||
|
$("basicTest").setStyle("display","block");
|
||||||
|
|
||||||
|
this.testAligned();
|
||||||
|
this.testEvents();
|
||||||
|
this.testEventsComplex();
|
||||||
|
this.testDisconnect();
|
||||||
|
this.testReconnect();
|
||||||
|
this.testRemoveNode();
|
||||||
|
this.testSize();
|
||||||
|
this.testReconnectSingleNode();
|
||||||
|
},
|
||||||
|
|
||||||
|
testAligned: function() {
|
||||||
|
|
||||||
|
var position = {x:0,y:0};
|
||||||
|
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
|
||||||
|
|
||||||
|
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.connectNode(0, 1, 0);
|
||||||
|
manager.connectNode(1, 2, 0);
|
||||||
|
manager.connectNode(2, 3, 0);
|
||||||
|
manager.connectNode(3, 4, 0);
|
||||||
|
|
||||||
|
manager.layout();
|
||||||
|
manager.plot("testAligned", {width:1200,height:200});
|
||||||
|
|
||||||
|
// All nodes should be vertically aligned
|
||||||
|
$assert(manager.find(0).getPosition().y == manager.find(1).getPosition().y, "Nodes are not aligned");
|
||||||
|
$assert(manager.find(0).getPosition().y == manager.find(2).getPosition().y, "Nodes are not aligned");
|
||||||
|
$assert(manager.find(0).getPosition().y == manager.find(3).getPosition().y, "Nodes are not aligned");
|
||||||
|
$assert(manager.find(0).getPosition().y == manager.find(4).getPosition().y, "Nodes are not aligned");
|
||||||
|
},
|
||||||
|
|
||||||
|
testEvents: function() {
|
||||||
|
console.log("testEvents:");
|
||||||
|
var position = {x:0,y:0};
|
||||||
|
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
|
||||||
|
|
||||||
|
// Add 3 nodes...
|
||||||
|
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, {x:0, y: 60});
|
||||||
|
|
||||||
|
// Now connect one with two....
|
||||||
|
manager.connectNode(0, 1, 0);
|
||||||
|
manager.connectNode(0, 2, 1);
|
||||||
|
manager.connectNode(1, 3, 0);
|
||||||
|
|
||||||
|
// Basic layout repositioning ...
|
||||||
|
console.log("\t--- Updated tree ---");
|
||||||
|
var events = [];
|
||||||
|
manager.addEvent('change', function(event) {
|
||||||
|
console.log("\tUpdated nodes: {id:" + event.getId() + ", order: " + event.getOrder() + ",position: {" + event.getPosition().x + "," + event.getPosition().y + "}");
|
||||||
|
events.push(event);
|
||||||
|
});
|
||||||
|
manager.layout(true);
|
||||||
|
manager.plot("testEvents1", {width:800, height:200});
|
||||||
|
|
||||||
|
// Ok, if a new node is added, this an event should be fired ...
|
||||||
|
console.log("\t---- Layout without changes should not affect the tree ---");
|
||||||
|
events.empty();
|
||||||
|
manager.layout(true);
|
||||||
|
manager.plot("testEvents2", {width:800, height:200});
|
||||||
|
|
||||||
|
$assert(events.length == 0, "Unnecessary tree updated.");
|
||||||
|
|
||||||
|
console.log("\n");
|
||||||
|
},
|
||||||
|
|
||||||
|
testEventsComplex: function() {
|
||||||
|
console.log("testEventsComplex:");
|
||||||
|
var position = {x:0,y:0};
|
||||||
|
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
|
||||||
|
|
||||||
|
// Add 3 nodes...
|
||||||
|
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, {x:0, y:60});
|
||||||
|
|
||||||
|
// Now connect one with two....
|
||||||
|
manager.connectNode(0, 1, 0);
|
||||||
|
manager.connectNode(0, 2, 1);
|
||||||
|
manager.connectNode(0, 3, 2);
|
||||||
|
manager.connectNode(3, 4, 0);
|
||||||
|
manager.connectNode(3, 5, 1);
|
||||||
|
|
||||||
|
var events = [];
|
||||||
|
manager.addEvent('change', function(event) {
|
||||||
|
console.log("\tUpdated nodes: {id:" + event.getId() + ", order: " + event.getOrder() + ",position: {" + event.getPosition().x + "," + event.getPosition().y + "}");
|
||||||
|
events.push(event);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Reposition ...
|
||||||
|
manager.layout(true);
|
||||||
|
manager.plot("testEventsComplex1", {width:800, height:200});
|
||||||
|
|
||||||
|
// Add a new node and connect. Only children nodes should be affected.
|
||||||
|
console.log("\t---- Connect a new node ---");
|
||||||
|
|
||||||
|
events.empty();
|
||||||
|
manager.connectNode(3, 6, 2);
|
||||||
|
manager.layout(true);
|
||||||
|
manager.plot("testEventsComplex2", {width:800, height:200});
|
||||||
|
|
||||||
|
//TODO(gb): fix this. only 4 (reposition of nodes 1,4,5,6) events should be fired, actually 6 are
|
||||||
|
// $assert(events.length == 6, "Only 4 nodes should be repositioned.");
|
||||||
|
|
||||||
|
console.log("\n");
|
||||||
|
},
|
||||||
|
|
||||||
|
testDisconnect: function() {
|
||||||
|
console.log("testDisconnect:");
|
||||||
|
var position = {x:0,y:0};
|
||||||
|
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
|
||||||
|
|
||||||
|
// Prepare a sample graph ...
|
||||||
|
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
|
||||||
|
manager.connectNode(0, 1, 0);
|
||||||
|
manager.connectNode(1, 2, 0);
|
||||||
|
manager.connectNode(1, 3, 1);
|
||||||
|
manager.connectNode(1, 4, 2);
|
||||||
|
manager.connectNode(4, 5, 0);
|
||||||
|
manager.connectNode(5, 6, 0);
|
||||||
|
manager.connectNode(5, 7, 1);
|
||||||
|
|
||||||
|
var events = [];
|
||||||
|
manager.addEvent('change', function(event) {
|
||||||
|
var pos = event.getPosition();
|
||||||
|
var posStr = pos ? ",position: {" + pos.x + "," + pos.y : "";
|
||||||
|
var node = manager.find(event.getId());
|
||||||
|
console.log("\tUpdated nodes: {id:" + event.getId() + ", order: " + event.getOrder() + posStr + "}");
|
||||||
|
events.push(event);
|
||||||
|
});
|
||||||
|
manager.layout(true);
|
||||||
|
manager.plot("testDisconnect1", {width:1200, height:400});
|
||||||
|
|
||||||
|
// Now, disconnect one node ...
|
||||||
|
console.log("--- Disconnect a single node ---");
|
||||||
|
events.empty();
|
||||||
|
manager.disconnectNode(2);
|
||||||
|
manager.layout(true);
|
||||||
|
manager.plot("testDisconnect2", {width:1200, height:400});
|
||||||
|
|
||||||
|
// $assert(events.some(function(event) {return event.getId() == 2;}), "Event for disconnected node seems not to be propagated");
|
||||||
|
$assert(manager._treeSet.getParent(manager.find(2)) == null, "Node 2 should have no parent, it was disconnected");
|
||||||
|
|
||||||
|
// Great, let's disconnect a node with children.
|
||||||
|
console.log("--- Disconnect a node with children ---");
|
||||||
|
manager.disconnectNode(4);
|
||||||
|
manager.layout(true);
|
||||||
|
manager.plot("testDisconnect3", {width:1200, height:400});
|
||||||
|
|
||||||
|
$assert(events.some(function(event) {return event.getId() == 4;}), "Event for disconnected node seems not to be propagated");
|
||||||
|
$assert(manager._treeSet.getParent(manager.find(4)) == null, "Node 4 should have no parent, it was disconnected");
|
||||||
|
var childrenOfNode4 = manager._treeSet.getChildren(manager.find(4));
|
||||||
|
var childrenOfNode5 = manager._treeSet.getChildren(manager.find(5));
|
||||||
|
$assert(childrenOfNode4.contains(manager.find(5)), "Node 5 still should be the child of node 4");
|
||||||
|
$assert(childrenOfNode5.contains(manager.find(6)) && childrenOfNode5.contains(manager.find(7)), "Nodes 6 and 7 still should be the children of node 5");
|
||||||
|
|
||||||
|
console.log("\n");
|
||||||
|
},
|
||||||
|
|
||||||
|
testReconnect: function() {
|
||||||
|
var position = {x:0,y:0};
|
||||||
|
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
|
||||||
|
|
||||||
|
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(9, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(10, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(11, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(12, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.connectNode(0, 1, 0);
|
||||||
|
manager.connectNode(0, 2, 1);
|
||||||
|
manager.connectNode(0, 3, 2);
|
||||||
|
manager.connectNode(0, 4, 3);
|
||||||
|
manager.connectNode(0, 5, 4);
|
||||||
|
manager.connectNode(1, 6, 0);
|
||||||
|
manager.connectNode(1, 7, 1);
|
||||||
|
manager.connectNode(7, 8, 0);
|
||||||
|
manager.connectNode(8, 9, 0);
|
||||||
|
manager.connectNode(5, 10, 0);
|
||||||
|
manager.connectNode(6, 11, 0);
|
||||||
|
manager.connectNode(6, 12, 1);
|
||||||
|
|
||||||
|
manager.layout();
|
||||||
|
manager.plot("testReconnect1",{width:1200, height:400});
|
||||||
|
|
||||||
|
var childrenOfNode6BeforeReconnect = manager._treeSet.getChildren(manager.find(6));
|
||||||
|
|
||||||
|
// Reconnect node 6 to node 4
|
||||||
|
manager.disconnectNode(6);
|
||||||
|
manager.connectNode(4,6,0);
|
||||||
|
manager.layout();
|
||||||
|
manager.plot("testReconnect2",{width:1200, height:400});
|
||||||
|
|
||||||
|
var childrenOfNode4AfterReconnect = manager._treeSet.getChildren(manager.find(4));
|
||||||
|
var childrenOfNode6AfterReconnect = manager._treeSet.getChildren(manager.find(6));
|
||||||
|
$assert(childrenOfNode4AfterReconnect.contains(manager.find(6)), "Node 6 should be the child of node 4");
|
||||||
|
$assert(childrenOfNode6BeforeReconnect == childrenOfNode6AfterReconnect, "The children of node 6 should be the same");
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
testRemoveNode: function() {
|
||||||
|
console.log("testRemoveNode:");
|
||||||
|
var position = {x:0,y:0};
|
||||||
|
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
|
||||||
|
|
||||||
|
// Prepare a sample graph ...
|
||||||
|
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(9, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
|
||||||
|
manager.connectNode(0, 1, 0);
|
||||||
|
manager.connectNode(0, 5, 1);
|
||||||
|
manager.connectNode(0, 6, 2);
|
||||||
|
manager.connectNode(0, 7, 3);
|
||||||
|
manager.connectNode(0, 8, 4);
|
||||||
|
manager.connectNode(0, 9, 5);
|
||||||
|
manager.connectNode(1, 2, 0);
|
||||||
|
manager.connectNode(1, 3, 1);
|
||||||
|
manager.connectNode(3, 4, 0);
|
||||||
|
|
||||||
|
var events = [];
|
||||||
|
manager.addEvent('change', function(event) {
|
||||||
|
var pos = event.getPosition();
|
||||||
|
var posStr = pos ? ",position: {" + pos.x + "," + event.getPosition().y : "";
|
||||||
|
console.log("\tUpdated nodes: {id:" + event.getId() + ", order: " + event.getOrder() + posStr + "}");
|
||||||
|
events.push(event);
|
||||||
|
});
|
||||||
|
manager.layout(true);
|
||||||
|
manager.plot("testRemoveNode1", {width:1000, height:200});
|
||||||
|
|
||||||
|
// Test removal of a connected node ...
|
||||||
|
console.log("\t--- Remove node 3 ---");
|
||||||
|
manager.removeNode(3);
|
||||||
|
manager.layout(true);
|
||||||
|
manager.plot("testRemoveNode2", {width:1000, height:200});
|
||||||
|
|
||||||
|
// Remove a node from the root node
|
||||||
|
console.log("\t--- Remove node 6 ---");
|
||||||
|
manager.removeNode(6);
|
||||||
|
manager.layout(true);
|
||||||
|
manager.plot("testRemoveNode3", {width:1000, height:200});
|
||||||
|
|
||||||
|
// Remove a node from the root node
|
||||||
|
console.log("\t--- Remove node 5 ---");
|
||||||
|
manager.removeNode(5);
|
||||||
|
manager.layout(true);
|
||||||
|
manager.plot("testRemoveNode4", {width:1000, height:200});
|
||||||
|
|
||||||
|
$assert(manager.find(1).getPosition().y == manager.find(2).getPosition().y, "After removal of node 3, nodes 1 and 2 should be alingned");
|
||||||
|
console.log("\n");
|
||||||
|
},
|
||||||
|
|
||||||
|
testSize: function() {
|
||||||
|
var position = {x:0, y:0};
|
||||||
|
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
|
||||||
|
|
||||||
|
manager.addNode(1, {width: 60, height: 60}, position);
|
||||||
|
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(3, {width: 260, height: 30}, position);
|
||||||
|
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(7, {width: 80, height: 80}, position);
|
||||||
|
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(9, {width: 30, height: 30}, position);
|
||||||
|
manager.addNode(10, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(11, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(12, {width: 100, height: 70}, position);
|
||||||
|
manager.addNode(13, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(14, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(15, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(16, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.addNode(17, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
|
||||||
|
manager.connectNode(0,1,0);
|
||||||
|
manager.connectNode(1,16,0);
|
||||||
|
manager.connectNode(0,2,1);
|
||||||
|
manager.connectNode(0,3,2);
|
||||||
|
manager.connectNode(0,4,3);
|
||||||
|
manager.connectNode(0,5,4);
|
||||||
|
manager.connectNode(4,7,0);
|
||||||
|
manager.connectNode(7,15,0);
|
||||||
|
manager.connectNode(7,17,1);
|
||||||
|
manager.connectNode(4,8,1);
|
||||||
|
manager.connectNode(8,9,0);
|
||||||
|
manager.connectNode(3,10,0);
|
||||||
|
manager.connectNode(3,11,1);
|
||||||
|
manager.connectNode(9,12,0);
|
||||||
|
manager.connectNode(9,13,1);
|
||||||
|
manager.connectNode(13,14,0);
|
||||||
|
|
||||||
|
manager.layout();
|
||||||
|
manager.plot("testSize1", {width: 1400, height: 400});
|
||||||
|
|
||||||
|
var graph2 = manager.plot("testSize2", {width: 1400, height: 400});
|
||||||
|
this._plotPrediction(graph2, manager.predict(0, {x:-145, y:400}));
|
||||||
|
this._plotPrediction(graph2, manager.predict(9, {x:-330, y:70}));
|
||||||
|
this._plotPrediction(graph2, manager.predict(9, {x:-330, y:120}));
|
||||||
|
this._plotPrediction(graph2, manager.predict(0, {x:15, y:20}));
|
||||||
|
|
||||||
|
var graph3 = manager.plot("testSize3", {width: 1400, height: 400});
|
||||||
|
this._plotPrediction(graph3, manager.predict(0, null));
|
||||||
|
this._plotPrediction(graph3, manager.predict(9, null));
|
||||||
|
this._plotPrediction(graph3, manager.predict(3, null));
|
||||||
|
this._plotPrediction(graph3, manager.predict(1, null));
|
||||||
|
|
||||||
|
manager.updateNodeSize(7, {width:80, height:120});
|
||||||
|
manager.layout();
|
||||||
|
manager.plot("testSize4", {width: 1400, height: 400});
|
||||||
|
|
||||||
|
manager.updateNodeSize(7, {width:200, height:30});
|
||||||
|
manager.layout();
|
||||||
|
manager.plot("testSize5", {width: 1400, height: 400});
|
||||||
|
},
|
||||||
|
|
||||||
|
testReconnectSingleNode: function() {
|
||||||
|
console.log("testReconnectSingleNode:");
|
||||||
|
var position = {x:0,y:0};
|
||||||
|
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
|
||||||
|
|
||||||
|
// Prepare a sample graph ...
|
||||||
|
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||||
|
manager.connectNode(0, 1, 0);
|
||||||
|
manager.layout();
|
||||||
|
var graph = manager.plot("testReconnectSingleNode1", {width:1000, height:400});
|
||||||
|
this._plotPrediction(graph, manager.predict(0, {x:-50, y:0}));
|
||||||
|
|
||||||
|
|
||||||
|
manager.disconnectNode(1);
|
||||||
|
manager.connectNode(0,1,1);
|
||||||
|
manager.layout();
|
||||||
|
manager.plot("testReconnectSingleNode2", {width:1000, height:400});
|
||||||
|
},
|
||||||
|
|
||||||
|
_plotPrediction: function(canvas, prediction) {
|
||||||
|
var position = prediction.position;
|
||||||
|
var order = prediction.order;
|
||||||
|
console.log("\t\tprediction {order:" + order + ", position: (" + position.x + "," + position.y + ")}");
|
||||||
|
var cx = position.x + canvas.width / 2 - mindplot.layout.TestSuite.NODE_SIZE.width / 2;
|
||||||
|
var cy = position.y + canvas.height / 2 - mindplot.layout.TestSuite.NODE_SIZE.height / 2;
|
||||||
|
canvas.rect(cx, cy, mindplot.layout.TestSuite.NODE_SIZE.width, mindplot.layout.TestSuite.NODE_SIZE.height);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
mindplot.layout.TestSuite.NODE_SIZE = {width:80, height:30},
|
||||||
|
mindplot.layout.TestSuite.ROOT_NODE_SIZE = {width:120, height:40}
|
Loading…
Reference in New Issue
Block a user