Root nodes support any position

This commit is contained in:
Gonzalo Bellver
2012-01-15 15:41:03 -03:00
parent 3eea7b9e88
commit 75af2aac87
5 changed files with 24 additions and 12 deletions

View File

@@ -179,8 +179,9 @@ mindplot.layout.BalancedSorter = new Class({
_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 > 0 ? child.getPosition().x > 0 : child.getPosition().x < 0;
return position.x > rootPosition.x ? child.getPosition().x > rootPosition.x : child.getPosition().x < rootPosition.x;
});
},

View File

@@ -20,11 +20,12 @@ mindplot.layout.LayoutManager = new Class({
initialize: function(rootNodeId, rootSize) {
$assert($defined(rootNodeId), "rootNodeId can not be null");
$assert(rootSize, "rootSize can not be null");
var position = position || {x:0, y:0};
this._treeSet = new mindplot.layout.RootedTreeSet();
this._layout = new mindplot.layout.OriginalLayout(this._treeSet);
var rootNode = this._layout.createNode(rootNodeId, rootSize, {x:0,y:0}, 'root');
var rootNode = this._layout.createNode(rootNodeId, rootSize, position, 'root');
this._treeSet.setRoot(rootNode);
this._events = [];
},

View File

@@ -112,6 +112,16 @@ mindplot.layout.RootedTreeSet = new Class({
return node._children;
},
getRootNode: function(node) {
$assert(node, "node cannot be null");
var parent = this.getParent(node);
if ($defined(parent)) {
return this.getRootNode(parent);
}
return node;
},
getAncestors: function(node) {
$assert(node, 'node cannot be null');
return this._getAncestors(this.getParent(node), []);

View File

@@ -22,7 +22,8 @@ mindplot.layout.SymmetricSorter = new Class({
},
predict : function(parent, graph, position) {
var direction = parent.getPosition().x > 0 ? 1 : -1;
var rootNode = graph.getRootNode(parent);
var direction = parent.getPosition().x > rootNode.getPosition().x ? 1 : -1;
// No children...
var children = graph.getChildren(parent);
@@ -112,8 +113,8 @@ mindplot.layout.SymmetricSorter = new Class({
ysum = ysum - heights[i].height;
var parent = treeSet.getParent(treeSet.find(heights[i].id));
//TODO(gb): actually compare to branch's root node position
var direction = parent.getPosition().x > 0 ? 1 : -1;
var rootNode = treeSet.getRootNode(treeSet.find(heights[i].id));
var direction = parent.getPosition().x > rootNode.getPosition().x ? 1 : -1;
var yOffset = ysum + heights[i].height / 2;
var xOffset = direction * (heights[i].width/2 + node.getSize().width/2 + mindplot.layout.SymmetricSorter.INTERNODE_HORIZONTAL_PADDING);