Fixed bug with BalancedSorter's predict

This commit is contained in:
Gonzalo Bellver 2012-01-19 12:20:43 -03:00
parent 419d2ffe79
commit e98d7f8147
3 changed files with 41 additions and 15 deletions

View File

@ -23,18 +23,20 @@ mindplot.layout.BalancedSorter = new Class({
}, },
predict : function(parent, graph, position) { predict : function(parent, graph, position) {
var rootNode = graph.getRootNode(parent);
if (!position) { if (!position) {
var right = this._getChildrenForOrder(parent, graph, 0); var right = this._getChildrenForOrder(parent, graph, 0);
var left = this._getChildrenForOrder(parent, graph, 1); var left = this._getChildrenForOrder(parent, graph, 1);
} }
// Filter nodes on one side.. // Filter nodes on one side..
var order = position ? (position.x > 0 ? 0 : 1) : ((right.length - left.length) > 0 ? 1 : 0); var order = position ? (position.x > rootNode.getPosition().x ? 0 : 1) : ((right.length - left.length) > 0 ? 1 : 0);
var direction = order%2 == 0 ? 1 : -1;
var children = this._getChildrenForOrder(parent, graph, order); var children = this._getChildrenForOrder(parent, graph, order);
// No children? // No children?
if (children.length == 0) { if (children.length == 0) {
return [0, {x:parent.getPosition().x + parent.getSize().width + mindplot.layout.BalancedSorter.INTERNODE_HORIZONTAL_PADDING * 2, y:parent.getPosition().y}]; return [order, {x:parent.getPosition().x + direction * (parent.getSize().width + mindplot.layout.BalancedSorter.INTERNODE_HORIZONTAL_PADDING * 2), y:parent.getPosition().y}];
} }

View File

@ -19,20 +19,21 @@ mindplot.layout.TestSuite = new Class({
Extends: mindplot.layout.ChildrenSorterStrategy, Extends: mindplot.layout.ChildrenSorterStrategy,
initialize:function() { initialize:function() {
// this.testAligned(); this.testAligned();
// this.testSymmetry(); this.testSymmetry();
// this.testBalanced(); this.testBalanced();
// this.testEvents(); this.testEvents();
// this.testEventsComplex(); this.testEventsComplex();
// this.testDisconnect(); this.testDisconnect();
// this.testReconnect(); this.testReconnect();
// this.testRemoveNode(); this.testRemoveNode();
// this.testSymmetricPredict(); this.testSymmetricPredict();
// this.testBalancedPredict(); this.testBalancedPredict();
// this.testSize(); this.testSize();
// this.testFreePosition(); this.testFreePosition();
// this.testFreePredict(); this.testFreePredict();
this.testReconnectFreeNode(); this.testReconnectFreeNode();
this.testReconnectSingleNode();
}, },
testAligned: function() { testAligned: function() {
@ -860,6 +861,25 @@ mindplot.layout.TestSuite = new Class({
// manager.moveNode(8, {x:370, y:30}); // manager.moveNode(8, {x:370, y:30});
// manager.layout(); // manager.layout();
// manager.plot("testReconnectFreeNode2", {width:1000, height:400}); // 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});
} }
}); });

View File

@ -132,5 +132,9 @@
<div id="testReconnectFreeNode5" class="col"></div> <div id="testReconnectFreeNode5" class="col"></div>
<div id="testReconnectFreeNode6" class="col"></div> <div id="testReconnectFreeNode6" class="col"></div>
<h2>testReconnectSingleNode:</h2>
<div id="testReconnectSingleNode1" class="col"></div>
<div id="testReconnectSingleNode2" class="col"></div>
</body> </body>
</html> </html>