diff --git a/mindplot/src/main/javascript/layout/AbstractBasicSorter.js b/mindplot/src/main/javascript/layout/AbstractBasicSorter.js index b3ee5aed..c3395d31 100644 --- a/mindplot/src/main/javascript/layout/AbstractBasicSorter.js +++ b/mindplot/src/main/javascript/layout/AbstractBasicSorter.js @@ -58,6 +58,11 @@ mindplot.layout.AbstractBasicSorter = new Class({ return a.getOrder() - b.getOrder() }); return result; + }, + + _getRelativeDirection: function(reference, position) { + var offset = position.x - reference.x; + return offset > 0 ? 1 : (offset < 0 ? -1 : 0); } }); diff --git a/mindplot/src/main/javascript/layout/BalancedSorter.js b/mindplot/src/main/javascript/layout/BalancedSorter.js index c93de9aa..684a0351 100644 --- a/mindplot/src/main/javascript/layout/BalancedSorter.js +++ b/mindplot/src/main/javascript/layout/BalancedSorter.js @@ -42,11 +42,13 @@ mindplot.layout.BalancedSorter = new Class({ // If it is a dragged node... if (node) { + $assert($defined(position), "position cannot be null for predict in dragging"); var nodeDirection = this._getRelativeDirection(rootNode.getPosition(), node.getPosition()); var positionDirection = this._getRelativeDirection(rootNode.getPosition(), position); var siblings = graph.getSiblings(node); - if (siblings.length == 0 && nodeDirection == positionDirection) { + var sameParent = parent == graph.getParent(node); + if (siblings.length == 0 && nodeDirection == positionDirection && sameParent) { return [node.getOrder(), node.getPosition()]; } } @@ -183,7 +185,6 @@ mindplot.layout.BalancedSorter = new Class({ // Check that all is consistent ... var children = this._getChildrenForOrder(node, treeSet, node.getOrder()); - // All odd ordered nodes should be "continuous" by themselves // All even numbered nodes should be "continuous" by themselves var factor = node.getOrder() % 2 == 0 ? 2 : 1; @@ -221,13 +222,7 @@ mindplot.layout.BalancedSorter = new Class({ _getVerticalPadding: function() { return mindplot.layout.BalancedSorter.INTERNODE_VERTICAL_PADDING; - }, - - _getRelativeDirection: function(reference, position) { - var offset = position.x - reference.x; - return offset > 0 ? 1 : (offset < 0 ? -1 : 0); } - }); mindplot.layout.BalancedSorter.INTERNODE_VERTICAL_PADDING = 5; diff --git a/mindplot/src/main/javascript/layout/SymmetricSorter.js b/mindplot/src/main/javascript/layout/SymmetricSorter.js index 38afd92f..bd86866c 100644 --- a/mindplot/src/main/javascript/layout/SymmetricSorter.js +++ b/mindplot/src/main/javascript/layout/SymmetricSorter.js @@ -37,12 +37,26 @@ mindplot.layout.SymmetricSorter = new Class({ return [0, {x: xPos, y:position.y}]; } - // Regular node var rootNode = graph.getRootNode(parent); + + // If it is a dragged node... + if (node) { + $assert($defined(position), "position cannot be null for predict in dragging"); + var nodeDirection = this._getRelativeDirection(rootNode.getPosition(), node.getPosition()); + var positionDirection = this._getRelativeDirection(rootNode.getPosition(), position); + var siblings = graph.getSiblings(node); + + var sameParent = parent == graph.getParent(node); + if (siblings.length == 0 && nodeDirection == positionDirection && sameParent) { + return [node.getOrder(), node.getPosition()]; + } + } + + // Regular node var direction = parent.getPosition().x > rootNode.getPosition().x ? 1 : -1; // No children... - var children = graph.getChildren(parent); + var children = graph.getChildren(parent).filter(function(child) { return child != node; }); if (children.length == 0) { position = position || {x:parent.getPosition().x + direction, y:parent.getPosition().y}; var pos = { diff --git a/mindplot/src/test/javascript/static/layout.html b/mindplot/src/test/javascript/static/layout.html index e72b7a6f..8fb37404 100644 --- a/mindplot/src/test/javascript/static/layout.html +++ b/mindplot/src/test/javascript/static/layout.html @@ -133,6 +133,9 @@
+ +

testSymmetricDragPredict:

+