Skip to content

Commit 8452e3e

Browse files
author
cristian-ungureanu
authored
Merge pull request #884 from Codeinwp/bugfix/883
Fix multiple charts loading issue
2 parents b8fc5e5 + 1e71599 commit 8452e3e

File tree

3 files changed

+33
-12
lines changed

3 files changed

+33
-12
lines changed

classes/Visualizer/Module/Frontend.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,11 +677,22 @@ function visualizerLoadScripts() {
677677
elem.setAttribute("src", elem.getAttribute("data-visualizer-script"));
678678
elem.removeAttribute("data-visualizer-script");
679679
setTimeout( function() {
680-
jQuery( '.visualizer-front:not(.visualizer-chart-loaded)' ).resize();
680+
visualizerRefreshChart();
681681
} );
682682
} );
683683
});
684684
}
685+
686+
function visualizerRefreshChart() {
687+
jQuery( '.visualizer-front:not(.visualizer-chart-loaded)' ).resize();
688+
if ( jQuery( 'div.viz-facade-loaded:not(.visualizer-lazy):empty' ).length > 0 ) {
689+
visualizerUserInteractionEvents.forEach( function( event ) {
690+
window.addEventListener( event, function() {
691+
jQuery( '.visualizer-front:not(.visualizer-chart-loaded)' ).resize();
692+
}, { passive: true } );
693+
} );
694+
}
695+
}
685696
</script>
686697
<?php
687698
}

js/render-facade.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@
106106
registerDefaultActions();
107107
});
108108

109+
// Refresh charts if chart not generated.
110+
function refreshEachCharts() {
111+
setTimeout( function() {
112+
displayChartsOnFrontEnd();
113+
}, 100 );
114+
}
115+
109116
function initChartDisplay() {
110117
if(visualizer.is_front == true){ // jshint ignore:line
111118
displayChartsOnFrontEnd();
@@ -132,6 +139,7 @@
132139
$('div.visualizer-front:not(.visualizer-lazy):not(.viz-facade-loaded)').each(function(index, element){
133140
var id = $(element).addClass('viz-facade-loaded').attr('id');
134141
showChart(id);
142+
refreshEachCharts();
135143
});
136144

137145
// interate through all charts that are to be lazy-loaded and observe each one.

js/render-google.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -508,19 +508,21 @@ var __visualizer_chart_images = [];
508508
}
509509

510510
objects = {};
511-
google.load( 'visualization', 'current', {packages: $chart_types, mapsApiKey: v.map_api_key, 'language' : v.language,
512-
callback: function () {
513-
gv = google.visualization;
514-
all_charts = v.charts;
515-
if(v.is_front == true && typeof v.id !== 'undefined'){ // jshint ignore:line
516-
if ( document.getElementById( v.id ).offsetParent !== null ) {
517-
renderChart(v.id);
511+
if ( 'object' === typeof google ) {
512+
google.load( 'visualization', 'current', {packages: $chart_types, mapsApiKey: v.map_api_key, 'language' : v.language,
513+
callback: function () {
514+
gv = google.visualization;
515+
all_charts = v.charts;
516+
if(v.is_front == true && typeof v.id !== 'undefined'){ // jshint ignore:line
517+
if ( document.getElementById( v.id ).offsetParent !== null ) {
518+
renderChart(v.id);
519+
}
520+
} else {
521+
render();
518522
}
519-
} else {
520-
render();
521523
}
522-
}
523-
});
524+
});
525+
}
524526
});
525527

526528
$('body').on('visualizer:render:specificchart:start', function(event, v){

0 commit comments

Comments
 (0)