diff --git a/mindplot/src/main/javascript/nlayout/BalancedSorter.js b/mindplot/src/main/javascript/nlayout/BalancedSorter.js index 6fd47012..8380185d 100644 --- a/mindplot/src/main/javascript/nlayout/BalancedSorter.js +++ b/mindplot/src/main/javascript/nlayout/BalancedSorter.js @@ -134,7 +134,7 @@ mindplot.nlayout.BalancedSorter = new Class({ // Compute heights ... var heights = children.map( function(child) { - return {id:child.getId(), order:child.getOrder(), height:this._computeChildrenHeight(treeSet, child)}; + return {id:child.getId(), order:child.getOrder(), width: child.getSize().width, height:this._computeChildrenHeight(treeSet, child)}; }, this).reverse(); @@ -167,7 +167,7 @@ mindplot.nlayout.BalancedSorter = new Class({ } var yOffset = ysum + heights[i].height / 2; - var xOffset = direction * (node.getSize().width + mindplot.nlayout.BalancedSorter.INTERNODE_HORIZONTAL_PADDING); + var xOffset = direction * (node.getSize().width/2 + heights[i].width/2 + + mindplot.nlayout.BalancedSorter.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/nlayout/RootedTreeSet.js b/mindplot/src/main/javascript/nlayout/RootedTreeSet.js index 107367eb..01392082 100644 --- a/mindplot/src/main/javascript/nlayout/RootedTreeSet.js +++ b/mindplot/src/main/javascript/nlayout/RootedTreeSet.js @@ -112,6 +112,20 @@ mindplot.nlayout.RootedTreeSet = new Class({ return node._children; }, + getAncestors: function(node) { + $assert(node, 'node cannot be null'); + return this._getAncestors(this.getParent(node), []); + }, + + _getAncestors: function(node, nodes) { + var result = nodes; + if (node) { + result.push(node); + this._getAncestors(this.getParent(node), result); + } + return result; + }, + getSiblings: function(node) { $assert(node, 'node cannot be null'); var siblings = node._parent._children; diff --git a/mindplot/src/main/javascript/nlayout/SymmetricSorter.js b/mindplot/src/main/javascript/nlayout/SymmetricSorter.js index ff811d79..ae50a611 100644 --- a/mindplot/src/main/javascript/nlayout/SymmetricSorter.js +++ b/mindplot/src/main/javascript/nlayout/SymmetricSorter.js @@ -44,7 +44,7 @@ mindplot.nlayout.SymmetricSorter = new Class({ if (position.y > cpos.y) { yOffset = child == last ? child.getSize().height + mindplot.nlayout.SymmetricSorter.INTERNODE_VERTICAL_PADDING * 2 : - (children[index + 1].getPosition().y - 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}]; } }); @@ -96,7 +96,7 @@ mindplot.nlayout.SymmetricSorter = new Class({ // Compute heights ... var heights = children.map( function(child) { - return {id:child.getId(), order:child.getOrder(), position: child.getPosition(), height: this._computeChildrenHeight(treeSet, child)}; + return {id:child.getId(), order:child.getOrder(), position: child.getPosition(), width: child.getSize().width, height: this._computeChildrenHeight(treeSet, child)}; }, this).reverse(); // Compute the center of the branch ... @@ -116,7 +116,7 @@ mindplot.nlayout.SymmetricSorter = new Class({ var direction = parent.getPosition().x > 0 ? 1 : -1; var yOffset = ysum + heights[i].height / 2; - var xOffset = direction * (node.getSize().width + mindplot.nlayout.SymmetricSorter.INTERNODE_HORIZONTAL_PADDING); + var xOffset = direction * (heights[i].width/2 + node.getSize().width/2 + mindplot.nlayout.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/test/javascript/static/TestSuite.js b/mindplot/src/test/javascript/static/TestSuite.js index d9a3da3d..4ab756d0 100644 --- a/mindplot/src/test/javascript/static/TestSuite.js +++ b/mindplot/src/test/javascript/static/TestSuite.js @@ -29,6 +29,7 @@ mindplot.nlayout.TestSuite = new Class({ this.testRemoveNode(); this.testSymmetricPredict(); this.testBalancedPredict(); + this.testSize(); }, testAligned: function() { @@ -583,6 +584,60 @@ mindplot.nlayout.TestSuite = new Class({ var cx = prediction.getLast().x + canvas.width / 2 - mindplot.nlayout.TestSuite.NODE_SIZE.width / 2; var cy = prediction.getLast().y + canvas.height / 2 - mindplot.nlayout.TestSuite.NODE_SIZE.height / 2; canvas.rect(cx, cy, mindplot.nlayout.TestSuite.NODE_SIZE.width, mindplot.nlayout.TestSuite.NODE_SIZE.height); + }, + + testSize: function() { + var position = {x:0, y:0}; + var manager = new mindplot.nlayout.LayoutManager(0, mindplot.nlayout.TestSuite.ROOT_NODE_SIZE); + + manager.addNode(1, {width: 60, height: 60}, position); + manager.addNode(2, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(3, {width: 260, height: 30}, position); + manager.addNode(4, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(5, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(7, {width: 80, height: 80}, position); + manager.addNode(8, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(9, {width: 30, height: 30}, position); + manager.addNode(10, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(11, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(12, {width: 100, height: 70}, position); + manager.addNode(13, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(14, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(15, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(16, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(17, mindplot.nlayout.TestSuite.NODE_SIZE, position); + + manager.connectNode(0,1,0); + manager.connectNode(1,16,0); + manager.connectNode(0,2,1); + manager.connectNode(0,3,2); + manager.connectNode(0,4,3); + manager.connectNode(0,5,4); + manager.connectNode(4,7,0); + manager.connectNode(7,15,0); + manager.connectNode(7,17,1); + manager.connectNode(4,8,1); + manager.connectNode(8,9,0); + manager.connectNode(3,10,0); + manager.connectNode(3,11,1); + manager.connectNode(9,12,0); + manager.connectNode(9,13,1); + manager.connectNode(13,14,0); + + manager.layout(); + manager.plot("testSize1", {width: 1400, height: 400}); + + var graph2 = manager.plot("testSize2", {width: 1400, height: 400}); + this._plotPrediction(graph2, manager.predict(0, {x:-145, y:400})); + this._plotPrediction(graph2, manager.predict(9, {x:-330, y:70})); + this._plotPrediction(graph2, manager.predict(9, {x:-330, y:120})); + this._plotPrediction(graph2, manager.predict(0, {x:15, y:20})); + + var graph3 = manager.plot("testSize3", {width: 1400, height: 400}); + this._plotPrediction(graph3, manager.predict(0, null)); + this._plotPrediction(graph3, manager.predict(9, null)); + this._plotPrediction(graph3, manager.predict(3, null)); + this._plotPrediction(graph3, manager.predict(1, null)); } }); diff --git a/mindplot/src/test/javascript/static/layout.html b/mindplot/src/test/javascript/static/layout.html index d20840ae..d817a728 100644 --- a/mindplot/src/test/javascript/static/layout.html +++ b/mindplot/src/test/javascript/static/layout.html @@ -103,5 +103,10 @@
+

testSize:

+
+
+
+ \ No newline at end of file