@@ -68,26 +68,26 @@ const Graph: React.FC<GraphProps> = ({
6868 } ,
6969 [ FREQ_RESOLUTION ]
7070 ) ;
71-
71+
7272 useEffect ( ( ) => {
7373 if ( fftData . length > 0 && fftData [ 0 ] . length > 0 ) {
7474 const channelData = fftData [ 0 ] ;
75-
75+
7676 const deltaPower = calculateBandPower ( channelData , DELTA_RANGE ) ;
7777 const thetaPower = calculateBandPower ( channelData , THETA_RANGE ) ;
7878 const alphaPower = calculateBandPower ( channelData , ALPHA_RANGE ) ;
7979 const betaPower = calculateBandPower ( channelData , BETA_RANGE ) ;
8080 const gammaPower = calculateBandPower ( channelData , GAMMA_RANGE ) ;
8181 const total = deltaPower + thetaPower + alphaPower + betaPower + gammaPower ;
82-
82+
8383 const newBandPowerData = [
8484 ( deltaPower / total ) * 100 ,
8585 ( thetaPower / total ) * 100 ,
8686 ( alphaPower / total ) * 100 ,
8787 ( betaPower / total ) * 100 ,
8888 ( gammaPower / total ) * 100 ,
8989 ] ;
90-
90+
9191 if (
9292 newBandPowerData . some ( ( value ) => ! isNaN ( value ) && value > - Infinity )
9393 ) {
@@ -97,14 +97,14 @@ const Graph: React.FC<GraphProps> = ({
9797 }
9898 return prev ;
9999 } ) ;
100-
100+
101101 if ( onBetaUpdate ) {
102102 onBetaUpdate ( newBandPowerData [ 3 ] ) ;
103103 }
104- }
104+ }
105105 }
106106 } , [ fftData , calculateBandPower , onBetaUpdate && onBetaUpdate . toString ( ) ] ) ; // Memoized dependencies
107-
107+
108108
109109 const drawGraph = useCallback (
110110 ( currentBandPowerData : number [ ] ) => {
@@ -132,7 +132,8 @@ const Graph: React.FC<GraphProps> = ({
132132 ctx . clearRect ( 0 , 0 , width , height ) ;
133133
134134 // Responsive bar sizing and margins
135- const leftMargin = width < 640 ? 40 : 70 ; // Smaller margin on mobile
135+ const leftMargin = width < 500 ? 50 : 70 ;
136+
136137 const rightMargin = 20 ;
137138 const bottomMargin = width < 640 ? 40 : 50 ; // Smaller margin on mobile
138139 const barWidth = ( width - leftMargin - rightMargin ) / bandNames . length ;
@@ -156,15 +157,23 @@ const Graph: React.FC<GraphProps> = ({
156157 ctx . stroke ( ) ;
157158
158159 // Draw bars
160+ // Draw bars and beta percentage
159161 currentBandPowerData . forEach ( ( power , index ) => {
160162 const x = leftMargin + index * barWidth ;
161- const normalizedHeight = Math . max ( 0 , ( power - minPower ) / ( maxPower - minPower ) ) ;
162- const barHeight = Math . max ( 0 , normalizedHeight * ( height - bottomMargin - 10 ) ) ;
163-
163+ const normalizedHeight = Math . max ( 0 , ( power - minPower ) / ( maxPower - minPower ) ) ;
164+ const barHeight = Math . max ( 0 , normalizedHeight * ( height - bottomMargin - 10 ) ) ;
165+
166+ const barX = x + barSpacing / 2 ;
167+ const barY = height - bottomMargin - barHeight ;
168+ const actualBarWidth = barWidth - barSpacing * 1.5 ; // Make it thinner than before
169+
164170 ctx . fillStyle = bandColors [ index ] ;
165- ctx . fillRect ( x + barSpacing / 2 , height - bottomMargin - barHeight , barWidth - barSpacing , barHeight ) ;
171+ ctx . fillRect ( barX , barY , actualBarWidth , barHeight ) ;
172+
173+
166174 } ) ;
167175
176+
168177 // Draw labels
169178 ctx . fillStyle = axisColor ;
170179 const fontSize = width < 640 ? 10 : 12 ; // Smaller text on mobile
@@ -188,16 +197,19 @@ const Graph: React.FC<GraphProps> = ({
188197 ctx . fillText ( band , labelX , height - bottomMargin + 5 ) ;
189198 } ) ;
190199
191- // Title
192- ctx . font = `${ Math . min ( fontSize + 2 , 14 ) } px Arial` ;
193- ctx . fillText ( "EEG Band Power" , width / 2 , height - 20 ) ;
200+ // EEG Band Power – same as "Frequency (Hz)"
201+ ctx . font = "16px Arial" ;
202+ ctx . textAlign = "center" ;
203+ ctx . fillText ( "EEG Band Power" , ( width + leftMargin ) / 2 , height - 17 ) ;
194204
195- // Rotate and position the y-axis label
205+ // Power – same as "Magnitude"
196206 ctx . save ( ) ;
197207 ctx . rotate ( - Math . PI / 2 ) ;
208+ ctx . font = "20px Arial" ;
198209 ctx . textAlign = "center" ;
199- ctx . fillText ( "Power" , - height / 2 + 15 , fontSize ) ;
210+ ctx . fillText ( "Power" , - height / 2 , 15 ) ;
200211 ctx . restore ( ) ;
212+
201213 } ,
202214 [ theme , bandColors , bandNames ]
203215 ) ;
@@ -243,12 +255,12 @@ const Graph: React.FC<GraphProps> = ({
243255 return (
244256 < div
245257 ref = { containerRef }
246- className = { `w-full h-full min-h-0 min-w-0` }
258+ className = { `w-full h-full min-h-0 min-w-0 px-4 ` }
247259 >
248- < canvas
249- ref = { canvasRef }
250- className = "w-full h-full dark:bg-highlight rounded-md"
251- />
260+ < canvas
261+ ref = { canvasRef }
262+ className = "w-full h-full dark:bg-highlight rounded-md"
263+ />
252264 </ div >
253265 ) ;
254266} ;
0 commit comments