@@ -5,8 +5,7 @@ import enhancer from './enhancer';
5
5
import { propTypes , defaultProps } from './types' ;
6
6
7
7
class Circle extends Component {
8
- getPathStyles ( ) {
9
- const { percent, strokeWidth, strokeColor, gapDegree = 0 , gapPosition } = this . props ;
8
+ getPathStyles ( offset , percent , strokeColor , strokeWidth , gapDegree = 0 , gapPosition ) {
10
9
const radius = 50 - ( strokeWidth / 2 ) ;
11
10
let beginPositionX = 0 ;
12
11
let beginPositionY = - radius ;
@@ -35,29 +34,66 @@ class Circle extends Component {
35
34
a ${ radius } ,${ radius } 0 1 1 ${ endPositionX } ,${ - endPositionY }
36
35
a ${ radius } ,${ radius } 0 1 1 ${ - endPositionX } ,${ endPositionY } ` ;
37
36
const len = Math . PI * 2 * radius ;
38
- const trailPathStyle = {
39
- strokeDasharray : `${ len - gapDegree } px ${ len } px` ,
40
- strokeDashoffset : `-${ gapDegree / 2 } px` ,
41
- transition : 'stroke-dashoffset .3s ease 0s, stroke-dasharray .3s ease 0s, stroke .3s' ,
42
- } ;
43
- const strokePathStyle = {
37
+
38
+ const pathStyle = {
44
39
stroke : strokeColor ,
45
40
strokeDasharray : `${ ( percent / 100 ) * ( len - gapDegree ) } px ${ len } px` ,
46
- strokeDashoffset : `-${ gapDegree / 2 } px` ,
41
+ strokeDashoffset : `-${ gapDegree / 2 + offset / 100 * ( len - gapDegree ) } px` ,
47
42
transition : 'stroke-dashoffset .3s ease 0s, stroke-dasharray .3s ease 0s, stroke .3s, stroke-width .06s ease .3s' , // eslint-disable-line
48
43
} ;
49
- return { pathString, trailPathStyle, strokePathStyle } ;
44
+
45
+ return {
46
+ pathString,
47
+ pathStyle,
48
+ } ;
50
49
}
51
50
51
+ getStokeList ( ) {
52
+ const {
53
+ prefixCls, percent, strokeColor, strokeWidth, strokeLinecap,
54
+ gapDegree, gapPosition,
55
+ } = this . props ;
56
+ const percentList = Array . isArray ( percent ) ? percent : [ percent ] ;
57
+ const strokeColorList = Array . isArray ( strokeColor ) ? strokeColor : [ strokeColor ] ;
58
+
59
+ let stackPtg = 0 ;
60
+ return percentList . map ( ( ptg , index ) => {
61
+ const color = strokeColorList [ index ] || strokeColorList [ strokeColorList . length - 1 ] ;
62
+ const { pathString, pathStyle } = this . getPathStyles (
63
+ stackPtg , ptg , color , strokeWidth , gapDegree , gapPosition
64
+ ) ;
65
+
66
+ stackPtg += ptg ;
67
+
68
+ return (
69
+ < path
70
+ key = { index }
71
+ className = { `${ prefixCls } -circle-path` }
72
+ d = { pathString }
73
+ strokeLinecap = { strokeLinecap }
74
+ strokeWidth = { ptg === 0 ? 0 : strokeWidth }
75
+ fillOpacity = "0"
76
+ style = { pathStyle }
77
+ ref = { ( path ) => {
78
+ this . paths [ index ] = path ;
79
+ } }
80
+ />
81
+ ) ;
82
+ } ) ;
83
+ }
84
+
85
+ paths = { } ;
86
+
52
87
render ( ) {
53
88
const {
54
- prefixCls, strokeWidth, trailWidth, percent,
89
+ prefixCls, strokeWidth, trailWidth,
90
+ gapDegree, gapPosition,
55
91
trailColor, strokeLinecap, style, className, ...restProps ,
56
92
} = this . props ;
57
- const { pathString, trailPathStyle, strokePathStyle } = this . getPathStyles ( ) ;
93
+ const { pathString, pathStyle } = this . getPathStyles (
94
+ 0 , 100 , trailColor , strokeWidth , gapDegree , gapPosition
95
+ ) ;
58
96
delete restProps . percent ;
59
- delete restProps . gapDegree ;
60
- delete restProps . gapPosition ;
61
97
delete restProps . strokeColor ;
62
98
return (
63
99
< svg
@@ -73,17 +109,9 @@ class Circle extends Component {
73
109
strokeLinecap = { strokeLinecap }
74
110
strokeWidth = { trailWidth || strokeWidth }
75
111
fillOpacity = "0"
76
- style = { trailPathStyle }
77
- />
78
- < path
79
- className = { `${ prefixCls } -circle-path` }
80
- d = { pathString }
81
- strokeLinecap = { strokeLinecap }
82
- strokeWidth = { this . props . percent === 0 ? 0 : strokeWidth }
83
- fillOpacity = "0"
84
- ref = { ( path ) => { this . path = path ; } }
85
- style = { strokePathStyle }
112
+ style = { pathStyle }
86
113
/>
114
+ { this . getStokeList ( ) }
87
115
</ svg >
88
116
) ;
89
117
}
0 commit comments