Improved test graphs

This commit is contained in:
Gonzalo Bellver 2012-01-04 14:37:58 -03:00
parent 344573d4bd
commit ad1bb136fd
4 changed files with 70 additions and 13 deletions

View File

@ -137,6 +137,9 @@ mindplot.nlayout.RootedTreeSet = new Class({
var fillColor = this._rootNodes.contains(node) ? "#000" : "#c00";
rect.attr('fill', fillColor);
rect.click(function() {console.log("[id:" + node.getId() + ", order:" + node.getOrder() + ", position: {" + node.getPosition().x + "," + node.getPosition().y + "}, size: {" + node.getSize().width + "," + node.getSize().height + "}");});
text.click(function() {console.log("[id:" + node.getId() + ", order:" + node.getOrder() + ", position: {" + node.getPosition().x + "," + node.getPosition().y + "}, size: {" + node.getSize().width + "," + node.getSize().height + "}");});
for (var i=0; i<children.length; i++) {
var child = children[i];
this._plot(canvas, child);

View File

@ -7,6 +7,7 @@ mindplot.nlayout.TestSuite = new Class({
this.testEvents();
this.testEventsComplex();
this.testDisconnect();
this.testReconnect();
this.testRemoveNode();
},
@ -29,6 +30,7 @@ mindplot.nlayout.TestSuite = new Class({
manager.dump();
manager.plot("testAligned", {w:300,h: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");
@ -52,11 +54,15 @@ mindplot.nlayout.TestSuite = new Class({
manager.addNode(10, size, position);
manager.addNode(11, size, position);
manager.addNode(12, 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.addNode(13, size, position);
manager.addNode(14, 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);
@ -66,8 +72,8 @@ mindplot.nlayout.TestSuite = new Class({
manager.connectNode(6, 12, 1);
manager.layout();
// manager.dump();
manager.plot("testSymmetry",{w:400, h:300});
manager.dump();
manager.plot("testSymmetry",{w:500, h:300});
//TODO(gb): make asserts
},
@ -205,14 +211,15 @@ mindplot.nlayout.TestSuite = new Class({
var events = [];
manager.addEvent('change', function(event) {
var pos = event.getPosition();
var posStr = pos ? ",position: {" + pos.x + "," + event.getPosition().y : "";
var posStr = pos ? ",position: {" + pos.x + "," + pos.y : "";
var node = manager.find(event.getId());
console.log("Updated nodes: {id:" + event.getId() + ", order: " + event.getOrder() + posStr + "}");
events.push(event);
});
manager.layout(true);
manager.dump();
// manager.dump();
manager.plot("testDisconnect1", {w:300, h:200});
// Now, disconnect one node ...
@ -220,7 +227,7 @@ mindplot.nlayout.TestSuite = new Class({
events.empty();
manager.disconnectNode(2);
manager.layout(true);
manager.dump();
// manager.dump();
manager.plot("testDisconnect2", {w:300, h:200});
$assert(events.some(
@ -232,7 +239,7 @@ mindplot.nlayout.TestSuite = new Class({
console.log("--- Disconnect a node with children ---");
manager.disconnectNode(3);
manager.layout(true);
manager.dump();
// manager.dump();
manager.plot("testDisconnect3", {w:300, h:200});
$assert(events.some(
@ -241,6 +248,50 @@ mindplot.nlayout.TestSuite = new Class({
}), "Event for disconnected node seems not to be propagated");
},
testReconnect: function() {
var size = {width:25,height:25};
var position = {x:0,y:0};
var manager = new mindplot.nlayout.LayoutManager(0, size);
manager.addNode(1, size, position);
manager.addNode(2, size, position);
manager.addNode(3, size, position);
manager.addNode(4, size, position);
manager.addNode(5, size, position);
manager.addNode(6, size, position);
manager.addNode(7, size, position);
manager.addNode(8, size, position);
manager.addNode(9, size, position);
manager.addNode(10, size, position);
manager.addNode(11, size, position);
manager.addNode(12, 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.dump();
manager.plot("testReconnect1",{w:400, h:300});
// Reconnect node 6 to node 4
manager.disconnectNode(6);
manager.connectNode(4,6,0);
manager.layout();
manager.dump();
manager.plot("testReconnect2",{w:400, h:300});
//TODO(gb): make asserts
},
testRemoveNode: function() {
var size = {width:25,height:25};
var position = {x:0,y:0};

View File

@ -25,6 +25,5 @@ Raphael.fn.drawGrid = function (x, y, w, h, wv, hv, color) {
path.attr({stroke: "#999"})
}
}
// return this.path(path.join(",")).attr({stroke: color});
return this.path;
};

View File

@ -70,6 +70,10 @@
<div id="testDisconnect2" class="col"></div>
<div id="testDisconnect3" class="col last"></div>
<h2>testReconnect:</h2>
<div id="testReconnect1" class="col"></div>
<div id="testReconnect2" class="col last"></div>
<h2>testRemoveNode:</h2>
<div id="testRemoveNode1" class="col"></div>
<div id="testRemoveNode2" class="col last"></div>