mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-05 07:03:24 +01:00
- Fix position of isolated nodes ...
This commit is contained in:
parent
39c2b37a1f
commit
890364f13c
@ -294,6 +294,12 @@ mindplot.CommandContext = new Class({
|
||||
return designerRel.filter(function (rel) {
|
||||
return relIds.contains(rel.getId());
|
||||
});
|
||||
},
|
||||
|
||||
moveTopic:function (topic, position) {
|
||||
$assert(topic, "topic cannot be null");
|
||||
$assert(position, "position cannot be null");
|
||||
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeMoveEvent, {node:topic.getModel(), position:position});
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -37,15 +37,10 @@ mindplot.commands.DragTopicCommand = new Class({
|
||||
|
||||
// Save old position ...
|
||||
var origParentTopic = topic.getOutgoingConnectedTopic();
|
||||
var origOrder = null;
|
||||
var origPosition = null;
|
||||
|
||||
// Cache nodes position ...
|
||||
var topics = designer.getModel().getTopics();
|
||||
|
||||
// In this case, topics are positioned using order ...
|
||||
origOrder = topic.getOrder();
|
||||
origPosition = topic.getPosition();
|
||||
var origOrder = topic.getOrder();
|
||||
var origPosition = topic.getPosition();
|
||||
|
||||
// Disconnect topic ..
|
||||
if ($defined(origParentTopic) && origParentTopic != this._parentId) {
|
||||
@ -56,8 +51,7 @@ mindplot.commands.DragTopicCommand = new Class({
|
||||
if (this._order != null) {
|
||||
topic.setOrder(this._order);
|
||||
} else if (this._position != null) {
|
||||
// Set position ...
|
||||
topic.setPosition(this._position);
|
||||
commandContext.moveTopic(topic, this._position);
|
||||
} else {
|
||||
$assert("Illegal command state exception.");
|
||||
}
|
||||
|
@ -202,26 +202,14 @@ mindplot.layout.BalancedSorter = new Class({
|
||||
}
|
||||
},
|
||||
|
||||
getDirection:function (treeSet, node) {
|
||||
return node.getOrder() % 2 == 0 ? 1 : -1;
|
||||
getChildDirection:function (treeSet, child) {
|
||||
return child.getOrder() % 2 == 0 ? 1 : -1;
|
||||
},
|
||||
|
||||
toString:function () {
|
||||
return "Balanced Sorter";
|
||||
},
|
||||
|
||||
_getOrderForPosition:function (rootNode, position) {
|
||||
return position.x > rootNode.getPosition().x ? 0 : 1;
|
||||
},
|
||||
|
||||
_getChildrenForSide:function (parent, graph, position) {
|
||||
position = position || {x:parent.getPosition().x + 1, y:parent.getPosition().y + 1};
|
||||
var rootPosition = graph.getRootNode(parent).getPosition();
|
||||
return graph.getChildren(parent).filter(function (child) {
|
||||
return position.x > rootPosition.x ? child.getPosition().x > rootPosition.x : child.getPosition().x < rootPosition.x;
|
||||
});
|
||||
},
|
||||
|
||||
_getChildrenForOrder:function (parent, graph, order) {
|
||||
return this._getSortedChildren(graph, parent).filter(function (child) {
|
||||
return child.getOrder() % 2 == order % 2;
|
||||
|
@ -44,7 +44,7 @@ mindplot.layout.ChildrenSorterStrategy = new Class({
|
||||
throw "Method must be implemented";
|
||||
},
|
||||
|
||||
getDirection: function(treeSet, node) {
|
||||
getChildDirection: function(treeSet, node) {
|
||||
throw "Method must be implemented";
|
||||
},
|
||||
|
||||
|
@ -58,8 +58,10 @@ mindplot.layout.LayoutManager = new Class({
|
||||
$assert($defined(position.y), "y can not be null");
|
||||
|
||||
var node = this._treeSet.find(id);
|
||||
node.setFree(true);
|
||||
node.setFreeDisplacement({x:position.x - node.getPosition().x, y:position.y - node.getPosition().y});
|
||||
// @Todo: this should not be here. This is broking the isolated node support...
|
||||
// node.setFree(true);
|
||||
// node.setFreeDisplacement({x:position.x - node.getPosition().x, y:position.y - node.getPosition().y});
|
||||
node.setPosition(position);
|
||||
},
|
||||
|
||||
connectNode: function(parentId, childId, order) {
|
||||
|
@ -112,7 +112,7 @@ mindplot.layout.OriginalLayout = new Class({
|
||||
var offset = offsetById[child.getId()];
|
||||
|
||||
var childFreeDisplacement = child.getFreeDisplacement();
|
||||
var direction = node.getSorter().getDirection(this._treeSet, child);
|
||||
var direction = node.getSorter().getChildDirection(this._treeSet, child);
|
||||
|
||||
if ((direction > 0 && childFreeDisplacement.x < 0) || (direction < 0 && childFreeDisplacement.x > 0)) {
|
||||
child.resetFreeDisplacement();
|
||||
|
@ -57,7 +57,9 @@ mindplot.layout.SymmetricSorter = new Class({
|
||||
var direction = parent.getPosition().x > rootNode.getPosition().x ? 1 : -1;
|
||||
|
||||
// No children...
|
||||
var children = graph.getChildren(parent).filter(function(child) { return child != node; });
|
||||
var children = graph.getChildren(parent).filter(function (child) {
|
||||
return child != node;
|
||||
});
|
||||
if (children.length == 0) {
|
||||
position = position || {x:parent.getPosition().x + direction, y:parent.getPosition().y};
|
||||
var pos = {
|
||||
@ -143,10 +145,7 @@ mindplot.layout.SymmetricSorter = new Class({
|
||||
for (var i = 0; i < heights.length; i++) {
|
||||
ysum = ysum - heights[i].height;
|
||||
var childNode = treeSet.find(heights[i].id);
|
||||
var parent = treeSet.getParent(childNode);
|
||||
|
||||
var rootNode = treeSet.getRootNode(childNode);
|
||||
var direction = parent.getPosition().x > rootNode.getPosition().x ? 1 : -1;
|
||||
var direction = this.getChildDirection(treeSet, childNode);
|
||||
|
||||
var yOffset = ysum + heights[i].height / 2;
|
||||
var xOffset = direction * (heights[i].width / 2 + node.getSize().width / 2 + mindplot.layout.SymmetricSorter.INTERNODE_HORIZONTAL_PADDING);
|
||||
@ -168,10 +167,24 @@ mindplot.layout.SymmetricSorter = new Class({
|
||||
}
|
||||
},
|
||||
|
||||
getDirection: function(treeSet, node) {
|
||||
var parent = treeSet.getParent(node);
|
||||
var rootNode = treeSet.getRootNode(node);
|
||||
return parent.getPosition().x >= rootNode.getPosition().x ? 1 : -1;
|
||||
getChildDirection:function (treeSet, child) {
|
||||
$assert(treeSet, "treeSet can no be null.");
|
||||
$assert(treeSet.getParent(child), "This should not happen");
|
||||
|
||||
var result;
|
||||
var rootNode = treeSet.getRootNode(child);
|
||||
if (treeSet.getParent(child) == rootNode) {
|
||||
// This is the case of a isolated child ... In this case, the directions is based on the root.
|
||||
result = Math.sign(rootNode.getPosition().x);
|
||||
} else {
|
||||
// if this is not the case, honor the direction of the parent ...
|
||||
var parent = treeSet.getParent(child);
|
||||
var grandParent = treeSet.getParent(parent);
|
||||
var sorter = grandParent.getSorter();
|
||||
result = sorter.getChildDirection(treeSet, parent);
|
||||
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
toString:function () {
|
||||
|
Loading…
Reference in New Issue
Block a user