Fixed bug for free positioning of balance sorted nodes

This commit is contained in:
Gonzalo Bellver
2012-01-26 17:20:48 -03:00
parent 015703d5b8
commit 306133cd5e
4 changed files with 82 additions and 15 deletions

View File

@@ -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;

View File

@@ -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 ) {