11'use client' ;
22
3- import { enrichEventWithDetails , useStylesheet } from '@ui5/webcomponents-react-base' ;
3+ import { enrichEventWithDetails , useStylesheet , useSyncRef } from '@ui5/webcomponents-react-base' ;
44import { clsx } from 'clsx' ;
55import type { CSSProperties } from 'react' ;
66import { cloneElement , forwardRef , isValidElement , useCallback , useMemo } from 'react' ;
@@ -108,6 +108,8 @@ const PieChart = forwardRef<HTMLDivElement, PieChartProps>((props, ref) => {
108108 } = props ;
109109
110110 useStylesheet ( styleData , PieChart . displayName ) ;
111+ const [ componentRef , chartRef ] = useSyncRef ( ref ) ;
112+ const isDonutChart = props [ 'data-component-name' ] === 'DonutChart' ;
111113
112114 const chartConfig = {
113115 margin : { right : 30 , left : 30 , bottom : 30 , top : 30 , ...( props . chartConfig ?. margin ?? { } ) } ,
@@ -192,12 +194,23 @@ const PieChart = forwardRef<HTMLDivElement, PieChartProps>((props, ref) => {
192194 const ex = mx + ( cos >= 0 ? 1 : - 1 ) * 22 ;
193195 const ey = my ;
194196 const textAnchor = cos >= 0 ? 'start' : 'end' ;
197+ const activeLegendItem = chartRef . current ?. querySelector < HTMLLIElement > (
198+ `.legend-item-${ chartConfig . activeSegment } `
199+ ) ;
200+ if ( ! activeLegendItem ?. dataset . activeLegend ) {
201+ const allLegendItems = chartRef . current ?. querySelectorAll ( '.recharts-legend-item' ) ;
202+
203+ allLegendItems . forEach ( ( item ) => item . removeAttribute ( 'data-active-legend' ) ) ;
204+ activeLegendItem . setAttribute ( 'data-active-legend' , 'true' ) ;
205+ }
195206
196207 return (
197208 < g >
198- < text x = { cx } y = { cy } dy = { 8 } textAnchor = "middle" fill = { fill } >
199- { payload . name }
200- </ text >
209+ { isDonutChart && (
210+ < text x = { cx } y = { cy } dy = { 8 } textAnchor = "middle" fill = { fill } >
211+ { payload . name }
212+ </ text >
213+ ) }
201214 < Sector
202215 cx = { cx }
203216 cy = { cy }
@@ -231,7 +244,7 @@ const PieChart = forwardRef<HTMLDivElement, PieChartProps>((props, ref) => {
231244 </ g >
232245 ) ;
233246 } ,
234- [ showActiveSegmentDataLabel ]
247+ [ showActiveSegmentDataLabel , chartConfig . activeSegment , isDonutChart ]
235248 ) ;
236249
237250 const renderLabelLine = useCallback (
@@ -248,11 +261,11 @@ const PieChart = forwardRef<HTMLDivElement, PieChartProps>((props, ref) => {
248261 if ( chartConfig . activeSegment != null && showActiveSegmentDataLabel ) {
249262 if ( chartConfig . legendPosition === 'bottom' ) {
250263 return {
251- paddingTop : '30px'
264+ paddingBlockStart : '30px'
252265 } ;
253266 } else if ( chartConfig . legendPosition === 'top' ) {
254267 return {
255- paddingBottom : '30px'
268+ paddingBlockEnd : '30px'
256269 } ;
257270 }
258271 }
@@ -265,7 +278,7 @@ const PieChart = forwardRef<HTMLDivElement, PieChartProps>((props, ref) => {
265278 return (
266279 < ChartContainer
267280 dataset = { dataset }
268- ref = { ref }
281+ ref = { componentRef }
269282 loading = { loading }
270283 Placeholder = { ChartPlaceholder ?? PieChartPlaceholder }
271284 style = { style }
@@ -296,6 +309,7 @@ const PieChart = forwardRef<HTMLDivElement, PieChartProps>((props, ref) => {
296309 label = { dataLabel }
297310 activeIndex = { chartConfig . activeSegment }
298311 activeShape = { chartConfig . activeSegment != null && renderActiveShape }
312+ rootTabIndex = { - 1 }
299313 >
300314 { centerLabel && < RechartsLabel position = "center" > { centerLabel } </ RechartsLabel > }
301315 { dataset &&
0 commit comments