@@ -3,8 +3,8 @@ import { enrichEventWithDetails } from '@ui5/webcomponents-react-base/lib/Utils'
3
3
import { ChartContainer } from '@ui5/webcomponents-react-charts/lib/components/ChartContainer' ;
4
4
import { PieChartPlaceholder } from '@ui5/webcomponents-react-charts/lib/PieChartPlaceholder' ;
5
5
import { useLegendItemClick } from '@ui5/webcomponents-react-charts/lib/useLegendItemClick' ;
6
- import React , { CSSProperties , FC , forwardRef , Ref , useCallback , useMemo } from 'react' ;
7
- import { Cell , Label , Legend , Pie , PieChart as PieChartLib , Tooltip } from 'recharts' ;
6
+ import React , { CSSProperties , FC , forwardRef , Ref , useCallback , useMemo , isValidElement , cloneElement } from 'react' ;
7
+ import { Cell , Label , Legend , Pie , PieChart as PieChartLib , Tooltip , Text } from 'recharts' ;
8
8
import { getValueByDataKey } from 'recharts/lib/util/ChartUtils' ;
9
9
import { IChartBaseProps } from '../../interfaces/IChartBaseProps' ;
10
10
import { IChartMeasure } from '../../interfaces/IChartMeasure' ;
@@ -101,14 +101,22 @@ const PieChart: FC<PieChartProps> = forwardRef((props: PieChartProps, ref: Ref<a
101
101
[ props . measure ]
102
102
) ;
103
103
104
- const label = useMemo ( ( ) => {
105
- if ( measure . hideDataLabel ) return null ;
106
- return {
107
- position : 'outside' ,
108
- content : measure . DataLabel ,
109
- formatter : measure . formatter
110
- } ;
111
- } , [ measure ] ) ;
104
+ const dataLabel = useCallback (
105
+ ( props ) => {
106
+ if ( measure . hideDataLabel ) return null ;
107
+
108
+ if ( isValidElement ( measure . DataLabel ) ) {
109
+ return cloneElement ( measure . DataLabel , { ...props , config : measure } ) ;
110
+ }
111
+
112
+ return (
113
+ < Text { ...props } alignmentBaseline = "middle" className = "recharts-pie-label-text" >
114
+ { measure . formatter ( props . value ) }
115
+ </ Text >
116
+ ) ;
117
+ } ,
118
+ [ measure ]
119
+ ) ;
112
120
113
121
const tooltipValueFormatter = useCallback ( ( value ) => measure . formatter ( value ) , [ measure . formatter ] ) ;
114
122
const chartRef = useConsolidatedRef < any > ( ref ) ;
@@ -158,7 +166,8 @@ const PieChart: FC<PieChartProps> = forwardRef((props: PieChartProps, ref: Ref<a
158
166
data = { dataset }
159
167
animationBegin = { 0 }
160
168
isAnimationActive = { noAnimation === false }
161
- label = { label }
169
+ labelLine = { measure . hideDataLabel !== true }
170
+ label = { dataLabel }
162
171
>
163
172
{ centerLabel && < Label position = { 'center' } > { centerLabel } </ Label > }
164
173
{ dataset &&
0 commit comments