diff --git a/mindplot/src/main/javascript/layout/AbstractBasicSorter.js b/mindplot/src/main/javascript/layout/AbstractBasicSorter.js index c3395d31..e78d6af7 100644 --- a/mindplot/src/main/javascript/layout/AbstractBasicSorter.js +++ b/mindplot/src/main/javascript/layout/AbstractBasicSorter.js @@ -62,7 +62,7 @@ mindplot.layout.AbstractBasicSorter = new Class({ _getRelativeDirection: function(reference, position) { var offset = position.x - reference.x; - return offset > 0 ? 1 : (offset < 0 ? -1 : 0); + return offset >= 0 ? 1 : -1; } }); diff --git a/mindplot/src/main/javascript/layout/BalancedSorter.js b/mindplot/src/main/javascript/layout/BalancedSorter.js index 01fcd99d..40bf1ae0 100644 --- a/mindplot/src/main/javascript/layout/BalancedSorter.js +++ b/mindplot/src/main/javascript/layout/BalancedSorter.js @@ -26,14 +26,16 @@ mindplot.layout.BalancedSorter = new Class({ // If its a free node... if (free) { $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 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 ? - (position.x >= parent.getPosition().x ? position.x : parent.getPosition().x) : - (position.x <= parent.getPosition().x ? position.x : parent.getPosition().x); + (position.x >= limitXPos ? position.x : limitXPos) : + (position.x <= limitXPos ? position.x : limitXPos) ; return [0, {x: xPos, y:position.y}]; } diff --git a/mindplot/src/test/javascript/static/layout.html b/mindplot/src/test/javascript/static/layout.html index 8fb37404..f71c5484 100644 --- a/mindplot/src/test/javascript/static/layout.html +++ b/mindplot/src/test/javascript/static/layout.html @@ -175,6 +175,9 @@
+ +