mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-25 23:44:54 +01:00
Added support for predict when dragging a symmetric sorted node
This commit is contained in:
parent
d632a079b1
commit
a0b838a7a6
@ -58,6 +58,11 @@ mindplot.layout.AbstractBasicSorter = new Class({
|
|||||||
return a.getOrder() - b.getOrder()
|
return a.getOrder() - b.getOrder()
|
||||||
});
|
});
|
||||||
return result;
|
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 it is a dragged node...
|
||||||
if (node) {
|
if (node) {
|
||||||
|
$assert($defined(position), "position cannot be null for predict in dragging");
|
||||||
var nodeDirection = this._getRelativeDirection(rootNode.getPosition(), node.getPosition());
|
var nodeDirection = this._getRelativeDirection(rootNode.getPosition(), node.getPosition());
|
||||||
var positionDirection = this._getRelativeDirection(rootNode.getPosition(), position);
|
var positionDirection = this._getRelativeDirection(rootNode.getPosition(), position);
|
||||||
var siblings = graph.getSiblings(node);
|
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()];
|
return [node.getOrder(), node.getPosition()];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -183,7 +185,6 @@ mindplot.layout.BalancedSorter = new Class({
|
|||||||
// Check that all is consistent ...
|
// Check that all is consistent ...
|
||||||
var children = this._getChildrenForOrder(node, treeSet, node.getOrder());
|
var children = this._getChildrenForOrder(node, treeSet, node.getOrder());
|
||||||
|
|
||||||
|
|
||||||
// All odd ordered nodes should be "continuous" by themselves
|
// All odd ordered nodes should be "continuous" by themselves
|
||||||
// All even numbered nodes should be "continuous" by themselves
|
// All even numbered nodes should be "continuous" by themselves
|
||||||
var factor = node.getOrder() % 2 == 0 ? 2 : 1;
|
var factor = node.getOrder() % 2 == 0 ? 2 : 1;
|
||||||
@ -221,13 +222,7 @@ mindplot.layout.BalancedSorter = new Class({
|
|||||||
|
|
||||||
_getVerticalPadding: function() {
|
_getVerticalPadding: function() {
|
||||||
return mindplot.layout.BalancedSorter.INTERNODE_VERTICAL_PADDING;
|
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;
|
mindplot.layout.BalancedSorter.INTERNODE_VERTICAL_PADDING = 5;
|
||||||
|
@ -37,12 +37,26 @@ mindplot.layout.SymmetricSorter = new Class({
|
|||||||
return [0, {x: xPos, y:position.y}];
|
return [0, {x: xPos, y:position.y}];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Regular node
|
|
||||||
var rootNode = graph.getRootNode(parent);
|
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;
|
var direction = parent.getPosition().x > rootNode.getPosition().x ? 1 : -1;
|
||||||
|
|
||||||
// No children...
|
// No children...
|
||||||
var children = graph.getChildren(parent);
|
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 = {
|
||||||
|
@ -133,6 +133,9 @@
|
|||||||
<div id="testSymmetricPredict3"></div>
|
<div id="testSymmetricPredict3"></div>
|
||||||
<div id="testSymmetricPredict4"></div>
|
<div id="testSymmetricPredict4"></div>
|
||||||
<div id="testSymmetricPredict5"></div>
|
<div id="testSymmetricPredict5"></div>
|
||||||
|
|
||||||
|
<h3>testSymmetricDragPredict:</h3>
|
||||||
|
<div id="testSymmetricDragPredict1"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="freeTest" style="display: none;">
|
<div id="freeTest" style="display: none;">
|
||||||
|
@ -23,6 +23,7 @@ mindplot.layout.SymmetricTestSuite = new Class({
|
|||||||
|
|
||||||
this.testSymmetry();
|
this.testSymmetry();
|
||||||
this.testSymmetricPredict();
|
this.testSymmetricPredict();
|
||||||
|
this.testSymmetricDragPredict();
|
||||||
},
|
},
|
||||||
|
|
||||||
testSymmetry: function() {
|
testSymmetry: function() {
|
||||||
@ -213,5 +214,53 @@ mindplot.layout.SymmetricTestSuite = new Class({
|
|||||||
$assert(prediction5d.position.y == manager.find(10).getPosition().y &&
|
$assert(prediction5d.position.y == manager.find(10).getPosition().y &&
|
||||||
prediction5d.position.x < manager.find(10).getPosition().x, "Prediction is incorrectly positioned");
|
prediction5d.position.x < manager.find(10).getPosition().x, "Prediction is incorrectly positioned");
|
||||||
$assert(prediction5d.order == 0, "Prediction order should be 0");
|
$assert(prediction5d.order == 0, "Prediction order should be 0");
|
||||||
|
|
||||||
|
console.log("OK!\n\n");
|
||||||
|
},
|
||||||
|
|
||||||
|
testSymmetricDragPredict: function() {
|
||||||
|
console.log("testSymmetricDragPredict:");
|
||||||
|
var position = {x:0,y:0};
|
||||||
|
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
|
||||||
|
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(0, 1, 1);
|
||||||
|
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position).connectNode(1, 2, 0);
|
||||||
|
manager.layout();
|
||||||
|
|
||||||
|
// Graph 1
|
||||||
|
var graph1 = manager.plot("testSymmetricDragPredict1", {width:1000, height:400});
|
||||||
|
|
||||||
|
var prediction1a = manager.predict(1, 2, {x:-250, y:-20});
|
||||||
|
this._plotPrediction(graph1, prediction1a);
|
||||||
|
$assert(prediction1a.position.x == manager.find(2).getPosition().x &&
|
||||||
|
prediction1a.position.y == manager.find(2).getPosition().y, "Prediction position should be the same as node 2");
|
||||||
|
$assert(prediction1a.order == manager.find(2).getOrder(), "Predicition order should be the same as node 2");
|
||||||
|
|
||||||
|
var prediction1b = manager.predict(1, 2, {x:-250, y:20});
|
||||||
|
this._plotPrediction(graph1, prediction1b);
|
||||||
|
$assert(prediction1b.position.x == manager.find(2).getPosition().x &&
|
||||||
|
prediction1b.position.y == manager.find(2).getPosition().y, "Prediction position should be the same as node 2");
|
||||||
|
$assert(prediction1b.order == manager.find(2).getOrder(), "Predicition order should be the same as node 2");
|
||||||
|
|
||||||
|
var prediction1c = manager.predict(0, 2, {x:-100, y:-20});
|
||||||
|
this._plotPrediction(graph1, prediction1c);
|
||||||
|
$assert(prediction1c.position.x == manager.find(1).getPosition().x &&
|
||||||
|
prediction1c.position.y < manager.find(1).getPosition().y, "Prediction is incorrectly positioned");
|
||||||
|
$assert(prediction1c.order == 1, "Prediction order should be 1");
|
||||||
|
|
||||||
|
var prediction1d = manager.predict(0, 2, {x:-100, y:20});
|
||||||
|
this._plotPrediction(graph1, prediction1d);
|
||||||
|
$assert(prediction1d.position.x == manager.find(1).getPosition().x &&
|
||||||
|
prediction1d.position.y > manager.find(1).getPosition().y, "Prediction is incorrectly positioned");
|
||||||
|
$assert(prediction1d.order == 3, "Prediction order should be 3");
|
||||||
|
|
||||||
|
var prediction1e = manager.predict(1, 2, {x:-250, y:0});
|
||||||
|
this._plotPrediction(graph1, prediction1e);
|
||||||
|
$assert(prediction1e.position.x == manager.find(2).getPosition().x &&
|
||||||
|
prediction1e.position.y == manager.find(2).getPosition().y, "Prediction position should be the same as node 2");
|
||||||
|
$assert(prediction1e.order == manager.find(2).getOrder(), "Predicition order should be the same as node 2");
|
||||||
|
|
||||||
|
console.log("OK!\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
Loading…
Reference in New Issue
Block a user