Commit ae2fa565 authored by Akikonata's avatar Akikonata

added icon

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