Free positioning started. Nodes can move freely, but collisions might occurr

This commit is contained in:
Gonzalo Bellver
2012-01-15 18:08:31 -03:00
parent 75af2aac87
commit 171c3aee8f
6 changed files with 108 additions and 13 deletions

View File

@@ -48,14 +48,20 @@ mindplot.layout.LayoutManager = new Class({
return this._treeSet.find(id);
},
move: function() {
//TODO(gb): implement
move: function(id, position) {
$assert($defined(id), "id cannot be null");
$assert($defined(position), "position cannot be null");
$assert($defined(position.x), "x can not be null");
$assert($defined(position.y), "y can not be null");
var node = this._treeSet.find(id);
node.setFree(true);
node.setFreeDisplacement({x:position.x - node.getPosition().x, y:position.y-node.getPosition().y});
},
connectNode: function(parentId, childId, order) {
$assert($defined(parentId), "parentId can not be null");
$assert($defined(childId), "childId can not be null");
$assert($defined(order), "order can not be null");
$assert($defined(parentId), "parentId cannot be null");
$assert($defined(childId), "childId cannot be null");
$assert($defined(order), "order cannot be null");
this._layout.connectNode(parentId, childId, order);
@@ -73,6 +79,8 @@ mindplot.layout.LayoutManager = new Class({
$assert($defined(id), "id can not be null");
var result = this._layout.createNode(id, size, position, 'topic');
this._treeSet.add(result);
return this;
},
removeNode: function(id) {
@@ -124,6 +132,8 @@ mindplot.layout.LayoutManager = new Class({
if (!$(fireEvents) || fireEvents) {
this._flushEvents();
}
return this;
},
_flushEvents: function() {

View File

@@ -35,6 +35,19 @@ mindplot.layout.Node = new Class({
return this._id;
},
setFree: function(value) {
this._setProperty('free', value);
},
isFree: function() {
var result = this._getProperty('free');
return this._getProperty('free');
},
hasFreeChanged: function() {
return this._isPropertyChanged('free');
},
setShrunken: function(value) {
this._setProperty('shrink', value);
},
@@ -88,6 +101,21 @@ mindplot.layout.Node = new Class({
return this._getProperty('size');
},
setFreeDisplacement: function(displacement) {
$assert($defined(displacement), "Position can not be null");
$assert($defined(displacement.x), "x can not be null");
$assert($defined(displacement.y), "y can not be null");
var oldDisplacement = this.getFreeDisplacement();
var newDisplacement = {x:oldDisplacement.x + displacement.x, y:oldDisplacement.y + displacement.y};
this._setProperty('freeDisplacement', Object.clone(newDisplacement));
},
getFreeDisplacement: function() {
var freeDisplacement = this._getProperty('freeDisplacement');
return (freeDisplacement || {x:0, y:0});
},
setPosition : function(position) {
$assert($defined(position), "Position can not be null");
$assert($defined(position.x), "x can not be null");

View File

@@ -71,7 +71,6 @@ mindplot.layout.OriginalLayout = new Class({
// Calculate all node heights ...
var sorter = node.getSorter();
// @Todo: This must not be implemented in this way.Each sorter could have different notion of heights ...
var heightById = sorter.computeChildrenIdByHeights(this._treeSet, node);
this._layoutChildren(node, heightById);
@@ -83,9 +82,10 @@ mindplot.layout.OriginalLayout = new Class({
var nodeId = node.getId();
var children = this._treeSet.getChildren(node);
var parent = this._treeSet.getParent(node);
var childrenOrderMoved = children.some(function(child) {
return child.hasOrderChanged();
});
var childrenOrderMoved = children.some(function(child) { return child.hasOrderChanged(); });
var childrenFreeChanged = children.some(function(child) { return child.hasFreeChanged(); });
var freeChanged = node.hasFreeChanged() || childrenFreeChanged;
// If ether any of the nodes has been changed of position or the height of the children is not
// the same, children nodes must be repositioned ....
@@ -95,17 +95,18 @@ mindplot.layout.OriginalLayout = new Class({
var heightChanged = node._branchHeight != newBranchHeight;
node._heightChanged = heightChanged || parentHeightChanged;
if (childrenOrderMoved || heightChanged || parentHeightChanged) {
if (childrenOrderMoved || heightChanged || parentHeightChanged || freeChanged) {
var sorter = node.getSorter();
var offsetById = sorter.computeOffsets(this._treeSet, node);
var parentPosition = node.getPosition();
children.forEach(function(child) {
var freeDisplacement = child.getFreeDisplacement();
var offset = offsetById[child.getId()];
var parentX = parentPosition.x;
var parentY = parentPosition.y;
var newPos = {x:parentX + offset.x,y:parentY + offset.y};
var newPos = {x:parentX + freeDisplacement.x + offset.x, y:parentY + freeDisplacement.y + offset.y};
this._treeSet.updateBranchPosition(child, newPos);
}.bind(this));

View File

@@ -111,9 +111,10 @@ mindplot.layout.SymmetricSorter = new Class({
var result = {};
for (var i = 0; i < heights.length; i++) {
ysum = ysum - heights[i].height;
var parent = treeSet.getParent(treeSet.find(heights[i].id));
var childNode = treeSet.find(heights[i].id);
var parent = treeSet.getParent(childNode);
var rootNode = treeSet.getRootNode(treeSet.find(heights[i].id));
var rootNode = treeSet.getRootNode(childNode);
var direction = parent.getPosition().x > rootNode.getPosition().x ? 1 : -1;
var yOffset = ysum + heights[i].height / 2;