mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-26 07:44:56 +01:00
Symmetric Sorter adapted to work on both directions
This commit is contained in:
parent
f355c5a23a
commit
f3d4c3cd5d
@ -123,7 +123,7 @@ mindplot.nlayout.BalancedSorter = new Class({
|
||||
// Compute the center of the branch ...
|
||||
var totalPHeight = 0;
|
||||
var totalNHeight = 0;
|
||||
//TODO(gb): optimize using filter
|
||||
|
||||
heights.forEach(function(elem) {
|
||||
if (elem.order % 2 == 0) {
|
||||
totalPHeight += elem.height;
|
||||
@ -133,7 +133,6 @@ mindplot.nlayout.BalancedSorter = new Class({
|
||||
});
|
||||
var psum = totalPHeight/2;
|
||||
var nsum = totalNHeight/2;
|
||||
var totalDifference = totalPHeight - totalNHeight;
|
||||
var ysum = 0;
|
||||
|
||||
// Calculate the offsets ...
|
||||
@ -149,10 +148,6 @@ mindplot.nlayout.BalancedSorter = new Class({
|
||||
ysum = nsum;
|
||||
}
|
||||
|
||||
// console.log("node {id: " + heights[i].id + ", order: " + heights[i].order + ", psum: " + psum + ", nsum: " + nsum + "}"); //TODO(gb): Remove trace!!!
|
||||
// console.log("totalPHeight: " + totalPHeight + ", totalNHeight: " + totalNHeight); //TODO(gb): Remove trace!!!
|
||||
console.log("node {id: " + heights[i].id + ", totalDifference: " + totalDifference + ", direction: " + direction + "}"); //TODO(gb): Remove trace!!!
|
||||
|
||||
var yOffset = ysum + heights[i].height/2;
|
||||
var xOffset = direction * (node.getSize().width + mindplot.nlayout.SymetricSorter.INTERNODE_HORIZONTAL_PADDING);
|
||||
|
||||
@ -161,7 +156,6 @@ mindplot.nlayout.BalancedSorter = new Class({
|
||||
|
||||
result[heights[i].id] = {x:xOffset,y:yOffset};
|
||||
}
|
||||
console.log("----------------------\n"); //TODO(gb): Remove trace!!!
|
||||
return result;
|
||||
},
|
||||
|
||||
@ -170,6 +164,5 @@ mindplot.nlayout.BalancedSorter = new Class({
|
||||
}
|
||||
});
|
||||
|
||||
mindplot.nlayout.BalancedSorter.INTERNODE_VERTICAL_PADDING = 5;
|
||||
mindplot.nlayout.BalancedSorter.INTERNODE_VERTICAL_PADDING = 10;
|
||||
mindplot.nlayout.BalancedSorter.INTERNODE_HORIZONTAL_PADDING = 5;
|
||||
mindplot.nlayout.BalancedSorter.INITIAL_HEIGHT = 100;
|
||||
|
@ -132,7 +132,7 @@ mindplot.nlayout.SymetricSorter = new Class({
|
||||
|
||||
// Compute heights ...
|
||||
var heights = children.map(function(child) {
|
||||
return {id:child.getId(),height:this._computeChildrenHeight(treeSet, child)};
|
||||
return {id:child.getId(), position: child.getPosition(), height: this._computeChildrenHeight(treeSet, child)};
|
||||
}, this);
|
||||
|
||||
|
||||
@ -148,18 +148,24 @@ mindplot.nlayout.SymetricSorter = new Class({
|
||||
for (var i = 0; i < heights.length; i++) {
|
||||
ysum = ysum - heights[i].height;
|
||||
|
||||
var parent = treeSet.getParent(treeSet.find(heights[i].id));
|
||||
var direction = parent.getPosition().x > 0 ? 1 : -1;
|
||||
|
||||
var yOffset = ysum + heights[i].height/2;
|
||||
var xOffset = node.getSize().width + mindplot.nlayout.SymetricSorter.INTERNODE_HORIZONTAL_PADDING;
|
||||
var xOffset = direction * (node.getSize().width + mindplot.nlayout.SymetricSorter.INTERNODE_HORIZONTAL_PADDING);
|
||||
|
||||
$assert(!isNaN(xOffset), "xOffset can not be null");
|
||||
$assert(!isNaN(yOffset), "yOffset can not be null");
|
||||
|
||||
result[heights[i].id] = {x:xOffset,y:yOffset};
|
||||
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
_getRootNode: function(treeSet) {
|
||||
var roots = treeSet.getTreeRoots();
|
||||
},
|
||||
|
||||
toString:function() {
|
||||
return "Symmetric Sorter";
|
||||
}
|
||||
|
@ -18,16 +18,16 @@
|
||||
mindplot.nlayout.TestSuite = new Class({
|
||||
Extends: mindplot.nlayout.ChildrenSorterStrategy,
|
||||
initialize:function() {
|
||||
// this.testAligned();
|
||||
// this.testSymmetry();
|
||||
this.testAligned();
|
||||
this.testSymmetry();
|
||||
this.testBalanced();
|
||||
// this.testGrid();
|
||||
// this.testEvents();
|
||||
// this.testEventsComplex();
|
||||
// this.testDisconnect();
|
||||
// this.testReconnect();
|
||||
// this.testRemoveNode();
|
||||
// this.testFreePosition();
|
||||
this.testGrid();
|
||||
this.testEvents();
|
||||
this.testEventsComplex();
|
||||
this.testDisconnect();
|
||||
this.testReconnect();
|
||||
this.testRemoveNode();
|
||||
this.testFreePosition();
|
||||
},
|
||||
|
||||
testAligned: function() {
|
||||
@ -98,12 +98,10 @@ mindplot.nlayout.TestSuite = new Class({
|
||||
},
|
||||
|
||||
testBalanced: function() {
|
||||
// var size = {width:80, height:30};
|
||||
var size = {width:25, height:25};
|
||||
var plotsize = {width: 400, height:280};
|
||||
var size = {width:80, height:30};
|
||||
var plotsize = {width: 800, height:400};
|
||||
var position = {x:0, y:0};
|
||||
// var manager = new mindplot.nlayout.LayoutManager(0, {width:120, height:40});
|
||||
var manager = new mindplot.nlayout.LayoutManager(0, size);
|
||||
var manager = new mindplot.nlayout.LayoutManager(0, {width:120, height:40});
|
||||
|
||||
manager.addNode(1, size, position);
|
||||
manager.connectNode(0, 1, 0);
|
||||
@ -134,6 +132,24 @@ mindplot.nlayout.TestSuite = new Class({
|
||||
manager.connectNode(0, 6, 5);
|
||||
manager.layout();
|
||||
manager.plot("testBalanced6", plotsize);
|
||||
|
||||
manager.addNode(7, size, position);
|
||||
manager.addNode(8, size, position);
|
||||
manager.addNode(9, size, position);
|
||||
manager.connectNode(3, 7, 0)
|
||||
manager.connectNode(7, 8, 0)
|
||||
manager.connectNode(7, 9, 1);
|
||||
manager.layout();
|
||||
manager.plot("testBalanced7", plotsize);
|
||||
|
||||
manager.addNode(10, size, position);
|
||||
manager.addNode(11, size, position);
|
||||
manager.addNode(12, size, position);
|
||||
manager.connectNode(6, 10, 0)
|
||||
manager.connectNode(10, 11, 0)
|
||||
manager.connectNode(10, 12, 1);
|
||||
manager.layout();
|
||||
manager.plot("testBalanced8", plotsize);
|
||||
},
|
||||
|
||||
testGrid: function() {
|
||||
|
@ -65,6 +65,8 @@
|
||||
<div id="testBalanced4" class="col"></div>
|
||||
<div id="testBalanced5" class="col"></div>
|
||||
<div id="testBalanced6" class="col last"></div>
|
||||
<div id="testBalanced7" class="col"></div>
|
||||
<div id="testBalanced8" class="col last"></div>
|
||||
|
||||
<h2>testEvents:</h2>
|
||||
<div id="testEvents1" class="col"></div>
|
||||
|
Loading…
Reference in New Issue
Block a user