Commit e766a386 authored by Akikonata's avatar Akikonata

dev

parent 102f2f3c
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
//标记左子树和右子树的元素 //标记左子树和右子树的元素
_root.setData("layerleft",[[_root]]); _root.setData("layerleft",[[_root]]);
_root.setData("layerright",[[_root]]); _root.setData("layerright",[[_root]]);
_root.setData("indexList",[0]);
//标记根节点以及添加子树的方向 //标记根节点以及添加子树的方向
_root.setData("appendside","right"); _root.setData("appendside","right");
......
...@@ -13,8 +13,10 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -13,8 +13,10 @@ KityMinder.registerModule( "LayoutModule", function () {
root.setData( "sidecount", sidecount + 1 ); root.setData( "sidecount", sidecount + 1 );
} }
} }
var _node = new MinderNode(); var _node = new MinderNode();
parent.insertChild( _node, index ); parent.insertChild( _node, index );
_node.setData( "appendside", appendSide ); _node.setData( "appendside", appendSide );
var parentX = parent.getData( "x" ); var parentX = parent.getData( "x" );
switch ( appendSide ) { switch ( appendSide ) {
...@@ -35,9 +37,43 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -35,9 +37,43 @@ KityMinder.registerModule( "LayoutModule", function () {
layerArray[ layer ] = layerArray[ layer ] || []; layerArray[ layer ] = layerArray[ layer ] || [];
var layerData = layerArray[ layer ]; var layerData = layerArray[ layer ];
var insertPos = 0; var insertPos = 0;
_node.setData( "layer", layer );
//获取层级链
var getIndexList = function ( node ) {
var indexList = [];
var parent = node;
do {
indexList.push( parent.getIndex() );
parent = parent.getParent();
} while ( parent );
return indexList.reverse();
};
//比较两个层级链的大小
var indexLarger = function ( List1, List2 ) {
var larger = true;
for ( var i = 0; i < List1.length; i++ ) {
if ( List1[ i ] == List2[ i ] ) {
continue;
}
if ( List1[ i ] < List2[ i ] ) {
larger = false;
}
break;
}
return larger;
};
//选定合适的位置插入节点
for ( var l = layerData.length - 1; l >= 0; l-- ) {
if ( !indexLarger( getIndexList( layerData[ l ] ), getIndexList( _node ) ) ) {
insertPos = l + 1;
break;
}
}
console.log( layerData );
layerData.splice( insertPos, 0, _node ); layerData.splice( insertPos, 0, _node );
_node.setData( "layer", layer );
//设置各节点Y坐标 //设置各节点Y坐标
var rootY = root.getData( "y" ); var rootY = root.getData( "y" );
...@@ -54,9 +90,6 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -54,9 +90,6 @@ KityMinder.registerModule( "LayoutModule", function () {
layerData[ j ].setData( "y", sY ); layerData[ j ].setData( "y", sY );
var part1 = ( layerData[ j ].getRenderContainer().getHeight() || defaultHeight ) / 2 + 15; var part1 = ( layerData[ j ].getRenderContainer().getHeight() || defaultHeight ) / 2 + 15;
var part2 = layerData[ j + 1 ] ? ( layerData[ j + 1 ].getRenderContainer().getHeight() || defaultHeight ) / 2 : 0; var part2 = layerData[ j + 1 ] ? ( layerData[ j + 1 ].getRenderContainer().getHeight() || defaultHeight ) / 2 : 0;
if ( layerData[ j + 1 ] ) {
console.log( layerData[ j + 1 ].getRenderContainer().getHeight() );
}
sY += ( part1 + part2 ); sY += ( part1 + part2 );
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment