diff --git a/mindplot/src/main/javascript/layout/OriginalLayout.js b/mindplot/src/main/javascript/layout/OriginalLayout.js index 2c0af97c..b8b4064f 100644 --- a/mindplot/src/main/javascript/layout/OriginalLayout.js +++ b/mindplot/src/main/javascript/layout/OriginalLayout.js @@ -162,7 +162,10 @@ mindplot.layout.OriginalLayout = new Class({ } }, this); - var branchesToShift = this._treeSet.getBranchesInVerticalDirection(node, node.getFreeDisplacement().y); + var branchesToShift = this._treeSet.getBranchesInVerticalDirection(node, node.getFreeDisplacement().y).filter(function(branch) { + return !shiftedBranches.contains(branch); + }); + branchesToShift.forEach(function(branch) { var overlappingOccurs = shiftedBranches.some(function(shiftedBranch) { return this._branchesOverlap(shiftedBranch, branch, heightById); @@ -177,6 +180,11 @@ mindplot.layout.OriginalLayout = new Class({ }, _branchesOverlap: function(branchA, branchB, heightById) { + // a branch doesn't really overlap with itself + if (branchA == branchB) { + return false; + } + var topA = branchA.getPosition().y - heightById[branchA.getId()]/2; var bottomA = branchA.getPosition().y + heightById[branchA.getId()]/2; var topB = branchB.getPosition().y - heightById[branchB.getId()]/2; diff --git a/mindplot/src/main/javascript/layout/RootedTreeSet.js b/mindplot/src/main/javascript/layout/RootedTreeSet.js index 1dac067a..5c9dec63 100644 --- a/mindplot/src/main/javascript/layout/RootedTreeSet.js +++ b/mindplot/src/main/javascript/layout/RootedTreeSet.js @@ -233,9 +233,12 @@ mindplot.layout.RootedTreeSet = new Class({ }, getSiblingsInVerticalDirection: function(node, yOffset) { - // siblings with lower or higher order, depending on the direction of the offset + // siblings with lower or higher order, depending on the direction of the offset and on the same side as their parent + var parent = this.getParent(node); var siblings = this.getSiblings(node).filter(function(sibling) { - return yOffset < 0 ? sibling.getOrder() < node.getOrder() : sibling.getOrder() > node.getOrder(); + var sameSide = node.getPosition().x > parent.getPosition().x ? sibling.getPosition().x > parent.getPosition().x : sibling.getPosition().x < parent.getPosition().x; + var orderOK = yOffset < 0 ? sibling.getOrder() < node.getOrder() : sibling.getOrder() > node.getOrder(); + return orderOK && sameSide; }); if (yOffset < 0 ) { diff --git a/mindplot/src/test/javascript/static/layout.html b/mindplot/src/test/javascript/static/layout.html index cb494534..2536fae5 100644 --- a/mindplot/src/test/javascript/static/layout.html +++ b/mindplot/src/test/javascript/static/layout.html @@ -156,10 +156,17 @@
-