Skip to content

Commit 28e0d95

Browse files
authored
fix(Bars): Fix inverted rect when rendered top-to-bottom or right-to-left. Fixes #540 (#613)
1 parent 0cce3ce commit 28e0d95

4 files changed

Lines changed: 14 additions & 5 deletions

File tree

.changeset/better-eagles-scream.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(Bars): Fix inverted rect when rendered top-to-bottom or right-to-left. Fixes #540

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@
136136
const rounded = $derived(
137137
roundedProp === 'edge'
138138
? isVertical
139-
? resolvedValue >= 0
139+
? resolvedValue >= 0 && ctx.yRange[0] > ctx.yRange[1] // not inverted (bottom to top)
140140
? 'top'
141141
: 'bottom'
142-
: resolvedValue >= 0
142+
: resolvedValue >= 0 && ctx.xRange[0] < ctx.xRange[1] // not inverted (left to right)
143143
? 'right'
144144
: 'left'
145145
: roundedProp

packages/layerchart/src/lib/utils/rect.svelte.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ export function createDimensionGetter<TData>(
152152
bottom = yValue;
153153
}
154154

155+
// If yRange is inverted (drawing from top), swap top and bottom
156+
if (ctx.yRange[0] < ctx.yRange[1]) {
157+
[top, bottom] = [bottom, top];
158+
}
159+
155160
const y = ctx.yScale(top) + insets.top;
156161
const height = ctx.yScale(bottom) - ctx.yScale(top) - insets.bottom - insets.top;
157162

packages/layerchart/src/routes/docs/examples/Compound/+page.svelte

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,8 @@
247247
padding={{ left: 32, right: 32, bottom: 20 }}
248248
props={{
249249
bars: {
250-
// TODO: Determine why non-rounded Rect within Bar is not working for inverted range
251-
// rounded: 'none',
252-
class: 'stroke-none fill-blue-500',
250+
rounded: 'none',
251+
class: '_stroke-none fill-blue-500',
253252
},
254253
}}
255254
{renderContext}

0 commit comments

Comments
 (0)