Added support for prediction when dragging a node
This commit is contained in:
@@ -323,7 +323,7 @@ mindplot.Designer = new Class({
|
||||
|
||||
// Create a new node ...
|
||||
var layoutManager = this._eventBussDispatcher.getLayoutManager();
|
||||
var result = layoutManager.predict(topic.getId(), null, mousePos);
|
||||
var result = layoutManager.predict(topic.getId(), null, mousePos);
|
||||
childModel.setOrder(result.order);
|
||||
|
||||
var position = result.position;
|
||||
|
@@ -41,7 +41,7 @@ mindplot.DragTopic = new Class({
|
||||
if (this.isFreeLayoutOn() && this.isConnected()) {
|
||||
var _layoutManager = this._layoutManager;
|
||||
var par = this.getConnectedToTopic();
|
||||
position = _layoutManager.predict(par.getId(), null, position, true).position;
|
||||
position = _layoutManager.predict(par.getId(), this._draggedNode.getId(), position, true).position;
|
||||
}
|
||||
this._position.setValue(position.x, position.y);
|
||||
|
||||
|
@@ -38,9 +38,19 @@ mindplot.layout.BalancedSorter = new Class({
|
||||
return {order:0, position:{x: xPos, y:position.y}};
|
||||
}
|
||||
|
||||
// Regular node
|
||||
var rootNode = graph.getRootNode(parent);
|
||||
|
||||
// If it is a dragged node...
|
||||
if (node) {
|
||||
var nodeDirection = this._getRelativeDirection(rootNode.getPosition(), node.getPosition());
|
||||
var positionDirection = this._getRelativeDirection(rootNode.getPosition(), position);
|
||||
var siblings = graph.getSiblings(node);
|
||||
|
||||
if (siblings.length == 0 && nodeDirection == positionDirection) {
|
||||
return [node.getOrder(), node.getPosition()];
|
||||
}
|
||||
}
|
||||
|
||||
if (!position) {
|
||||
var right = this._getChildrenForOrder(parent, graph, 0);
|
||||
var left = this._getChildrenForOrder(parent, graph, 1);
|
||||
@@ -48,14 +58,17 @@ mindplot.layout.BalancedSorter = new Class({
|
||||
// Filter nodes on one side..
|
||||
var order = position ? (position.x > rootNode.getPosition().x ? 0 : 1) : ((right.length - left.length) > 0 ? 1 : 0);
|
||||
var direction = order%2 == 0 ? 1 : -1;
|
||||
var children = this._getChildrenForOrder(parent, graph, order);
|
||||
|
||||
// Exclude the dragged node (if set)
|
||||
var children = this._getChildrenForOrder(parent, graph, order).filter(function(child) {
|
||||
return child != node;
|
||||
});
|
||||
|
||||
// No children?
|
||||
if (children.length == 0) {
|
||||
return [order, {x:parent.getPosition().x + direction * (parent.getSize().width + mindplot.layout.BalancedSorter.INTERNODE_HORIZONTAL_PADDING * 2), y:parent.getPosition().y}];
|
||||
}
|
||||
|
||||
|
||||
// Try to fit within ...
|
||||
var result = null;
|
||||
var last = children.getLast();
|
||||
@@ -166,24 +179,11 @@ mindplot.layout.BalancedSorter = new Class({
|
||||
return result;
|
||||
},
|
||||
|
||||
_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(node) {
|
||||
return node.getOrder() % 2 == order % 2;
|
||||
});
|
||||
},
|
||||
|
||||
verify:function(treeSet, node) {
|
||||
// Check that all is consistent ...
|
||||
var children = this._getChildrenForOrder(node, treeSet, node.getOrder());
|
||||
|
||||
|
||||
// All odd ordered nodes should be "continuous" by themselves
|
||||
// All even numbered nodes should be "continuous" by themselves
|
||||
var factor = node.getOrder() % 2 == 0 ? 2 : 1;
|
||||
@@ -201,8 +201,31 @@ mindplot.layout.BalancedSorter = new Class({
|
||||
return "Balanced Sorter";
|
||||
},
|
||||
|
||||
_getVerticalPadding:function() {
|
||||
_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;
|
||||
});
|
||||
},
|
||||
|
||||
_getVerticalPadding: function() {
|
||||
return mindplot.layout.BalancedSorter.INTERNODE_VERTICAL_PADDING;
|
||||
},
|
||||
|
||||
_getRelativeDirection: function(reference, position) {
|
||||
var offset = position.x - reference.x;
|
||||
return offset > 0 ? 1 : (offset < 0 ? -1 : 0);
|
||||
}
|
||||
|
||||
});
|
||||
|
@@ -106,9 +106,13 @@ mindplot.layout.LayoutManager = new Class({
|
||||
$assert($defined(parentId), "parentId can not be null");
|
||||
|
||||
var parent = this._treeSet.find(parentId);
|
||||
var node = nodeId == null ? null : this._treeSet.find(nodeId);
|
||||
var node = nodeId ? this._treeSet.find(nodeId) : null;
|
||||
var sorter = parent.getSorter();
|
||||
|
||||
var result = sorter.predict(this._treeSet, parent, node, position, free);
|
||||
$assert(result[0] != null, "Prediction order cannot be null");
|
||||
$assert(result[1] != null, "Prediction position cannot be null");
|
||||
$assert(result[1].x != null && result[1].y != null, "Prediction position is not valid");
|
||||
return {order:result[0],position:result[1]};
|
||||
},
|
||||
|
||||
|
Reference in New Issue
Block a user