2012-01-09 23:50:52 -03:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2011-12-11 13:13:43 -03:00
|
|
|
mindplot.nlayout.TestSuite = new Class({
|
|
|
|
Extends: mindplot.nlayout.ChildrenSorterStrategy,
|
2012-01-10 10:01:04 -03:00
|
|
|
|
2011-12-11 13:13:43 -03:00
|
|
|
initialize:function() {
|
2012-01-10 09:44:33 -03:00
|
|
|
this.testAligned();
|
|
|
|
this.testSymmetry();
|
2012-01-05 17:34:14 -03:00
|
|
|
this.testBalanced();
|
2012-01-10 09:44:33 -03:00
|
|
|
this.testEvents();
|
|
|
|
this.testEventsComplex();
|
|
|
|
this.testDisconnect();
|
|
|
|
this.testReconnect();
|
|
|
|
this.testRemoveNode();
|
|
|
|
this.testFreePosition();
|
2011-12-11 13:13:43 -03:00
|
|
|
},
|
|
|
|
|
|
|
|
testAligned: function() {
|
|
|
|
|
|
|
|
var position = {x:0,y:0};
|
2012-01-10 10:01:04 -03:00
|
|
|
var manager = new mindplot.nlayout.LayoutManager(0, mindplot.nlayout.TestSuite.ROOT_NODE_SIZE);
|
2011-12-11 13:13:43 -03:00
|
|
|
|
2012-01-10 10:01:04 -03:00
|
|
|
manager.addNode(1, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(2, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(3, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(4, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
2011-12-11 13:13:43 -03:00
|
|
|
manager.connectNode(0, 1, 0);
|
2012-01-02 17:10:14 -03:00
|
|
|
manager.connectNode(1, 2, 0);
|
|
|
|
manager.connectNode(2, 3, 0);
|
|
|
|
manager.connectNode(3, 4, 0);
|
2011-12-11 13:13:43 -03:00
|
|
|
|
|
|
|
manager.layout();
|
2012-01-10 10:01:04 -03:00
|
|
|
manager.plot("testAligned", {width:1200,height:200});
|
2011-12-30 15:28:03 -03:00
|
|
|
|
2012-01-04 14:37:58 -03:00
|
|
|
// All nodes should be vertically aligned
|
2012-01-02 17:10:14 -03:00
|
|
|
$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");
|
2011-12-30 17:48:11 -03:00
|
|
|
},
|
|
|
|
|
|
|
|
testSymmetry: function() {
|
|
|
|
var position = {x:0,y:0};
|
2012-01-10 10:01:04 -03:00
|
|
|
var manager = new mindplot.nlayout.LayoutManager(0, mindplot.nlayout.TestSuite.ROOT_NODE_SIZE);
|
|
|
|
|
|
|
|
manager.addNode(1, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(2, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(3, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(4, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(5, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(6, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(7, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(8, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(9, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(10, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(11, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(12, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(13, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(14, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
2012-01-04 14:37:58 -03:00
|
|
|
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);
|
2012-01-02 17:10:14 -03:00
|
|
|
manager.connectNode(1, 6, 0);
|
|
|
|
manager.connectNode(1, 7, 1);
|
2011-12-30 17:48:11 -03:00
|
|
|
manager.connectNode(7, 8, 0);
|
|
|
|
manager.connectNode(8, 9, 0);
|
2012-01-02 17:10:14 -03:00
|
|
|
manager.connectNode(5, 10, 0);
|
|
|
|
manager.connectNode(6, 11, 0);
|
|
|
|
manager.connectNode(6, 12, 1);
|
2011-12-30 17:48:11 -03:00
|
|
|
|
|
|
|
manager.layout();
|
2012-01-10 10:01:04 -03:00
|
|
|
manager.plot("testSymmetry",{width:1200, height:400});
|
2012-01-02 17:10:14 -03:00
|
|
|
|
|
|
|
//TODO(gb): make asserts
|
|
|
|
},
|
|
|
|
|
2012-01-05 17:34:14 -03:00
|
|
|
testBalanced: function() {
|
|
|
|
var position = {x:0, y:0};
|
2012-01-10 10:01:04 -03:00
|
|
|
var plotsize = {width:800, height:400};
|
|
|
|
var manager = new mindplot.nlayout.LayoutManager(0, mindplot.nlayout.TestSuite.ROOT_NODE_SIZE);
|
2012-01-05 17:34:14 -03:00
|
|
|
|
2012-01-10 10:01:04 -03:00
|
|
|
manager.addNode(1, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
2012-01-05 17:34:14 -03:00
|
|
|
manager.connectNode(0, 1, 0);
|
|
|
|
manager.layout();
|
|
|
|
manager.plot("testBalanced1", plotsize);
|
|
|
|
|
2012-01-10 10:01:04 -03:00
|
|
|
manager.addNode(2, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
2012-01-05 17:34:14 -03:00
|
|
|
manager.connectNode(0, 2, 1);
|
|
|
|
manager.layout();
|
|
|
|
manager.plot("testBalanced2", plotsize);
|
|
|
|
|
2012-01-10 10:01:04 -03:00
|
|
|
manager.addNode(3, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
2012-01-05 17:34:14 -03:00
|
|
|
manager.connectNode(0, 3, 2);
|
|
|
|
manager.layout();
|
|
|
|
manager.plot("testBalanced3", plotsize);
|
|
|
|
|
2012-01-10 10:01:04 -03:00
|
|
|
manager.addNode(4, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
2012-01-05 17:34:14 -03:00
|
|
|
manager.connectNode(0, 4, 3);
|
|
|
|
manager.layout();
|
|
|
|
manager.plot("testBalanced4", plotsize);
|
|
|
|
|
2012-01-10 10:01:04 -03:00
|
|
|
manager.addNode(5, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
2012-01-05 17:34:14 -03:00
|
|
|
manager.connectNode(0, 5, 4);
|
|
|
|
manager.layout();
|
|
|
|
manager.plot("testBalanced5", plotsize);
|
|
|
|
|
2012-01-10 10:01:04 -03:00
|
|
|
manager.addNode(6, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
2012-01-05 17:34:14 -03:00
|
|
|
manager.connectNode(0, 6, 5);
|
|
|
|
manager.layout();
|
|
|
|
manager.plot("testBalanced6", plotsize);
|
2012-01-10 09:44:33 -03:00
|
|
|
|
2012-01-10 10:01:04 -03:00
|
|
|
manager.addNode(7, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(8, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(9, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
2012-01-10 09:44:33 -03:00
|
|
|
manager.connectNode(3, 7, 0)
|
|
|
|
manager.connectNode(7, 8, 0)
|
|
|
|
manager.connectNode(7, 9, 1);
|
|
|
|
manager.layout();
|
|
|
|
manager.plot("testBalanced7", plotsize);
|
|
|
|
|
2012-01-10 10:01:04 -03:00
|
|
|
manager.addNode(10, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(11, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(12, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
2012-01-10 09:44:33 -03:00
|
|
|
manager.connectNode(6, 10, 0)
|
|
|
|
manager.connectNode(10, 11, 0)
|
|
|
|
manager.connectNode(10, 12, 1);
|
|
|
|
manager.layout();
|
|
|
|
manager.plot("testBalanced8", plotsize);
|
2011-12-30 17:48:11 -03:00
|
|
|
|
2012-01-02 17:10:14 -03:00
|
|
|
//TODO(gb): make asserts
|
2011-12-11 13:13:43 -03:00
|
|
|
},
|
|
|
|
|
|
|
|
testEvents: function() {
|
2012-01-10 19:35:52 -03:00
|
|
|
console.log("testEvents:"); //TODO(gb): Remove trace!!!
|
2011-12-11 13:13:43 -03:00
|
|
|
var position = {x:0,y:0};
|
2012-01-10 10:01:04 -03:00
|
|
|
var manager = new mindplot.nlayout.LayoutManager(0, mindplot.nlayout.TestSuite.ROOT_NODE_SIZE);
|
2011-12-11 13:13:43 -03:00
|
|
|
|
|
|
|
// Add 3 nodes...
|
2012-01-10 10:01:04 -03:00
|
|
|
manager.addNode(1, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(2, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(3, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(4, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
2011-12-11 13:13:43 -03:00
|
|
|
|
|
|
|
// Now connect one with two....
|
|
|
|
manager.connectNode(0, 1, 0);
|
|
|
|
manager.connectNode(0, 2, 0);
|
|
|
|
manager.connectNode(1, 3, 0);
|
|
|
|
|
2011-12-11 23:47:01 -03:00
|
|
|
// Basic layout repositioning ...
|
2012-01-10 19:35:52 -03:00
|
|
|
console.log("\t--- Updated tree ---");
|
2011-12-11 23:47:01 -03:00
|
|
|
var events = [];
|
|
|
|
manager.addEvent('change', function(event) {
|
2012-01-10 19:35:52 -03:00
|
|
|
console.log("\tUpdated nodes: {id:" + event.getId() + ", order: " + event.getOrder() + ",position: {" + event.getPosition().x + "," + event.getPosition().y + "}");
|
2011-12-11 23:47:01 -03:00
|
|
|
events.push(event);
|
|
|
|
});
|
|
|
|
manager.layout(true);
|
2012-01-10 10:01:04 -03:00
|
|
|
manager.plot("testEvents1", {width:800, height:400});
|
2011-12-11 13:13:43 -03:00
|
|
|
|
2011-12-11 23:47:01 -03:00
|
|
|
// Ok, if a new node is added, this an event should be fired ...
|
2012-01-10 19:35:52 -03:00
|
|
|
console.log("\t---- Layout without changes should not affect the tree ---");
|
2011-12-11 23:47:01 -03:00
|
|
|
events.empty();
|
|
|
|
manager.layout(true);
|
2012-01-10 10:01:04 -03:00
|
|
|
manager.plot("testEvents2", {width:800, height:400});
|
2011-12-11 23:47:01 -03:00
|
|
|
|
|
|
|
$assert(events.length == 0, "Unnecessary tree updated.");
|
2012-01-10 10:01:04 -03:00
|
|
|
|
|
|
|
//TODO(gb): make asserts
|
2012-01-10 19:35:52 -03:00
|
|
|
console.log("\n"); //TODO(gb): Remove trace!!!
|
2011-12-11 23:47:01 -03:00
|
|
|
},
|
|
|
|
|
|
|
|
testEventsComplex: function() {
|
2012-01-10 19:35:52 -03:00
|
|
|
console.log("testEventsComplex:"); //TODO(gb): Remove trace!!!
|
2011-12-11 23:47:01 -03:00
|
|
|
var position = {x:0,y:0};
|
2012-01-10 10:01:04 -03:00
|
|
|
var manager = new mindplot.nlayout.LayoutManager(0, mindplot.nlayout.TestSuite.ROOT_NODE_SIZE);
|
2011-12-11 23:47:01 -03:00
|
|
|
|
|
|
|
// Add 3 nodes...
|
2012-01-10 10:01:04 -03:00
|
|
|
manager.addNode(1, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(2, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(3, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(4, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
2011-12-11 23:47:01 -03:00
|
|
|
|
|
|
|
// Now connect one with two....
|
|
|
|
manager.connectNode(0, 1, 0);
|
|
|
|
manager.connectNode(1, 2, 0);
|
|
|
|
manager.connectNode(1, 3, 1);
|
|
|
|
|
2011-12-11 13:13:43 -03:00
|
|
|
var events = [];
|
|
|
|
manager.addEvent('change', function(event) {
|
2012-01-10 19:35:52 -03:00
|
|
|
console.log("\tUpdated nodes: {id:" + event.getId() + ", order: " + event.getOrder() + ",position: {" + event.getPosition().x + "," + event.getPosition().y + "}");
|
2011-12-11 13:13:43 -03:00
|
|
|
events.push(event);
|
|
|
|
});
|
|
|
|
|
2011-12-11 23:47:01 -03:00
|
|
|
// Reposition ...
|
|
|
|
manager.layout(true);
|
2012-01-10 10:01:04 -03:00
|
|
|
manager.plot("testEventsComplex1", {width:800, height:400});
|
2011-12-11 23:47:01 -03:00
|
|
|
|
|
|
|
// Add a new node and connect. Only children nodes should be affected.
|
2012-01-10 19:35:52 -03:00
|
|
|
console.log("\t---- Connect a new node ---");
|
2011-12-11 13:13:43 -03:00
|
|
|
|
|
|
|
events.empty();
|
2011-12-11 23:47:01 -03:00
|
|
|
manager.connectNode(1, 4, 2);
|
|
|
|
manager.layout(true);
|
2012-01-10 10:01:04 -03:00
|
|
|
manager.plot("testEventsComplex2", {width:800, height:400});
|
2011-12-11 13:13:43 -03:00
|
|
|
|
2011-12-11 23:47:01 -03:00
|
|
|
// @todo: This seems no to be ok...
|
|
|
|
$assert(events.length == 4, "Only 3 nodes should be repositioned.");
|
2012-01-10 10:01:04 -03:00
|
|
|
|
|
|
|
//TODO(gb): make asserts
|
2012-01-10 19:35:52 -03:00
|
|
|
console.log("\n"); //TODO(gb): Remove trace!!!
|
2011-12-11 23:47:01 -03:00
|
|
|
},
|
|
|
|
|
|
|
|
testDisconnect: function() {
|
2012-01-10 19:35:52 -03:00
|
|
|
console.log("testDisconnect:"); //TODO(gb): Remove trace!!!
|
2011-12-11 23:47:01 -03:00
|
|
|
var position = {x:0,y:0};
|
2012-01-10 10:01:04 -03:00
|
|
|
var manager = new mindplot.nlayout.LayoutManager(0, mindplot.nlayout.TestSuite.ROOT_NODE_SIZE);
|
2011-12-11 23:47:01 -03:00
|
|
|
|
|
|
|
// Prepare a sample graph ...
|
2012-01-10 10:01:04 -03:00
|
|
|
manager.addNode(1, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(2, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(3, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(4, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
2011-12-11 23:47:01 -03:00
|
|
|
|
|
|
|
manager.connectNode(0, 1, 0);
|
|
|
|
manager.connectNode(1, 2, 0);
|
|
|
|
manager.connectNode(1, 3, 1);
|
|
|
|
manager.connectNode(3, 4, 0);
|
|
|
|
|
|
|
|
var events = [];
|
|
|
|
manager.addEvent('change', function(event) {
|
2012-01-04 14:37:58 -03:00
|
|
|
|
2011-12-11 23:47:01 -03:00
|
|
|
var pos = event.getPosition();
|
2012-01-04 14:37:58 -03:00
|
|
|
var posStr = pos ? ",position: {" + pos.x + "," + pos.y : "";
|
|
|
|
var node = manager.find(event.getId());
|
2012-01-10 19:35:52 -03:00
|
|
|
console.log("\tUpdated nodes: {id:" + event.getId() + ", order: " + event.getOrder() + posStr + "}");
|
2011-12-11 23:47:01 -03:00
|
|
|
events.push(event);
|
|
|
|
});
|
|
|
|
manager.layout(true);
|
2012-01-10 10:01:04 -03:00
|
|
|
manager.plot("testDisconnect1", {width:800, height:400});
|
2011-12-11 23:47:01 -03:00
|
|
|
|
|
|
|
// Now, disconnect one node ...
|
2012-01-10 19:35:52 -03:00
|
|
|
console.log("\t--- Disconnect a single node ---");
|
2011-12-11 13:13:43 -03:00
|
|
|
events.empty();
|
2011-12-11 23:47:01 -03:00
|
|
|
manager.disconnectNode(2);
|
2011-12-11 13:13:43 -03:00
|
|
|
manager.layout(true);
|
2012-01-10 10:01:04 -03:00
|
|
|
manager.plot("testDisconnect2", {width:800, height:400});
|
2011-12-11 13:13:43 -03:00
|
|
|
|
2011-12-11 23:47:01 -03:00
|
|
|
$assert(events.some(
|
|
|
|
function(event) {
|
|
|
|
return event.getId() == 2;
|
|
|
|
}), "Event for disconnected node seems not to be propagated");
|
|
|
|
|
|
|
|
// Great, let's disconnect a not with children.
|
2012-01-10 19:35:52 -03:00
|
|
|
console.log("\t--- Disconnect a node with children ---");
|
2011-12-11 23:47:01 -03:00
|
|
|
manager.disconnectNode(3);
|
|
|
|
manager.layout(true);
|
2012-01-10 10:01:04 -03:00
|
|
|
manager.plot("testDisconnect3", {width:800, height:400});
|
2011-12-11 23:47:01 -03:00
|
|
|
|
|
|
|
$assert(events.some(
|
|
|
|
function(event) {
|
|
|
|
return event.getId() == 2;
|
|
|
|
}), "Event for disconnected node seems not to be propagated");
|
2012-01-10 10:01:04 -03:00
|
|
|
|
|
|
|
//TODO(gb): make asserts
|
2012-01-10 19:35:52 -03:00
|
|
|
console.log("\n"); //TODO(gb): Remove trace!!!
|
2011-12-11 23:47:01 -03:00
|
|
|
},
|
|
|
|
|
2012-01-04 14:37:58 -03:00
|
|
|
testReconnect: function() {
|
|
|
|
var position = {x:0,y:0};
|
2012-01-10 10:01:04 -03:00
|
|
|
var manager = new mindplot.nlayout.LayoutManager(0, mindplot.nlayout.TestSuite.ROOT_NODE_SIZE);
|
|
|
|
|
|
|
|
manager.addNode(1, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(2, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(3, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(4, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(5, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(6, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(7, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(8, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(9, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(10, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(11, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(12, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
2012-01-04 14:37:58 -03:00
|
|
|
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();
|
2012-01-10 10:01:04 -03:00
|
|
|
manager.plot("testReconnect1",{width:1000, height:400});
|
2012-01-04 14:37:58 -03:00
|
|
|
|
|
|
|
// Reconnect node 6 to node 4
|
|
|
|
manager.disconnectNode(6);
|
|
|
|
manager.connectNode(4,6,0);
|
|
|
|
manager.layout();
|
2012-01-10 10:01:04 -03:00
|
|
|
manager.plot("testReconnect2",{width:1000, height:400});
|
2012-01-04 14:37:58 -03:00
|
|
|
|
|
|
|
//TODO(gb): make asserts
|
|
|
|
},
|
|
|
|
|
2011-12-11 23:47:01 -03:00
|
|
|
testRemoveNode: function() {
|
2012-01-10 19:35:52 -03:00
|
|
|
console.log("testRemoveNode:"); //TODO(gb): Remove trace!!!
|
2011-12-11 23:47:01 -03:00
|
|
|
var position = {x:0,y:0};
|
2012-01-10 10:01:04 -03:00
|
|
|
var manager = new mindplot.nlayout.LayoutManager(0, mindplot.nlayout.TestSuite.ROOT_NODE_SIZE);
|
2011-12-11 23:47:01 -03:00
|
|
|
|
|
|
|
// Prepare a sample graph ...
|
2012-01-10 10:01:04 -03:00
|
|
|
manager.addNode(1, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(2, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(3, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(4, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
2011-12-11 23:47:01 -03:00
|
|
|
|
|
|
|
manager.connectNode(0, 1, 0);
|
|
|
|
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 : "";
|
2012-01-10 19:35:52 -03:00
|
|
|
console.log("\tUpdated nodes: {id:" + event.getId() + ", order: " + event.getOrder() + posStr + "}");
|
2011-12-11 23:47:01 -03:00
|
|
|
events.push(event);
|
|
|
|
});
|
|
|
|
manager.layout(true);
|
2012-01-10 10:01:04 -03:00
|
|
|
manager.plot("testRemoveNode1", {width:800, height:200});
|
2011-12-11 23:47:01 -03:00
|
|
|
|
|
|
|
// Test removal of a connected node ...
|
2012-01-10 19:35:52 -03:00
|
|
|
console.log("\t--- Remove node 3 ---");
|
2011-12-11 23:47:01 -03:00
|
|
|
manager.removeNode(3);
|
|
|
|
manager.layout(true);
|
2012-01-10 10:01:04 -03:00
|
|
|
manager.plot("testRemoveNode2", {width:800, height:200});
|
|
|
|
|
|
|
|
//TODO(gb): make asserts
|
2012-01-10 19:35:52 -03:00
|
|
|
console.log("\n"); //TODO(gb): Remove trace!!!
|
2012-01-05 17:34:14 -03:00
|
|
|
},
|
|
|
|
|
|
|
|
testFreePosition: function() {
|
|
|
|
var position = {x:0,y:0};
|
2012-01-10 10:01:04 -03:00
|
|
|
var manager = new mindplot.nlayout.LayoutManager(0, mindplot.nlayout.TestSuite.ROOT_NODE_SIZE);
|
2012-01-05 17:34:14 -03:00
|
|
|
|
|
|
|
// Prepare a sample graph ...
|
2012-01-10 10:01:04 -03:00
|
|
|
manager.addNode(1, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(2, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(3, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
|
|
|
manager.addNode(4, mindplot.nlayout.TestSuite.NODE_SIZE, position);
|
2012-01-05 17:34:14 -03:00
|
|
|
|
|
|
|
manager.connectNode(0, 4, 0);
|
|
|
|
manager.connectNode(4, 1, 0);
|
|
|
|
manager.connectNode(4, 2, 1);
|
|
|
|
manager.connectNode(4, 3, 2);
|
|
|
|
|
|
|
|
manager.layout();
|
2012-01-10 10:01:04 -03:00
|
|
|
manager.plot("testFreePosition", {width:800, height:400});
|
2011-12-11 23:47:01 -03:00
|
|
|
|
2012-01-10 10:01:04 -03:00
|
|
|
//TODO(gb): make asserts
|
|
|
|
}
|
2011-12-11 13:13:43 -03:00
|
|
|
});
|
|
|
|
|
2012-01-10 10:01:04 -03:00
|
|
|
mindplot.nlayout.TestSuite.NODE_SIZE = {width:80, height:30},
|
|
|
|
mindplot.nlayout.TestSuite.ROOT_NODE_SIZE = {width:120, height:40}
|
|
|
|
|