Fix collapse.

This commit is contained in:
Paulo Veiga 2012-01-17 00:26:29 -03:00
parent 171c3aee8f
commit e5beb4f034
10 changed files with 37 additions and 51 deletions

View File

@ -122,7 +122,6 @@ mindplot.DragTopic = new Class({
var dragPivot = this._getDragPivot();
dragPivot.addToWorkspace(workspace);
dragPivot.setVisibility(true);
},
_getDragPivot : function() {

View File

@ -225,7 +225,7 @@ mindplot.StandaloneActionDispatcher = new Class({
};
var command = new mindplot.commands.GenericFunctionCommand(commandFunc, topicsIds, collapse);
this.execute(command);
this.execute(command, false);
},
execute:function(command) {

View File

@ -28,6 +28,7 @@ mindplot.commands.GenericFunctionCommand = new Class({
this._oldValues = [];
this._id = mindplot.Command._nextUUID();
},
execute: function(commandContext) {
if (!this.applied) {
var topics = commandContext.findTopics(this._topicsIds);
@ -41,6 +42,7 @@ mindplot.commands.GenericFunctionCommand = new Class({
}
},
undoExecute: function(commandContext) {
if (this.applied) {
var topics = commandContext.findTopics(this._topicsIds);

View File

@ -15,6 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
mindplot.layout.AbstractBasicSorter = new Class({
Extends: mindplot.layout.ChildrenSorterStrategy,
@ -24,8 +25,12 @@ mindplot.layout.AbstractBasicSorter = new Class({
return result;
},
_getVerticalPadding: function() {
return mindplot.layout.AbstractBasicSorter.INTERNODE_VERTICAL_PADDING;
},
_computeChildrenHeight : function(treeSet, node, heightCache) {
var height = node.getSize().height + (mindplot.layout.AbstractBasicSorter.INTERNODE_VERTICAL_PADDING * 2); // 2* Top and down padding;
var height = node.getSize().height + (this._getVerticalPadding() * 2); // 2* Top and down padding;
var result;
var children = treeSet.getChildren(node);
@ -54,6 +59,7 @@ mindplot.layout.AbstractBasicSorter = new Class({
});
return result;
}
});
mindplot.layout.AbstractBasicSorter.INTERNODE_VERTICAL_PADDING = 5;

View File

@ -22,35 +22,6 @@ mindplot.layout.BalancedSorter = new Class({
},
computeChildrenIdByHeights: function(treeSet, node) {
var result = {};
this._computeChildrenHeight(treeSet, node, result);
return result;
},
_computeChildrenHeight : function(treeSet, node, heightCache) {
var height = node.getSize().height + (mindplot.layout.BalancedSorter.INTERNODE_VERTICAL_PADDING * 2); // 2* Top and down padding;
var result;
var children = treeSet.getChildren(node);
if (children.length == 0 || node.areChildrenShrunken()) {
result = height;
} else {
var childrenHeight = 0;
children.forEach(function(child) {
childrenHeight += this._computeChildrenHeight(treeSet, child, heightCache);
}, this);
result = Math.max(height, childrenHeight);
}
if (heightCache) {
heightCache[node.getId()] = result;
}
return result;
},
predict : function(parent, graph, position) {
if (!position) {
@ -76,7 +47,7 @@ mindplot.layout.BalancedSorter = new Class({
if (position.y > cpos.y) {
yOffset = child == last ?
child.getSize().height + mindplot.layout.BalancedSorter.INTERNODE_VERTICAL_PADDING * 2 :
(children[index + 1].getPosition().y - child.getPosition().y)/2;
(children[index + 1].getPosition().y - child.getPosition().y) / 2;
result = [child.getOrder() + 2,{x:cpos.x, y:cpos.y + yOffset}];
}
});
@ -108,7 +79,7 @@ mindplot.layout.BalancedSorter = new Class({
}
}
var newOrder = order > (max+1) ? (max + 2) : order;
var newOrder = order > (max + 1) ? (max + 2) : order;
child.setOrder(newOrder);
},
@ -167,7 +138,7 @@ mindplot.layout.BalancedSorter = new Class({
}
var yOffset = ysum + heights[i].height / 2;
var xOffset = direction * (node.getSize().width/2 + heights[i].width/2 + + mindplot.layout.BalancedSorter.INTERNODE_HORIZONTAL_PADDING);
var xOffset = direction * (node.getSize().width / 2 + heights[i].width / 2 + + mindplot.layout.BalancedSorter.INTERNODE_HORIZONTAL_PADDING);
$assert(!isNaN(xOffset), "xOffset can not be null");
$assert(!isNaN(yOffset), "yOffset can not be null");
@ -200,13 +171,18 @@ mindplot.layout.BalancedSorter = new Class({
var factor = node.getOrder() % 2 == 0 ? 2 : 1;
for (var i = 0; i < children.length; i++) {
var order = i == 0 && factor == 1 ? 1 : (factor * i);
$assert(children[i].getOrder() == order, "Missing order elements. Missing order: " + (i*factor));
$assert(children[i].getOrder() == order, "Missing order elements. Missing order: " + (i * factor));
}
},
toString:function() {
return "Balanced Sorter";
},
_getVerticalPadding:function() {
return mindplot.layout.BalancedSorter.INTERNODE_VERTICAL_PADDING;
}
});
mindplot.layout.BalancedSorter.INTERNODE_VERTICAL_PADDING = 5;

View File

@ -27,8 +27,6 @@ mindplot.layout.EventBusDispatcher = new Class({
this._layoutManager.addEvent('change', function(event) {
var id = event.getId();
var topic = designerModel.findTopicById(id);
console.log("Modify position to:" + id);
topic.setPosition(event.getPosition());
topic.setOrder(event.getOrder());
});
@ -88,9 +86,10 @@ mindplot.layout.EventBusDispatcher = new Class({
_doLayout: function() {
// (function() {
this._layoutManager.layout(true);
console.log("---------");
// console.log("---------");
this._layoutManager.dump();
console.log("---------");
// console.log("---------");
// console.log("---------");
// }).delay(0, this);
},

View File

@ -39,9 +39,12 @@ mindplot.layout.LayoutManager = new Class({
updateShrinkState: function(id, value) {
$assert($defined(id), "id can not be null");
$assert($defined(value), "value can not be null");
var node = this._treeSet.find(id);
node.setShrunken(value);
return this;
},
find: function(id) {
@ -53,6 +56,7 @@ mindplot.layout.LayoutManager = new Class({
$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});
@ -169,7 +173,6 @@ mindplot.layout.LayoutManager = new Class({
}
this._collectChanges(this._treeSet.getChildren(node));
}, this);
}
});

View File

@ -135,12 +135,12 @@ mindplot.layout.Node = new Class({
}
// Only update if the property has changed ...
if (JSON.encode(prop.oldValue) != JSON.encode(value)) {
if (JSON.encode(prop.value) != JSON.encode(value)) {
prop.oldValue = prop.value;
prop.value = value;
prop.hasChanged = true;
this._properties[key] = prop;
}
this._properties[key] = prop;
},
_getProperty: function(key) {
@ -159,7 +159,7 @@ mindplot.layout.Node = new Class({
toString: function() {
return "[id:" + this.getId() + ", order:" + this.getOrder() + ", position: {" + this.getPosition().x + "," + this.getPosition().y + "}, size: {" + this.getSize().width + "," + this.getSize().height + "}";
return "[id:" + this.getId() + ", order:" + this.getOrder() + ", position: {" + this.getPosition().x + "," + this.getPosition().y + "}, size: {" + this.getSize().width + "}," + this.getSize().height + ", shrink:" + this.areChildrenShrunken() + "]";
}
});

View File

@ -29,11 +29,11 @@ mindplot.layout.SymmetricSorter = new Class({
var children = graph.getChildren(parent);
if (children.length == 0) {
position = position || {x:parent.getPosition().x + direction, y:parent.getPosition().y};
var position = {
var pos = {
x: parent.getPosition().x + direction * (parent.getSize().width + mindplot.layout.SymmetricSorter.INTERNODE_HORIZONTAL_PADDING),
y:parent.getPosition().y
}
return [0, position];
};
return [0, pos];
}
// Try to fit within ...
@ -43,9 +43,9 @@ mindplot.layout.SymmetricSorter = new Class({
children.each(function(child, index) {
var cpos = child.getPosition();
if (position.y > cpos.y) {
yOffset = child == last ?
var yOffset = child == last ?
child.getSize().height + mindplot.layout.SymmetricSorter.INTERNODE_VERTICAL_PADDING * 2 :
(children[index + 1].getPosition().y + children[index + 1].getSize().height/2 - 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}];
}
});
@ -118,7 +118,7 @@ mindplot.layout.SymmetricSorter = new Class({
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);
var xOffset = direction * (heights[i].width / 2 + node.getSize().width / 2 + mindplot.layout.SymmetricSorter.INTERNODE_HORIZONTAL_PADDING);
$assert(!isNaN(xOffset), "xOffset can not be null");
$assert(!isNaN(yOffset), "yOffset can not be null");

View File

@ -164,7 +164,8 @@ mindplot.model.INodeModel = new Class({
},
areChildrenShrunken : function() {
return this.getProperty('shrunken');
var result = this.getProperty('shrunken');
return $defined(result) ? result : false;
},
setChildrenShrunken : function(value) {