Skip to content

Commit 6f8a45f

Browse files
refactor: improve the chart rendering conditions
1 parent 1cb2e55 commit 6f8a45f

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

js/render-facade.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
/* global jQuery */
44
var vizClipboard1=null;
55
(function($, visualizer){
6-
7-
// Once the facade is loaded, we need to refresh the charts. But we need to it one time only per chart.
8-
var chartReloadedAfterFacade = [];
9-
6+
107
function initActionsButtons(v) {
118
if($('a.visualizer-chart-shortcode').length > 0 && vizClipboard1 === null) {
129
vizClipboard1 = new ClipboardJS('a.visualizer-chart-shortcode'); // jshint ignore:line
@@ -116,13 +113,13 @@ var vizClipboard1=null;
116113
return;
117114
}
118115
setTimeout( function() {
119-
displayChartsOnFrontEnd();
116+
displayChartsOnFrontEnd();
120117
}, 100 );
121118
}
122119

123120
function initChartDisplay() {
124121
if(visualizer.is_front == true){ // jshint ignore:line
125-
displayChartsOnFrontEnd();
122+
displayChartsOnFrontEnd();
126123
}else{
127124
showChart();
128125
}
@@ -141,20 +138,23 @@ var vizClipboard1=null;
141138
}
142139

143140
function displayChartsOnFrontEnd() {
144-
// display all charts that are NOT to be lazy-loaded.
145-
$( 'div.viz-facade-loaded:not(.visualizer-lazy):not(.visualizer-cw-error):empty' ).removeClass( 'viz-facade-loaded' );
146-
$('div.visualizer-front:not(.visualizer-lazy):not(.viz-facade-loaded)').each(function(index, element){
147-
if ( $(element).is(':visible') ) {
148-
var id = $(element).addClass('viz-facade-loaded').attr('id');
149-
showChart(id);
150-
151-
// Reload the chart and mark it as reloaded.
152-
if ( chartReloadedAfterFacade.indexOf( id ) === -1 ) {
153-
refreshEachCharts();
154-
chartReloadedAfterFacade.push( id );
141+
142+
// Render the charts that are not lazy-loaded and with no errors.
143+
var nonLazyLoadedCharts = $('div.visualizer-front:not(.viz-facade-loaded):not(.visualizer-lazy):not(.visualizer-cw-error');
144+
145+
if ( nonLazyLoadedCharts.length ) {
146+
nonLazyLoadedCharts.each(function(index, element){
147+
if ( $(element).is(':visible') ) {
148+
var id = $(element).addClass('viz-facade-loaded').attr('id');
149+
showChart(id);
155150
}
156-
}
157-
});
151+
});
152+
153+
refreshEachCharts();
154+
} else {
155+
// Remove the loaded status for charts that are empty.
156+
$( 'div.viz-facade-loaded:not(.visualizer-lazy):not(.visualizer-cw-error):empty' ).removeClass( 'viz-facade-loaded' );
157+
}
158158

159159
// interate through all charts that are to be lazy-loaded and observe each one.
160160
$('div.visualizer-front.visualizer-lazy').each(function(index, element){

0 commit comments

Comments
 (0)