Commit ae2fa565 authored by Akikonata's avatar Akikonata

added icon

parent 14521fb9
Subproject commit 113f82dc2dc4ad1e740f9264839aea0f117957e2 Subproject commit dd0e68ce6b5467c07d1e92ba7af16d4569232365
KityMinder.registerModule( "IconModule", function () { KityMinder.registerModule( "IconModule", function () {
var PriorityIcon = kity.createClass( "PriorityIcon", ( function () { var renderPriorityIcon = function ( node, val ) {
var colors = [ "", "red", "blue", "green", "orange", "purple" ]; var colors = [ "", "red", "blue", "green", "orange", "purple" ];
return { var _bg = new kity.Rect().fill( colors[ val ] ).setRadius( 3 ).setWidth( 20 ).setHeight( 20 );
constructor: function ( node, value ) { var _number = new kity.Text().setContent( val ).fill( "white" ).setSize( 12 );
this._node = node; var _rc = new kity.Group();
this._bg = new kity.Rect().fill( colors[ value ] ).setRadius( 3 ).setWidth( 20 ).setHeight( 20 ); _rc.addShapes( [ _bg, _number ] );
this._number = new kity.Text().setContent( value ).fill( "white" ).setSize( 12 ); node.getIconRc().addShape( _rc );
this._rc = new kity.Group(); _number.setTransform( new kity.Matrix().translate( 6, 15 ) );
this._rc.addShapes( [ this._bg, this._number ] );
node.getIconRc().addShape( this._rc );
},
setValue: function ( val ) {
this._number.fill( colors[ val ] ).setContent( val );
},
getShape: function () {
return this._rc;
},
remove: function () {
this._node.setData( "PriorityIcon", null );
this._rc.remove();
}
}; };
} )() ); var renderProgressIcon = function ( node, val, left ) {
var ProgressIcon = kity.createClass( "PriorityIcon", ( function () { var _rc = new kity.Group();
var color = "blue"; var _bg = new kity.Circle().setRadius( 8 ).fill( "white" ).stroke( new kity.Pen( "blue", 2 ) );
return { var _percent, d;
constructor: function ( node ) { if ( val < 5 ) {
this._node = node; _percent = new kity.Path();
var iconRc = node.getIconRc(); d = _percent.getDrawer();
}, d.moveTo( 0, 0 ).lineTo( 6, 0 );
setValue: function ( val ) { } else _percent = new kity.Group();
_rc.addShapes( [ _bg, _percent ] );
}, node.getIconRc().addShape( _rc );
getShape: function () { _rc.setTransform( new kity.Matrix().translate( left, 10 ) );
return this._rc; _percent.setTransform( 10, 10 );
}, switch ( val ) {
remove: function () { case 1:
this._node.setData( "ProgressIcon", null ); break;
this._rc.remove(); case 2:
d.carcTo( 6, 0, -6 );
break;
case 3:
d.carcTo( 6, -6, 0 );
break;
case 4:
d.carcTo( 6, 0, 6, 1, 0 );
break;
case 5:
_percent.addShape( new kity.Circle().setRadius( 6 ).fill( "blue" ) );
break;
} }
}; if ( val < 5 ) d.close();
} )() ); _percent.fill( "blue" );
var icons = {
"PriorityIcon": PriorityIcon,
"ProgressIcon": ProgressIcon
}; };
var ChangeIconCommand = kity.createClass( "AddIconCommand", ( function () { var ChangeIconCommand = kity.createClass( "AddIconCommand", ( function () {
return { return {
...@@ -51,16 +46,10 @@ KityMinder.registerModule( "IconModule", function () { ...@@ -51,16 +46,10 @@ KityMinder.registerModule( "IconModule", function () {
execute: function ( km, iconType, value ) { execute: function ( km, iconType, value ) {
var nodes = km.getSelectedNodes(); var nodes = km.getSelectedNodes();
for ( var i = 0; i < nodes.length; i++ ) { for ( var i = 0; i < nodes.length; i++ ) {
var iconRc = nodes[ i ].getIconRc(); nodes[ i ].setData( iconType, value );
var icon = nodes[ i ].getData( iconType );
if ( icon ) {
icon.setValue( value );
} else {
nodes[ i ].setData( iconType, new icons[ iconType ]( nodes[ i ], value ) );
km.updateLayout( nodes[ i ] ); km.updateLayout( nodes[ i ] );
} }
} }
}
}; };
} )() ); } )() );
var RemoveIconCommand = kity.createClass( "RemoveIconCommand", ( function () { var RemoveIconCommand = kity.createClass( "RemoveIconCommand", ( function () {
...@@ -69,9 +58,8 @@ KityMinder.registerModule( "IconModule", function () { ...@@ -69,9 +58,8 @@ KityMinder.registerModule( "IconModule", function () {
execute: function ( km, iconType ) { execute: function ( km, iconType ) {
var nodes = km.getSelectedNodes(); var nodes = km.getSelectedNodes();
for ( var i = 0; i < nodes.length; i++ ) { for ( var i = 0; i < nodes.length; i++ ) {
var icon = nodes[ i ].getData( iconType ); nodes[ i ].setData( iconType, null );
km.updateLayout( nodes[ i ] ); km.updateLayout( nodes[ i ] );
icon.remove();
} }
} }
}; };
...@@ -85,8 +73,19 @@ KityMinder.registerModule( "IconModule", function () { ...@@ -85,8 +73,19 @@ KityMinder.registerModule( "IconModule", function () {
"RenderNode": function ( e ) { "RenderNode": function ( e ) {
var node = e.node; var node = e.node;
var iconRc = node.getIconRc(); var iconRc = node.getIconRc();
var PriorityIconVal = node.getData( "PriorityIcon" );
var ProgressIconVal = node.getData( "ProgressIcon" );
//依次排布图标、文字 //依次排布图标、文字
iconRc.setTransform( new kity.Matrix().translate( 0, -20 ) ); iconRc.setTransform( new kity.Matrix().translate( 0, -20 ) );
iconRc.clear();
var PriorityIconWidth = 0;
if ( PriorityIconVal ) {
renderPriorityIcon( node, PriorityIconVal );
PriorityIconWidth = 22;
}
if ( ProgressIconVal ) {
renderProgressIcon( node, ProgressIconVal, PriorityIconWidth + 10 );
}
var iconWidth = iconRc.getWidth(); var iconWidth = iconRc.getWidth();
var textShape = node.getTextShape(); var textShape = node.getTextShape();
if ( iconWidth ) textShape.setTransform( new kity.Matrix().translate( iconWidth + 5, 0 ) ); if ( iconWidth ) textShape.setTransform( new kity.Matrix().translate( iconWidth + 5, 0 ) );
......
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