Skip to content

Commit 9093625

Browse files
committed
draw fret lines
1 parent 8d79e22 commit 9093625

1 file changed

Lines changed: 46 additions & 18 deletions

File tree

src/lib/FretBoard.svelte

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,58 @@
66
let { fretData } = $props();
77
88
let containerRef = $state(null);
9-
let width = $derived(containerRef.clientWidth);
10-
let height = $derived(containerRef.clientHeight);
9+
let width = $state(0);
10+
let height = $state(0);
1111
12-
let fretX;
13-
let strY;
1412
let margin = { top: 20, right: 20, bottom: 20, left: 20 };
1513
16-
// onMount(() => {
17-
// width = containerRef.clientWidth;
18-
// height = containerRef.clientHeight;
14+
let fretX = $derived(
15+
scaleBand()
16+
.domain(range(fretData.count))
17+
.range([margin.left, width - margin.right])
18+
.padding(0.1),
19+
);
1920
20-
// fretX = scaleBand()
21-
// .domain(range(fretData.count))
22-
// .range([margin.left, width - margin.right])
23-
// .padding(0.1);
21+
let strY = $derived(
22+
scalePoint()
23+
.domain(range(fretData.tuning.length))
24+
.range([margin.top, height - margin.bottom]),
25+
);
2426
25-
// strY = scalePoint()
26-
// .domain(range(fretData.tuning.length))
27-
// .range([margin.top, height - margin.bottom]);
28-
// });
27+
onMount(() => {
28+
width = containerRef.clientWidth;
29+
height = containerRef.clientHeight;
30+
});
2931
</script>
3032

31-
<div bind:this={containerRef}>
32-
{#if width && height}
33-
<svg viewBox="0 0 {width} {height}"> </svg>
33+
<div bind:this={containerRef} class="h-full w-full">
34+
{#if width}
35+
<svg viewBox="0 0 {width} {height}">
36+
{#each fretX.domain() as fret}
37+
<g transform="translate({fretX(fret)}, {margin.top})">
38+
<text class="fret-label">{fret}</text>
39+
<rect
40+
class="fret-line"
41+
x="0"
42+
y="0"
43+
width={1}
44+
height={height - margin.top - margin.bottom}></rect>
45+
</g>
46+
{/each}
47+
</svg>
3448
{/if}
3549
</div>
50+
51+
<style>
52+
@reference "tailwindcss";
53+
54+
.fret-label {
55+
@apply text-sm font-bold fill-gray-800 text-center;
56+
text-anchor: middle;
57+
dominant-baseline: ideographic;
58+
}
59+
60+
.fret-line {
61+
@apply fill-gray-200 stroke-0;
62+
}
63+
</style>

0 commit comments

Comments
 (0)