Nodes of any size now supported

This commit is contained in:
Gonzalo Bellver
2012-01-13 20:06:14 -03:00
parent 78c1de5c67
commit b9e5469907
5 changed files with 79 additions and 5 deletions

View File

@@ -134,7 +134,7 @@ mindplot.nlayout.BalancedSorter = new Class({
// Compute heights ...
var heights = children.map(
function(child) {
return {id:child.getId(), order:child.getOrder(), height:this._computeChildrenHeight(treeSet, child)};
return {id:child.getId(), order:child.getOrder(), width: child.getSize().width, height:this._computeChildrenHeight(treeSet, child)};
}, this).reverse();
@@ -167,7 +167,7 @@ mindplot.nlayout.BalancedSorter = new Class({
}
var yOffset = ysum + heights[i].height / 2;
var xOffset = direction * (node.getSize().width + mindplot.nlayout.BalancedSorter.INTERNODE_HORIZONTAL_PADDING);
var xOffset = direction * (node.getSize().width/2 + heights[i].width/2 + + mindplot.nlayout.BalancedSorter.INTERNODE_HORIZONTAL_PADDING);
$assert(!isNaN(xOffset), "xOffset can not be null");
$assert(!isNaN(yOffset), "yOffset can not be null");

View File

@@ -112,6 +112,20 @@ mindplot.nlayout.RootedTreeSet = new Class({
return node._children;
},
getAncestors: function(node) {
$assert(node, 'node cannot be null');
return this._getAncestors(this.getParent(node), []);
},
_getAncestors: function(node, nodes) {
var result = nodes;
if (node) {
result.push(node);
this._getAncestors(this.getParent(node), result);
}
return result;
},
getSiblings: function(node) {
$assert(node, 'node cannot be null');
var siblings = node._parent._children;

View File

@@ -44,7 +44,7 @@ mindplot.nlayout.SymmetricSorter = new Class({
if (position.y > cpos.y) {
yOffset = child == last ?
child.getSize().height + mindplot.nlayout.SymmetricSorter.INTERNODE_VERTICAL_PADDING * 2 :
(children[index + 1].getPosition().y - child.getPosition().y)/2;
(children[index + 1].getPosition().y + children[index + 1].getSize().height/2 - child.getPosition().y)/2;
result = [child.getOrder() + 1,{x:cpos.x, y:cpos.y + yOffset}];
}
});
@@ -96,7 +96,7 @@ mindplot.nlayout.SymmetricSorter = new Class({
// Compute heights ...
var heights = children.map(
function(child) {
return {id:child.getId(), order:child.getOrder(), position: child.getPosition(), height: this._computeChildrenHeight(treeSet, child)};
return {id:child.getId(), order:child.getOrder(), position: child.getPosition(), width: child.getSize().width, height: this._computeChildrenHeight(treeSet, child)};
}, this).reverse();
// Compute the center of the branch ...
@@ -116,7 +116,7 @@ mindplot.nlayout.SymmetricSorter = new Class({
var direction = parent.getPosition().x > 0 ? 1 : -1;
var yOffset = ysum + heights[i].height / 2;
var xOffset = direction * (node.getSize().width + mindplot.nlayout.SymmetricSorter.INTERNODE_HORIZONTAL_PADDING);
var xOffset = direction * (heights[i].width/2 + node.getSize().width/2 + mindplot.nlayout.SymmetricSorter.INTERNODE_HORIZONTAL_PADDING);
$assert(!isNaN(xOffset), "xOffset can not be null");
$assert(!isNaN(yOffset), "yOffset can not be null");