Skip to content

Commit ae48029

Browse files
authored
Merge pull request #72 from timoncool/codex/refactor-audiowaveform-for-responsive-svg
Adjust AudioWaveform SVG to scale with parent width
2 parents fb8aaa6 + 392b3a0 commit ae48029

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

src/components/video/track.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,31 +126,34 @@ function AudioWaveform({ data }: AudioWaveformProps) {
126126
staleTime: Number.POSITIVE_INFINITY,
127127
});
128128

129-
const svgWidth = waveform.length * 3;
130129
const svgHeight = 100;
131130

131+
if (waveform.length === 0) {
132+
return null;
133+
}
134+
132135
return (
133136
<div className="h-full flex items-center overflow-hidden">
134-
<div className="min-w-max">
137+
<div className="w-full">
135138
<svg
136-
width={`${svgWidth}px`}
139+
width="100%"
137140
height="80%"
138-
viewBox={`0 0 ${svgWidth} ${svgHeight}`}
139-
preserveAspectRatio="xMinYMid meet"
141+
viewBox={`0 0 ${waveform.length} ${svgHeight}`}
142+
preserveAspectRatio="none"
140143
>
141144
<title>Audio Waveform</title>
142145
{waveform.map((v, index) => {
143146
const amplitude = Math.abs(v);
144147
const height = Math.max(amplitude * svgHeight, 2);
145-
const x = index * 3;
148+
const x = index;
146149
const y = (svgHeight - height) / 2;
147150

148151
return (
149152
<rect
150153
key={`waveform-${index}-${x}`}
151154
x={x}
152155
y={y}
153-
width="2"
156+
width="1"
154157
height={height}
155158
className="fill-black/40"
156159
rx="4"

0 commit comments

Comments
 (0)