Skip to content

Commit 1f16eb0

Browse files
authored
Merge branch 'master' into adjust-placement
2 parents 6a98d72 + 37bd08c commit 1f16eb0

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

packages/x-charts/src/RadarChart/RadarAxisHighlight/RadarAxisSliceHighlight.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,19 @@ export function RadarAxisSliceHighlight(props: RadarAxisSliceHighlightProps) {
3030
{series.map(({ id, color }, seriesIndex) => {
3131
const { highlighted, next = highlighted, previous = highlighted } = points[seriesIndex];
3232

33+
const ratioPrev = previous.r / (previous.r + highlighted.r);
34+
const ratioNext = next.r / (next.r + highlighted.r);
35+
3336
return (
3437
<path
3538
className={classes?.slice}
3639
key={id}
3740
fill={color}
3841
d={`M
3942
${center.cx} ${center.cy}
40-
L ${(previous.x + highlighted.x) / 2} ${(previous.y + highlighted.y) / 2}
43+
L ${previous.x * (1 - ratioPrev) + highlighted.x * ratioPrev} ${previous.y * (1 - ratioPrev) + highlighted.y * ratioPrev}
4144
L ${highlighted.x} ${highlighted.y}
42-
L ${(next.x + highlighted.x) / 2} ${(next.y + highlighted.y) / 2}
45+
L ${next.x * (1 - ratioNext) + highlighted.x * ratioNext} ${next.y * (1 - ratioNext) + highlighted.y * ratioNext}
4346
Z
4447
`}
4548
pointerEvents="none"

packages/x-charts/src/RadarChart/RadarAxisHighlight/useRadarAxisHighlight.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ interface UseRadarAxisHighlightReturnValue {
5959
interface Point {
6060
x: number;
6161
y: number;
62+
r: number;
63+
angle: number;
6264
value: number;
6365
}
6466

@@ -110,12 +112,15 @@ export function useRadarAxisHighlight(
110112
points: radarSeries.map((series) => {
111113
const value = series.data[highlightedIndex];
112114

113-
const [x, y] = instance.polar2svg(radiusScale(value)!, angle);
115+
const r = radiusScale(value)!;
116+
const [x, y] = instance.polar2svg(r, angle);
114117

115118
const retrunedValue: Points = {
116119
highlighted: {
117120
x,
118121
y,
122+
r,
123+
angle,
119124
value,
120125
},
121126
};
@@ -139,6 +144,8 @@ export function useRadarAxisHighlight(
139144
retrunedValue.previous = {
140145
x: px,
141146
y: py,
147+
r: prevR,
148+
angle: prevAngle,
142149
value: prevValue,
143150
};
144151
}
@@ -151,6 +158,8 @@ export function useRadarAxisHighlight(
151158
retrunedValue.next = {
152159
x: nx,
153160
y: ny,
161+
r: nextR,
162+
angle: nextAngle,
154163
value: nextValue,
155164
};
156165
}

0 commit comments

Comments
 (0)