Skip to content

Commit 1d888f8

Browse files
committed
fix(Axis): Default tickSpacing to null for band scales, showing all ticks by default instead of thinning them. Use tickSpacing={80} to opt-in to tick thinning on band scale axes.
1 parent 0fb5400 commit 1d888f8

3 files changed

Lines changed: 21 additions & 5 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'layerchart': minor
3+
---
4+
5+
fix(Axis): Default `tickSpacing` to `null` for band scales, showing all ticks by default instead of thinning them. Use `tickSpacing={80}` to opt-in to tick thinning on band scale axes.

docs/src/examples/components/BarChart/pan-zoom-band.svelte

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@
1212
y="value"
1313
clip
1414
transform={{ mode: 'domain', axis: 'x', scaleExtent: [1, 10] }}
15+
props={{
16+
xAxis: { tickSpacing: 25 }
17+
}}
1518
height={300}
1619
/>

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,7 @@
150150
rule = false,
151151
grid = false,
152152
ticks,
153-
tickSpacing = ['top', 'bottom', 'angle'].includes(placement)
154-
? 80
155-
: ['left', 'right', 'radius'].includes(placement)
156-
? 50
157-
: undefined,
153+
tickSpacing: tickSpacingProp,
158154
tickMultiline = false,
159155
tickLength = 4,
160156
tickMarks = true,
@@ -185,6 +181,18 @@
185181
const scale = $derived(
186182
scaleProp ?? (['horizontal', 'angle'].includes(orientation) ? ctx.xScale : ctx.yScale)
187183
);
184+
185+
const tickSpacing = $derived(
186+
tickSpacingProp !== undefined
187+
? tickSpacingProp
188+
: isScaleBand(scale)
189+
? null
190+
: ['top', 'bottom', 'angle'].includes(placement)
191+
? 80
192+
: ['left', 'right', 'radius'].includes(placement)
193+
? 50
194+
: undefined
195+
);
188196
const interval = $derived(
189197
['horizontal', 'angle'].includes(orientation) ? ctx.xInterval : ctx.yInterval
190198
);

0 commit comments

Comments
 (0)