import { IGroup , IShape } from '@antv/g-base' ; import { Item , ComboConfig , ShapeStyle } from '../../types' ; import Global from '../../global' ; import Shape from '../shape' ; import { ShapeOptions } from '../../interface/shape' ; import { isNumber , clone , mix , isArray } from '@antv/util' ; Shape . registerCombo ( 'circle' , { options : { size : [ Global . defaultCombo . size [ 0 ] , Global . defaultCombo . size [ 0 ] ] , padding : Global . defaultCombo . padding [ 0 ] , animate : true , 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 , } , refX : 0 , refY : 0 , } , stateStyles : { ... Global . comboStateStyles , } , } , shapeType : 'circle' , labelPosition : 'top' , drawShape ( cfg , group ) { const style = this . getShapeStyle ! ( cfg ) ; delete style . height ; delete style . width ; const keyShape = group . addShape ( 'circle' , { attrs : style , className : 'circle-combo' , name : 'circle-combo' , draggable : true , } ) ; return keyShape ; } , param { Object } cfg return { Object } getShapeStyle ( cfg ) { const { style : defaultStyle } = this . options as ComboConfig ; let padding = cfg . padding || this . options . padding ; if ( isArray ( padding ) ) padding = padding [ 0 ] ; const strokeStyle = { stroke : cfg . color , } ; const style = mix ( { } , defaultStyle , strokeStyle , cfg . style ) ; let r ; if ( cfg . fixSize ) { r = isNumber ( cfg . fixSize ) ? cfg . fixSize : cfg . fixSize [ 0 ] ; } else { const size = ( this as ShapeOptions ) . getSize ! ( cfg ) ; if ( ! isNumber ( style . r ) || isNaN ( style . r ) ) r = size [ 0 ] / 2 || Global . defaultCombo . style . r ; else r = Math . max ( style . r , size [ 0 ] / 2 ) || size [ 0 ] / 2 ; } style . r = r + padding ; const styles = { x : 0 , y : 0 , ... style , } ; if ( cfg . style ) cfg . style . r = r ; else { cfg . style = { r } ; } return styles ; } , update ( cfg , item ) { const size = ( this as ShapeOptions ) . getSize ! ( cfg ) ; let padding = cfg . padding || this . options . padding ; if ( isArray ( padding ) ) padding = padding [ 0 ] ; const cfgStyle = clone ( cfg . style ) ; let r ; if ( cfg . fixSize ) { r = isNumber ( cfg . fixSize ) ? cfg . fixSize : cfg . fixSize [ 0 ] ; } else { r = Math . max ( cfgStyle . r , size [ 0 ] / 2 ) || size [ 0 ] / 2 ; } cfgStyle . r = r + padding ; const itemCacheSize = item . get ( 'sizeCache' ) ; if ( itemCacheSize ) { itemCacheSize . r = cfgStyle . r ; } const strokeStyle = { stroke : cfg . color , } ; const keyShape = item . get ( 'keyShape' ) ; const style = mix ( { } , keyShape . attr ( ) , strokeStyle , cfgStyle ) ; if ( cfg . style ) cfg . style . r = r ; else { cfg . style = { r } ; } ( this as any ) . updateShape ( cfg , item , style , true ) ; } , } , 'single-combo' ) ;