@@ -48,17 +48,7 @@ export class CoreFileUploaderAudioHistogramComponent implements AfterViewInit, O
4848 this . context = this . canvas ?. getContext ( '2d' ) ;
4949 this . buffer = new Uint8Array ( this . analyser . fftSize ) ;
5050
51- if ( this . context && this . canvas ) {
52- const styles = getComputedStyle ( this . element ) ;
53-
54- this . canvas . width = this . canvas . clientWidth ;
55- this . canvas . height = this . canvas . clientHeight ;
56- this . context . fillStyle = styles . getPropertyValue ( '--background-color' ) ;
57- this . context . lineCap = 'round' ;
58- this . context . lineWidth = CoreFileUploaderAudioHistogramComponent . BARS_WIDTH ;
59- this . context . strokeStyle = styles . getPropertyValue ( '--bars-color' ) ;
60- }
61-
51+ this . updateCanvas ( this . element . clientWidth , this . element . clientHeight ) ;
6252 this . draw ( ) ;
6353 }
6454
@@ -77,6 +67,10 @@ export class CoreFileUploaderAudioHistogramComponent implements AfterViewInit, O
7767 return ;
7868 }
7969
70+ if ( this . canvas . width !== this . element . clientWidth || this . canvas . height !== this . element . clientHeight ) {
71+ this . updateCanvas ( this . element . clientWidth , this . element . clientHeight ) ;
72+ }
73+
8074 const width = this . canvas . width ;
8175 const height = this . canvas . height ;
8276 const barsWidth = CoreFileUploaderAudioHistogramComponent . BARS_WIDTH ;
@@ -157,4 +151,25 @@ export class CoreFileUploaderAudioHistogramComponent implements AfterViewInit, O
157151 }
158152 }
159153
154+ /**
155+ * Set canvas element dimensions and configure styles.
156+ *
157+ * @param width Canvas width.
158+ * @param height Canvas height.
159+ */
160+ private updateCanvas ( width : number , height : number ) : void {
161+ if ( ! this . canvas || ! this . context ) {
162+ return ;
163+ }
164+
165+ const styles = getComputedStyle ( this . element ) ;
166+
167+ this . canvas . width = width ;
168+ this . canvas . height = height ;
169+ this . context . fillStyle = styles . getPropertyValue ( '--background-color' ) ;
170+ this . context . lineCap = 'round' ;
171+ this . context . lineWidth = CoreFileUploaderAudioHistogramComponent . BARS_WIDTH ;
172+ this . context . strokeStyle = styles . getPropertyValue ( '--bars-color' ) ;
173+ }
174+
160175}
0 commit comments