@@ -668,15 +668,39 @@ <h2 class="text-base font-medium mb-2 text-slate-900 dark:text-white">Treasury A
668668 window . testAPIs = testAPIs ;
669669
670670 function createChart ( canvasId , data , label , color ) {
671- // Restore canvas element if it was replaced by loading/error state
672- const container = document . getElementById ( canvasId ) ?. parentElement ;
673- if ( container && ! document . getElementById ( canvasId ) ) {
674- container . innerHTML = `<canvas id="${ canvasId } "></canvas>` ;
671+ // Store reference to container for this canvas
672+ const chartContainers = {
673+ 'bitcoinChart' : 'Bitcoin Price (USD)' ,
674+ 'm2BitcoinChart' : 'M2 vs Bitcoin YoY' ,
675+ 'dxyBitcoinChart' : 'DXY vs Bitcoin 3M' ,
676+ 'pmiChart' : 'Industrial Production' ,
677+ 'nfciChart' : 'Financial Conditions' ,
678+ 'm2Chart' : 'M2 Money Supply' ,
679+ 'tgaChart' : 'Treasury Account'
680+ } ;
681+
682+ // Find the canvas or restore it if it was replaced by loading/error state
683+ let canvas = document . getElementById ( canvasId ) ;
684+
685+ if ( ! canvas ) {
686+ // Find the section with the matching title and restore the canvas
687+ const sections = document . querySelectorAll ( 'section' ) ;
688+ for ( const section of sections ) {
689+ const title = section . querySelector ( 'h2' ) ;
690+ if ( title && title . textContent . includes ( chartContainers [ canvasId ] ) ) {
691+ const container = section . querySelector ( '.h-48.mb-2' ) ;
692+ if ( container ) {
693+ container . innerHTML = `<canvas id="${ canvasId } "></canvas>` ;
694+ canvas = document . getElementById ( canvasId ) ;
695+ console . log ( `✅ Restored canvas: ${ canvasId } ` ) ;
696+ break ;
697+ }
698+ }
699+ }
675700 }
676701
677- const canvas = document . getElementById ( canvasId ) ;
678702 if ( ! canvas ) {
679- console . error ( `Canvas ${ canvasId } not found` ) ;
703+ console . error ( `❌ Canvas ${ canvasId } not found and could not be restored ` ) ;
680704 return ;
681705 }
682706
@@ -819,15 +843,39 @@ <h2 class="text-base font-medium mb-2 text-slate-900 dark:text-white">Treasury A
819843 }
820844
821845 function createDualAxisChart ( canvasId , data1 , data2 , label1 , label2 , color1 , color2 ) {
822- // Restore canvas element if it was replaced by loading/error state
823- const container = document . getElementById ( canvasId ) ?. parentElement ;
824- if ( container && ! document . getElementById ( canvasId ) ) {
825- container . innerHTML = `<canvas id="${ canvasId } "></canvas>` ;
846+ // Store reference to container for this canvas
847+ const chartContainers = {
848+ 'bitcoinChart' : 'Bitcoin Price (USD)' ,
849+ 'm2BitcoinChart' : 'M2 vs Bitcoin YoY' ,
850+ 'dxyBitcoinChart' : 'DXY vs Bitcoin 3M' ,
851+ 'pmiChart' : 'Industrial Production' ,
852+ 'nfciChart' : 'Financial Conditions' ,
853+ 'm2Chart' : 'M2 Money Supply' ,
854+ 'tgaChart' : 'Treasury Account'
855+ } ;
856+
857+ // Find the canvas or restore it if it was replaced by loading/error state
858+ let canvas = document . getElementById ( canvasId ) ;
859+
860+ if ( ! canvas ) {
861+ // Find the section with the matching title and restore the canvas
862+ const sections = document . querySelectorAll ( 'section' ) ;
863+ for ( const section of sections ) {
864+ const title = section . querySelector ( 'h2' ) ;
865+ if ( title && title . textContent . includes ( chartContainers [ canvasId ] ) ) {
866+ const container = section . querySelector ( '.h-48.mb-2' ) ;
867+ if ( container ) {
868+ container . innerHTML = `<canvas id="${ canvasId } "></canvas>` ;
869+ canvas = document . getElementById ( canvasId ) ;
870+ console . log ( `✅ Restored dual-axis canvas: ${ canvasId } ` ) ;
871+ break ;
872+ }
873+ }
874+ }
826875 }
827876
828- const canvas = document . getElementById ( canvasId ) ;
829877 if ( ! canvas ) {
830- console . error ( `Canvas ${ canvasId } not found` ) ;
878+ console . error ( `❌ Canvas ${ canvasId } not found and could not be restored ` ) ;
831879 return ;
832880 }
833881
0 commit comments