Fixed bug where free positioning could cause sibling overlapping

This commit is contained in:
Gonzalo Bellver
2012-01-26 15:52:32 -03:00
parent 9ada52d720
commit 015703d5b8
4 changed files with 67 additions and 4 deletions

View File

@@ -147,12 +147,30 @@ mindplot.layout.OriginalLayout = new Class({
},
_shiftBranches: function(node, heightById) {
var branchesToShift = this._treeSet.getBranchesInVerticalDirection(node, node.getFreeDisplacement().y);
var shiftedBranches = [node];
var siblingsToShift = this._treeSet.getSiblingsInVerticalDirection(node, node.getFreeDisplacement().y);
var last = node;
siblingsToShift.forEach(function(sibling) {
var overlappingOccurs = shiftedBranches.some(function(shiftedBranch) {
return this._branchesOverlap(shiftedBranch, sibling, heightById);
}, this);
if (!sibling.isFree() || overlappingOccurs) {
this._treeSet.shiftBranchPosition(sibling, 0, node.getFreeDisplacement().y);
shiftedBranches.push(sibling);
}
}, this);
var branchesToShift = this._treeSet.getBranchesInVerticalDirection(node, node.getFreeDisplacement().y);
branchesToShift.forEach(function(branch) {
if (this._branchesOverlap(branch, last, heightById)) {
var overlappingOccurs = shiftedBranches.some(function(shiftedBranch) {
return this._branchesOverlap(shiftedBranch, branch, heightById);
}, this);
if (overlappingOccurs) {
this._treeSet.shiftBranchPosition(branch, 0, node.getFreeDisplacement().y);
shiftedBranches.push(branch);
}
last = branch;
},this);

View File

@@ -232,12 +232,20 @@ mindplot.layout.RootedTreeSet = new Class({
}.bind(this));
},
getBranchesInVerticalDirection: function(node, yOffset) {
getSiblingsInVerticalDirection: function(node, yOffset) {
// siblings with lower or higher order, depending on the direction of the offset
var siblings = this.getSiblings(node).filter(function(sibling) {
return yOffset < 0 ? sibling.getOrder() < node.getOrder() : sibling.getOrder() > node.getOrder();
});
if (yOffset < 0 ) {
siblings.reverse();
}
return siblings;
},
getBranchesInVerticalDirection: function(node, yOffset) {
// direct descendants of the root that do not contain the node and are on the same side
// and on the direction of the offset
var rootNode = this.getRootNode(node);
@@ -252,7 +260,7 @@ mindplot.layout.RootedTreeSet = new Class({
return sameSide && sameDirection;
}, this);
return siblings.combine(rootDescendants);
return rootDescendants;
}
});