@@ -19,9 +19,10 @@ import { useLabelFormatter } from '../../hooks/useLabelFormatter.js';
19
19
import { useLegendItemClick } from '../../hooks/useLegendItemClick.js' ;
20
20
import { useLongestYAxisLabel } from '../../hooks/useLongestYAxisLabel.js' ;
21
21
import { useObserveXAxisHeights } from '../../hooks/useObserveXAxisHeights.js' ;
22
+ import { useOnClickInternal } from '../../hooks/useOnClickInternal.js' ;
22
23
import { usePrepareDimensionsAndMeasures } from '../../hooks/usePrepareDimensionsAndMeasures.js' ;
23
24
import { useTooltipFormatter } from '../../hooks/useTooltipFormatter.js' ;
24
- import type { IChartBaseProps } from '../../interfaces/IChartBaseProps.js' ;
25
+ import type { ActivePayload , IChartBaseProps } from '../../interfaces/IChartBaseProps.js' ;
25
26
import type { IChartDimension } from '../../interfaces/IChartDimension.js' ;
26
27
import type { IChartMeasure } from '../../interfaces/IChartMeasure.js' ;
27
28
import { ChartContainer } from '../../internal/ChartContainer.js' ;
@@ -160,7 +161,7 @@ const LineChart = forwardRef<HTMLDivElement, LineChartProps>((props, ref) => {
160
161
dimensionDefaults ,
161
162
measureDefaults ,
162
163
) ;
163
-
164
+ const activePayloadsRef = useRef < ActivePayload [ ] > ( measures ) ;
164
165
const tooltipValueFormatter = useTooltipFormatter ( measures ) ;
165
166
166
167
const primaryDimension = dimensions [ 0 ] ;
@@ -180,8 +181,8 @@ const LineChart = forwardRef<HTMLDivElement, LineChartProps>((props, ref) => {
180
181
181
182
const onItemLegendClick = useLegendItemClick ( onLegendClick ) ;
182
183
const preventOnClickCall = useRef ( 0 ) ;
184
+ const handleClick = useOnClickInternal ( onClick , dataset , activePayloadsRef ) ;
183
185
184
- //todo: check this
185
186
const onDataPointClickInternal = useCallback (
186
187
( payload , eventOrIndex ) => {
187
188
if ( eventOrIndex . dataKey && typeof onDataPointClick === 'function' ) {
@@ -195,18 +196,13 @@ const LineChart = forwardRef<HTMLDivElement, LineChartProps>((props, ref) => {
195
196
} ) ,
196
197
) ;
197
198
} else if ( typeof onClick === 'function' && preventOnClickCall . current === 0 ) {
198
- onClick (
199
- enrichEventWithDetails ( eventOrIndex , {
200
- payload : payload ?. activePayload ?. [ 0 ] ?. payload ,
201
- activePayloads : payload ?. activePayload ,
202
- } ) ,
203
- ) ;
199
+ handleClick ( payload , eventOrIndex ) ;
204
200
}
205
201
if ( preventOnClickCall . current > 0 ) {
206
202
preventOnClickCall . current -= 1 ;
207
203
}
208
204
} ,
209
- [ onDataPointClick , preventOnClickCall . current ] ,
205
+ [ handleClick , onClick , onDataPointClick ] ,
210
206
) ;
211
207
212
208
const isBigDataSet = dataset ?. length > 30 ;
@@ -299,17 +295,28 @@ const LineChart = forwardRef<HTMLDivElement, LineChartProps>((props, ref) => {
299
295
/>
300
296
) }
301
297
{ measures . map ( ( element , index ) => {
298
+ const color = element . color ?? `var(--sapChart_OrderedColor_${ ( index % 12 ) + 1 } )` ;
299
+ const dataKey = element . accessor ;
300
+ const name = element . label ?? element . accessor ;
301
+ const opacity = element . opacity ?? 1 ;
302
+ activePayloadsRef . current [ index ] . color = color ;
303
+ activePayloadsRef . current [ index ] . stroke = color ;
304
+ activePayloadsRef . current [ index ] . dataKey = dataKey ;
305
+ activePayloadsRef . current [ index ] . hide = element . hide ;
306
+ activePayloadsRef . current [ index ] . name = name ;
307
+ activePayloadsRef . current [ index ] . fillOpacity = opacity ;
308
+ activePayloadsRef . current [ index ] . strokeOpacity = opacity ;
302
309
return (
303
310
< Line
304
311
dot = { element . showDot ?? ! isBigDataSet }
305
312
yAxisId = { chartConfig . secondYAxis ?. dataKey === element . accessor ? 'right' : 'left' }
306
313
key = { element . reactKey }
307
- name = { element . label ?? element . accessor }
308
- strokeOpacity = { element . opacity }
314
+ name = { name }
315
+ strokeOpacity = { opacity }
309
316
label = { isBigDataSet ? false : < ChartDataLabel config = { element } chartType = "line" position = "top" /> }
310
317
type = "monotone"
311
- dataKey = { element . accessor }
312
- stroke = { element . color ?? `var(--sapChart_OrderedColor_ ${ ( index % 12 ) + 1 } )` }
318
+ dataKey = { dataKey }
319
+ stroke = { color }
313
320
strokeWidth = { element . width }
314
321
activeDot = { { onClick : onDataPointClickInternal } }
315
322
isAnimationActive = { ! noAnimation }
@@ -335,7 +342,6 @@ const LineChart = forwardRef<HTMLDivElement, LineChartProps>((props, ref) => {
335
342
label = { referenceLine ?. label }
336
343
/>
337
344
) }
338
- { /*ToDo: remove conditional rendering once `active` is working again (https://github.com/recharts/recharts/issues/2703)*/ }
339
345
{ tooltipConfig ?. active !== false && (
340
346
< Tooltip
341
347
cursor = { tooltipFillOpacity }
0 commit comments