diff --git a/mindplot/src/main/javascript/layout/BalancedSorter.js b/mindplot/src/main/javascript/layout/BalancedSorter.js index 085757e5..41fa4b55 100644 --- a/mindplot/src/main/javascript/layout/BalancedSorter.js +++ b/mindplot/src/main/javascript/layout/BalancedSorter.js @@ -177,6 +177,10 @@ mindplot.layout.BalancedSorter = new Class({ } }, + getDirection: function(treeSet, node) { + return node.getOrder() % 2 == 0 ? 1 : -1; + }, + toString:function() { return "Balanced Sorter"; }, diff --git a/mindplot/src/main/javascript/layout/ChildrenSorterStrategy.js b/mindplot/src/main/javascript/layout/ChildrenSorterStrategy.js index 2b3bc428..bcbccb9f 100644 --- a/mindplot/src/main/javascript/layout/ChildrenSorterStrategy.js +++ b/mindplot/src/main/javascript/layout/ChildrenSorterStrategy.js @@ -44,6 +44,10 @@ mindplot.layout.ChildrenSorterStrategy = new Class({ throw "Method must be implemented"; }, + getDirection: function(treeSet, node) { + throw "Method must be implemented"; + }, + toString:function() { throw "Method must be implemented: print name"; } diff --git a/mindplot/src/main/javascript/layout/LayoutManager.js b/mindplot/src/main/javascript/layout/LayoutManager.js index ea4d3565..e41f45ab 100644 --- a/mindplot/src/main/javascript/layout/LayoutManager.js +++ b/mindplot/src/main/javascript/layout/LayoutManager.js @@ -109,6 +109,8 @@ mindplot.layout.LayoutManager = new Class({ if (free) { $assert($defined(position), "position cannot be null for predict in free positioning"); + + //TODO(gb): check this. Should direction be obtained by the sorter? var rootNode = this._treeSet.getRootNode(parent); var direction = parent.getPosition().x > rootNode.getPosition().x ? 1 : -1; diff --git a/mindplot/src/main/javascript/layout/Node.js b/mindplot/src/main/javascript/layout/Node.js index 1a0225cd..40600562 100644 --- a/mindplot/src/main/javascript/layout/Node.js +++ b/mindplot/src/main/javascript/layout/Node.js @@ -124,6 +124,10 @@ mindplot.layout.Node = new Class({ this._setProperty('freeDisplacement', Object.clone(newDisplacement)); }, + resetFreeDisplacement: function() { + this._setProperty('freeDisplacement', {x:0, y:0}); + }, + getFreeDisplacement: function() { var freeDisplacement = this._getProperty('freeDisplacement'); return (freeDisplacement || {x:0, y:0}); diff --git a/mindplot/src/main/javascript/layout/OriginalLayout.js b/mindplot/src/main/javascript/layout/OriginalLayout.js index a37295f4..f630b1d0 100644 --- a/mindplot/src/main/javascript/layout/OriginalLayout.js +++ b/mindplot/src/main/javascript/layout/OriginalLayout.js @@ -55,7 +55,7 @@ mindplot.layout.OriginalLayout = new Class({ // Make it fixed node.setFree(false); - node.setFreeDisplacement({x:0, y:0}); + node.resetFreeDisplacement(); // Remove from children list. var sorter = parent.getSorter(); @@ -107,6 +107,14 @@ mindplot.layout.OriginalLayout = new Class({ children.forEach(function(child) { var offset = offsetById[child.getId()]; + var childFreeDisplacement = child.getFreeDisplacement(); + var direction = node.getSorter().getDirection(this._treeSet, child); + + if ((direction > 0 && childFreeDisplacement.x < 0) || (direction < 0 && childFreeDisplacement.x > 0)) { + child.resetFreeDisplacement(); + child.setFreeDisplacement({x: -childFreeDisplacement.x, y:childFreeDisplacement.y}); + } + offset.x += child.getFreeDisplacement().x; offset.y += child.getFreeDisplacement().y; diff --git a/mindplot/src/main/javascript/layout/RootedTreeSet.js b/mindplot/src/main/javascript/layout/RootedTreeSet.js index 4af7438a..e7ab4594 100644 --- a/mindplot/src/main/javascript/layout/RootedTreeSet.js +++ b/mindplot/src/main/javascript/layout/RootedTreeSet.js @@ -195,10 +195,10 @@ mindplot.layout.RootedTreeSet = new Class({ var rectPosition = {x: rect.attr("x") - canvas.width/2 + rect.attr("width")/2, y:rect.attr("y") - canvas.height/2 + rect.attr("height")/2}; var rectSize = {width: rect.attr("width"), height:rect.attr("height")}; rect.click(function() { - console.log("[id:" + node.getId() + ", order:" + node.getOrder() + ", position:(" + rectPosition.x + "," + rectPosition.y + "), size:" + rectSize.width + "x" + rectSize.height + ", sorter:" + node.getSorter() +"]"); + console.log("[id:" + node.getId() + ", order:" + node.getOrder() + ", position:(" + rectPosition.x + "," + rectPosition.y + "), size:" + rectSize.width + "x" + rectSize.height + ", freeDisplacement:(" + node.getFreeDisplacement().x + "," + node.getFreeDisplacement().y +")]"); }); text.click(function() { - console.log("[id:" + node.getId() + ", order:" + node.getOrder() + ", position:(" + rectPosition.x + "," + rectPosition.y + "), size:" + rectSize.width + "x" + rectSize.height + ", sorter:" + node.getSorter() +"]"); + console.log("[id:" + node.getId() + ", order:" + node.getOrder() + ", position:(" + rectPosition.x + "," + rectPosition.y + "), size:" + rectSize.width + "x" + rectSize.height + ", freeDisplacement:(" + node.getFreeDisplacement().x + "," + node.getFreeDisplacement().y +")]"); }); for (var i = 0; i < children.length; i++) { diff --git a/mindplot/src/main/javascript/layout/SymmetricSorter.js b/mindplot/src/main/javascript/layout/SymmetricSorter.js index a8596a57..e9db580d 100644 --- a/mindplot/src/main/javascript/layout/SymmetricSorter.js +++ b/mindplot/src/main/javascript/layout/SymmetricSorter.js @@ -137,6 +137,12 @@ mindplot.layout.SymmetricSorter = new Class({ } }, + getDirection: function(treeSet, node) { + var parent = treeSet.getParent(node); + var rootNode = treeSet.getRootNode(node); + return parent.getPosition().x >= rootNode.getPosition().x ? 1 : -1; + }, + toString:function() { return "Symmetric Sorter"; } diff --git a/mindplot/src/test/javascript/static/layout.html b/mindplot/src/test/javascript/static/layout.html index 05fc82df..2e979c7d 100644 --- a/mindplot/src/test/javascript/static/layout.html +++ b/mindplot/src/test/javascript/static/layout.html @@ -154,6 +154,7 @@
+