@@ -5,6 +5,10 @@ import type { ProgressProps, GapPositionType } from './interface';
55
66let gradientSeed = 0 ;
77
8+ function pxToNumber ( px : string ) {
9+ return parseInt ( px . slice ( 0 , px . indexOf ( 'p' ) ) , 10 ) ;
10+ }
11+
812function stripPercentToNumber ( percent : string ) {
913 return + percent . replace ( '%' , '' ) ;
1014}
@@ -76,6 +80,7 @@ const Circle: React.FC<ProgressProps> = ({
7680 className,
7781 strokeColor,
7882 percent,
83+ dot,
7984 ...restProps
8085} ) => {
8186 const gradientId = React . useMemo ( ( ) => {
@@ -98,31 +103,62 @@ const Circle: React.FC<ProgressProps> = ({
98103
99104 const [ paths ] = useTransitionDuration ( percentList ) ;
100105
106+ const getDotList = ( pathDoms ) => {
107+ const path = document . createElementNS ( 'http://www.w3.org/2000/svg' , 'path' ) ;
108+ if ( dot ) {
109+ return pathDoms . map ( ( pathDom , index ) => {
110+ const strokeDasharrayTemp = pathDom . props . style . strokeDasharray ;
111+ const strokeLength =
112+ pxToNumber ( strokeDasharrayTemp . slice ( 0 , strokeDasharrayTemp . indexOf ( ' ' ) ) ) +
113+ Math . abs ( pxToNumber ( pathDom . props . style . strokeDashoffset ) ) +
114+ strokeWidth / 2 ;
115+
116+ path . setAttribute ( 'd' , pathDom . props . d ) ;
117+ const dotPoint = path . getPointAtLength ( strokeLength ) ;
118+ return (
119+ < circle
120+ key = { index + 10 }
121+ className = { `${ prefixCls } -circle-dot` }
122+ cx = { dotPoint . x }
123+ cy = { dotPoint . y }
124+ r = { typeof dot === 'object' ? dot . size : strokeWidth }
125+ fill = { pathDom . props . stroke ? pathDom . props . stroke : pathDom . props . style . stroke }
126+ />
127+ ) ;
128+ } ) ;
129+ }
130+ return [ ] ;
131+
132+ } ;
133+
101134 const getStokeList = ( ) => {
102135 let stackPtg = 0 ;
103- return percentList . map ( ( ptg , index ) => {
104- const color = strokeColorList [ index ] || strokeColorList [ strokeColorList . length - 1 ] ;
105- const stroke =
106- Object . prototype . toString . call ( color ) === '[object Object]'
107- ? `url(#${ prefixCls } -gradient-${ gradientId } )`
108- : '' ;
109- const pathStyles = getPathStyles ( stackPtg , ptg , color , strokeWidth , gapDegree , gapPosition ) ;
110- stackPtg += ptg ;
111- return (
112- < path
113- key = { index }
114- className = { `${ prefixCls } -circle-path` }
115- d = { pathStyles . pathString }
116- stroke = { stroke }
117- strokeLinecap = { strokeLinecap }
118- strokeWidth = { strokeWidth }
119- opacity = { ptg === 0 ? 0 : 1 }
120- fillOpacity = "0"
121- style = { pathStyles . pathStyle }
122- ref = { paths [ index ] }
123- />
124- ) ;
125- } ) ;
136+ const pathDoms = percentList
137+ . map ( ( ptg , index ) => {
138+ const color = strokeColorList [ index ] || strokeColorList [ strokeColorList . length - 1 ] ;
139+ const stroke =
140+ Object . prototype . toString . call ( color ) === '[object Object]'
141+ ? `url(#${ prefixCls } -gradient-${ gradientId } )`
142+ : '' ;
143+ const pathStyles = getPathStyles ( stackPtg , ptg , color , strokeWidth , gapDegree , gapPosition ) ;
144+ stackPtg += ptg ;
145+ return (
146+ < path
147+ key = { index }
148+ className = { `${ prefixCls } -circle-path` }
149+ d = { pathStyles . pathString }
150+ stroke = { stroke }
151+ strokeLinecap = { strokeLinecap }
152+ strokeWidth = { strokeWidth }
153+ opacity = { ptg === 0 ? 0 : 1 }
154+ fillOpacity = "0"
155+ style = { pathStyles . pathStyle }
156+ ref = { paths [ index ] }
157+ />
158+ ) ;
159+ } )
160+ . reverse ( ) ;
161+ return pathDoms . concat ( getDotList ( pathDoms ) ) ;
126162 } ;
127163
128164 return (
@@ -158,7 +194,7 @@ const Circle: React.FC<ProgressProps> = ({
158194 fillOpacity = "0"
159195 style = { pathStyle }
160196 />
161- { getStokeList ( ) . reverse ( ) }
197+ { getStokeList ( ) }
162198 </ svg >
163199 ) ;
164200} ;
0 commit comments