mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-26 07:44:56 +01:00
Fixed bug for free positioning of balanced sorted nodes
This commit is contained in:
parent
7c3ffebc84
commit
4391afdf7b
@ -62,7 +62,7 @@ mindplot.layout.AbstractBasicSorter = new Class({
|
|||||||
|
|
||||||
_getRelativeDirection: function(reference, position) {
|
_getRelativeDirection: function(reference, position) {
|
||||||
var offset = position.x - reference.x;
|
var offset = position.x - reference.x;
|
||||||
return offset > 0 ? 1 : (offset < 0 ? -1 : 0);
|
return offset >= 0 ? 1 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -26,14 +26,16 @@ mindplot.layout.BalancedSorter = new Class({
|
|||||||
// If its a free node...
|
// If its a free node...
|
||||||
if (free) {
|
if (free) {
|
||||||
$assert($defined(position), "position cannot be null for predict in free positioning");
|
$assert($defined(position), "position cannot be null for predict in free positioning");
|
||||||
|
$assert($defined(node), "node cannot be null for predict in free positioning");
|
||||||
|
|
||||||
//TODO(gb): check this. Should direction be obtained by the sorter?
|
|
||||||
var rootNode = graph.getRootNode(parent);
|
var rootNode = graph.getRootNode(parent);
|
||||||
var direction = parent.getPosition().x > rootNode.getPosition().x ? 1 : -1;
|
var direction = this._getRelativeDirection(rootNode.getPosition(), node.getPosition());
|
||||||
|
|
||||||
|
var limitXPos = parent.getPosition().x + direction * (parent.getSize().width/2 + node.getSize().width/2 + mindplot.layout.BalancedSorter.INTERNODE_HORIZONTAL_PADDING);
|
||||||
|
|
||||||
var xPos = direction > 0 ?
|
var xPos = direction > 0 ?
|
||||||
(position.x >= parent.getPosition().x ? position.x : parent.getPosition().x) :
|
(position.x >= limitXPos ? position.x : limitXPos) :
|
||||||
(position.x <= parent.getPosition().x ? position.x : parent.getPosition().x);
|
(position.x <= limitXPos ? position.x : limitXPos) ;
|
||||||
|
|
||||||
return [0, {x: xPos, y:position.y}];
|
return [0, {x: xPos, y:position.y}];
|
||||||
}
|
}
|
||||||
|
@ -175,6 +175,9 @@
|
|||||||
<div id="testRootNodeChildrenPositioning3" class="col"></div>
|
<div id="testRootNodeChildrenPositioning3" class="col"></div>
|
||||||
<div id="testRootNodeChildrenPositioning4" class="col"></div>
|
<div id="testRootNodeChildrenPositioning4" class="col"></div>
|
||||||
<div id="testRootNodeChildrenPositioning5" class="col"></div>
|
<div id="testRootNodeChildrenPositioning5" class="col"></div>
|
||||||
|
|
||||||
|
<h3>testBalancedFreePredict:</h3>
|
||||||
|
<div id="testBalancedFreePredict1" class="col"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
@ -26,6 +26,7 @@ mindplot.layout.FreeTestSuite = new Class({
|
|||||||
this.testReconnectFreeNode();
|
this.testReconnectFreeNode();
|
||||||
this.testSiblingOverlapping();
|
this.testSiblingOverlapping();
|
||||||
this.testRootNodeChildrenPositioning();
|
this.testRootNodeChildrenPositioning();
|
||||||
|
this.testBalancedFreePredict();
|
||||||
},
|
},
|
||||||
|
|
||||||
testFreePosition: function() {
|
testFreePosition: function() {
|
||||||
@ -344,6 +345,23 @@ mindplot.layout.FreeTestSuite = new Class({
|
|||||||
console.log("OK!\n\n");
|
console.log("OK!\n\n");
|
||||||
},
|
},
|
||||||
|
|
||||||
|
testBalancedFreePredict: function() {
|
||||||
|
console.log("testBalancedFreePredict:");
|
||||||
|
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).connectNode(0,1,0);
|
||||||
|
manager.layout();
|
||||||
|
var graph1 = manager.plot("testBalancedFreePredict1", {width:800, height:400});
|
||||||
|
|
||||||
|
var predict1 = manager.predict(0, 1, {x:70, y:0}, true);
|
||||||
|
this._plotPrediction(graph1, predict1);
|
||||||
|
$assert(predict1.position.x == manager.find(1).getPosition().x, "Prediction x pos should be the same as node 1");
|
||||||
|
|
||||||
|
console.log("OK!\n\n");
|
||||||
|
},
|
||||||
|
|
||||||
_assertFreePosition: function(manager, id, position) {
|
_assertFreePosition: function(manager, id, position) {
|
||||||
if (id != null && position.x != null && position.y != null) {
|
if (id != null && position.x != null && position.y != null) {
|
||||||
var node = manager.find(id);
|
var node = manager.find(id);
|
||||||
|
Loading…
Reference in New Issue
Block a user