Skip to content

Commit c8faeb7

Browse files
committed
fix: Pie and Arc components now correctly use Chart's xRange prop for angle degrees instead of the computed viewport pixel range, and compute radius from chart dimensions instead of scale range
1 parent e6af86a commit c8faeb7

3 files changed

Lines changed: 21 additions & 9 deletions

File tree

.changeset/fix-pie-arc-xrange.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'layerchart': patch
3+
---
4+
5+
fix: Pie and Arc components now correctly use Chart's `xRange` prop for angle degrees instead of the computed viewport pixel range, and compute radius from chart dimensions instead of scale range

packages/layerchart/src/lib/components/Arc.svelte

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,10 @@
254254
const ctx = getChartContext();
255255
256256
const endAngle = $derived(
257-
endAngleProp ?? degreesToRadians(ctx.xRange ? max(ctx.xRange) : max(range))
257+
endAngleProp ??
258+
degreesToRadians(
259+
(ctx.config.xRange ? max(ctx.config.xRange as number[]) : max(range))!
260+
)
258261
);
259262
260263
const motionEndAngle = createMotion(initialValue, () => value, motion);
@@ -279,13 +282,11 @@
279282
}
280283
}
281284
282-
const outerRadius = $derived(
283-
getOuterRadius(outerRadiusProp, (Math.min(ctx.xRange[1], ctx.yRange[0]) ?? 0) / 2)
284-
);
285+
const chartRadius = $derived((Math.min(ctx.width, ctx.height) ?? 0) / 2);
286+
287+
const outerRadius = $derived(getOuterRadius(outerRadiusProp, chartRadius));
285288
const trackOuterRadius = $derived(
286-
trackOuterRadiusProp
287-
? getOuterRadius(trackOuterRadiusProp, (Math.min(ctx.xRange[1], ctx.yRange[0]) ?? 0) / 2)
288-
: outerRadius
289+
trackOuterRadiusProp ? getOuterRadius(trackOuterRadiusProp, chartRadius) : outerRadius
289290
);
290291
291292
function getInnerRadius(innerRadius: number | undefined, outerRadius: number) {

packages/layerchart/src/lib/components/Pie.svelte

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,21 @@
108108
const ctx = getChartContext();
109109
110110
const endAngle = $derived(
111-
endAngleProp ?? degreesToRadians(ctx.config.xRange ? max(ctx.xRange) : max(range))
111+
endAngleProp ??
112+
degreesToRadians(
113+
(ctx.config.xRange ? max(ctx.config.xRange as number[]) : max(range))!
114+
)
112115
);
113116
114117
const motionEndAngle = createMotion(0, () => endAngle, motion);
115118
116119
const pie = $derived.by(() => {
117120
let _pie = d3pie<any>()
118121
.startAngle(
119-
startAngleProp ?? degreesToRadians(ctx.config.xRange ? min(ctx.xRange) : min(range))
122+
startAngleProp ??
123+
degreesToRadians(
124+
(ctx.config.xRange ? min(ctx.config.xRange as number[]) : min(range))!
125+
)
120126
)
121127
.endAngle(motionEndAngle.current)
122128
.padAngle(padAngle)

0 commit comments

Comments
 (0)