Skip to content

Commit 8c36c4d

Browse files
authored
fix(Bar): Clamp radius to width/height to not cause artifacts with small values (including 0) when rounding a single edge. Fixes #383 (#610)
1 parent e5ccdae commit 8c36c4d

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

.changeset/nine-carrots-grin.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(Bar): Clamp radius to width/height to not cause artifacts with small values (including `0`) when rounding a single edge. Fixes #383

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,20 @@
151151
const bottomRight = $derived(['all', 'bottom', 'right', 'bottom-right'].includes(rounded));
152152
const width = $derived(dimensions.width);
153153
const height = $derived(dimensions.height);
154-
const diameter = $derived(2 * radius);
154+
155+
// Clamp radius to prevent extending beyond bounding box
156+
const r = $derived(Math.min(radius, width / 2, height / 2));
157+
const diameter = $derived(2 * r);
158+
155159
const pathData = $derived(
156-
`M${dimensions.x + radius},${dimensions.y} h${width - diameter}
157-
${topRight ? `a${radius},${radius} 0 0 1 ${radius},${radius}` : `h${radius}v${radius}`}
160+
`M${dimensions.x + r},${dimensions.y} h${width - diameter}
161+
${topRight ? `a${r},${r} 0 0 1 ${r},${r}` : `h${r}v${r}`}
158162
v${height - diameter}
159-
${bottomRight ? `a${radius},${radius} 0 0 1 ${-radius},${radius}` : `v${radius}h${-radius}`}
163+
${bottomRight ? `a${r},${r} 0 0 1 ${-r},${r}` : `v${r}h${-r}`}
160164
h${diameter - width}
161-
${bottomLeft ? `a${radius},${radius} 0 0 1 ${-radius},${-radius}` : `h${-radius}v${-radius}`}
165+
${bottomLeft ? `a${r},${r} 0 0 1 ${-r},${-r}` : `h${-r}v${-r}`}
162166
v${diameter - height}
163-
${topLeft ? `a${radius},${radius} 0 0 1 ${radius},${-radius}` : `v${-radius}h${radius}`}
167+
${topLeft ? `a${r},${r} 0 0 1 ${r},${-r}` : `v${-r}h${r}`}
164168
z`
165169
.split('\n')
166170
.join('')

0 commit comments

Comments
 (0)