1
1
import React , { Component } from "react"
2
- import * as d3 from "d3"
3
2
import Donut from "./Donut"
4
3
import classNames from "classnames"
5
4
import { translate } from "react-i18next"
5
+ import { numberFormat , labelFormat } from "./utils"
6
6
7
7
const margin = { left : 18 , top : 18 , right : 18 , bottom : 18 }
8
8
@@ -45,14 +45,6 @@ class SuccessRate extends Component<Props> {
45
45
window . removeEventListener ( "resize" , this . recalculate )
46
46
}
47
47
48
- numberFormat ( number ) {
49
- return number < 0.1 ? d3 . format ( ".1%" ) ( number ) : d3 . format ( ".0%" ) ( number )
50
- }
51
-
52
- labelFormat ( number ) {
53
- return number > 0 && number < 1 ? d3 . format ( ".2f" ) ( number ) : d3 . format ( ".0f" ) ( number )
54
- }
55
-
56
48
render ( ) {
57
49
const { progress, weight, initial, actual, estimated, exhausted, t } = this . props
58
50
const zeroExhausted = exhausted == 0
@@ -86,14 +78,14 @@ class SuccessRate extends Component<Props> {
86
78
className = "initial label"
87
79
transform = { `translate(${ - arcRadius - offset } , 0) rotate(-90)` }
88
80
>
89
- { this . labelFormat ( 1 - progress ) }
81
+ { labelFormat ( 1 - progress ) }
90
82
</ text >
91
83
< text
92
84
ref = "foregroundLabel"
93
85
className = "actual label hanging"
94
86
transform = { `translate(${ weight - arcRadius + offset } , 0) rotate(-90)` }
95
87
>
96
- { this . labelFormat ( progress ) }
88
+ { labelFormat ( progress ) }
97
89
</ text >
98
90
</ g >
99
91
</ g >
@@ -128,7 +120,7 @@ class SuccessRate extends Component<Props> {
128
120
{ t ( "estimated success rate" ) }
129
121
</ text >
130
122
< text x = { arcRadius } y = { arcRadius / 2 } className = "percent large" >
131
- { this . numberFormat ( estimated ) }
123
+ { numberFormat ( estimated ) }
132
124
</ text >
133
125
< g
134
126
ref = "progress"
@@ -146,7 +138,7 @@ class SuccessRate extends Component<Props> {
146
138
{ t ( "Progress" ) }
147
139
</ text >
148
140
< text x = { donutRadius } y = { donutRadius - margin . bottom } className = "progress percent" >
149
- { this . numberFormat ( progress ) }
141
+ { numberFormat ( progress ) }
150
142
</ text >
151
143
</ g >
152
144
< g
@@ -166,7 +158,7 @@ class SuccessRate extends Component<Props> {
166
158
{ t ( "initial success rate" ) }
167
159
</ text >
168
160
< text x = { donutRadius / 2 } y = { donutRadius / 2 } className = "initial percent middle" >
169
- { this . numberFormat ( initial ) }
161
+ { numberFormat ( initial ) }
170
162
</ text >
171
163
</ g >
172
164
< g
@@ -198,7 +190,7 @@ class SuccessRate extends Component<Props> {
198
190
"zero-exhausted" : zeroExhausted ,
199
191
} ) }
200
192
>
201
- { this . numberFormat ( actual ) }
193
+ { numberFormat ( actual ) }
202
194
</ text >
203
195
</ g >
204
196
</ g >
0 commit comments