Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/nine-carrots-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'layerchart': patch
---

fix(Bar): Clamp radius to width/height to not cause artifacts with small values (including `0`) when rounding a single edge. Fixes #383
16 changes: 10 additions & 6 deletions packages/layerchart/src/lib/components/Bar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,20 @@
const bottomRight = $derived(['all', 'bottom', 'right', 'bottom-right'].includes(rounded));
const width = $derived(dimensions.width);
const height = $derived(dimensions.height);
const diameter = $derived(2 * radius);

// Clamp radius to prevent extending beyond bounding box
const r = $derived(Math.min(radius, width / 2, height / 2));
const diameter = $derived(2 * r);

const pathData = $derived(
`M${dimensions.x + radius},${dimensions.y} h${width - diameter}
${topRight ? `a${radius},${radius} 0 0 1 ${radius},${radius}` : `h${radius}v${radius}`}
`M${dimensions.x + r},${dimensions.y} h${width - diameter}
${topRight ? `a${r},${r} 0 0 1 ${r},${r}` : `h${r}v${r}`}
v${height - diameter}
${bottomRight ? `a${radius},${radius} 0 0 1 ${-radius},${radius}` : `v${radius}h${-radius}`}
${bottomRight ? `a${r},${r} 0 0 1 ${-r},${r}` : `v${r}h${-r}`}
h${diameter - width}
${bottomLeft ? `a${radius},${radius} 0 0 1 ${-radius},${-radius}` : `h${-radius}v${-radius}`}
${bottomLeft ? `a${r},${r} 0 0 1 ${-r},${-r}` : `h${-r}v${-r}`}
v${diameter - height}
${topLeft ? `a${radius},${radius} 0 0 1 ${radius},${-radius}` : `v${-radius}h${radius}`}
${topLeft ? `a${r},${r} 0 0 1 ${r},${-r}` : `v${-r}h${r}`}
z`
.split('\n')
.join('')
Expand Down