Commit a0ecff6d authored by Akikonata's avatar Akikonata

recover the layout

parent afec1e6f
......@@ -47,11 +47,11 @@ KityMinder.registerModule( "Expand", function () {
node.setData( EXPAND_STATE_DATA, STATE_COLLAPSE );
},
isExpanded: function () {
return node.getData( EXPAND_STATE_DATA ) === STATE_EXPAND;
//return this.getData( EXPAND_STATE_DATA ) === STATE_EXPAND;
return true;
}
} );
return {
'commands': {
}
'commands': {}
};
} );
\ No newline at end of file
......@@ -423,9 +423,6 @@ KityMinder.registerModule( "LayoutDefault", function () {
if ( nodeType !== "root" && node.getChildren().length !== 0 ) {
if ( !Layout.shicon ) {
Layout.shicon = new ShIcon( node );
if ( Layout.expand ) {
Layout.shicon.switchState();
}
}
Layout.shicon.update();
}
......@@ -546,7 +543,13 @@ KityMinder.registerModule( "LayoutDefault", function () {
var mains = _root.getChildren();
for ( var i = 0; i < mains.length; i++ ) {
this.appendChildNode( _root, mains[ i ] );
//console.log( mains[ i ].isExpanded() );
if ( mains[ i ].isExpanded() && mains[ i ].getChildren().length > 0 ) {
debugger;
minder.expandNode( mains[ i ] );
}
}
_root.setPoint( _root.getLayout().x, _root.getLayout().y );
},
expandNode: function ( ico ) {
var isExpand, node;
......@@ -557,15 +560,24 @@ KityMinder.registerModule( "LayoutDefault", function () {
isExpand = ico.icon.switchState();
node = ico.icon._node;
}
var Layout = node.getLayout();
Layout.expand = isExpand;
var _buffer = node.getChildren();
var _buffer;
if ( isExpand ) {
for ( var j = 0; j < _buffer.length; j++ ) {
minder.appendChildNode( node, _buffer[ j ] );
//遍历子树展开需要展开的节点
_buffer = [ node ];
debugger;
while ( _buffer.length !== 0 ) {
var c = _buffer[ 0 ].getChildren();
if ( _buffer[ 0 ].isExpanded() && c.length !== 0 ) {
for ( var x = 0; x < c.length; x++ ) {
minder.appendChildNode( _buffer[ 0 ], c[ x ] );
}
_buffer = _buffer.concat( c );
}
_buffer.shift();
}
} else {
var _buffer = node.getChildren();
//遍历子树移除需要移除的节点
_buffer = node.getChildren();
while ( _buffer.length !== 0 ) {
var Layout = _buffer[ 0 ].getLayout();
if ( Layout.added ) {
......@@ -577,85 +589,38 @@ KityMinder.registerModule( "LayoutDefault", function () {
_buffer = _buffer.concat( _buffer[ 0 ].getChildren() );
_buffer.shift();
}
}
var set = [];
if ( !isExpand ) set = updateLayoutVertical( node, node.getParent(), "contract" );
var set = updateLayoutVertical( node, node.getParent(), "contract" );
for ( var i = 0; i < set.length; i++ ) {
translateNode( set[ i ] );
updateConnectAndshIcon( set[ i ] );
}
},
// initStyle: function ( expandall ) {
// var _root = minder.getRoot();
// var historyPoint = _root.getPoint();
// if ( historyPoint ) historyPoint = JSON.parse( JSON.stringify( historyPoint ) );
// minder.handelNodeInsert( _root );
// //设置root的align
// _root.getLayout().align = "center";
// updateBg( _root );
// initLayout( _root );
// _root.getContRc().clear();
// this._firePharse( new MinderEvent( "RenderNodeLeft", {
// node: _root
// }, false ) );
// this._firePharse( new MinderEvent( "RenderNodeCenter", {
// node: _root
// }, false ) );
// this._firePharse( new MinderEvent( "RenderNodeRight", {
// node: _root
// }, false ) );
// this._firePharse( new MinderEvent( "RenderNodeBottom", {
// node: _root
// }, false ) );
// this._firePharse( new MinderEvent( "RenderNodeTop", {
// node: _root
// }, false ) );
// this._firePharse( new MinderEvent( "RenderNode", {
// node: _root
// }, false ) );
// updateShapeByCont( _root );
// updateLayoutHorizon( _root );
// updateLayoutVertical( _root );
// translateNode( _root );
// if ( historyPoint ) _root.setPoint( historyPoint.x, historyPoint.y );
// var expandoptions = minder.getOptions( 'defaultExpand' );
// var cur_layer = 0;
// var expand_layer = expandoptions.defaultLayer;
// var mains = _root.getChildren();
// for ( var i = 0; i < mains.length; i++ ) {
// this.appendChildNode( _root, mains[ i ] );
// }
// cur_layer++;
// var clonelayer0 = function () {
// var items = [];
// for ( var i = 0; i < mains.length; i++ ) {
// items.push( mains[ i ] );
}
// var _buffer = node.getChildren();
// if ( isExpand ) {
// for ( var j = 0; j < _buffer.length; j++ ) {
// minder.appendChildNode( node, _buffer[ j ] );
// }
// return items;
// };
// //创建一级节点的副本
// var _buffer = clonelayer0();
// next = [];
// var layer_nolimit = expandall || ( expand_layer < 1 ) || false;
// var sub_nolimit = expandall || ( expandoptions.defaultSubShow < 1 ) || false;
// } else {
// var _buffer = node.getChildren();
// while ( _buffer.length !== 0 ) {
// cur_layer++;
// var layer_len = _buffer.length;
// for ( var j = 0; j < layer_len; j++ ) {
// var c = _buffer[ j ].getChildren();
// if (
// (
// ( ( sub_nolimit || ( c.length <= expandoptions.defaultSubShow ) ) && ( layer_nolimit || ( cur_layer <= expand_layer ) ) ) ||
// _buffer[ j ].getLayout().expand
// ) && c.length !== 0 ) {
// this.expandNode( _buffer[ j ] );
// _buffer = _buffer.concat( _buffer[ j ].getChildren() );
// var Layout = _buffer[ 0 ].getLayout();
// if ( Layout.added ) {
// Layout.added = false;
// _buffer[ 0 ].getRenderContainer().remove();
// Layout.connect.remove();
// if ( Layout.shicon ) Layout.shicon.remove();
// }
// _buffer = _buffer.concat( _buffer[ 0 ].getChildren() );
// _buffer.shift();
// }
// }
// _buffer.splice( 0, layer_len );
// var set = [];
// if ( !isExpand ) set = updateLayoutVertical( node, node.getParent(), "contract" );
// for ( var i = 0; i < set.length; i++ ) {
// translateNode( set[ i ] );
// updateConnectAndshIcon( set[ i ] );
// }
// _root.setPoint( _root.getLayout().x, _root.getLayout().y );
// },
},
appendChildNode: function ( parent, node, focus, sibling ) {
minder.handelNodeInsert( node );
var Layout = node.getLayout();
......@@ -810,48 +775,7 @@ KityMinder.registerModule( "LayoutDefault", function () {
_buffer.shift();
}
}
},
expandNode: function ( ico ) {
}
//,
// expandNode: function ( ico ) {
// var isExpand, node;
// if ( ico instanceof MinderNode ) {
// node = ico;
// isExpand = node.getLayout().shicon.switchState();
// } else {
// isExpand = ico.icon.switchState();
// node = ico.icon._node;
// }
// var Layout = node.getLayout();
// Layout.expand = isExpand;
// var _buffer = node.getChildren();
// if ( isExpand ) {
// for ( var j = 0; j < _buffer.length; j++ ) {
// minder.appendChildNode( node, _buffer[ j ] );
// }
// } else {
// var _buffer = node.getChildren();
// while ( _buffer.length !== 0 ) {
// var Layout = _buffer[ 0 ].getLayout();
// if ( Layout.added ) {
// Layout.added = false;
// _buffer[ 0 ].getRenderContainer().remove();
// Layout.connect.remove();
// if ( Layout.shicon ) Layout.shicon.remove();
// }
// _buffer = _buffer.concat( _buffer[ 0 ].getChildren() );
// _buffer.shift();
// }
// }
// var set = [];
// if ( !isExpand ) set = updateLayoutVertical( node, node.getParent(), "contract" );
// for ( var i = 0; i < set.length; i++ ) {
// translateNode( set[ i ] );
// updateConnectAndshIcon( set[ i ] );
// }
// }
};
this.addLayoutStyle( "default", _style );
return {};
......
......@@ -38,7 +38,7 @@ KityMinder.registerModule( "LayoutModule", function () {
var curStyle = this.getCurrentStyle();
this.getLayoutStyle( curStyle ).highlightNode.call( this, node );
},
initStyle: function ( expandall ) {
initStyle: function () {
var curStyle = this.getCurrentStyle();
this._rc.remove();
this._rc = new kity.Group();
......@@ -46,10 +46,9 @@ KityMinder.registerModule( "LayoutModule", function () {
var _root = this.getRoot();
_root.preTraverse( function ( n ) {
var oldLayout = n.getLayout();
n.clearLayout();
} );
this.getLayoutStyle( curStyle ).initStyle.call( this, expandall );
this.getLayoutStyle( curStyle ).initStyle.call( this );
this.fire( 'afterinitstyle' );
},
restoreStyle: function () {
......@@ -127,7 +126,7 @@ KityMinder.registerModule( "LayoutModule", function () {
if ( !parent ) {
return null;
}
if ( parent.getType() !== "root" && parent.getChildren().length !== 0 && parent.getLayout().expand === false ) {
if ( parent.getType() !== "root" && parent.getChildren().length !== 0 && !parent.isExpanded() ) {
km.expandNode( parent );
}
......
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