fileOverview author shiwu.wyy antfin import { IGroup , IShape } from '@antv/g-base' ; import { isArray , isNil , clone } from '@antv/util' ; import { ILabelConfig , ShapeOptions } from '../interface/shape' ; import { Item , LabelStyle , NodeConfig , ModelConfig , ShapeStyle } from '../types' ; import Global from '../global' ; import Shape from './shape' ; import { shapeBase } from './shapeBase' ; const singleCombo = { itemType : 'combo' , shapeType : 'single-combo' , type { String } labelPosition : 'top' , type { Number } refX : Global . comboLabel . refX , refY : Global . comboLabel . refY , options : { style : { stroke : Global . defaultCombo . style . stroke , fill : Global . defaultCombo . style . fill , lineWidth : Global . defaultCombo . style . lineWidth , } , labelCfg : { style : { fill : Global . comboLabel . style . fill , fontSize : Global . comboLabel . style . fontSize , fontFamily : Global . windowFontFamily } , } , stateStyles : { ... Global . comboStateStyles , } , } , internal param { Object } cfg return { Array } getSize ( cfg ) { let size = clone ( cfg . size || this . options ! . size || Global . defaultCombo . size ) ; if ( isArray ( size ) && size . length === 1 ) { size = [ size [ 0 ] , size [ 0 ] ] ; } if ( ! isArray ( size ) ) { size = [ size , size ] ; } return size ; } , getLabelStyleByPosition ( cfg , labelCfg ) { const labelPosition = labelCfg . position || this . labelPosition ; const { style : cfgStyle } = cfg ; let padding = cfg . padding || this . options . padding ; if ( isArray ( padding ) ) padding = padding [ 0 ] ; let { refX , refY } = labelCfg ; if ( isNil ( refX ) ) { refX = this . refX as number ; } if ( isNil ( refY ) ) { refY = this . refY as number ; } const size = this . getSize ! ( cfg as ModelConfig ) ; const r = Math . max ( cfgStyle . r , size [ 0 ] / 2 ) || size [ 0 ] / 2 ; const dis = r + padding ; let style ; switch ( labelPosition ) { case 'top' : style = { x : 0 , y : - dis - ( refY as number ) , textBaseline : 'bottom' , textAlign : 'center' , } ; break ; case 'bottom' : style = { x : 0 , y : dis + ( refY as number ) , textBaseline : 'bottom' , textAlign : 'center' , } ; break ; case 'left' : style = { x : - dis + ( refX as number ) , y : 0 , textAlign : 'left' , } ; break ; case 'center' : style = { x : 0 , y : 0 , text : cfg ! . label , textAlign : 'center' , } ; break ; default : style = { x : dis + ( refX as number ) , y : 0 , textAlign : 'right' , } ; break ; } style . text = cfg . label ; return style ; } , drawShape ( cfg , group ) { const { shapeType } = this ; const style = this . getShapeStyle ! ( cfg ) ; const shape = group . addShape ( shapeType , { attrs : style , draggable : true , name : 'combo-shape' , } ) ; return shape ; } , updateShape ( cfg , item , keyShapeStyle ) { const keyShape = item . get ( 'keyShape' ) ; const animate = cfg . animate === undefined ? this . options . animate : cfg . animate ; if ( animate && keyShape . animate ) { keyShape . animate ( keyShapeStyle , { duration : 200 , easing : 'easeLinear' , } ) ; } else { keyShape . attr ( { ... keyShapeStyle , } ) ; } ( this as any ) . updateLabel ( cfg , item ) ; } , } ; const singleComboDef = { ... shapeBase , ... singleCombo } ; Shape . registerCombo ( 'single-combo' , singleComboDef ) ;