3
3
import { enrichEventWithDetails , useStylesheet , useSyncRef } from '@ui5/webcomponents-react-base' ;
4
4
import { clsx } from 'clsx' ;
5
5
import type { CSSProperties } from 'react' ;
6
- import { cloneElement , forwardRef , isValidElement , useCallback , useMemo } from 'react' ;
6
+ import { useRef , cloneElement , forwardRef , isValidElement , useCallback , useMemo } from 'react' ;
7
7
import {
8
8
Cell ,
9
9
Curve ,
@@ -18,7 +18,7 @@ import {
18
18
import { getValueByDataKey } from 'recharts/lib/util/ChartUtils.js' ;
19
19
import { useLegendItemClick } from '../../hooks/useLegendItemClick.js' ;
20
20
import { useOnClickInternal } from '../../hooks/useOnClickInternal.js' ;
21
- import type { IChartBaseProps } from '../../interfaces/IChartBaseProps.js' ;
21
+ import type { ActivePayload , IChartBaseProps } from '../../interfaces/IChartBaseProps.js' ;
22
22
import type { IChartDimension } from '../../interfaces/IChartDimension.js' ;
23
23
import type { IChartMeasure } from '../../interfaces/IChartMeasure.js' ;
24
24
import type { IPolarChartConfig } from '../../interfaces/IPolarChartConfig.js' ;
@@ -141,6 +141,16 @@ const PieChart = forwardRef<HTMLDivElement, PieChartProps>((props, ref) => {
141
141
} ) ,
142
142
[ props . measure ] ,
143
143
) ;
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
+ } ) ;
144
154
145
155
const dataLabel = ( props ) => {
146
156
const hideDataLabel =
@@ -164,11 +174,12 @@ const PieChart = forwardRef<HTMLDivElement, PieChartProps>((props, ref) => {
164
174
) ;
165
175
166
176
const onItemLegendClick = useLegendItemClick ( onLegendClick , ( ) => measure . accessor ) ;
167
- const onClickInternal = useOnClickInternal ( onClick ) ;
177
+ const onClickInternal = useOnClickInternal ( onClick , dataset , activePayloadsRef ) ;
168
178
169
179
const onDataPointClickInternal = useCallback (
170
180
( payload , dataIndex , event ) => {
171
181
if ( payload && payload && typeof onDataPointClick === 'function' ) {
182
+ //todo check values
172
183
onDataPointClick (
173
184
enrichEventWithDetails ( event , {
174
185
value : payload . value ,
@@ -302,6 +313,10 @@ const PieChart = forwardRef<HTMLDivElement, PieChartProps>((props, ref) => {
302
313
classNames . piechart ,
303
314
) }
304
315
>
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*/ }
305
320
< Pie
306
321
onClick = { onDataPointClickInternal }
307
322
innerRadius = { chartConfig . innerRadius }
@@ -315,17 +330,23 @@ const PieChart = forwardRef<HTMLDivElement, PieChartProps>((props, ref) => {
315
330
labelLine = { renderLabelLine }
316
331
label = { dataLabel }
317
332
activeShape = { chartConfig . activeSegment != null && renderActiveShape }
318
- rootTabIndex = { - 1 }
333
+ //todo: why do we need this?
334
+ // rootTabIndex={-1}
319
335
>
320
336
{ centerLabel && < RechartsLabel position = "center" > { centerLabel } </ RechartsLabel > }
321
337
{ 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
+ } ) }
329
350
</ Pie >
330
351
{ tooltipConfig ?. active !== false && (
331
352
< Tooltip
0 commit comments