@@ -129,19 +129,21 @@ window['vizClipboard2'] = window['vizClipboard2'] || null;
129129 }
130130
131131 function displayChartsOnFrontEnd ( ) {
132- function renderVisibleLazyCharts ( ) {
132+ function renderVisibleLazyCharts ( checkViewport ) {
133133 $ ( 'div.visualizer-front:not(.viz-facade-loaded):not(.visualizer-lazy):not(.visualizer-cw-error):empty' ) . each ( function ( index , element ) {
134134 // Do not render charts that are intentionally hidden.
135135 const style = window . getComputedStyle ( element ) ;
136136 if ( style . display === 'none' || style . visibility === 'hidden' ) {
137137 return ;
138138 }
139139
140- // Only render charts that are currently within the viewport.
141- const rect = element . getBoundingClientRect ( ) ;
142- const inViewport = rect . bottom >= 0 && rect . top <= ( window . innerHeight || document . documentElement . clientHeight ) ;
143- if ( ! inViewport ) {
144- return ;
140+ // On scroll, only render charts that are currently within the viewport.
141+ if ( checkViewport ) {
142+ const rect = element . getBoundingClientRect ( ) ;
143+ const inViewport = rect . bottom >= 0 && rect . top <= ( window . innerHeight || document . documentElement . clientHeight ) ;
144+ if ( ! inViewport ) {
145+ return ;
146+ }
145147 }
146148
147149 const id = $ ( element ) . addClass ( 'viz-facade-loaded' ) . attr ( 'id' ) ;
@@ -152,10 +154,12 @@ window['vizClipboard2'] = window['vizClipboard2'] || null;
152154 } ) ;
153155 }
154156
155- $ ( window ) . on ( 'scroll' , renderVisibleLazyCharts ) ;
157+ $ ( window ) . on ( 'scroll' , function ( ) { renderVisibleLazyCharts ( true ) ; } ) ;
156158
157- // Run once on page load to render any lazy charts already in the viewport.
158- renderVisibleLazyCharts ( ) ;
159+ // Run once on page load to render all non-lazy charts regardless of viewport position.
160+ // Skipping the viewport check here avoids missing charts when the browser window is
161+ // not in focus (e.g. mouse outside the window) and layout may not be fully computed.
162+ renderVisibleLazyCharts ( false ) ;
159163
160164 $ ( 'div.visualizer-front-container:not(.visualizer-lazy-render)' ) . each ( function ( index , element ) {
161165 // Do not render charts that are intentionally hidden.
0 commit comments