mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-29 17:04:59 +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 designerRel.filter(function (rel) {
|
||||||
return relIds.contains(rel.getId());
|
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});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
mindplot.commands.DragTopicCommand = new Class({
|
mindplot.commands.DragTopicCommand = new Class({
|
||||||
Extends:mindplot.Command,
|
Extends:mindplot.Command,
|
||||||
initialize: function(topicIds, position, order, parentTopic) {
|
initialize:function (topicIds, position, order, parentTopic) {
|
||||||
$assert(topicIds, "topicIds must be defined");
|
$assert(topicIds, "topicIds must be defined");
|
||||||
|
|
||||||
this._topicsIds = topicIds;
|
this._topicsIds = topicIds;
|
||||||
@ -31,21 +31,16 @@ mindplot.commands.DragTopicCommand = new Class({
|
|||||||
this._id = mindplot.Command._nextUUID();
|
this._id = mindplot.Command._nextUUID();
|
||||||
},
|
},
|
||||||
|
|
||||||
execute: function(commandContext) {
|
execute:function (commandContext) {
|
||||||
|
|
||||||
var topic = commandContext.findTopics([this._topicsIds])[0];
|
var topic = commandContext.findTopics([this._topicsIds])[0];
|
||||||
|
|
||||||
// Save old position ...
|
// Save old position ...
|
||||||
var origParentTopic = topic.getOutgoingConnectedTopic();
|
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 ...
|
// In this case, topics are positioned using order ...
|
||||||
origOrder = topic.getOrder();
|
var origOrder = topic.getOrder();
|
||||||
origPosition = topic.getPosition();
|
var origPosition = topic.getPosition();
|
||||||
|
|
||||||
// Disconnect topic ..
|
// Disconnect topic ..
|
||||||
if ($defined(origParentTopic) && origParentTopic != this._parentId) {
|
if ($defined(origParentTopic) && origParentTopic != this._parentId) {
|
||||||
@ -56,8 +51,7 @@ mindplot.commands.DragTopicCommand = new Class({
|
|||||||
if (this._order != null) {
|
if (this._order != null) {
|
||||||
topic.setOrder(this._order);
|
topic.setOrder(this._order);
|
||||||
} else if (this._position != null) {
|
} else if (this._position != null) {
|
||||||
// Set position ...
|
commandContext.moveTopic(topic, this._position);
|
||||||
topic.setPosition(this._position);
|
|
||||||
} else {
|
} else {
|
||||||
$assert("Illegal command state exception.");
|
$assert("Illegal command state exception.");
|
||||||
}
|
}
|
||||||
@ -83,7 +77,7 @@ mindplot.commands.DragTopicCommand = new Class({
|
|||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
undoExecute: function(commandContext) {
|
undoExecute:function (commandContext) {
|
||||||
this.execute(commandContext);
|
this.execute(commandContext);
|
||||||
}
|
}
|
||||||
});
|
});
|
@ -202,26 +202,14 @@ mindplot.layout.BalancedSorter = new Class({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
getDirection:function (treeSet, node) {
|
getChildDirection:function (treeSet, child) {
|
||||||
return node.getOrder() % 2 == 0 ? 1 : -1;
|
return child.getOrder() % 2 == 0 ? 1 : -1;
|
||||||
},
|
},
|
||||||
|
|
||||||
toString:function () {
|
toString:function () {
|
||||||
return "Balanced Sorter";
|
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) {
|
_getChildrenForOrder:function (parent, graph, order) {
|
||||||
return this._getSortedChildren(graph, parent).filter(function (child) {
|
return this._getSortedChildren(graph, parent).filter(function (child) {
|
||||||
return child.getOrder() % 2 == order % 2;
|
return child.getOrder() % 2 == order % 2;
|
||||||
|
@ -44,7 +44,7 @@ mindplot.layout.ChildrenSorterStrategy = new Class({
|
|||||||
throw "Method must be implemented";
|
throw "Method must be implemented";
|
||||||
},
|
},
|
||||||
|
|
||||||
getDirection: function(treeSet, node) {
|
getChildDirection: function(treeSet, node) {
|
||||||
throw "Method must be implemented";
|
throw "Method must be implemented";
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -58,8 +58,10 @@ mindplot.layout.LayoutManager = new Class({
|
|||||||
$assert($defined(position.y), "y can not be null");
|
$assert($defined(position.y), "y can not be null");
|
||||||
|
|
||||||
var node = this._treeSet.find(id);
|
var node = this._treeSet.find(id);
|
||||||
node.setFree(true);
|
// @Todo: this should not be here. This is broking the isolated node support...
|
||||||
node.setFreeDisplacement({x:position.x - node.getPosition().x, y:position.y - node.getPosition().y});
|
// 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) {
|
connectNode: function(parentId, childId, order) {
|
||||||
|
@ -112,7 +112,7 @@ mindplot.layout.OriginalLayout = new Class({
|
|||||||
var offset = offsetById[child.getId()];
|
var offset = offsetById[child.getId()];
|
||||||
|
|
||||||
var childFreeDisplacement = child.getFreeDisplacement();
|
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)) {
|
if ((direction > 0 && childFreeDisplacement.x < 0) || (direction < 0 && childFreeDisplacement.x > 0)) {
|
||||||
child.resetFreeDisplacement();
|
child.resetFreeDisplacement();
|
||||||
|
@ -16,12 +16,12 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
mindplot.layout.SymmetricSorter = new Class({
|
mindplot.layout.SymmetricSorter = new Class({
|
||||||
Extends: mindplot.layout.AbstractBasicSorter,
|
Extends:mindplot.layout.AbstractBasicSorter,
|
||||||
initialize:function() {
|
initialize:function () {
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
predict : function(graph, parent, node, position, free) {
|
predict:function (graph, parent, node, position, free) {
|
||||||
// If its a free node...
|
// If its a free node...
|
||||||
if (free) {
|
if (free) {
|
||||||
$assert($defined(position), "position cannot be null for predict in free positioning");
|
$assert($defined(position), "position cannot be null for predict in free positioning");
|
||||||
@ -29,13 +29,13 @@ mindplot.layout.SymmetricSorter = new Class({
|
|||||||
|
|
||||||
var rootNode = graph.getRootNode(parent);
|
var rootNode = graph.getRootNode(parent);
|
||||||
var direction = this._getRelativeDirection(rootNode.getPosition(), parent.getPosition());
|
var direction = this._getRelativeDirection(rootNode.getPosition(), parent.getPosition());
|
||||||
var limitXPos = parent.getPosition().x + direction * (parent.getSize().width/2 + node.getSize().width/2 + mindplot.layout.SymmetricSorter.INTERNODE_HORIZONTAL_PADDING);
|
var limitXPos = parent.getPosition().x + direction * (parent.getSize().width / 2 + node.getSize().width / 2 + mindplot.layout.SymmetricSorter.INTERNODE_HORIZONTAL_PADDING);
|
||||||
|
|
||||||
var xPos = direction > 0 ?
|
var xPos = direction > 0 ?
|
||||||
(position.x >= limitXPos ? position.x : limitXPos) :
|
(position.x >= limitXPos ? position.x : limitXPos) :
|
||||||
(position.x <= limitXPos ? position.x : limitXPos) ;
|
(position.x <= limitXPos ? position.x : limitXPos);
|
||||||
|
|
||||||
return [0, {x: xPos, y:position.y}];
|
return [0, {x:xPos, y:position.y}];
|
||||||
}
|
}
|
||||||
|
|
||||||
var rootNode = graph.getRootNode(parent);
|
var rootNode = graph.getRootNode(parent);
|
||||||
@ -57,11 +57,13 @@ mindplot.layout.SymmetricSorter = new Class({
|
|||||||
var direction = parent.getPosition().x > rootNode.getPosition().x ? 1 : -1;
|
var direction = parent.getPosition().x > rootNode.getPosition().x ? 1 : -1;
|
||||||
|
|
||||||
// No children...
|
// 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) {
|
if (children.length == 0) {
|
||||||
position = position || {x:parent.getPosition().x + direction, y:parent.getPosition().y};
|
position = position || {x:parent.getPosition().x + direction, y:parent.getPosition().y};
|
||||||
var pos = {
|
var pos = {
|
||||||
x: parent.getPosition().x + direction * (parent.getSize().width + mindplot.layout.SymmetricSorter.INTERNODE_HORIZONTAL_PADDING),
|
x:parent.getPosition().x + direction * (parent.getSize().width + mindplot.layout.SymmetricSorter.INTERNODE_HORIZONTAL_PADDING),
|
||||||
y:parent.getPosition().y
|
y:parent.getPosition().y
|
||||||
};
|
};
|
||||||
return [0, pos];
|
return [0, pos];
|
||||||
@ -71,13 +73,13 @@ mindplot.layout.SymmetricSorter = new Class({
|
|||||||
var result = null;
|
var result = null;
|
||||||
var last = children.getLast();
|
var last = children.getLast();
|
||||||
position = position || {x:last.getPosition().x + direction, y:last.getPosition().y + 1};
|
position = position || {x:last.getPosition().x + direction, y:last.getPosition().y + 1};
|
||||||
children.each(function(child, index) {
|
children.each(function (child, index) {
|
||||||
var cpos = child.getPosition();
|
var cpos = child.getPosition();
|
||||||
if (position.y > cpos.y) {
|
if (position.y > cpos.y) {
|
||||||
var yOffset = child == last ?
|
var yOffset = child == last ?
|
||||||
child.getSize().height + mindplot.layout.SymmetricSorter.INTERNODE_VERTICAL_PADDING * 2 :
|
child.getSize().height + mindplot.layout.SymmetricSorter.INTERNODE_VERTICAL_PADDING * 2 :
|
||||||
(children[index + 1].getPosition().y + children[index + 1].getSize().height / 2 - child.getPosition().y) / 2;
|
(children[index + 1].getPosition().y + children[index + 1].getSize().height / 2 - child.getPosition().y) / 2;
|
||||||
result = [child.getOrder() + 1,{x:cpos.x, y:cpos.y + yOffset}];
|
result = [child.getOrder() + 1, {x:cpos.x, y:cpos.y + yOffset}];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -93,7 +95,7 @@ mindplot.layout.SymmetricSorter = new Class({
|
|||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
|
|
||||||
insert: function(treeSet, parent, child, order) {
|
insert:function (treeSet, parent, child, order) {
|
||||||
var children = this._getSortedChildren(treeSet, parent);
|
var children = this._getSortedChildren(treeSet, parent);
|
||||||
$assert(order <= children.length, "Order must be continues and can not have holes. Order:" + order);
|
$assert(order <= children.length, "Order must be continues and can not have holes. Order:" + order);
|
||||||
|
|
||||||
@ -105,7 +107,7 @@ mindplot.layout.SymmetricSorter = new Class({
|
|||||||
child.setOrder(order);
|
child.setOrder(order);
|
||||||
},
|
},
|
||||||
|
|
||||||
detach:function(treeSet, node) {
|
detach:function (treeSet, node) {
|
||||||
var parent = treeSet.getParent(node);
|
var parent = treeSet.getParent(node);
|
||||||
var children = this._getSortedChildren(treeSet, parent);
|
var children = this._getSortedChildren(treeSet, parent);
|
||||||
var order = node.getOrder();
|
var order = node.getOrder();
|
||||||
@ -119,7 +121,7 @@ mindplot.layout.SymmetricSorter = new Class({
|
|||||||
node.setOrder(0);
|
node.setOrder(0);
|
||||||
},
|
},
|
||||||
|
|
||||||
computeOffsets:function(treeSet, node) {
|
computeOffsets:function (treeSet, node) {
|
||||||
$assert(treeSet, "treeSet can no be null.");
|
$assert(treeSet, "treeSet can no be null.");
|
||||||
$assert(node, "node can no be null.");
|
$assert(node, "node can no be null.");
|
||||||
|
|
||||||
@ -127,13 +129,13 @@ mindplot.layout.SymmetricSorter = new Class({
|
|||||||
|
|
||||||
// Compute heights ...
|
// Compute heights ...
|
||||||
var heights = children.map(
|
var heights = children.map(
|
||||||
function(child) {
|
function (child) {
|
||||||
return {id:child.getId(), order:child.getOrder(), position: child.getPosition(), width: child.getSize().width, height: this._computeChildrenHeight(treeSet, child)};
|
return {id:child.getId(), order:child.getOrder(), position:child.getPosition(), width:child.getSize().width, height:this._computeChildrenHeight(treeSet, child)};
|
||||||
}, this).reverse();
|
}, this).reverse();
|
||||||
|
|
||||||
// Compute the center of the branch ...
|
// Compute the center of the branch ...
|
||||||
var totalHeight = 0;
|
var totalHeight = 0;
|
||||||
heights.each(function(elem) {
|
heights.each(function (elem) {
|
||||||
totalHeight += elem.height;
|
totalHeight += elem.height;
|
||||||
});
|
});
|
||||||
var ysum = totalHeight / 2;
|
var ysum = totalHeight / 2;
|
||||||
@ -143,10 +145,7 @@ mindplot.layout.SymmetricSorter = new Class({
|
|||||||
for (var i = 0; i < heights.length; i++) {
|
for (var i = 0; i < heights.length; i++) {
|
||||||
ysum = ysum - heights[i].height;
|
ysum = ysum - heights[i].height;
|
||||||
var childNode = treeSet.find(heights[i].id);
|
var childNode = treeSet.find(heights[i].id);
|
||||||
var parent = treeSet.getParent(childNode);
|
var direction = this.getChildDirection(treeSet, childNode);
|
||||||
|
|
||||||
var rootNode = treeSet.getRootNode(childNode);
|
|
||||||
var direction = parent.getPosition().x > rootNode.getPosition().x ? 1 : -1;
|
|
||||||
|
|
||||||
var yOffset = ysum + heights[i].height / 2;
|
var yOffset = ysum + heights[i].height / 2;
|
||||||
var xOffset = direction * (heights[i].width / 2 + node.getSize().width / 2 + mindplot.layout.SymmetricSorter.INTERNODE_HORIZONTAL_PADDING);
|
var xOffset = direction * (heights[i].width / 2 + node.getSize().width / 2 + mindplot.layout.SymmetricSorter.INTERNODE_HORIZONTAL_PADDING);
|
||||||
@ -154,12 +153,12 @@ mindplot.layout.SymmetricSorter = new Class({
|
|||||||
$assert(!isNaN(xOffset), "xOffset can not be null");
|
$assert(!isNaN(xOffset), "xOffset can not be null");
|
||||||
$assert(!isNaN(yOffset), "yOffset can not be null");
|
$assert(!isNaN(yOffset), "yOffset can not be null");
|
||||||
|
|
||||||
result[heights[i].id] = {x:xOffset,y:yOffset};
|
result[heights[i].id] = {x:xOffset, y:yOffset};
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
|
|
||||||
verify:function(treeSet, node) {
|
verify:function (treeSet, node) {
|
||||||
// Check that all is consistent ...
|
// Check that all is consistent ...
|
||||||
var children = this._getSortedChildren(treeSet, node);
|
var children = this._getSortedChildren(treeSet, node);
|
||||||
|
|
||||||
@ -168,17 +167,31 @@ mindplot.layout.SymmetricSorter = new Class({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
getDirection: function(treeSet, node) {
|
getChildDirection:function (treeSet, child) {
|
||||||
var parent = treeSet.getParent(node);
|
$assert(treeSet, "treeSet can no be null.");
|
||||||
var rootNode = treeSet.getRootNode(node);
|
$assert(treeSet.getParent(child), "This should not happen");
|
||||||
return parent.getPosition().x >= rootNode.getPosition().x ? 1 : -1;
|
|
||||||
|
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() {
|
toString:function () {
|
||||||
return "Symmetric Sorter";
|
return "Symmetric Sorter";
|
||||||
},
|
},
|
||||||
|
|
||||||
_getVerticalPadding: function() {
|
_getVerticalPadding:function () {
|
||||||
return mindplot.layout.SymmetricSorter.INTERNODE_VERTICAL_PADDING;
|
return mindplot.layout.SymmetricSorter.INTERNODE_VERTICAL_PADDING;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user