mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-25 15:37:56 +01:00
Fixed bug with BalancedSorter's predict
This commit is contained in:
parent
419d2ffe79
commit
e98d7f8147
@ -23,18 +23,20 @@ mindplot.layout.BalancedSorter = new Class({
|
||||
},
|
||||
|
||||
predict : function(parent, graph, position) {
|
||||
var rootNode = graph.getRootNode(parent);
|
||||
|
||||
if (!position) {
|
||||
var right = this._getChildrenForOrder(parent, graph, 0);
|
||||
var left = this._getChildrenForOrder(parent, graph, 1);
|
||||
}
|
||||
// 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);
|
||||
|
||||
// No children?
|
||||
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}];
|
||||
}
|
||||
|
||||
|
||||
|
@ -19,20 +19,21 @@ 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.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() {
|
||||
@ -860,6 +861,25 @@ mindplot.layout.TestSuite = new Class({
|
||||
// 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});
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -132,5 +132,9 @@
|
||||
<div id="testReconnectFreeNode5" 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>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user