@@ -40,6 +40,7 @@ interface IProps {
40
40
renderLabel ?: ( data : ChartData ) => string
41
41
renderTooltip ?: ( data : ChartData ) => React . ReactElement | string
42
42
labelAs ?: 'value' | 'percentage'
43
+ hideLabelTitle ?: boolean
43
44
}
44
45
45
46
const ANIMATION_DURATION_MS = 100
@@ -56,6 +57,7 @@ const DonutChart = (props: IProps) => {
56
57
labelAs = 'value' ,
57
58
renderLabel,
58
59
renderTooltip,
60
+ hideLabelTitle = false
59
61
} = props
60
62
61
63
const margin = config ?. margin || 98
@@ -134,7 +136,7 @@ const DonutChart = (props: IProps) => {
134
136
. select ( svgRef . current )
135
137
. attr ( 'width' , width )
136
138
. attr ( 'height' , height )
137
- . attr ( 'data-testid' , `donut-${ name } ` )
139
+ . attr ( 'data-testid' , `donut-svg- ${ name } ` )
138
140
. attr ( 'class' , cx ( classNames ?. chart ) )
139
141
. append ( 'g' )
140
142
. attr ( 'transform' , `translate(${ width / 2 } ,${ height / 2 } )` )
@@ -160,7 +162,7 @@ const DonutChart = (props: IProps) => {
160
162
. append ( 'text' )
161
163
. attr ( 'class' , cx ( styles . chartLabel , classNames ?. arcLabel ) )
162
164
. attr ( 'transform' , getLabelPosition )
163
- . text ( ( d ) => ( isShowLabel ( d ) ? d . data . name : '' ) )
165
+ . text ( ( d ) => ( isShowLabel ( d ) && ! hideLabelTitle ? ` ${ d . data . name } : ` : '' ) )
164
166
. attr ( 'data-testid' , ( d ) => `label-${ d . data . name } -${ d . data . value } ` )
165
167
. style ( 'text-anchor' , ( d ) => ( ( d . endAngle + d . startAngle ) / 2 > Math . PI ? 'end' : 'start' ) )
166
168
. on ( 'mouseenter mousemove' , onMouseEnterSlice )
@@ -175,12 +177,11 @@ const DonutChart = (props: IProps) => {
175
177
return renderLabel ( d . data )
176
178
}
177
179
178
- const separator = ': '
179
180
if ( labelAs === 'percentage' ) {
180
- return `${ separator } ${ getPercentage ( d . value , sum ) } %`
181
+ return `${ getPercentage ( d . value , sum ) } %`
181
182
}
182
183
183
- return ` ${ separator } ${ truncateNumberToRange ( d . value ) } `
184
+ return truncateNumberToRange ( d . value )
184
185
} )
185
186
. attr ( 'class' , cx ( styles . chartLabelValue , classNames ?. arcLabelValue ) )
186
187
} , [ data ] )
@@ -190,7 +191,7 @@ const DonutChart = (props: IProps) => {
190
191
}
191
192
192
193
return (
193
- < div className = { styles . wrapper } >
194
+ < div className = { styles . wrapper } data-testid = { `donut- ${ name } ` } >
194
195
< svg ref = { svgRef } />
195
196
< div
196
197
className = { cx ( styles . tooltip , classNames ?. tooltip ) }
0 commit comments