@@ -186,26 +186,34 @@ const SlidingWaveform: React.FC<SlidingWaveformProps> = (props) => {
186186 // Clear canvas
187187 ctx . clearRect ( 0 , 0 , canvas . width , canvas . height ) ;
188188
189- // Draw waveform bars
189+ // Draw waveform bars - calculate to fill full width
190190 const samples = samplesRef . current ;
191- const barWidth = Math . max ( 1 , Math . floor ( canvas . width / samples . length ) ) ;
192- const gap = Math . max ( 1 , Math . floor ( barWidth * 0.3 ) ) ;
193- const effectiveBarWidth = barWidth - gap ;
191+ const numBars = samples . length ;
192+
193+ // Calculate bar and gap sizes to fill exactly the canvas width
194+ // We want: numBars * barWidth + (numBars - 1) * gap = canvasWidth
195+ // With gap = barWidth * 0.4, we get:
196+ // numBars * barWidth + (numBars - 1) * 0.4 * barWidth = canvasWidth
197+ // barWidth * (numBars + 0.4 * numBars - 0.4) = canvasWidth
198+ // barWidth = canvasWidth / (1.4 * numBars - 0.4)
199+ const totalWidth = canvas . width ;
200+ const barWidth = totalWidth / ( 1.4 * numBars - 0.4 ) ;
201+ const gap = barWidth * 0.4 ;
194202 const centerY = canvas . height / 2 ;
195203
196204 ctx . fillStyle = props . color ;
197205
198- for ( let i = 0 ; i < samples . length ; i ++ ) {
206+ for ( let i = 0 ; i < numBars ; i ++ ) {
199207 const amplitude = samples [ i ] ;
200208 // Scale amplitude for visibility (boost quiet sounds)
201209 const scaledAmplitude = Math . min ( 1 , amplitude * 3 ) ;
202210 const barHeight = Math . max ( 2 , scaledAmplitude * canvas . height * 0.9 ) ;
203211
204- const x = i * barWidth ;
212+ const x = i * ( barWidth + gap ) ;
205213 const y = centerY - barHeight / 2 ;
206214
207215 ctx . beginPath ( ) ;
208- ctx . roundRect ( x , y , effectiveBarWidth , barHeight , 1 ) ;
216+ ctx . roundRect ( x , y , barWidth , barHeight , 1 ) ;
209217 ctx . fill ( ) ;
210218 }
211219
@@ -223,12 +231,12 @@ const SlidingWaveform: React.FC<SlidingWaveformProps> = (props) => {
223231 } , [ draw ] ) ;
224232
225233 return (
226- < div ref = { containerRef } className = "h-full w-full" >
234+ < div ref = { containerRef } className = "flex h-full w-full items-center justify-center " >
227235 < canvas
228236 ref = { canvasRef }
229237 width = { containerWidth }
230238 height = { props . height }
231- className = "h-full w-full"
239+ style = { { width : containerWidth , height : props . height } }
232240 />
233241 </ div >
234242 ) ;
0 commit comments