Skip to content

Commit bbbb5f8

Browse files
committed
Allow passing null to ignore tickSpacing for band scales
1 parent 9bdd4c4 commit bbbb5f8

3 files changed

Lines changed: 35 additions & 1 deletion

File tree

docs/src/content/components/Axis.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Default: `80` for horizontal axes (top/bottom/angle) and `50` for vertical axes
1919

2020
:example{ name="linechart-tickspacing" showCode }
2121

22+
:example{ name="barchart-tickspacing" showCode }
23+
2224
::tip
2325
See also: time scale [auto](/docs/components/Axis/time-scale-auto), [multiline](/docs/components/Axis/time-scale-auto-multiline), and [brush](/docs/components/Axis/time-scale-brush-multiline) examples
2426
::
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<script lang="ts">
2+
import { BarChart } from 'layerchart';
3+
import { getRandomInteger } from '$lib/utils/data.js';
4+
import { Switch } from 'svelte-ux';
5+
6+
const states = [
7+
'AL', 'AK', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'FL', 'GA',
8+
'HI', 'ID', 'IL', 'IN', 'IA', 'KS', 'KY', 'LA', 'ME', 'MD',
9+
'MA', 'MI', 'MN', 'MS', 'MO', 'MT', 'NE', 'NV', 'NH', 'NJ',
10+
'NM', 'NY', 'NC', 'ND', 'OH', 'OK', 'OR', 'PA', 'RI', 'SC',
11+
'SD', 'TN', 'TX', 'UT', 'VT', 'VA', 'WA', 'WV', 'WI', 'WY',
12+
];
13+
14+
const data = states.map((state) => ({ state, value: getRandomInteger(20, 100) }));
15+
16+
let tickSpacing = $state(true);
17+
18+
export { data };
19+
</script>
20+
21+
<label class="flex gap-2 pb-4 screenshot-hidden">
22+
<Switch bind:checked={tickSpacing} />
23+
{tickSpacing ? 'Applying tickSpacing' : 'Not applying tickSpacing'}
24+
</label>
25+
26+
<BarChart
27+
{data}
28+
x="state"
29+
y="value"
30+
props={{ xAxis: { tickSpacing: tickSpacing ? 80 : null } }}
31+
height={300}
32+
/>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
* Width or height of each tick in pixels (enabling responsive count)
4848
* @default 80 (top|bottom|angle) or 50 (left|right|radius)
4949
*/
50-
tickSpacing?: number;
50+
tickSpacing?: number | null;
5151
5252
/**
5353
* Whether to render tick labels on multiple lines for additional context

0 commit comments

Comments
 (0)