Skip to content

Commit 53d1c07

Browse files
committed
onClick RadarChart
1 parent 9292307 commit 53d1c07

File tree

2 files changed

+16
-26
lines changed

2 files changed

+16
-26
lines changed

packages/charts/src/components/RadialChart/RadialChart.tsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { enrichEventWithDetails, ThemingParameters } from '@ui5/webcomponents-re
55
import type { CSSProperties } from 'react';
66
import { forwardRef } from 'react';
77
import { PolarAngleAxis, RadialBar, RadialBarChart } from 'recharts';
8-
import { useOnClickInternal } from '../../hooks/useOnClickInternal.js';
8+
import type { CategoricalChartFunc } from 'recharts/types/chart/types.js';
99
import type { IChartBaseProps } from '../../interfaces/IChartBaseProps.js';
1010
import { ChartContainer } from '../../internal/ChartContainer.js';
1111
import { PieChartPlaceholder } from '../PieChart/Placeholder.js';
@@ -18,6 +18,7 @@ interface RadialChartConfig {
1818

1919
[rest: string]: any;
2020
}
21+
2122
export interface RadialChartProps
2223
extends Omit<CommonProps, 'onClick' | 'children' | 'onLegendClick'>,
2324
Pick<IChartBaseProps, 'loading' | 'loadingDelay'> {
@@ -57,7 +58,7 @@ export interface RadialChartProps
5758
*/
5859
onClick?: (
5960
event: CustomEvent<{
60-
// todo: map new values to old ones to prevent breaking changes
61+
// todo: remove payload and activePayloads in next major?
6162
payload: unknown;
6263
activePayloads: Record<string, unknown>[];
6364
dataIndex: number;
@@ -127,7 +128,15 @@ const RadialChart = forwardRef<HTMLDivElement, RadialChartProps>((props, ref) =>
127128
}
128129
};
129130

130-
const onClickInternal = useOnClickInternal(onClick);
131+
const handleOnClick: CategoricalChartFunc = (_, e) => {
132+
onClick(
133+
// @ts-expect-error: enrichEventWithDetails expects a CustomEvent
134+
enrichEventWithDetails(e, {
135+
// @ts-expect-error: detail property exists
136+
activePayloads: [e.detail.payload],
137+
}),
138+
);
139+
};
131140

132141
return (
133142
<ChartContainer
@@ -143,7 +152,7 @@ const RadialChart = forwardRef<HTMLDivElement, RadialChartProps>((props, ref) =>
143152
{...rest}
144153
>
145154
<RadialBarChart
146-
onClick={onClickInternal}
155+
onClick={handleOnClick}
147156
innerRadius="90%"
148157
outerRadius="100%"
149158
barSize={10}
@@ -168,8 +177,9 @@ const RadialChart = forwardRef<HTMLDivElement, RadialChartProps>((props, ref) =>
168177
y="50%"
169178
textAnchor="middle"
170179
dominantBaseline="middle"
171-
className="progress-label"
172-
style={{ ...defaultDisplayValueStyles, ...displayValueStyle }}
180+
//todo: why do we need this?
181+
// className="progress-label"
182+
style={displayValueStyle}
173183
>
174184
{displayValue}
175185
</text>

packages/charts/src/hooks/useOnClickInternal.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,3 @@ export const useOnClickInternal = (
3737
};
3838

3939
//todo: integrate LineChart, RadarChart click here as well?
40-
41-
//bar, bullet, column, withTrend, composed, donut, line, pie, radial, scatter
42-
//activeCoordinate
43-
// :
44-
// {x: 746, y: 243.2412109375}
45-
// activeDataKey
46-
// :
47-
// undefined
48-
// activeIndex
49-
// :
50-
// "8"
51-
// activeLabel
52-
// :
53-
// "September"
54-
// activeTooltipIndex
55-
// :
56-
// "8"
57-
// isTooltipActive
58-
// :
59-
// true

0 commit comments

Comments
 (0)