From e5beb4f034a578c00156ce9e33b4eed1d8ab72db Mon Sep 17 00:00:00 2001 From: Paulo Veiga Date: Tue, 17 Jan 2012 00:26:29 -0300 Subject: [PATCH] Fix collapse. --- mindplot/src/main/javascript/DragTopic.js | 1 - .../javascript/StandaloneActionDispatcher.js | 2 +- .../commands/GenericFunctionCommand.js | 2 + .../javascript/layout/AbstractBasicSorter.js | 8 +++- .../main/javascript/layout/BalancedSorter.js | 42 ++++--------------- .../javascript/layout/EventBusDispatcher.js | 7 ++-- .../main/javascript/layout/LayoutManager.js | 5 ++- mindplot/src/main/javascript/layout/Node.js | 6 +-- .../main/javascript/layout/SymmetricSorter.js | 12 +++--- .../src/main/javascript/model/INodeModel.js | 3 +- 10 files changed, 37 insertions(+), 51 deletions(-) diff --git a/mindplot/src/main/javascript/DragTopic.js b/mindplot/src/main/javascript/DragTopic.js index 348c1312..b9702153 100644 --- a/mindplot/src/main/javascript/DragTopic.js +++ b/mindplot/src/main/javascript/DragTopic.js @@ -122,7 +122,6 @@ mindplot.DragTopic = new Class({ var dragPivot = this._getDragPivot(); dragPivot.addToWorkspace(workspace); - dragPivot.setVisibility(true); }, _getDragPivot : function() { diff --git a/mindplot/src/main/javascript/StandaloneActionDispatcher.js b/mindplot/src/main/javascript/StandaloneActionDispatcher.js index 4efcc00f..ba838b38 100644 --- a/mindplot/src/main/javascript/StandaloneActionDispatcher.js +++ b/mindplot/src/main/javascript/StandaloneActionDispatcher.js @@ -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) { diff --git a/mindplot/src/main/javascript/commands/GenericFunctionCommand.js b/mindplot/src/main/javascript/commands/GenericFunctionCommand.js index 00d9f576..41e9ea4c 100644 --- a/mindplot/src/main/javascript/commands/GenericFunctionCommand.js +++ b/mindplot/src/main/javascript/commands/GenericFunctionCommand.js @@ -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); diff --git a/mindplot/src/main/javascript/layout/AbstractBasicSorter.js b/mindplot/src/main/javascript/layout/AbstractBasicSorter.js index ef72c718..b3ee5aed 100644 --- a/mindplot/src/main/javascript/layout/AbstractBasicSorter.js +++ b/mindplot/src/main/javascript/layout/AbstractBasicSorter.js @@ -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; diff --git a/mindplot/src/main/javascript/layout/BalancedSorter.js b/mindplot/src/main/javascript/layout/BalancedSorter.js index 2d8d0d83..0d35677b 100644 --- a/mindplot/src/main/javascript/layout/BalancedSorter.js +++ b/mindplot/src/main/javascript/layout/BalancedSorter.js @@ -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; diff --git a/mindplot/src/main/javascript/layout/EventBusDispatcher.js b/mindplot/src/main/javascript/layout/EventBusDispatcher.js index b70a2939..1a7f976d 100644 --- a/mindplot/src/main/javascript/layout/EventBusDispatcher.js +++ b/mindplot/src/main/javascript/layout/EventBusDispatcher.js @@ -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); }, diff --git a/mindplot/src/main/javascript/layout/LayoutManager.js b/mindplot/src/main/javascript/layout/LayoutManager.js index a8a67526..bb049ee1 100644 --- a/mindplot/src/main/javascript/layout/LayoutManager.js +++ b/mindplot/src/main/javascript/layout/LayoutManager.js @@ -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); - } }); diff --git a/mindplot/src/main/javascript/layout/Node.js b/mindplot/src/main/javascript/layout/Node.js index 77a1e269..409d190d 100644 --- a/mindplot/src/main/javascript/layout/Node.js +++ b/mindplot/src/main/javascript/layout/Node.js @@ -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() + "]"; } }); diff --git a/mindplot/src/main/javascript/layout/SymmetricSorter.js b/mindplot/src/main/javascript/layout/SymmetricSorter.js index 310e9dc0..a8596a57 100644 --- a/mindplot/src/main/javascript/layout/SymmetricSorter.js +++ b/mindplot/src/main/javascript/layout/SymmetricSorter.js @@ -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"); diff --git a/mindplot/src/main/javascript/model/INodeModel.js b/mindplot/src/main/javascript/model/INodeModel.js index d11eab28..d7bd055d 100644 --- a/mindplot/src/main/javascript/model/INodeModel.js +++ b/mindplot/src/main/javascript/model/INodeModel.js @@ -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) {