Fixed bug where free positioning could cause sibling overlapping
This commit is contained in:
@@ -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);
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
});
|
||||
|
Reference in New Issue
Block a user