Reconnect free node

This commit is contained in:
Gonzalo Bellver 2012-01-18 19:15:01 -03:00
parent c80726e1c0
commit 830f65caa9
3 changed files with 94 additions and 17 deletions

View File

@ -53,6 +53,10 @@ mindplot.layout.OriginalLayout = new Class({
var parent = this._treeSet.getParent(node);
$assert(parent, "Node already disconnected");
// Make it fixed
node.setFree(false);
node.setFreeDisplacement({x:0, y:0});
// Remove from children list.
var sorter = parent.getSorter();
sorter.detach(this._treeSet, node);
@ -86,9 +90,6 @@ mindplot.layout.OriginalLayout = new Class({
var parent = this._treeSet.getParent(node);
var childrenOrderMoved = children.some(function(child) { return child.hasOrderChanged(); });
var childrenFreeChanged = children.some(function(child) { return child.hasFreeChanged(); });
var freeChanged = node.hasFreeChanged() || childrenFreeChanged;
// If ether any of the nodes has been changed of position or the height of the children is not
// the same, children nodes must be repositioned ....
var newBranchHeight = heightById[nodeId];

View File

@ -19,20 +19,20 @@ 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.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();
},
testAligned: function() {
@ -793,6 +793,73 @@ mindplot.layout.TestSuite = new Class({
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});
}
});

View File

@ -123,5 +123,14 @@
<h2>testFreePredict:</h2>
<div id="testFreePredict1" class="col"></div>
<h2>testReconnectFreeNode:</h2>
<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>
</body>
</html>