diff --git a/mindplot/src/main/javascript/layout/BalancedSorter.js b/mindplot/src/main/javascript/layout/BalancedSorter.js index e59b6d3f..2d8d0d83 100644 --- a/mindplot/src/main/javascript/layout/BalancedSorter.js +++ b/mindplot/src/main/javascript/layout/BalancedSorter.js @@ -179,8 +179,9 @@ mindplot.layout.BalancedSorter = new Class({ _getChildrenForSide: function(parent, graph, position) { position = position || {x: parent.getPosition().x + 1, y:parent.getPosition().y + 1}; + var rootPosition = graph.getRootNode(parent).getPosition(); return graph.getChildren(parent).filter(function(child) { - return position.x > 0 ? child.getPosition().x > 0 : child.getPosition().x < 0; + return position.x > rootPosition.x ? child.getPosition().x > rootPosition.x : child.getPosition().x < rootPosition.x; }); }, diff --git a/mindplot/src/main/javascript/layout/LayoutManager.js b/mindplot/src/main/javascript/layout/LayoutManager.js index 184eeb7d..b0182359 100644 --- a/mindplot/src/main/javascript/layout/LayoutManager.js +++ b/mindplot/src/main/javascript/layout/LayoutManager.js @@ -20,11 +20,12 @@ mindplot.layout.LayoutManager = new Class({ initialize: function(rootNodeId, rootSize) { $assert($defined(rootNodeId), "rootNodeId can not be null"); $assert(rootSize, "rootSize can not be null"); + var position = position || {x:0, y:0}; this._treeSet = new mindplot.layout.RootedTreeSet(); this._layout = new mindplot.layout.OriginalLayout(this._treeSet); - var rootNode = this._layout.createNode(rootNodeId, rootSize, {x:0,y:0}, 'root'); + var rootNode = this._layout.createNode(rootNodeId, rootSize, position, 'root'); this._treeSet.setRoot(rootNode); this._events = []; }, diff --git a/mindplot/src/main/javascript/layout/RootedTreeSet.js b/mindplot/src/main/javascript/layout/RootedTreeSet.js index f1133c23..de162409 100644 --- a/mindplot/src/main/javascript/layout/RootedTreeSet.js +++ b/mindplot/src/main/javascript/layout/RootedTreeSet.js @@ -112,6 +112,16 @@ mindplot.layout.RootedTreeSet = new Class({ return node._children; }, + getRootNode: function(node) { + $assert(node, "node cannot be null"); + var parent = this.getParent(node); + if ($defined(parent)) { + return this.getRootNode(parent); + } + + return node; + }, + getAncestors: function(node) { $assert(node, 'node cannot be null'); return this._getAncestors(this.getParent(node), []); diff --git a/mindplot/src/main/javascript/layout/SymmetricSorter.js b/mindplot/src/main/javascript/layout/SymmetricSorter.js index 756c580a..4cec29a0 100644 --- a/mindplot/src/main/javascript/layout/SymmetricSorter.js +++ b/mindplot/src/main/javascript/layout/SymmetricSorter.js @@ -22,7 +22,8 @@ mindplot.layout.SymmetricSorter = new Class({ }, predict : function(parent, graph, position) { - var direction = parent.getPosition().x > 0 ? 1 : -1; + var rootNode = graph.getRootNode(parent); + var direction = parent.getPosition().x > rootNode.getPosition().x ? 1 : -1; // No children... var children = graph.getChildren(parent); @@ -112,8 +113,8 @@ mindplot.layout.SymmetricSorter = new Class({ ysum = ysum - heights[i].height; var parent = treeSet.getParent(treeSet.find(heights[i].id)); - //TODO(gb): actually compare to branch's root node position - var direction = parent.getPosition().x > 0 ? 1 : -1; + var rootNode = treeSet.getRootNode(treeSet.find(heights[i].id)); + 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); diff --git a/mindplot/src/test/javascript/static/TestSuite.js b/mindplot/src/test/javascript/static/TestSuite.js index f2babc8b..91a7b082 100644 --- a/mindplot/src/test/javascript/static/TestSuite.js +++ b/mindplot/src/test/javascript/static/TestSuite.js @@ -182,13 +182,13 @@ mindplot.layout.TestSuite = new Class({ manager.layout(); manager.plot("testBalanced13", {width:1000, height:400}); - $assert(manager.find(1).getPosition().x > 0, "even order nodes must be at right of central topic"); - $assert(manager.find(3).getPosition().x > 0, "even order nodes must be at right of central topic"); - $assert(manager.find(5).getPosition().x > 0, "even order nodes must be at right of central topic"); + $assert(manager.find(1).getPosition().x > manager.find(0).getPosition().x, "even order nodes must be at right of central topic"); + $assert(manager.find(3).getPosition().x > manager.find(0).getPosition().x, "even order nodes must be at right of central topic"); + $assert(manager.find(5).getPosition().x > manager.find(0).getPosition().x, "even order nodes must be at right of central topic"); - $assert(manager.find(2).getPosition().x < 0, "odd order nodes must be at right of central topic"); - $assert(manager.find(4).getPosition().x < 0, "odd order nodes must be at right of central topic"); - $assert(manager.find(6).getPosition().x < 0, "odd order nodes must be at right of central topic"); + $assert(manager.find(2).getPosition().x < manager.find(0).getPosition().x, "odd order nodes must be at right of central topic"); + $assert(manager.find(4).getPosition().x < manager.find(0).getPosition().x, "odd order nodes must be at right of central topic"); + $assert(manager.find(6).getPosition().x < manager.find(0).getPosition().x, "odd order nodes must be at right of central topic"); $assert(manager.find(7).getPosition().x > manager.find(3).getPosition().x, "children of 1st level even order nodes must be to the right"); $assert(manager.find(8).getPosition().x > manager.find(7).getPosition().x, "children of 1st level even order nodes must be to the right"); @@ -580,7 +580,6 @@ mindplot.layout.TestSuite = new Class({ }, _plotPrediction: function(canvas, prediction) { - console.log(prediction); //TODO(gb): Remove trace!!! var position = prediction.position; var order = prediction.order; console.log("\t\tprediction {order:" + order + ", position: (" + position.x + "," + position.y + ")}");