mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-12-23 03:43:48 +01:00
Predict for free positioning.
This commit is contained in:
parent
c6fa09ec7d
commit
c80726e1c0
@ -102,11 +102,24 @@ mindplot.layout.LayoutManager = new Class({
|
||||
return this;
|
||||
},
|
||||
|
||||
predict: function(parentId, position) {
|
||||
predict: function(parentId, position, free) {
|
||||
$assert($defined(parentId), "parentId can not be null");
|
||||
|
||||
var parent = this._treeSet.find(parentId);
|
||||
var sorter = parent.getSorter();
|
||||
|
||||
if (free) {
|
||||
$assert($defined(position), "position cannot be null for predict in free positioning");
|
||||
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);
|
||||
return {order:result[0],position:result[1]};
|
||||
},
|
||||
|
@ -31,6 +31,8 @@ mindplot.layout.TestSuite = new Class({
|
||||
this.testBalancedPredict();
|
||||
this.testSize();
|
||||
this.testFreePosition();
|
||||
this.testFreePredict();
|
||||
// this.testReconnectFreeNode();
|
||||
},
|
||||
|
||||
testAligned: function() {
|
||||
@ -734,6 +736,63 @@ mindplot.layout.TestSuite = new Class({
|
||||
manager.connectNode(17,25,0);
|
||||
manager.layout(true);
|
||||
manager.plot("testFreePosition9", {width:1400, height:600});
|
||||
},
|
||||
|
||||
testFreePredict: function() {
|
||||
console.log("testFreePredict:");
|
||||
var position = {x:0,y:0};
|
||||
var manager = new mindplot.layout.LayoutManager(0, mindplot.layout.TestSuite.ROOT_NODE_SIZE);
|
||||
|
||||
// Prepare a sample graph ...
|
||||
manager.addNode(1, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(2, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(3, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(4, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(5, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(6, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(7, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(8, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(9, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(10, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(11, mindplot.layout.TestSuite.NODE_SIZE, position);
|
||||
|
||||
manager.connectNode(0, 1, 0);
|
||||
manager.connectNode(0, 2, 1);
|
||||
manager.connectNode(0, 3, 2);
|
||||
manager.connectNode(3, 4, 0);
|
||||
manager.connectNode(3, 5, 1);
|
||||
manager.connectNode(3, 6, 2);
|
||||
manager.connectNode(5, 7, 0);
|
||||
manager.connectNode(5, 8, 1);
|
||||
manager.connectNode(5, 11, 2);
|
||||
manager.connectNode(2, 9, 0);
|
||||
manager.connectNode(2, 10, 1);
|
||||
|
||||
manager.layout();
|
||||
var graph = manager.plot("testFreePredict1", {width:1000, height:400});
|
||||
|
||||
var pos1 = {x: 370, y:80};
|
||||
var predict1 = manager.predict(11, pos1, true);
|
||||
$assert(predict1.position.x == pos1.x && predict1.position.y == pos1.y, "free predict should return the same position");
|
||||
|
||||
var pos2 = {x: -200, y:80};
|
||||
var predict2 = manager.predict(2, pos2, true);
|
||||
$assert(predict2.position.x == pos2.x && predict2.position.y == pos2.y, "free predict should return the same position");
|
||||
|
||||
var pos3 = {x: 200, y:30};
|
||||
var node5 = manager.find(5);
|
||||
var predict3 = manager.predict(5, pos3, true);
|
||||
$assert(predict3.position.x == node5.getPosition().x && predict3.position.y == pos3.y, "free predict should return the x-coordinate of the node");
|
||||
|
||||
var pos4 = {x: -100, y:45};
|
||||
var node10 = manager.find(10);
|
||||
var predict4 = manager.predict(10, pos4, true);
|
||||
$assert(predict4.position.x == node10.getPosition().x && predict4.position.y == pos4.y, "free predict should return the x-coordinate of the node");
|
||||
|
||||
this._plotPrediction(graph, predict1);
|
||||
this._plotPrediction(graph, predict2);
|
||||
this._plotPrediction(graph, predict3);
|
||||
this._plotPrediction(graph, predict4);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -121,5 +121,7 @@
|
||||
<div id="testFreePosition8" class="col last"></div>
|
||||
<div id="testFreePosition9" class="col last"></div>
|
||||
|
||||
<h2>testFreePredict:</h2>
|
||||
<div id="testFreePredict1" class="col"></div>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user