Fixed bug for free positioning of balance sorted nodes
This commit is contained in:
@@ -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;
|
||||
|
@@ -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 ) {
|
||||
|
Reference in New Issue
Block a user