@@ -130,6 +130,11 @@ class SequencerVisualEngine {
130130 ) ;
131131
132132 console . log ( `🎨 Canvas sized: ${ size } x${ size } px` ) ;
133+
134+ // Trigger re-render now that canvas is properly sized
135+ if ( size > 0 ) {
136+ setTimeout ( ( ) => this . render ( ) , 50 ) ;
137+ }
133138 }
134139
135140 /**
@@ -183,15 +188,28 @@ class SequencerVisualEngine {
183188 if ( typeof CenterOfGravityCalculator !== 'undefined' ) {
184189 try {
185190 const cogResult = CenterOfGravityCalculator . calculateCenterOfGravity ( this . pattern . steps ) ;
186- this . cogData = {
187- distance : cogResult . distance ,
188- angle : cogResult . angle ,
189- x : cogResult . x ,
190- y : cogResult . y ,
191- isCalculated : true
192- } ;
191+ // CoG calculation successful
193192
194- console . log ( `🎨 CoG calculated: distance=${ cogResult . distance . toFixed ( 3 ) } , angle=${ cogResult . angle . toFixed ( 2 ) } °` ) ;
193+ if ( cogResult && typeof cogResult . magnitude === 'number' ) {
194+ // Convert the result format to what we expect
195+ const distance = cogResult . normalizedMagnitude || cogResult . magnitude ;
196+ const x = cogResult . coordinates ?. x || cogResult . x || 0 ;
197+ const y = cogResult . coordinates ?. y || cogResult . y || 0 ;
198+ const angle = Math . atan2 ( y , x ) * ( 180 / Math . PI ) ;
199+
200+ this . cogData = {
201+ distance : distance ,
202+ angle : angle ,
203+ x : x ,
204+ y : y ,
205+ isCalculated : true
206+ } ;
207+
208+ console . log ( `🎨 CoG calculated: distance=${ distance . toFixed ( 4 ) } , angle=${ angle . toFixed ( 1 ) } °` ) ;
209+ } else {
210+ console . warn ( '⚠️ Invalid CoG result:' , cogResult ) ;
211+ this . cogData . isCalculated = false ;
212+ }
195213 } catch ( error ) {
196214 console . warn ( '⚠️ CoG calculation failed:' , error ) ;
197215 this . cogData . isCalculated = false ;
@@ -285,9 +303,20 @@ class SequencerVisualEngine {
285303 return ;
286304 }
287305
288- const startTime = performance . now ( ) ;
306+ // Skip rendering if canvas isn't properly sized yet
307+ if ( this . config . canvasSize <= 0 ) {
308+ return ;
309+ }
289310
290- console . log ( `🎨 Rendering pattern: ${ this . pattern . stepCount } steps, canvas: ${ this . config . canvasSize } x${ this . config . canvasSize } ` ) ;
311+ // If canvas element isn't sized yet, try to size it now
312+ if ( this . canvas . width <= 0 ) {
313+ this . setupResponsiveCanvas ( ) ;
314+ if ( this . canvas . width <= 0 ) {
315+ return ;
316+ }
317+ }
318+
319+ const startTime = performance . now ( ) ;
291320
292321 // Clear canvas
293322 this . ctx . clearRect ( 0 , 0 , this . config . canvasSize , this . config . canvasSize ) ;
@@ -464,7 +493,7 @@ class SequencerVisualEngine {
464493 const stepSize = this . config . stepElementActualSize ;
465494 const fontSize = stepSize * 0.4 ;
466495
467- console . log ( `🎨 Drawing ${ this . pattern . stepCount } steps:` , this . pattern . steps . slice ( 0 , 8 ) ) ;
496+ // Draw step elements around the circle
468497
469498 for ( let i = 0 ; i < this . pattern . stepCount ; i ++ ) {
470499 const angle = ( i / this . pattern . stepCount ) * Math . PI * 2 - Math . PI / 2 ;
0 commit comments