33import { enrichEventWithDetails , useStylesheet , useSyncRef } from '@ui5/webcomponents-react-base' ;
44import { clsx } from 'clsx' ;
55import type { CSSProperties } from 'react' ;
6- import { cloneElement , forwardRef , isValidElement , useCallback , useMemo } from 'react' ;
6+ import { useRef , cloneElement , forwardRef , isValidElement , useCallback , useMemo } from 'react' ;
77import {
88 Cell ,
99 Curve ,
@@ -18,7 +18,7 @@ import {
1818import { getValueByDataKey } from 'recharts/lib/util/ChartUtils.js' ;
1919import { useLegendItemClick } from '../../hooks/useLegendItemClick.js' ;
2020import { useOnClickInternal } from '../../hooks/useOnClickInternal.js' ;
21- import type { IChartBaseProps } from '../../interfaces/IChartBaseProps.js' ;
21+ import type { ActivePayload , IChartBaseProps } from '../../interfaces/IChartBaseProps.js' ;
2222import type { IChartDimension } from '../../interfaces/IChartDimension.js' ;
2323import type { IChartMeasure } from '../../interfaces/IChartMeasure.js' ;
2424import type { IPolarChartConfig } from '../../interfaces/IPolarChartConfig.js' ;
@@ -141,6 +141,16 @@ const PieChart = forwardRef<HTMLDivElement, PieChartProps>((props, ref) => {
141141 } ) ,
142142 [ props . measure ] ,
143143 ) ;
144+ const activePayloadsRef = useRef < ActivePayload > ( {
145+ ...measure ,
146+ // these properties must be either set in the component, or in the `useOnClickInternal` hook
147+ dataKey : measure . accessor ,
148+ name : measure . accessor ,
149+ color : '' ,
150+ stroke : '' ,
151+ payload : { } ,
152+ value : '' ,
153+ } ) ;
144154
145155 const dataLabel = ( props ) => {
146156 const hideDataLabel =
@@ -164,11 +174,12 @@ const PieChart = forwardRef<HTMLDivElement, PieChartProps>((props, ref) => {
164174 ) ;
165175
166176 const onItemLegendClick = useLegendItemClick ( onLegendClick , ( ) => measure . accessor ) ;
167- const onClickInternal = useOnClickInternal ( onClick ) ;
177+ const onClickInternal = useOnClickInternal ( onClick , dataset , activePayloadsRef ) ;
168178
169179 const onDataPointClickInternal = useCallback (
170180 ( payload , dataIndex , event ) => {
171181 if ( payload && payload && typeof onDataPointClick === 'function' ) {
182+ //todo check values
172183 onDataPointClick (
173184 enrichEventWithDetails ( event , {
174185 value : payload . value ,
@@ -302,6 +313,10 @@ const PieChart = forwardRef<HTMLDivElement, PieChartProps>((props, ref) => {
302313 classNames . piechart ,
303314 ) }
304315 >
316+ { /*todo: accessibility layer needs active shape?*/ }
317+ { /*todo: keyboard nav with active shape doesn't hide the default label of the Cell when active*/ }
318+ { /*todo: when clicked while activeShape is set, it takes a lot of time to rerender the component, leading to
319+ strange behavior*/ }
305320 < Pie
306321 onClick = { onDataPointClickInternal }
307322 innerRadius = { chartConfig . innerRadius }
@@ -315,17 +330,23 @@ const PieChart = forwardRef<HTMLDivElement, PieChartProps>((props, ref) => {
315330 labelLine = { renderLabelLine }
316331 label = { dataLabel }
317332 activeShape = { chartConfig . activeSegment != null && renderActiveShape }
318- rootTabIndex = { - 1 }
333+ //todo: why do we need this?
334+ // rootTabIndex={-1}
319335 >
320336 { centerLabel && < RechartsLabel position = "center" > { centerLabel } </ RechartsLabel > }
321337 { dataset &&
322- dataset . map ( ( data , index ) => (
323- < Cell
324- key = { index }
325- name = { `${ dimension . formatter ( getValueByDataKey ( data , dimension . accessor , '' ) ) } ` }
326- fill = { measure . colors ?. [ index ] ?? `var(--sapChart_OrderedColor_${ ( index % 12 ) + 1 } )` }
327- />
328- ) ) }
338+ dataset . map ( ( data , index ) => {
339+ const color = measure . colors ?. [ index ] ?? `var(--sapChart_OrderedColor_${ ( index % 12 ) + 1 } )` ;
340+ activePayloadsRef . current . color = color ;
341+ activePayloadsRef . current . stroke = color ;
342+ return (
343+ < Cell
344+ key = { index }
345+ name = { `${ dimension . formatter ( getValueByDataKey ( data , dimension . accessor , '' ) ) } ` }
346+ fill = { color }
347+ />
348+ ) ;
349+ } ) }
329350 </ Pie >
330351 { tooltipConfig ?. active !== false && (
331352 < Tooltip
0 commit comments