Skip to content

Commit 7cd7b83

Browse files
Merge pull request #1065 from Codeinwp/fix/charts-refresh
Fix multiple charts facade and small google fix
2 parents 8722e1b + 8a0dfcb commit 7cd7b83

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

js/render-facade.js

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/* global jQuery */
44
var vizClipboard1=null;
55
(function($, visualizer){
6-
6+
77
function initActionsButtons(v) {
88
if($('a.visualizer-chart-shortcode').length > 0 && vizClipboard1 === null) {
99
vizClipboard1 = new ClipboardJS('a.visualizer-chart-shortcode'); // jshint ignore:line
@@ -107,20 +107,10 @@ var vizClipboard1=null;
107107
registerDefaultActions();
108108
});
109109

110-
// Refresh charts if chart not generated.
111-
function refreshEachCharts() {
112-
if ( 'object' === typeof window.fusionAnimationsVars ) {
113-
return;
114-
}
115-
setTimeout( function() {
116-
displayChartsOnFrontEnd();
117-
}, 100 );
118-
}
119-
120110
function initChartDisplay() {
121111
if(visualizer.is_front == true){ // jshint ignore:line
122112
displayChartsOnFrontEnd();
123-
}else{
113+
} else {
124114
showChart();
125115
}
126116
}
@@ -138,14 +128,15 @@ var vizClipboard1=null;
138128
}
139129

140130
function displayChartsOnFrontEnd() {
141-
// display all charts that are NOT to be lazy-loaded.
142-
$( 'div.viz-facade-loaded:not(.visualizer-lazy):not(.visualizer-cw-error):empty' ).removeClass( 'viz-facade-loaded' );
143-
$('div.visualizer-front:not(.visualizer-lazy):not(.viz-facade-loaded)').each(function(index, element){
131+
132+
$('div.visualizer-front:not(.viz-facade-loaded):not(.visualizer-lazy):not(.visualizer-cw-error):empty').each(function(index, element){
144133
if ( $(element).is(':visible') ) {
145134
var id = $(element).addClass('viz-facade-loaded').attr('id');
146-
showChart(id);
135+
setTimeout(function(){
136+
// Add a short delay between each chart to avoid overloading the browser event loop.
137+
showChart(id);
138+
}, ( index + 1 ) * 100);
147139
}
148-
refreshEachCharts();
149140
});
150141

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

js/render-google.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,18 @@ var isResizeRequest = false;
1414
var rendered_charts = [];
1515

1616
function renderChart(id) {
17+
18+
if ( ! all_charts || 0 === Object.keys( all_charts ).length ) {
19+
return;
20+
}
21+
1722
var chart = all_charts[id];
1823
var hasAnnotation = false;
1924

25+
if ( ! chart ) {
26+
return;
27+
}
28+
2029
// re-render the chart only if it doesn't have annotations and it is on the front-end
2130
// this is to prevent the chart from showing "All series on a given axis must be of the same data type" during resize.
2231
// remember, some charts do not support annotations so they should not be included in this.

0 commit comments

Comments
 (0)