Added support for predict when dragging a symmetric sorted node
This commit is contained in:
@@ -58,6 +58,11 @@ mindplot.layout.AbstractBasicSorter = new Class({
|
||||
return a.getOrder() - b.getOrder()
|
||||
});
|
||||
return result;
|
||||
},
|
||||
|
||||
_getRelativeDirection: function(reference, position) {
|
||||
var offset = position.x - reference.x;
|
||||
return offset > 0 ? 1 : (offset < 0 ? -1 : 0);
|
||||
}
|
||||
|
||||
});
|
||||
|
@@ -42,11 +42,13 @@ mindplot.layout.BalancedSorter = new Class({
|
||||
|
||||
// If it is a dragged node...
|
||||
if (node) {
|
||||
$assert($defined(position), "position cannot be null for predict in dragging");
|
||||
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) {
|
||||
var sameParent = parent == graph.getParent(node);
|
||||
if (siblings.length == 0 && nodeDirection == positionDirection && sameParent) {
|
||||
return [node.getOrder(), node.getPosition()];
|
||||
}
|
||||
}
|
||||
@@ -183,7 +185,6 @@ mindplot.layout.BalancedSorter = new Class({
|
||||
// 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;
|
||||
@@ -221,13 +222,7 @@ mindplot.layout.BalancedSorter = new Class({
|
||||
|
||||
_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);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
mindplot.layout.BalancedSorter.INTERNODE_VERTICAL_PADDING = 5;
|
||||
|
@@ -37,12 +37,26 @@ mindplot.layout.SymmetricSorter = new Class({
|
||||
return [0, {x: xPos, y:position.y}];
|
||||
}
|
||||
|
||||
// Regular node
|
||||
var rootNode = graph.getRootNode(parent);
|
||||
|
||||
// If it is a dragged node...
|
||||
if (node) {
|
||||
$assert($defined(position), "position cannot be null for predict in dragging");
|
||||
var nodeDirection = this._getRelativeDirection(rootNode.getPosition(), node.getPosition());
|
||||
var positionDirection = this._getRelativeDirection(rootNode.getPosition(), position);
|
||||
var siblings = graph.getSiblings(node);
|
||||
|
||||
var sameParent = parent == graph.getParent(node);
|
||||
if (siblings.length == 0 && nodeDirection == positionDirection && sameParent) {
|
||||
return [node.getOrder(), node.getPosition()];
|
||||
}
|
||||
}
|
||||
|
||||
// Regular node
|
||||
var direction = parent.getPosition().x > rootNode.getPosition().x ? 1 : -1;
|
||||
|
||||
// No children...
|
||||
var children = graph.getChildren(parent);
|
||||
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 = {
|
||||
|
Reference in New Issue
Block a user