11import * as React from 'react' ;
22import { Circle , ProgressProps } from 'rc-progress' ;
33
4- const colorMap = [ '#3FC7FA' , '#85D262' , '#FE8C6A' ] ;
4+ const colorMap = [ '#3FC7FA' , '#85D262' , '#FE8C6A' , '#FF5959' , '#BC3FFA' ] ;
55
66function getColor ( index ) {
77 return colorMap [ ( index + colorMap . length ) % colorMap . length ] ;
@@ -13,8 +13,10 @@ class Example extends React.Component<ProgressProps, any> {
1313 this . state = {
1414 percent : 30 ,
1515 colorIndex : 0 ,
16+ subPathsCount : 3 ,
1617 } ;
1718 this . changeState = this . changeState . bind ( this ) ;
19+ this . changeCount = this . changeCount . bind ( this ) ;
1820 }
1921
2022 changeState ( ) {
@@ -26,19 +28,38 @@ class Example extends React.Component<ProgressProps, any> {
2628 } ) ;
2729 }
2830
31+ changeCount ( ) {
32+ this . setState ( {
33+ ...this . state ,
34+ subPathsCount : ( this . state . subPathsCount % 6 ) + 1 ,
35+ } ) ;
36+ }
37+
2938 render ( ) {
3039 const circleContainerStyle = {
3140 width : '200px' ,
3241 height : '200px' ,
3342 } ;
34- const { percent, colorIndex } = this . state ;
43+ const { percent, colorIndex, subPathsCount } = this . state ;
3544 const color = getColor ( colorIndex ) ;
45+
46+ const multiPercentage = new Array ( subPathsCount ) . fill (
47+ percent / subPathsCount ,
48+ 0 ,
49+ subPathsCount ,
50+ ) ;
51+ const multiPercentageStrokeColors = multiPercentage . map ( ( v , index ) => getColor ( index ) ) ;
52+
3653 return (
3754 < div >
3855 < p >
3956 < button type = "button" onClick = { this . changeState } >
4057 Change State [{ percent } ]
4158 </ button >
59+
60+ < button type = "button" onClick = { this . changeCount } >
61+ Change Count [{ subPathsCount } ]
62+ </ button >
4263 </ p >
4364 < div style = { circleContainerStyle } >
4465 < Circle
@@ -52,13 +73,13 @@ class Example extends React.Component<ProgressProps, any> {
5273 </ div >
5374 < div style = { circleContainerStyle } >
5475 < Circle
55- percent = { [ percent / 3 , percent / 3 , percent / 3 ] }
76+ percent = { multiPercentage }
5677 gapDegree = { 70 }
5778 gapPosition = "bottom"
5879 strokeWidth = { 6 }
5980 trailWidth = { 6 }
6081 strokeLinecap = "round"
61- strokeColor = { [ color , getColor ( colorIndex + 1 ) , getColor ( colorIndex + 2 ) ] }
82+ strokeColor = { multiPercentageStrokeColors }
6283 />
6384 </ div >
6485
0 commit comments