Commit ba2e8cfd authored by Akikonata's avatar Akikonata

added highlight

parent 63e5cf18
...@@ -148,20 +148,31 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -148,20 +148,31 @@ KityMinder.registerModule( "LayoutDefault", function () {
var MinderNodeShape = kity.createClass( "MinderNodeShape", ( function () { var MinderNodeShape = kity.createClass( "MinderNodeShape", ( function () {
return { return {
constructor: function ( node ) { constructor: function ( node ) {
var txt = new kity.Text(); var txt = this._txt = new kity.Text();
var rect = new kity.Rect(); var rect = this._rect = new kity.Rect();
this._node = node;
var container = node.getRenderContainer();
container.addShapes( [ rect, txt ] );
node.setData( "shape", this );
var ND = JSON.parse( JSON.stringify( nodeDefautStyle ) ); var ND = JSON.parse( JSON.stringify( nodeDefautStyle ) );
node.setData( "style", Utils.extend( ND, node.getData( "style" ) ) ); node.setData( "style", Utils.extend( ND, node.getData( "style" ) ) );
var _style = node.getData( "style" ); var _style = node.getData( "style" );
var container = node.getRenderContainer();
container.addShapes( [ rect, txt ] );
txt.setContent( node.getData( "text" ) || "新建节点" ).setSize( _style.fontSize ).fill( _style.color ); txt.setContent( node.getData( "text" ) || "新建节点" ).setSize( _style.fontSize ).fill( _style.color );
var _txtHeight = txt.getHeight(); var _txtHeight = txt.getHeight();
txt.translate( _style.padding[ 3 ], _txtHeight + _style.padding[ 0 ] ); txt.translate( _style.padding[ 3 ], _txtHeight + _style.padding[ 0 ] );
this.update();
},
update: function () {
var node = this._node;
var txt = this._txt;
var rect = this._rect;
var _style = node.getData( "style" );
txt.setContent( node.getData( "text" ) || "新建节点" ).setSize( _style.fontSize ).fill( _style.color );
var _txtHeight = txt.getHeight();
var _rectWidth = _style.padding[ 1 ] + _style.padding[ 3 ] + txt.getWidth(); var _rectWidth = _style.padding[ 1 ] + _style.padding[ 3 ] + txt.getWidth();
var _rectHeight = _style.padding[ 0 ] + _style.padding[ 2 ] + _txtHeight; var _rectHeight = _style.padding[ 0 ] + _style.padding[ 2 ] + _txtHeight;
rect.fill( _style.fill ).stroke( _style.stroke ).setRadius( _style.radius ).setWidth( _rectWidth ).setHeight( _rectHeight ); rect.fill( _style.fill ).stroke( _style.stroke ).setRadius( _style.radius ).setWidth( _rectWidth ).setHeight( _rectHeight );
if ( node.highlight ) { if ( node.getData( "highlight" ) ) {
rect.stroke( new kity.Pen( "white", 3 ) ); rect.stroke( new kity.Pen( "white", 3 ) );
} }
} }
...@@ -200,8 +211,9 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -200,8 +211,9 @@ KityMinder.registerModule( "LayoutDefault", function () {
//绘制node //绘制node
var drawNode = function ( node ) { var drawNode = function ( node ) {
var container = node.getRenderContainer(); var container = node.getRenderContainer();
container.clear(); var shape = node.getData( "shape" );
var shape = new MinderNodeShape( node ); if ( !shape ) new MinderNodeShape( node );
else shape.update();
updateConnect( minder, node ); updateConnect( minder, node );
}; };
//调整node的位置 //调整node的位置
...@@ -240,9 +252,6 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -240,9 +252,6 @@ KityMinder.registerModule( "LayoutDefault", function () {
var centerY = node.getData( "y" ); var centerY = node.getData( "y" );
var nodeBranchHeight = node.getData( appendside + "Height" ) || node.getData( "branchheight" ); var nodeBranchHeight = node.getData( appendside + "Height" ) || node.getData( "branchheight" );
var nodeChildren = node.getData( appendside + "List" ) || node.getChildren(); var nodeChildren = node.getData( appendside + "List" ) || node.getChildren();
if ( node === root ) {
console.log( nodeChildren );
}
var sY = centerY - nodeBranchHeight / 2; var sY = centerY - nodeBranchHeight / 2;
for ( var i = 0; i < nodeChildren.length; i++ ) { for ( var i = 0; i < nodeChildren.length; i++ ) {
var childBranchHeight = nodeChildren[ i ].getData( "branchheight" ); var childBranchHeight = nodeChildren[ i ].getData( "branchheight" );
...@@ -327,6 +336,7 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -327,6 +336,7 @@ KityMinder.registerModule( "LayoutDefault", function () {
var set2 = updateLayoutVertical( node, node.getParent(), "append" ); var set2 = updateLayoutVertical( node, node.getParent(), "append" );
//获取水平方向和垂直方向受影响的点的并集然后进行统一translate //获取水平方向和垂直方向受影响的点的并集然后进行统一translate
var set = uSet( set1, set2 ); var set = uSet( set1, set2 );
console.log( set );
for ( var i = 0; i < set.length; i++ ) { for ( var i = 0; i < set.length; i++ ) {
translateNode( set[ i ] ); translateNode( set[ i ] );
} }
......
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