import { IGroup , IShape } from '@antv/g-base' ; import { mix } from '@antv/util' ; import { Item , NodeConfig , ShapeStyle , UpdateType } from '../../types' ; import Global from '../../global' ; import Shape from '../shape' ; import { ShapeOptions } from '../../interface/shape' ; Shape . registerNode ( 'simple-rect' , { options : { size : [ 100 , 30 ] , style : { radius : 0 , stroke : Global . defaultNode . style . stroke , fill : Global . defaultNode . style . fill , lineWidth : Global . defaultNode . style . lineWidth , } , labelCfg : { style : { fill : Global . nodeLabel . style . fill , fontSize : Global . nodeLabel . style . fontSize , fontFamily : Global . windowFontFamily } , } , anchorPoints : [ [ 0 , 0.5 ] , [ 1 , 0.5 ] , ] , stateStyles : { ... Global . nodeStateStyles , } , } , shapeType : 'simple-rect' , labelPosition : 'center' , drawShape ( cfg , group ) { const style = this . getShapeStyle ! ( cfg ) ; const keyShape = group . addShape ( 'rect' , { attrs : style , className : `${ this . type }-keyShape` , name : `${ this . type }-keyShape` , draggable : true , } ) ; return keyShape ; } , param { Object } cfg return { Object } getShapeStyle ( cfg ) { const { style : defaultStyle } = this . mergeStyle || this . getOptions ( cfg ) as NodeConfig ; const strokeStyle = { stroke : cfg . color , } ; const style = mix ( { } , defaultStyle , strokeStyle ) ; const size = ( this as ShapeOptions ) . getSize ! ( cfg ) ; const width = style . width || size [ 0 ] ; const height = style . height || size [ 1 ] ; const styles = { x : - width / 2 , y : - height / 2 , width , height , ... style , } ; return styles ; } , update ( cfg , item , updateType ? ) { const group = item . getContainer ( ) ; const { style : defaultStyle } = this . mergeStyle || this . getOptions ( cfg ) as NodeConfig ; const size = ( this as ShapeOptions ) . getSize ! ( cfg ) ; const keyShape = item . get ( 'keyShape' ) ; if ( ! cfg . size ) { size [ 0 ] = keyShape . attr ( 'width' ) || defaultStyle . width ; size [ 1 ] = keyShape . attr ( 'height' ) || defaultStyle . height ; } const strokeStyle = { stroke : cfg . color , x : - size [ 0 ] / 2 , y : - size [ 1 ] / 2 , width : size [ 0 ] , height : size [ 1 ] , } ; let style = mix ( { } , defaultStyle , keyShape . attr ( ) , strokeStyle ) ; style = mix ( style , cfg . style ) ; ( this as any ) . updateShape ( cfg , item , style , false , updateType ) ; } , } , 'single-node' ) ;