22
33import { enrichEventWithDetails , ThemingParameters , useIsRTL , useSyncRef } from '@ui5/webcomponents-react-base' ;
44import type { CSSProperties , FC } from 'react' ;
5- import { forwardRef , useCallback } from 'react' ;
5+ import { useRef , forwardRef , useCallback } from 'react' ;
66import {
77 Area ,
88 Bar ,
@@ -27,7 +27,7 @@ import { useObserveXAxisHeights } from '../../hooks/useObserveXAxisHeights.js';
2727import { useOnClickInternal } from '../../hooks/useOnClickInternal.js' ;
2828import { usePrepareDimensionsAndMeasures } from '../../hooks/usePrepareDimensionsAndMeasures.js' ;
2929import { useTooltipFormatter } from '../../hooks/useTooltipFormatter.js' ;
30- import type { IChartBaseProps } from '../../interfaces/IChartBaseProps.js' ;
30+ import type { ActivePayload , IChartBaseProps } from '../../interfaces/IChartBaseProps.js' ;
3131import type { IChartDimension } from '../../interfaces/IChartDimension.js' ;
3232import type { IChartMeasure } from '../../interfaces/IChartMeasure.js' ;
3333import { ChartContainer } from '../../internal/ChartContainer.js' ;
@@ -188,6 +188,7 @@ const ComposedChart = forwardRef<HTMLDivElement, ComposedChartProps>((props, ref
188188 measureDefaults ,
189189 ) ;
190190
191+ const activePayloadsRef = useRef < ActivePayload [ ] > ( measures ) ;
191192 const tooltipValueFormatter = useTooltipFormatter ( measures ) ;
192193
193194 const primaryDimension = dimensions [ 0 ] ;
@@ -238,7 +239,7 @@ const ComposedChart = forwardRef<HTMLDivElement, ComposedChartProps>((props, ref
238239 } ;
239240
240241 const onItemLegendClick = useLegendItemClick ( onLegendClick ) ;
241- const onClickInternal = useOnClickInternal ( onClick ) ;
242+ const onClickInternal = useOnClickInternal ( onClick , dataset , activePayloadsRef ) ;
242243
243244 const isBigDataSet = dataset ?. length > 30 ;
244245 const primaryDimensionAccessor = primaryDimension ?. accessor ;
@@ -438,11 +439,22 @@ const ComposedChart = forwardRef<HTMLDivElement, ComposedChartProps>((props, ref
438439 ) }
439440 { measures ?. map ( ( element , index ) => {
440441 const ChartElement = ChartTypes [ element . type ] as any as FC < any > ;
441-
442442 const chartElementProps : any = {
443443 isAnimationActive : ! noAnimation ,
444444 } ;
445445 let labelPosition = 'top' ;
446+ const color = element . color ?? `var(--sapChart_OrderedColor_${ ( index % 12 ) + 1 } )` ;
447+ const dataKey = element . accessor ;
448+ const name = element . label ?? element . accessor ;
449+ const opacity = element . opacity ?? 1 ;
450+ const hide = element . hide ;
451+ activePayloadsRef . current [ index ] . color = color ;
452+ activePayloadsRef . current [ index ] . stroke = color ;
453+ activePayloadsRef . current [ index ] . dataKey = dataKey ;
454+ activePayloadsRef . current [ index ] . hide = hide ;
455+ activePayloadsRef . current [ index ] . name = name ;
456+ activePayloadsRef . current [ index ] . fillOpacity = opacity ;
457+ activePayloadsRef . current [ index ] . strokeOpacity = opacity ;
446458
447459 switch ( element . type ) {
448460 case 'line' :
@@ -452,9 +464,12 @@ const ComposedChart = forwardRef<HTMLDivElement, ComposedChartProps>((props, ref
452464 chartElementProps . strokeWidth = element . width ;
453465 chartElementProps . strokeOpacity = element . opacity ;
454466 chartElementProps . dot = element . showDot ?? ! isBigDataSet ;
467+
468+ activePayloadsRef . current [ index ] . fillOpacity = opacity ;
469+ activePayloadsRef . current [ index ] . strokeOpacity = opacity ;
455470 break ;
456471 case 'bar' :
457- chartElementProps . hide = element . hide ;
472+ chartElementProps . hide = hide ;
458473 chartElementProps . fillOpacity = element . opacity ;
459474 chartElementProps . strokeOpacity = element . opacity ;
460475 chartElementProps . barSize = element . width ;
@@ -475,6 +490,9 @@ const ComposedChart = forwardRef<HTMLDivElement, ComposedChartProps>((props, ref
475490 chartElementProps . activeDot = {
476491 onClick : onDataPointClickInternal ,
477492 } ;
493+
494+ activePayloadsRef . current [ index ] . fillOpacity = 0.3 ;
495+ activePayloadsRef . current [ index ] . strokeOpacity = opacity ;
478496 break ;
479497 }
480498
@@ -486,22 +504,22 @@ const ComposedChart = forwardRef<HTMLDivElement, ComposedChartProps>((props, ref
486504 return (
487505 < ChartElement
488506 key = { element . reactKey }
489- name = { element . label ?? element . accessor }
507+ name = { name }
490508 label = {
491509 element . type === 'bar' || isBigDataSet ? undefined : (
492510 < ChartDataLabel config = { element } chartType = { element . type } position = { labelPosition } />
493511 )
494512 }
495- stroke = { element . color ?? `var(--sapChart_OrderedColor_ ${ ( index % 12 ) + 1 } )` }
496- fill = { element . color ?? `var(--sapChart_OrderedColor_ ${ ( index % 12 ) + 1 } )` }
513+ stroke = { color }
514+ fill = { color }
497515 type = "monotone"
498- dataKey = { element . accessor }
516+ dataKey = { dataKey }
499517 { ...chartElementProps }
500518 >
501519 { element . type === 'bar' && (
502520 < >
503521 < LabelList
504- dataKey = { element . accessor }
522+ dataKey = { dataKey }
505523 content = { < ChartDataLabel config = { element } chartType = "column" position = { 'insideTop' } /> }
506524 />
507525 { dataset . map ( ( data , i ) => {
0 commit comments