mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-25 15:37:56 +01:00
Free position layout fixes
This commit is contained in:
parent
42f2763ec0
commit
402226afbc
@ -105,25 +105,15 @@ mindplot.layout.OriginalLayout = new Class({
|
|||||||
var parentPosition = node.getPosition();
|
var parentPosition = node.getPosition();
|
||||||
|
|
||||||
children.forEach(function(child) {
|
children.forEach(function(child) {
|
||||||
var childHeightChanged = heightById[child.getId()] != child._branchHeight;
|
|
||||||
var offset = offsetById[child.getId()];
|
var offset = offsetById[child.getId()];
|
||||||
|
|
||||||
if (child.isFree()) {
|
offset.x += child.getFreeDisplacement().x;
|
||||||
if (heightChanged && (parentHeightChanged || childHeightChanged)) {
|
offset.y += child.getFreeDisplacement().y;
|
||||||
offset.x += child.getFreeDisplacement().x;
|
|
||||||
this._shiftBranches(child);
|
|
||||||
} else {
|
|
||||||
offset.x += child.getFreeDisplacement().x;
|
|
||||||
offset.y += child.getFreeDisplacement().y;
|
|
||||||
this._shiftBranches(child);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var parentX = parentPosition.x;
|
var parentX = parentPosition.x;
|
||||||
var parentY = parentPosition.y;
|
var parentY = parentPosition.y;
|
||||||
|
|
||||||
var newPos = {x:parentX + offset.x, y:parentY + offset.y};
|
var newPos = {x:parentX + offset.x, y:parentY + offset.y};
|
||||||
|
|
||||||
this._treeSet.updateBranchPosition(child, newPos);
|
this._treeSet.updateBranchPosition(child, newPos);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
@ -139,8 +129,8 @@ mindplot.layout.OriginalLayout = new Class({
|
|||||||
_fixOverlapping: function(node, heightById) {
|
_fixOverlapping: function(node, heightById) {
|
||||||
var children = this._treeSet.getChildren(node);
|
var children = this._treeSet.getChildren(node);
|
||||||
|
|
||||||
if ((node.isFree() && node.hasFreeDisplacementChanged())) {
|
if (node.isFree()) {
|
||||||
this._shiftBranches(node);
|
this._shiftBranches(node, heightById);
|
||||||
}
|
}
|
||||||
|
|
||||||
children.forEach(function(child) {
|
children.forEach(function(child) {
|
||||||
@ -148,19 +138,25 @@ mindplot.layout.OriginalLayout = new Class({
|
|||||||
}, this);
|
}, this);
|
||||||
},
|
},
|
||||||
|
|
||||||
_shiftBranches: function(node) {
|
_shiftBranches: function(node, heightById) {
|
||||||
this._treeSet.shiftBranchPosition(node, node.getFreeDisplacement().x, node.getFreeDisplacement().y);
|
|
||||||
var branchesToShift = this._treeSet.getBranchesInVerticalDirection(node, node.getFreeDisplacement().y);
|
var branchesToShift = this._treeSet.getBranchesInVerticalDirection(node, node.getFreeDisplacement().y);
|
||||||
|
|
||||||
|
var last = node;
|
||||||
branchesToShift.forEach(function(branch) {
|
branchesToShift.forEach(function(branch) {
|
||||||
this._treeSet.shiftBranchPosition(branch, 0, node.getFreeDisplacement().y);
|
if (this._branchesOverlap(branch, last, heightById)) {
|
||||||
|
this._treeSet.shiftBranchPosition(branch, 0, node.getFreeDisplacement().y);
|
||||||
|
}
|
||||||
|
last = branch;
|
||||||
},this);
|
},this);
|
||||||
},
|
},
|
||||||
|
|
||||||
_nodesCollide: function(nodeA, nodeB) {
|
_branchesOverlap: function(branchA, branchB, heightById) {
|
||||||
var nodeAVertex = nodeA.getVertex();
|
var topA = branchA.getPosition().y - heightById[branchA.getId()]/2;
|
||||||
var nodeBVertex = nodeB.getVertex();
|
var bottomA = branchA.getPosition().y + heightById[branchA.getId()]/2;
|
||||||
return nodeAVertex.a.x < nodeBVertex.b.x && nodeAVertex.b.x > nodeBVertex.a.x &&
|
var topB = branchB.getPosition().y - heightById[branchB.getId()]/2;
|
||||||
nodeAVertex.a.y < nodeBVertex.b.y && nodeAVertex.b.y > nodeBVertex.a.y;
|
var bottomB = branchB.getPosition().y + heightById[branchB.getId()]/2;
|
||||||
|
|
||||||
|
return !(topA >= bottomB || bottomA <= topB);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -235,10 +235,7 @@ mindplot.layout.RootedTreeSet = new Class({
|
|||||||
getBranchesInVerticalDirection: function(node, yOffset) {
|
getBranchesInVerticalDirection: 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
|
||||||
var siblings = this.getSiblings(node).filter(function(sibling) {
|
var siblings = this.getSiblings(node).filter(function(sibling) {
|
||||||
if (yOffset < 0)
|
return yOffset < 0 ? sibling.getOrder() < node.getOrder() : sibling.getOrder() > node.getOrder();
|
||||||
return sibling.getOrder() < node.getOrder();
|
|
||||||
else
|
|
||||||
return sibling.getOrder() > node.getOrder();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// direct descendants of the root that do not contain the node and are on the same side
|
// direct descendants of the root that do not contain the node and are on the same side
|
||||||
|
Loading…
Reference in New Issue
Block a user