diff --git a/mindplot/src/main/javascript/nlayout/AbstractBasicSorter.js b/mindplot/src/main/javascript/nlayout/AbstractBasicSorter.js new file mode 100644 index 00000000..162b334d --- /dev/null +++ b/mindplot/src/main/javascript/nlayout/AbstractBasicSorter.js @@ -0,0 +1,66 @@ +/* + * Copyright [2011] [wisemapping] + * + * Licensed under WiseMapping Public License, Version 1.0 (the "License"). + * It is basically the Apache License, Version 2.0 (the "License") plus the + * "powered by wisemapping" text requirement on every single page; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the license at + * + * http://www.wisemapping.org/license + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +mindplot.nlayout.AbstractBasicSorter = new Class({ + Extends: mindplot.nlayout.ChildrenSorterStrategy, + + computeChildrenIdByHeights: function(treeSet, node) { + var result = {}; + this._computeChildrenHeight(treeSet, node, result); + return result; + }, + + _computeChildrenHeight : function(treeSet, node, heightCache) { + var height = node.getSize().height + (mindplot.nlayout.SymmetricSorter.INTERNODE_VERTICAL_PADDING * 2); // 2* Top and down padding; + + var result; + var children = treeSet.getChildren(node); + if (children.length == 0) { + 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; + }, + + _getSortedChildren:function(treeSet, node) { + var result = treeSet.getChildren(node); + result.sort(function(a, b) { + return a.getOrder() - b.getOrder() + }); + return result; + }, + + verify:function(treeSet, node) { + // Check that all is consistent ... + var children = this._getSortedChildren(treeSet, node); + + for (var i = 0; i < children.length; i++) { + $assert(children[i].getOrder() == i, "missing order elements"); + } + } +}); \ No newline at end of file diff --git a/mindplot/src/main/javascript/nlayout/BalancedSorter.js b/mindplot/src/main/javascript/nlayout/BalancedSorter.js index d6894427..15a0f2e2 100644 --- a/mindplot/src/main/javascript/nlayout/BalancedSorter.js +++ b/mindplot/src/main/javascript/nlayout/BalancedSorter.js @@ -1,5 +1,5 @@ mindplot.nlayout.BalancedSorter = new Class({ - Extends: mindplot.nlayout.ChildrenSorterStrategy, + Extends: mindplot.nlayout.AbstractBasicSorter, initialize: function() { @@ -91,23 +91,6 @@ mindplot.nlayout.BalancedSorter = new Class({ node.setOrder(0); }, - _getSortedChildren:function(treeSet, node) { - var result = treeSet.getChildren(node); - result.sort(function(a, b) { - return a.getOrder() - b.getOrder(); - }); - return result; - }, - - verify:function(treeSet, node) { - // Check that all is consistent ... - var children = this._getSortedChildren(treeSet, node); - - for (var i = 0; i < children.length; i++) { - $assert(children[i].getOrder() == i, "missing order elements"); - } - }, - computeOffsets:function(treeSet, node) { $assert(treeSet, "treeSet can no be null."); $assert(node, "node can no be null."); diff --git a/mindplot/src/main/javascript/nlayout/GridSorter.js b/mindplot/src/main/javascript/nlayout/GridSorter.js index 7ee470bd..21679022 100644 --- a/mindplot/src/main/javascript/nlayout/GridSorter.js +++ b/mindplot/src/main/javascript/nlayout/GridSorter.js @@ -16,7 +16,7 @@ * limitations under the License. */ mindplot.nlayout.GridSorter = new Class({ - Extends: mindplot.nlayout.SymmetricSorter, + Extends: mindplot.nlayout.AbstractBasicSorter, computeOffsets: function(treeSet, node) { $assert(treeSet, "treeSet can no be null."); diff --git a/mindplot/src/main/javascript/nlayout/SymmetricSorter.js b/mindplot/src/main/javascript/nlayout/SymmetricSorter.js index cc0b934b..db871d78 100644 --- a/mindplot/src/main/javascript/nlayout/SymmetricSorter.js +++ b/mindplot/src/main/javascript/nlayout/SymmetricSorter.js @@ -16,40 +16,11 @@ * limitations under the License. */ mindplot.nlayout.SymmetricSorter = new Class({ - Extends: mindplot.nlayout.ChildrenSorterStrategy, + Extends: mindplot.nlayout.AbstractBasicSorter, initialize:function() { }, - computeChildrenIdByHeights: function(treeSet, node) { - var result = {}; - this._computeChildrenHeight(treeSet, node, result); - return result; - }, - - _computeChildrenHeight : function(treeSet, node, heightCache) { - var height = node.getSize().height + (mindplot.nlayout.SymmetricSorter.INTERNODE_VERTICAL_PADDING * 2); // 2* Top and down padding; - - var result; - var children = treeSet.getChildren(node); - if (children.length == 0) { - 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) { // No children... @@ -107,23 +78,6 @@ mindplot.nlayout.SymmetricSorter = new Class({ node.setOrder(0); }, - _getSortedChildren:function(treeSet, node) { - var result = treeSet.getChildren(node); - result.sort(function(a, b) { - return a.getOrder() - b.getOrder() - }); - return result; - }, - - verify:function(treeSet, node) { - // Check that all is consistent ... - var children = this._getSortedChildren(treeSet, node); - - for (var i = 0; i < children.length; i++) { - $assert(children[i].getOrder() == i, "missing order elements"); - } - }, - computeOffsets:function(treeSet, node) { $assert(treeSet, "treeSet can no be null."); $assert(node, "node can no be null."); @@ -161,10 +115,6 @@ mindplot.nlayout.SymmetricSorter = new Class({ return result; }, - _getRootNode: function(treeSet) { - var roots = treeSet.getTreeRoots(); - }, - toString:function() { return "Symmetric Sorter"; } diff --git a/mindplot/src/test/javascript/static/layout.html b/mindplot/src/test/javascript/static/layout.html index 35958da0..67be2ff7 100644 --- a/mindplot/src/test/javascript/static/layout.html +++ b/mindplot/src/test/javascript/static/layout.html @@ -12,6 +12,7 @@ +