File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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"
You can’t perform that action at this time.
0 commit comments