@@ -3,8 +3,8 @@ import { enrichEventWithDetails } from '@ui5/webcomponents-react-base/lib/Utils'
33import { ChartContainer } from '@ui5/webcomponents-react-charts/lib/next/ChartContainer' ;
44import { PieChartPlaceholder } from '@ui5/webcomponents-react-charts/lib/PieChartPlaceholder' ;
55import { 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' ;
88import { getValueByDataKey } from 'recharts/lib/util/ChartUtils' ;
99import { IChartMeasure } from '../../interfaces/IChartMeasure' ;
1010import { IPolarChartConfig } from '../../interfaces/IPolarChartConfig' ;
@@ -101,14 +101,22 @@ const PieChart: FC<PieChartProps> = forwardRef((props: PieChartProps, ref: Ref<a
101101 [ props . measure ]
102102 ) ;
103103
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+ ) ;
112120
113121 const tooltipValueFormatter = useCallback ( ( value ) => measure . formatter ( value ) , [ measure . formatter ] ) ;
114122 const chartRef = useConsolidatedRef < any > ( ref ) ;
@@ -158,7 +166,8 @@ const PieChart: FC<PieChartProps> = forwardRef((props: PieChartProps, ref: Ref<a
158166 data = { dataset }
159167 animationBegin = { 0 }
160168 isAnimationActive = { noAnimation === false }
161- label = { label }
169+ labelLine = { measure . hideDataLabel !== true }
170+ label = { dataLabel }
162171 >
163172 { centerLabel && < Label position = { 'center' } > { centerLabel } </ Label > }
164173 { dataset &&
0 commit comments