Commit 016b3222 authored by campaign's avatar campaign

Merge branch 'dev' of https://github.com/kitygraph/kityminder into dev

parents 14502fba d0f3ce2b
...@@ -22,6 +22,6 @@ ...@@ -22,6 +22,6 @@
</div> </div>
</body> </body>
<script> <script>
var km = KM.getKityMinder('kityminder'); window.km = KM.getKityMinder('kityminder');
</script> </script>
</html> </html>
\ No newline at end of file
This diff is collapsed.
...@@ -51,7 +51,8 @@ $dependency = Array( ...@@ -51,7 +51,8 @@ $dependency = Array(
,'src/adapter/adapter.js' ,'src/adapter/adapter.js'
,'src/adapter/button.js' ,'src/adapter/button.js'
,'src/adapter/combobox.js' ,'src/adapter/combobox.js'
,'src/protocal/plain.js'
,'src/protocal/json.js'
); );
$content = ""; $content = "";
......
utils.extend(KityMinder,function(){ utils.extend( KityMinder, function () {
var _kityminderUI = {}, var _kityminderUI = {},
_activeWidget = null, _activeWidget = null,
_widgetData = {}, _widgetData = {},
_widgetCallBack = {}; _widgetCallBack = {};
return { return {
registerUI:function(uiname,fn){ registerUI: function ( uiname, fn ) {
utils.each(uiname.split(/\s+/), function (i,name) { utils.each( uiname.split( /\s+/ ), function ( i, name ) {
_kityminderUI[name] = fn; _kityminderUI[ name ] = fn;
}) } )
}, },
_createUI:function(id){ _createUI: function ( id ) {
var $cont = $('<div class="kmui-container"></div>'), var $cont = $( '<div class="kmui-container"></div>' ),
$toolbar = $.kmuitoolbar(), $toolbar = $.kmuitoolbar(),
$kmbody = $('<div class="kmui-editor-body"></div>'), $kmbody = $( '<div class="kmui-editor-body"></div>' ),
$statusbar = $('<div class="kmui-statusbar"></div>'); $statusbar = $( '<div class="kmui-statusbar"></div>' );
$cont.append($toolbar).append($kmbody).append($statusbar); $cont.append( $toolbar ).append( $kmbody ).append( $statusbar );
$(utils.isString(id) ? '#' + id : id).append($cont); $( utils.isString( id ) ? '#' + id : id ).append( $cont );
return { return {
'$container':$cont, '$container': $cont,
'$toolbar':$toolbar, '$toolbar': $toolbar,
'$body':$kmbody, '$body': $kmbody,
'$statusbar':$statusbar '$statusbar': $statusbar
}; };
}, },
_createToolbar:function($toolbar,km){ _createToolbar: function ( $toolbar, km ) {
var toolbars = km.getOptions('toolbars'); var toolbars = km.getOptions( 'toolbars' );
if (toolbars && toolbars.length) { if ( toolbars && toolbars.length ) {
var btns = []; var btns = [];
$.each(toolbars,function(i,uiNames){ $.each( toolbars, function ( i, uiNames ) {
$.each(uiNames.split(/\s+/),function(index,name){ $.each( uiNames.split( /\s+/ ), function ( index, name ) {
if(name == '|'){ if ( name == '|' ) {
$.kmuiseparator && btns.push($.kmuiseparator()); $.kmuiseparator && btns.push( $.kmuiseparator() );
}else{ } else {
if(_kityminderUI[name]){ if ( _kityminderUI[ name ] ) {
var ui = _kityminderUI[name].call(km,name); var ui = _kityminderUI[ name ].call( km, name );
ui && btns.push(ui); ui && btns.push( ui );
} }
} }
}); } );
btns.length && $toolbar.kmui().appendToBtnmenu(btns); btns.length && $toolbar.kmui().appendToBtnmenu( btns );
}); } );
} }
$toolbar.append($('<div class="kmui-dialog-container"></div>')); $toolbar.append( $( '<div class="kmui-dialog-container"></div>' ) );
}, },
_createStatusbar:function($statusbar,km){ _createStatusbar: function ( $statusbar, km ) {
}, },
getKityMinder:function(id,options){ getKityMinder: function ( id, options ) {
var containers = this._createUI(id); var containers = this._createUI( id );
var km = this.getMinder(containers.$body.get(0),options); var km = this.getMinder( containers.$body.get( 0 ), options );
this._createToolbar(containers.$toolbar,km); this._createToolbar( containers.$toolbar, km );
this._createStatusbar(containers.$statusbar,km); this._createStatusbar( containers.$statusbar, km );
km.$container = containers.$container; km.$container = containers.$container;
return km; return km;
}, },
registerWidget : function(name,pro,cb){ registerWidget: function ( name, pro, cb ) {
_widgetData[name] = $.extend2(pro,{ _widgetData[ name ] = $.extend2( pro, {
$root : '', $root: '',
_preventDefault:false, _preventDefault: false,
root:function($el){ root: function ( $el ) {
return this.$root || (this.$root = $el); return this.$root || ( this.$root = $el );
}, },
preventDefault:function(){ preventDefault: function () {
this._preventDefault = true; this._preventDefault = true;
}, },
clear:false clear: false
}); } );
if(cb){ if ( cb ) {
_widgetCallBack[name] = cb; _widgetCallBack[ name ] = cb;
} }
}, },
getWidgetData : function(name){ getWidgetData: function ( name ) {
return _widgetData[name] return _widgetData[ name ]
}, },
setWidgetBody : function(name,$widget,km){ setWidgetBody: function ( name, $widget, km ) {
if(!km._widgetData){ if ( !km._widgetData ) {
utils.extend(km,{ utils.extend( km, {
_widgetData : {}, _widgetData: {},
getWidgetData : function(name){ getWidgetData: function ( name ) {
return this._widgetData[name]; return this._widgetData[ name ];
}, },
getWidgetCallback : function(widgetName){ getWidgetCallback: function ( widgetName ) {
var me = this; var me = this;
return function(){ return function () {
return _widgetCallBack[widgetName].apply(me,[me,$widget].concat(utils.argsToArray(arguments,0))) return _widgetCallBack[ widgetName ].apply( me, [ me, $widget ].concat( utils.argsToArray( arguments, 0 ) ) )
} }
} }
}) } )
} }
var pro = _widgetData[name]; var pro = _widgetData[ name ];
if(!pro){ if ( !pro ) {
return null; return null;
} }
pro = km._widgetData[name]; pro = km._widgetData[ name ];
if(!pro){ if ( !pro ) {
pro = _widgetData[name]; pro = _widgetData[ name ];
pro = km._widgetData[name] = $.type(pro) == 'function' ? pro : utils.clone(pro); pro = km._widgetData[ name ] = $.type( pro ) == 'function' ? pro : utils.clone( pro );
} }
pro.root($widget.kmui().getBodyContainer()); pro.root( $widget.kmui().getBodyContainer() );
pro.initContent(km,$widget); pro.initContent( km, $widget );
if(!pro._preventDefault){ if ( !pro._preventDefault ) {
pro.initEvent(km,$widget); pro.initEvent( km, $widget );
} }
pro.width && $widget.width(pro.width); pro.width && $widget.width( pro.width );
}, },
setActiveWidget : function($widget){ setActiveWidget: function ( $widget ) {
_activeWidget = $widget; _activeWidget = $widget;
} }
} }
}()); }() );
Utils.extend( KityMinder, {
_protocals: {},
registerProtocal: function ( name, protocalDeal ) {
KityMinder._protocals[ name ] = protocalDeal();
},
findProtocal: function ( name ) {
return KityMinder._protocals[ name ] || null;
},
getSupportedProtocals: function () {
return Utils.keys( KityMinder._protocals );
}
} );
// 这里的 Json 是一个对象
function exportNode( node ) {
var exported = {};
exported.data = node.getData();
var childNodes = node.getChildren();
if ( childNodes.length ) {
exported.children = [];
for ( var i = 0; i < childNodes.length; i++ ) {
exported.children.push( exportNode( childNodes[ i ] ) );
}
}
return exported;
}
function importNode( node, json ) {
var data = json.data;
for ( var field in data ) {
node.setData( field, data[ field ] );
}
var childrenTreeData = json.children;
if ( !childrenTreeData ) return;
for ( var i = 0; i < childrenTreeData.length; i++ ) {
var childNode = new MinderNode();
importNode( childNode, childrenTreeData[ i ] );
node.appendChild( childNode );
}
return node;
}
// 导入导出 // 导入导出
kity.extendClass( Minder, { kity.extendClass( Minder, {
exportData: function ( node ) { exportData: function ( protocalName ) {
var exported = {}; var json, protocal;
node = node || this.getRoot();
exported.data = node.getData(); json = exportNode( this.getRoot() );
var childNodes = node.getChildren(); protocal = KityMinder.findProtocal( protocalName );
if ( childNodes.length ) { if ( protocal ) {
exported.children = []; return protocal.encode( json );
for ( var i = 0; i < childNodes.length; i++ ) { } else {
exported.children.push( this.exportData( childNodes[ i ] ) ); return json;
}
} }
return exported;
}, },
importData: function ( treeData ) { importData: function ( local, protocalName ) {
function importToNode( treeData, node ) { var json, protocal;
var data = treeData.data;
for ( var field in data ) { if ( protocalName ) {
node.setData( field, data[ field ] ); protocal = KityMinder.findProtocal( protocalName );
} } else {
KityMinder.getSupportedProtocals().every( function ( name ) {
var childrenTreeData = treeData.children; var test = KityMinder.findProtocal( name );
if ( !childrenTreeData ) return; if ( test.recognize && test.recognize( local ) ) {
for ( var i = 0; i < childrenTreeData.length; i++ ) { protocal = test;
var childNode = new MinderNode(); }
importToNode( childrenTreeData[ i ], childNode ); return !test;
node.appendChild( childNode ); } );
} }
if ( !protocal ) {
throw new Error( "Unsupported protocal: " + protocalName );
} }
var params = { var params = {
importData: treeData local: local,
protocalName: protocalName,
protocal: protocal
}; };
// 是否需要阻止导入
var stoped = this._fire( new MinderEvent( 'beforeimport', params, true ) ); var stoped = this._fire( new MinderEvent( 'beforeimport', params, true ) );
if ( stoped ) return this; if ( stoped ) return this;
json = params.json || ( params.json = protocal.decode( local ) );
this._fire( new MinderEvent( 'preimport', params, false ) ); this._fire( new MinderEvent( 'preimport', params, false ) );
// 删除当前所有节点
while ( this._root.getChildren().length ) { while ( this._root.getChildren().length ) {
this._root.removeChild( 0 ); this._root.removeChild( 0 );
} }
importToNode( treeData, this._root );
importNode( this._root, json );
this._fire( new MinderEvent( 'import', params, false ) ); this._fire( new MinderEvent( 'import', params, false ) );
this._firePharse( { this._firePharse( {
...@@ -52,6 +103,7 @@ kity.extendClass( Minder, { ...@@ -52,6 +103,7 @@ kity.extendClass( Minder, {
this._firePharse( { this._firePharse( {
type: 'interactchange' type: 'interactchange'
} ); } );
return this; return this;
} }
} ); } );
\ No newline at end of file
...@@ -3,7 +3,7 @@ kity.extendClass( Minder, { ...@@ -3,7 +3,7 @@ kity.extendClass( Minder, {
getRoot: function () { getRoot: function () {
return this._root; return this._root;
}, },
setRoot:function(root){ setRoot: function ( root ) {
this._root = root; this._root = root;
}, },
handelNodeInsert: function ( node ) { handelNodeInsert: function ( node ) {
......
...@@ -227,7 +227,7 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", { ...@@ -227,7 +227,7 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", {
}, },
clone: function () { clone: function () {
function cloneNode( parent, isClonedNode ) { function cloneNode( parent, isClonedNode ) {
var _tmp = new KM.MinderNode(isClonedNode.getText()); var _tmp = new KM.MinderNode( isClonedNode.getText() );
_tmp.data = Utils.clonePlainObject( isClonedNode.getData() ); _tmp.data = Utils.clonePlainObject( isClonedNode.getData() );
_tmp.parent = parent; _tmp.parent = parent;
...@@ -266,5 +266,8 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", { ...@@ -266,5 +266,8 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", {
}, },
isSelected: function () { isSelected: function () {
return this.getData( 'highlight' ) === true; return this.getData( 'highlight' ) === true;
},
clearChildren: function () {
this.children = [];
} }
} ); } );
\ No newline at end of file
KityMinder.registerModule( "fontmodule", function () { KityMinder.registerModule( "fontmodule", function () {
return { return {
defaultOptions:{ defaultOptions: {
'fontfamily': [ 'fontfamily': [ {
{ name: 'songti', val: '宋体,SimSun'}, name: 'songti',
{ name: 'yahei', val: '微软雅黑,Microsoft YaHei'}, val: '宋体,SimSun'
{ name: 'kaiti', val: '楷体,楷体_GB2312, SimKai'}, }, {
{ name: 'heiti', val: '黑体, SimHei'}, name: 'yahei',
{ name: 'lishu', val: '隶书, SimLi'}, val: '微软雅黑,Microsoft YaHei'
{ name: 'andaleMono', val: 'andale mono'}, }, {
{ name: 'arial', val: 'arial, helvetica,sans-serif'}, name: 'kaiti',
{ name: 'arialBlack', val: 'arial black,avant garde'}, val: '楷体,楷体_GB2312, SimKai'
{ name: 'comicSansMs', val: 'comic sans ms'}, }, {
{ name: 'impact', val: 'impact,chicago'}, name: 'heiti',
{ name: 'timesNewRoman', val: 'times new roman'}, val: '黑体, SimHei'
{ name: 'sans-serif',val:'sans-serif'} }, {
], name: 'lishu',
'fontsize': [10, 12, 16, 18,24, 32,48] val: '隶书, SimLi'
}, {
name: 'andaleMono',
val: 'andale mono'
}, {
name: 'arial',
val: 'arial, helvetica,sans-serif'
}, {
name: 'arialBlack',
val: 'arial black,avant garde'
}, {
name: 'comicSansMs',
val: 'comic sans ms'
}, {
name: 'impact',
val: 'impact,chicago'
}, {
name: 'timesNewRoman',
val: 'times new roman'
}, {
name: 'sans-serif',
val: 'sans-serif'
} ],
'fontsize': [ 10, 12, 16, 18, 24, 32, 48 ]
}, },
"commands": { "commands": {
"forecolor": kity.createClass( "fontcolorCommand", { "forecolor": kity.createClass( "fontcolorCommand", {
...@@ -39,7 +62,7 @@ KityMinder.registerModule( "fontmodule", function () { ...@@ -39,7 +62,7 @@ KityMinder.registerModule( "fontmodule", function () {
utils.each( nodes, function ( i, n ) { utils.each( nodes, function ( i, n ) {
n.setData( 'fontfamily', family ); n.setData( 'fontfamily', family );
n.getTextShape().setAttr( 'font-family', family ); n.getTextShape().setAttr( 'font-family', family );
km.updateLayout(n) km.updateLayout( n )
} ) } )
} }
} ), } ),
...@@ -50,8 +73,8 @@ KityMinder.registerModule( "fontmodule", function () { ...@@ -50,8 +73,8 @@ KityMinder.registerModule( "fontmodule", function () {
var nodes = km.getSelectedNodes(); var nodes = km.getSelectedNodes();
utils.each( nodes, function ( i, n ) { utils.each( nodes, function ( i, n ) {
n.setData( 'fontsize', size ); n.setData( 'fontsize', size );
n.getTextShape().setSize(size); n.getTextShape().setSize( size );
km.updateLayout(n) km.updateLayout( n )
} ) } )
} }
} ) } )
......
...@@ -51,6 +51,7 @@ KityMinder.registerModule( "HistoryModule", function () { ...@@ -51,6 +51,7 @@ KityMinder.registerModule( "HistoryModule", function () {
}, },
restore: function () { restore: function () {
var scene = this.list[ this.index ]; var scene = this.list[ this.index ];
debugger;
this.km.setRoot( scene.cloneData() ); this.km.setRoot( scene.cloneData() );
this.km.initStyle(); this.km.initStyle();
this.update(); this.update();
...@@ -59,6 +60,7 @@ KityMinder.registerModule( "HistoryModule", function () { ...@@ -59,6 +60,7 @@ KityMinder.registerModule( "HistoryModule", function () {
return new Scene( this.km.getRoot() ) return new Scene( this.km.getRoot() )
}, },
saveScene: function () { saveScene: function () {
debugger;
var currentScene = this.getScene(); var currentScene = this.getScene();
var lastScene = this.list[ this.index ]; var lastScene = this.list[ this.index ];
if ( lastScene && lastScene.equals( currentScene ) ) { if ( lastScene && lastScene.equals( currentScene ) ) {
......
...@@ -27,7 +27,6 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -27,7 +27,6 @@ KityMinder.registerModule( "LayoutDefault", function () {
dec.stroke( "gray" ); dec.stroke( "gray" );
minder.getRenderContainer().addShape( iconShape ); minder.getRenderContainer().addShape( iconShape );
iconShape.addShapes( [ circle, plus, dec ] ); iconShape.addShapes( [ circle, plus, dec ] );
node.setData( "shicon", this );
this.update(); this.update();
this.switchState(); this.switchState();
}, },
...@@ -107,15 +106,13 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -107,15 +106,13 @@ KityMinder.registerModule( "LayoutDefault", function () {
switch ( node.getType() ) { switch ( node.getType() ) {
case "root": case "root":
case "main": case "main":
if ( !Layout.bgRect ) { node.getBgRc().clear().addShape( Layout.bgRect = new kity.Rect() );
node.getBgRc().addShape( Layout.bgRect = new kity.Rect() );
}
Layout.bgRect.fill( nodeStyle.fill ).setRadius( nodeStyle.radius ); Layout.bgRect.fill( nodeStyle.fill ).setRadius( nodeStyle.radius );
break; break;
case "sub": case "sub":
var underline = Layout.underline = new kity.Path(); var underline = Layout.underline = new kity.Path();
var highlightshape = Layout.highlightshape = new kity.Rect(); var highlightshape = Layout.highlightshape = new kity.Rect();
node.getBgRc().addShapes( [ highlightshape, underline ] ); node.getBgRc().clear().addShapes( [ highlightshape, underline ] );
break; break;
default: default:
break; break;
...@@ -134,6 +131,7 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -134,6 +131,7 @@ KityMinder.registerModule( "LayoutDefault", function () {
Layout.leftHeight = 0; Layout.leftHeight = 0;
Layout.rightHeight = 0; Layout.rightHeight = 0;
} }
minder.highlightNode( node );
}; };
//根据内容调整节点尺寸 //根据内容调整节点尺寸
var updateShapeByCont = function ( node ) { var updateShapeByCont = function ( node ) {
...@@ -153,7 +151,6 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -153,7 +151,6 @@ KityMinder.registerModule( "LayoutDefault", function () {
var _contWidth = contRc.getWidth(); var _contWidth = contRc.getWidth();
var _contHeight = contRc.getHeight(); var _contHeight = contRc.getHeight();
Layout.underline.getDrawer() Layout.underline.getDrawer()
.clear()
.moveTo( 0, _contHeight + nodeStyle.padding[ 2 ] + nodeStyle.padding[ 0 ] ) .moveTo( 0, _contHeight + nodeStyle.padding[ 2 ] + nodeStyle.padding[ 0 ] )
.lineTo( _contWidth + nodeStyle.padding[ 1 ] + nodeStyle.padding[ 3 ], _contHeight + nodeStyle.padding[ 2 ] + nodeStyle.padding[ 0 ] ); .lineTo( _contWidth + nodeStyle.padding[ 1 ] + nodeStyle.padding[ 3 ], _contHeight + nodeStyle.padding[ 2 ] + nodeStyle.padding[ 0 ] );
Layout.underline.stroke( nodeStyle.stroke ); Layout.underline.stroke( nodeStyle.stroke );
...@@ -208,7 +205,7 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -208,7 +205,7 @@ KityMinder.registerModule( "LayoutDefault", function () {
} else { } else {
if ( action === "append" || action === "contract" ) { if ( action === "append" || action === "contract" ) {
Layout.branchheight = node.getRenderContainer().getHeight() + nodeStyle.margin[ 0 ] + nodeStyle.margin[ 2 ]; Layout.branchheight = node.getRenderContainer().getHeight() + nodeStyle.margin[ 0 ] + nodeStyle.margin[ 2 ];
} else if ( action === "expand" || action === "change" ) { //展开 } else if ( action === "change" ) { //展开
Layout.branchheight = countBranchHeight( node ); Layout.branchheight = countBranchHeight( node );
} }
var parentLayout = parent.getData( "layout" ); var parentLayout = parent.getData( "layout" );
...@@ -293,6 +290,7 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -293,6 +290,7 @@ KityMinder.registerModule( "LayoutDefault", function () {
nodeShape.setTransform( new kity.Matrix().translate( Layout.x, Layout.y - _rectHeight / 2 ) ); nodeShape.setTransform( new kity.Matrix().translate( Layout.x, Layout.y - _rectHeight / 2 ) );
break; break;
} }
node.setPoint( Layout.x, Layout.y );
}; };
var updateConnectAndshIcon = function ( node ) { var updateConnectAndshIcon = function ( node ) {
var nodeType = node.getType(); var nodeType = node.getType();
...@@ -430,11 +428,26 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -430,11 +428,26 @@ KityMinder.registerModule( "LayoutDefault", function () {
updateLayoutHorizon( _root ); updateLayoutHorizon( _root );
updateLayoutVertical( _root ); updateLayoutVertical( _root );
translateNode( _root ); translateNode( _root );
var _buffer = [ _root ];
var _cleanbuffer = [];
//打散结构
while ( _buffer.length !== 0 ) {
var children = _buffer[ 0 ].getChildren();
_buffer = _buffer.concat( children );
for ( var i = 0; i < children.length; i++ ) {
children[ i ].getData( "layout" ).parent = _buffer[ 0 ];
}
_buffer[ 0 ].clearChildren();
if ( _buffer[ 0 ] !== _root ) _cleanbuffer.push( _buffer[ 0 ] );
_buffer.shift();
}
//重组结构
for ( var j = 0; j < _cleanbuffer.length; j++ ) {
this.appendChildNode( _cleanbuffer[ j ].getData( "layout" ).parent, _cleanbuffer[ j ] );
}
}, },
appendChildNode: function ( parent, node, sibling ) { appendChildNode: function ( parent, node, sibling ) {
minder.handelNodeInsert( node ); minder.handelNodeInsert( node );
//设置align和appendside属性并在合适的位置插入节点
var insert = ( parent.getChildren().indexOf( node ) === -1 );
var Layout = node.getData( "layout" ); var Layout = node.getData( "layout" );
var parentLayout = parent.getData( "layout" ); var parentLayout = parent.getData( "layout" );
if ( sibling ) { if ( sibling ) {
...@@ -452,24 +465,35 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -452,24 +465,35 @@ KityMinder.registerModule( "LayoutDefault", function () {
var prtLayout = parent.getData( "layout" ); var prtLayout = parent.getData( "layout" );
Layout.appendside = prtLayout.appendside; Layout.appendside = prtLayout.appendside;
Layout.align = prtLayout.align; Layout.align = prtLayout.align;
parent.appendChild( node );
} else { } else {
if ( parentLayout.rightList.length > 1 && parentLayout.rightList.length > parentLayout.leftList.length ) { var nodeP = node.getPoint();
Layout.appendside = "left"; if ( nodeP && nodeP.x && nodeP.y ) {
Layout.align = "right"; if ( nodeP.x > parentLayout.x ) {
Layout.appendside = "right";
Layout.align = "left";
} else {
Layout.appendside = "left";
Layout.align = "right";
}
} else { } else {
Layout.appendside = "right"; if ( parentLayout.rightList.length > 1 && parentLayout.rightList.length > parentLayout.leftList.length ) {
Layout.align = "left"; Layout.appendside = "left";
Layout.align = "right";
} else {
Layout.appendside = "right";
Layout.align = "left";
}
} }
} var sideList1 = parentLayout[ Layout.appendside + "List" ];
if ( insert ) { sideList1.push( node );
if ( parent.getType() === "root" ) { var idx1;
var sideList1 = parentLayout[ Layout.appendside + "List" ]; if ( Layout.appendside === "right" ) {
var idx1 = sideList1.length; idx1 = sideList1.length;
parent.insertChild( node, idx1 );
sideList1.push( node );
} else { } else {
parent.insertChild( node ); idx1 = parent.getChildren().length;
} }
parent.insertChild( node, idx1 );
} }
} }
//设置分支类型 //设置分支类型
...@@ -539,12 +563,15 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -539,12 +563,15 @@ KityMinder.registerModule( "LayoutDefault", function () {
var isExpand = ico.icon.switchState(); var isExpand = ico.icon.switchState();
var node = ico.icon._node; var node = ico.icon._node;
var _buffer = node.getChildren(); var _buffer = node.getChildren();
var _cleanbuffer = [];
while ( _buffer.length !== 0 ) { while ( _buffer.length !== 0 ) {
var Layout = _buffer[ 0 ].getData( "layout" ); var Layout = _buffer[ 0 ].getData( "layout" );
if ( isExpand ) { if ( isExpand ) {
var parent = _buffer[ 0 ].getParent(); var parent = _buffer[ 0 ].getParent();
minder.appendChildNode( parent, _buffer[ 0 ] ); Layout.parent = parent;
_cleanbuffer.push( _buffer[ 0 ] );
//minder.appendChildNode( parent, _buffer[ 0 ] );
Layout.connect = null; Layout.connect = null;
Layout.shicon = null; Layout.shicon = null;
} else { } else {
...@@ -555,53 +582,21 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -555,53 +582,21 @@ KityMinder.registerModule( "LayoutDefault", function () {
_buffer = _buffer.concat( _buffer[ 0 ].getChildren() ); _buffer = _buffer.concat( _buffer[ 0 ].getChildren() );
_buffer.shift(); _buffer.shift();
} }
var set; if ( isExpand ) {
if ( isExpand ) set = updateLayoutVertical( node, node.getParent(), "expand" ); node.clearChildren();
else set = updateLayoutVertical( node, node.getParent(), "contract" ); for ( var j = 0; j < _cleanbuffer.length; j++ ) {
_cleanbuffer[ j ].clearChildren();
minder.appendChildNode( _cleanbuffer[ j ].getData( "layout" ).parent, _cleanbuffer[ j ] );
}
}
var set = [];
if ( !isExpand ) set = updateLayoutVertical( node, node.getParent(), "contract" );
for ( var i = 0; i < set.length; i++ ) { for ( var i = 0; i < set.length; i++ ) {
translateNode( set[ i ] ); translateNode( set[ i ] );
updateConnectAndshIcon( set[ i ] ); updateConnectAndshIcon( set[ i ] );
} }
} }
}; };
this.addLayoutStyle( "default", _style ); this.addLayoutStyle( "default", _style );
return { return {};
// "events": {
// "click": function ( e ) {
// var ico = e.kityEvent.targetShape.container;
// if ( ico.class === "shicon" ) {
// var isShow = ico.icon.switchState();
// var node = ico.icon._node;
// var _buffer;
// if ( isShow ) {
// _buffer = node.getChildren();
// while ( _buffer.length !== 0 ) {
// minder.appendChildNode( _buffer[ 0 ].getParent(), _buffer[ 0 ] );
// _buffer = _buffer.concat( _buffer[ 0 ].getChildren() );
// _buffer.shift();
// }
// } else {
// var Layout = node.getData( "layout" );
// var marginTop = Layout.margin[ 0 ];
// var marginBottom = Layout.margin[ 2 ];
// Layout.branchheight = node.getRenderContainer().getHeight() + marginTop + marginBottom;
// _buffer = node.getChildren();
// while ( _buffer.length !== 0 ) {
// try {
// _buffer[ 0 ].getData( "layout" ).shape.clear();
// _buffer[ 0 ].getRenderContainer().remove();
// } catch ( error ) {}
// _buffer = _buffer.concat( _buffer[ 0 ].getChildren() );
// _buffer.shift();
// }
// var set = updateLayoutVertical( node, node.getParent(), "append" );
// for ( var i = 0; i < set.length; i++ ) {
// translateNode( set[ i ] );
// }
// }
// }
// }
// }
};
} ); } );
\ No newline at end of file
...@@ -25,7 +25,15 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -25,7 +25,15 @@ KityMinder.registerModule( "LayoutModule", function () {
}, },
initStyle: function () { initStyle: function () {
var curStyle = this.getCurrentStyle(); var curStyle = this.getCurrentStyle();
this.getRenderContainer().clear(); //this.getRenderContainer().clear();
this._rc.remove();
this._rc = new kity.Group();
this._paper.addShape( this._rc );
var _root = this.getRoot();
_root.preTraverse( function ( n ) {
n.clearLayout();
} );
this.getLayoutStyle( curStyle ).initStyle.call( this ); this.getLayoutStyle( curStyle ).initStyle.call( this );
}, },
appendChildNode: function ( parent, node, index ) { appendChildNode: function ( parent, node, index ) {
...@@ -79,7 +87,7 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -79,7 +87,7 @@ KityMinder.registerModule( "LayoutModule", function () {
var switchLayout = function ( km, style ) { var switchLayout = function ( km, style ) {
var _root = km.getRoot(); var _root = km.getRoot();
_root.preTraverse( function ( n ) { _root.preTraverse( function ( n ) {
n.clearLayout(); //n.clearLayout();
n.setPoint(); n.setPoint();
n.getBgRc().clear(); n.getBgRc().clear();
} ); } );
......
KityMinder.registerProtocal( 'json', function () {
function filter( key, value ) {
if ( key == 'layout' || key == 'shicon' ) {
return undefined;
}
return value;
}
return {
encode: function ( json ) {
return JSON.stringify( json, filter );
},
decode: function ( local ) {
return JSON.parse( local );
},
recognize: function ( local ) {
return Utils.isString( local ) && local.charAt( 0 ) == '{' && local.charAt( local.length - 1 ) == '}';
}
};
} );
\ No newline at end of file
KityMinder.registerProtocal( "plain", function () {
var LINE_ENDING = '\n',
TAB_CHAR = '\t';
function repeat( s, n ) {
var result = "";
while ( n-- ) result += s;
return result;
}
function encode( json, level ) {
var local = "";
level = level || 0;
local += repeat( TAB_CHAR, level );
local += json.data.text + LINE_ENDING;
if ( json.children ) {
json.children.forEach( function ( child ) {
local += encode( child, level + 1 );
} );
}
return local;
}
function isEmpty( line ) {
return !/\S/.test( line );
}
function getLevel( line ) {
var level = 0;
while ( line.charAt( level ) === TAB_CHAR ) level++;
return level;
}
function getNode( line ) {
return {
data: {
text: line.replace( new RegExp( '^' + TAB_CHAR + '*' ), '' )
}
};
}
function decode( local ) {
var json,
parentMap = {},
lines = local.split( LINE_ENDING ),
line, level, node;
function addChild( parent, child ) {
var children = parent.children || ( parent.children = [] );
children.push( child );
}
for ( var i = 0; i < lines.length; i++ ) {
line = lines[ i ];
if ( isEmpty( line ) ) continue;
level = getLevel( line );
node = getNode( line );
if ( level === 0 ) {
if ( json ) {
throw new Error( 'Invalid local format' );
}
json = node;
} else {
if ( !parentMap[ level - 1 ] ) {
throw new Error( 'Invalid local format' );
}
addChild( parentMap[ level - 1 ], node );
}
parentMap[ level ] = node;
}
return json;
}
var lastTry, lastResult;
function recognize( local ) {
if ( !Utils.isString( local ) ) return false;
lastTry = local;
try {
lastResult = decode( local );
} catch ( e ) {
lastResult = null;
}
return !!lastResult;
}
return {
encode: function ( json ) {
return encode( json, 0 );
},
decode: function ( local ) {
if ( lastTry == local && lastResult ) {
return lastResult;
}
return decode( local );
},
recognize: recognize
};
} );
\ No newline at end of file
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