Commit fdeb0a30 authored by techird's avatar techird

merge changes

parents ce1fca81 7bbed859
...@@ -41,7 +41,7 @@ function importNode( node, json, km ) { ...@@ -41,7 +41,7 @@ function importNode( node, json, km ) {
for ( var field in data ) { for ( var field in data ) {
node.setData( field, data[ field ] ); node.setData( field, data[ field ] );
} }
node.setData( 'text',data.text || km.getLang( DEFAULT_TEXT[ node.getType() ] ) ); node.setData( 'text', data.text || km.getLang( DEFAULT_TEXT[ node.getType() ] ) );
var childrenTreeData = json.children; var childrenTreeData = json.children;
if ( !childrenTreeData ) return; if ( !childrenTreeData ) return;
...@@ -53,7 +53,6 @@ function importNode( node, json, km ) { ...@@ -53,7 +53,6 @@ function importNode( node, json, km ) {
return node; return node;
} }
// 导入导出 // 导入导出
kity.extendClass( Minder, { kity.extendClass( Minder, {
exportData: function ( protocalName ) { exportData: function ( protocalName ) {
...@@ -62,11 +61,11 @@ kity.extendClass( Minder, { ...@@ -62,11 +61,11 @@ kity.extendClass( Minder, {
json = exportNode( this.getRoot() ); json = exportNode( this.getRoot() );
protocal = KityMinder.findProtocal( protocalName ); protocal = KityMinder.findProtocal( protocalName );
if(this._fire( new MinderEvent( 'beforeexport', { if ( this._fire( new MinderEvent( 'beforeexport', {
json:json, json: json,
protocalName: protocalName, protocalName: protocalName,
protocal: protocal protocal: protocal
},true ) ) === true) return; }, true ) ) === true ) return;
if ( protocal ) { if ( protocal ) {
return protocal.encode( json, this ); return protocal.encode( json, this );
...@@ -106,44 +105,48 @@ kity.extendClass( Minder, { ...@@ -106,44 +105,48 @@ kity.extendClass( Minder, {
//******************* //*******************
function ts(d, str, last){ function ts( d, str, last ) {
var h = d.getHours(), var h = d.getHours(),
m = d.getMinutes(), m = d.getMinutes(),
s = d.getSeconds(), s = d.getSeconds(),
ms = d.getMilliseconds(); ms = d.getMilliseconds();
if(last){ if ( last ) {
console.log('--- '+str+': '+(d-last)+' ---'); console.log( '--- ' + str + ': ' + ( d - last ) + ' ---' );
}else{ } else {
console.log('--- '+str+' ---'); console.log( '--- ' + str + ' ---' );
} }
return d; return d;
} }
var t1 = ts(new Date(), '开始解析'); var t1 = ts( new Date(), '开始解析' );
//******************* //*******************
json = params.json || ( params.json = protocal.decode( local ) ); json = params.json || ( params.json = protocal.decode( local ) );
this._fire(new MinderEvent('importData',{
data:json
},true));
if ( typeof json === 'object' && 'then' in json ) { if ( typeof json === 'object' && 'then' in json ) {
var self = this; var self = this;
json.then( local, function ( data ) { json.then( local, function ( data ) {
//******************* //*******************
var t2 = ts(new Date(), '解压解析耗时', t1); var t2 = ts( new Date(), '解压解析耗时', t1 );
//******************* //*******************
self._afterImportData( data, params ); self._afterImportData( data, params );
//******************* //*******************
ts(new Date(), '渲染耗时', t2); ts( new Date(), '渲染耗时', t2 );
//******************* //*******************
} ); } );
} else { } else {
//******************* //*******************
var t2 = ts(new Date(), '解压解析耗时', t1); var t2 = ts( new Date(), '解压解析耗时', t1 );
//******************* //*******************
this._afterImportData( json, params ); this._afterImportData( json, params );
//******************* //*******************
ts(new Date(), '渲染耗时', t2); ts( new Date(), '渲染耗时', t2 );
//******************* //*******************
} }
return this; return this;
......
...@@ -14,6 +14,7 @@ KityMinder.registerModule( "Expand", function () { ...@@ -14,6 +14,7 @@ KityMinder.registerModule( "Expand", function () {
* @param {Function} policy_after_level 超过的层数执行的策略 * @param {Function} policy_after_level 超过的层数执行的策略
*/ */
function generateDeepPolicy( deep_level, policy_after_level ) { function generateDeepPolicy( deep_level, policy_after_level ) {
return function ( node, state, policy, level ) { return function ( node, state, policy, level ) {
var children, child, i; var children, child, i;
...@@ -93,10 +94,15 @@ KityMinder.registerModule( "Expand", function () { ...@@ -93,10 +94,15 @@ KityMinder.registerModule( "Expand", function () {
* 判断节点当前的状态是否为展开 * 判断节点当前的状态是否为展开
*/ */
isExpanded: function () { isExpanded: function () {
return !!node.getData( EXPAND_STATE_DATA ); return this.getData( EXPAND_STATE_DATA ) === STATE_EXPAND;
} }
} ); } );
return { return {
'events': {
'importData': function ( e ) {
var data = e.data;
}
},
'commands': {} 'commands': {}
}; };
} ); } );
\ No newline at end of file
...@@ -423,9 +423,6 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -423,9 +423,6 @@ KityMinder.registerModule( "LayoutDefault", function () {
if ( nodeType !== "root" && node.getChildren().length !== 0 ) { if ( nodeType !== "root" && node.getChildren().length !== 0 ) {
if ( !Layout.shicon ) { if ( !Layout.shicon ) {
Layout.shicon = new ShIcon( node ); Layout.shicon = new ShIcon( node );
if ( Layout.expand ) {
Layout.shicon.switchState();
}
} }
Layout.shicon.update(); Layout.shicon.update();
} }
...@@ -508,7 +505,8 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -508,7 +505,8 @@ KityMinder.registerModule( "LayoutDefault", function () {
this.highlightNode( node ) this.highlightNode( node )
} }
}, },
initStyle: function ( expandall ) { initStyle: function () {
//渲染根节点
var _root = minder.getRoot(); var _root = minder.getRoot();
var historyPoint = _root.getPoint(); var historyPoint = _root.getPoint();
if ( historyPoint ) historyPoint = JSON.parse( JSON.stringify( historyPoint ) ); if ( historyPoint ) historyPoint = JSON.parse( JSON.stringify( historyPoint ) );
...@@ -541,61 +539,71 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -541,61 +539,71 @@ KityMinder.registerModule( "LayoutDefault", function () {
updateLayoutVertical( _root ); updateLayoutVertical( _root );
translateNode( _root ); translateNode( _root );
if ( historyPoint ) _root.setPoint( historyPoint.x, historyPoint.y ); 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(); var mains = _root.getChildren();
for ( var i = 0; i < mains.length; i++ ) { for ( var i = 0; i < mains.length; i++ ) {
this.appendChildNode( _root, mains[ 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 ] );
} }
cur_layer++;
var clonelayer0 = function () {
var items = [];
for ( var i = 0; i < mains.length; i++ ) {
items.push( mains[ i ] );
} }
return items; _root.setPoint( _root.getLayout().x, _root.getLayout().y );
}; },
//创建一级节点的副本 expandNode: function ( ico ) {
var _buffer = clonelayer0(); var isExpand, node;
next = []; if ( ico instanceof MinderNode ) {
var layer_nolimit = expandall || ( expand_layer < 1 ) || false; node = ico;
var sub_nolimit = expandall || ( expandoptions.defaultSubShow < 1 ) || false; isExpand = node.getLayout().shicon.switchState();
} else {
isExpand = ico.icon.switchState();
node = ico.icon._node;
}
var _buffer;
if ( isExpand ) {
node.expand();
//遍历子树展开需要展开的节点
_buffer = [ node ];
debugger;
while ( _buffer.length !== 0 ) { while ( _buffer.length !== 0 ) {
cur_layer++; var c = _buffer[ 0 ].getChildren();
var layer_len = _buffer.length; if ( _buffer[ 0 ].isExpanded() && c.length !== 0 ) {
for ( var j = 0; j < layer_len; j++ ) { for ( var x = 0; x < c.length; x++ ) {
var c = _buffer[ j ].getChildren(); minder.appendChildNode( _buffer[ 0 ], c[ x ] );
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() );
} }
_buffer = _buffer.concat( c );
}
_buffer.shift();
}
} else {
node.collapse();
//遍历子树移除需要移除的节点
_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 = updateLayoutVertical( node, node.getParent(), "contract" );
for ( var i = 0; i < set.length; i++ ) {
translateNode( set[ i ] );
updateConnectAndshIcon( set[ i ] );
} }
_buffer.splice( 0, layer_len );
} }
_root.setPoint( _root.getLayout().x, _root.getLayout().y );
}, },
appendChildNode: function ( parent, node, focus, sibling ) { appendChildNode: function ( parent, node, focus, sibling ) {
if ( parent.getType() !== "root" && parent.getChildren().length !== 0 && parent.getLayout().expand === false ) {
minder.expandNode( parent );
}
minder.handelNodeInsert( node ); minder.handelNodeInsert( node );
var Layout = node.getLayout(); var Layout = node.getLayout();
var oldExpand;
if ( Layout ) {
oldExpand = Layout.expand;
}
node.clearLayout(); node.clearLayout();
node.getContRc().clear(); node.getContRc().clear();
Layout = node.getLayout(); Layout = node.getLayout();
Layout.expand = oldExpand || false;
if ( parent.getType() !== 'root' ) {
parent.getLayout().expand = true;
}
Layout.added = true; Layout.added = true;
var parentLayout = parent.getLayout(); var parentLayout = parent.getLayout();
var children = parent.getChildren(); var children = parent.getChildren();
...@@ -744,43 +752,6 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -744,43 +752,6 @@ KityMinder.registerModule( "LayoutDefault", function () {
_buffer.shift(); _buffer.shift();
} }
} }
},
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 ); this.addLayoutStyle( "default", _style );
......
...@@ -38,7 +38,7 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -38,7 +38,7 @@ KityMinder.registerModule( "LayoutModule", function () {
var curStyle = this.getCurrentStyle(); var curStyle = this.getCurrentStyle();
this.getLayoutStyle( curStyle ).highlightNode.call( this, node ); this.getLayoutStyle( curStyle ).highlightNode.call( this, node );
}, },
initStyle: function ( expandall ) { initStyle: function () {
var curStyle = this.getCurrentStyle(); var curStyle = this.getCurrentStyle();
this._rc.remove(); this._rc.remove();
this._rc = new kity.Group(); this._rc = new kity.Group();
...@@ -46,10 +46,9 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -46,10 +46,9 @@ KityMinder.registerModule( "LayoutModule", function () {
var _root = this.getRoot(); var _root = this.getRoot();
_root.preTraverse( function ( n ) { _root.preTraverse( function ( n ) {
var oldLayout = n.getLayout();
n.clearLayout(); n.clearLayout();
} ); } );
this.getLayoutStyle( curStyle ).initStyle.call( this, expandall ); this.getLayoutStyle( curStyle ).initStyle.call( this );
this.fire( 'afterinitstyle' ); this.fire( 'afterinitstyle' );
}, },
restoreStyle: function () { restoreStyle: function () {
...@@ -127,7 +126,7 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -127,7 +126,7 @@ KityMinder.registerModule( "LayoutModule", function () {
if ( !parent ) { if ( !parent ) {
return null; 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 ); 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