mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-25 23:44:54 +01:00
Fixed bug where adding a new node borke free positioning
This commit is contained in:
parent
069c39df6b
commit
c6fa09ec7d
@ -75,7 +75,7 @@ mindplot.layout.OriginalLayout = new Class({
|
||||
|
||||
this._layoutChildren(node, heightById);
|
||||
|
||||
this._fixOverlapping(node);
|
||||
this._fixOverlapping(node, heightById);
|
||||
}, this);
|
||||
},
|
||||
|
||||
@ -97,21 +97,30 @@ mindplot.layout.OriginalLayout = new Class({
|
||||
var heightChanged = node._branchHeight != newBranchHeight;
|
||||
node._heightChanged = heightChanged || parentHeightChanged;
|
||||
|
||||
|
||||
|
||||
if (childrenOrderMoved || heightChanged || parentHeightChanged) {
|
||||
var sorter = node.getSorter();
|
||||
var offsetById = sorter.computeOffsets(this._treeSet, node);
|
||||
var parentPosition = node.getPosition();
|
||||
|
||||
children.forEach(function(child) {
|
||||
var freeDisplacement = child.getFreeDisplacement();
|
||||
var freeDisplacement = {x:0, y:0};
|
||||
var childHeightChanged = heightById[child.getId()] != child._branchHeight;
|
||||
var offset = offsetById[child.getId()];
|
||||
|
||||
if (child.isFree()) {
|
||||
if (heightChanged && (parentHeightChanged || childHeightChanged)) {
|
||||
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 parentY = parentPosition.y;
|
||||
|
||||
var newPos = {x:parentX + freeDisplacement.x + offset.x, y:parentY + freeDisplacement.y + offset.y};
|
||||
var newPos = {x:parentX + offset.x, y:parentY + offset.y};
|
||||
|
||||
this._treeSet.updateBranchPosition(child, newPos);
|
||||
}.bind(this));
|
||||
@ -125,24 +134,26 @@ mindplot.layout.OriginalLayout = new Class({
|
||||
}, this);
|
||||
},
|
||||
|
||||
_fixOverlapping: function(node) {
|
||||
_fixOverlapping: function(node, heightById) {
|
||||
var children = this._treeSet.getChildren(node);
|
||||
if (node.hasFreeDisplacementChanged()) {
|
||||
var yOffset = node.getFreeDisplacement().y;
|
||||
var branchesToShift = this._treeSet.getBranchesInVerticalDirection(node, yOffset);
|
||||
this._treeSet.shiftBranchPosition(node, node.getFreeDisplacement().x, node.getFreeDisplacement().y);
|
||||
|
||||
branchesToShift.forEach(function(branch) {
|
||||
this._treeSet.shiftBranchPosition(branch, 0, yOffset);
|
||||
},this);
|
||||
|
||||
if ((node.isFree() && node.hasFreeDisplacementChanged())) {
|
||||
this._shiftBranches(node);
|
||||
}
|
||||
|
||||
children.forEach(function(child) {
|
||||
this._fixOverlapping(child);
|
||||
this._fixOverlapping(child, heightById);
|
||||
}, this);
|
||||
},
|
||||
|
||||
_shiftBranches: function(node) {
|
||||
this._treeSet.shiftBranchPosition(node, node.getFreeDisplacement().x, node.getFreeDisplacement().y);
|
||||
var branchesToShift = this._treeSet.getBranchesInVerticalDirection(node, node.getFreeDisplacement().y);
|
||||
branchesToShift.forEach(function(branch) {
|
||||
this._treeSet.shiftBranchPosition(branch, 0, node.getFreeDisplacement().y);
|
||||
},this);
|
||||
},
|
||||
|
||||
_nodesCollide: function(nodeA, nodeB) {
|
||||
var nodeAVertex = nodeA.getVertex();
|
||||
var nodeBVertex = nodeB.getVertex();
|
||||
|
@ -712,7 +712,7 @@ mindplot.layout.TestSuite = new Class({
|
||||
manager.layout(true);
|
||||
manager.plot("testFreePosition5", {width:1400, height:600});
|
||||
|
||||
//TODO(gb): fix this. when new node is connected, free layout is lost
|
||||
console.log("add node 23 to 12:");
|
||||
manager.addNode(23, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||
manager.connectNode(12,23,3);
|
||||
manager.layout(true);
|
||||
@ -722,6 +722,18 @@ mindplot.layout.TestSuite = new Class({
|
||||
manager.moveNode(4, {x:-300, y:190});
|
||||
manager.layout(true);
|
||||
manager.plot("testFreePosition7", {width:1400, height:600});
|
||||
|
||||
console.log("add node 24 to 3:");
|
||||
manager.addNode(24, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||
manager.connectNode(3,24,3);
|
||||
manager.layout(true);
|
||||
manager.plot("testFreePosition8", {width:1400, height:600});
|
||||
|
||||
console.log("add node 25 to 17:");
|
||||
manager.addNode(25, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||
manager.connectNode(17,25,0);
|
||||
manager.layout(true);
|
||||
manager.plot("testFreePosition9", {width:1400, height:600});
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -118,6 +118,8 @@
|
||||
<div id="testFreePosition5" class="col last"></div>
|
||||
<div id="testFreePosition6" class="col last"></div>
|
||||
<div id="testFreePosition7" class="col last"></div>
|
||||
<div id="testFreePosition8" class="col last"></div>
|
||||
<div id="testFreePosition9" class="col last"></div>
|
||||
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user