predict method refactored: it now includes the node for the prediction
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(), 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(), position, true).position;
|
||||
position = _layoutManager.predict(par.getId(), null, position, true).position;
|
||||
}
|
||||
this._position.setValue(position.x, position.y);
|
||||
|
||||
@@ -56,7 +56,7 @@ mindplot.DragTopic = new Class({
|
||||
// In case is not free, pivot must be draw ...
|
||||
if (this.isConnected() && !this.isFreeLayoutOn()) {
|
||||
var parent = this.getConnectedToTopic();
|
||||
var predict = this._layoutManager.predict(parent.getId(), this.getPosition());
|
||||
var predict = this._layoutManager.predict(parent.getId(), this._draggedNode.getId(), this.getPosition());
|
||||
if (this._order != predict.order) {
|
||||
var dragPivot = this._getDragPivot();
|
||||
var pivotPosition = predict.position;
|
||||
@@ -122,7 +122,7 @@ mindplot.DragTopic = new Class({
|
||||
$assert(parent, 'Parent connection node can not be null.');
|
||||
|
||||
// Where it should be connected ?
|
||||
var predict = designer._eventBussDispatcher._layoutManager.predict(parent.getId(), this.getPosition());
|
||||
var predict = designer._eventBussDispatcher._layoutManager.predict(parent.getId(), this._draggedNode.getId(), this.getPosition());
|
||||
|
||||
// Connect pivot ...
|
||||
var dragPivot = this._getDragPivot();
|
||||
|
@@ -22,7 +22,23 @@ mindplot.layout.BalancedSorter = new Class({
|
||||
|
||||
},
|
||||
|
||||
predict : function(parent, graph, position) {
|
||||
predict : function(graph, parent, node, position, free) {
|
||||
// If its a free node...
|
||||
if (free) {
|
||||
$assert($defined(position), "position cannot be null for predict in free positioning");
|
||||
|
||||
//TODO(gb): check this. Should direction be obtained by the sorter?
|
||||
var rootNode = graph.getRootNode(parent);
|
||||
var direction = parent.getPosition().x > rootNode.getPosition().x ? 1 : -1;
|
||||
|
||||
var xPos = direction > 0 ?
|
||||
(position.x >= parent.getPosition().x ? position.x : parent.getPosition().x) :
|
||||
(position.x <= parent.getPosition().x ? position.x : parent.getPosition().x);
|
||||
|
||||
return {order:0, position:{x: xPos, y:position.y}};
|
||||
}
|
||||
|
||||
// Regular node
|
||||
var rootNode = graph.getRootNode(parent);
|
||||
|
||||
if (!position) {
|
||||
|
@@ -36,7 +36,7 @@ mindplot.layout.ChildrenSorterStrategy = new Class({
|
||||
throw "Method must be implemented";
|
||||
},
|
||||
|
||||
predict:function(treeSet, parent, position) {
|
||||
predict:function(treeSet, parent, node, position, free) {
|
||||
throw "Method must be implemented";
|
||||
},
|
||||
|
||||
|
@@ -102,27 +102,13 @@ mindplot.layout.LayoutManager = new Class({
|
||||
return this;
|
||||
},
|
||||
|
||||
predict: function(parentId, position, free) {
|
||||
predict: function(parentId, nodeId, position, free) {
|
||||
$assert($defined(parentId), "parentId can not be null");
|
||||
|
||||
var parent = this._treeSet.find(parentId);
|
||||
var node = nodeId == null ? null : this._treeSet.find(nodeId);
|
||||
var sorter = parent.getSorter();
|
||||
|
||||
if (free) {
|
||||
$assert($defined(position), "position cannot be null for predict in free positioning");
|
||||
|
||||
//TODO(gb): check this. Should direction be obtained by the sorter?
|
||||
var rootNode = this._treeSet.getRootNode(parent);
|
||||
var direction = parent.getPosition().x > rootNode.getPosition().x ? 1 : -1;
|
||||
|
||||
var xPos = direction > 0 ?
|
||||
(position.x >= parent.getPosition().x ? position.x : parent.getPosition().x) :
|
||||
(position.x <= parent.getPosition().x ? position.x : parent.getPosition().x);
|
||||
|
||||
return {order:0, position:{x: xPos, y:position.y}};
|
||||
}
|
||||
|
||||
|
||||
var result = sorter.predict(parent, this._treeSet, position);
|
||||
var result = sorter.predict(this._treeSet, parent, node, position, free);
|
||||
return {order:result[0],position:result[1]};
|
||||
},
|
||||
|
||||
|
@@ -21,7 +21,23 @@ mindplot.layout.SymmetricSorter = new Class({
|
||||
|
||||
},
|
||||
|
||||
predict : function(parent, graph, position) {
|
||||
predict : function(graph, parent, node, position, free) {
|
||||
// If its a free node...
|
||||
if (free) {
|
||||
$assert($defined(position), "position cannot be null for predict in free positioning");
|
||||
|
||||
//TODO(gb): check this. Should direction be obtained by the sorter?
|
||||
var rootNode = graph.getRootNode(parent);
|
||||
var direction = parent.getPosition().x > rootNode.getPosition().x ? 1 : -1;
|
||||
|
||||
var xPos = direction > 0 ?
|
||||
(position.x >= parent.getPosition().x ? position.x : parent.getPosition().x) :
|
||||
(position.x <= parent.getPosition().x ? position.x : parent.getPosition().x);
|
||||
|
||||
return [0, {x: xPos, y:position.y}];
|
||||
}
|
||||
|
||||
// Regular node
|
||||
var rootNode = graph.getRootNode(parent);
|
||||
var direction = parent.getPosition().x > rootNode.getPosition().x ? 1 : -1;
|
||||
|
||||
|
Reference in New Issue
Block a user