Skip to content

Commit 3c43d06

Browse files
load only relevant chart modules
1 parent c7377e2 commit 3c43d06

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

classes/Visualizer/Module/Admin.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,7 @@ public function renderLibraryPage() {
705705
),
706706
),
707707
'page_type' => 'library',
708+
'is_front' => false,
708709
)
709710
);
710711
// render library page

classes/Visualizer/Module/Chart.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ private function _handleDataAndSettingsPage() {
478478
),
479479
'is_pro' => VISUALIZER_PRO,
480480
'page_type' => 'chart',
481+
'is_front' => false,
481482
)
482483
);
483484

classes/Visualizer/Module/Frontend.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ public function renderChart( $atts ) {
277277
'copied' => __( 'Copied!', 'visualizer' ),
278278
),
279279
'page_type' => 'frontend',
280+
'is_front' => true,
280281
)
281282
);
282283
wp_enqueue_style( 'visualizer-front' );

js/render-google.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,42 @@ var __visualizer_chart_images = [];
325325
}
326326

327327
$('body').on('visualizer:render:chart:start', function(event, v){
328+
var $chart_types = ['corechart', 'geochart', 'gauge', 'table', 'timeline'];
329+
if(v.is_front == true){ // jshint ignore:line
330+
// check what all chart types to load.
331+
$chart_types = [];
332+
$.each(v.charts, function(i, c){
333+
var $type = c.type;
334+
switch($type){
335+
case 'bar':
336+
case 'column':
337+
case 'line':
338+
case 'area':
339+
case 'stepped area':
340+
case 'bubble':
341+
case 'pie':
342+
case 'donut':
343+
case 'combo':
344+
case 'candlestick':
345+
case 'histogram':
346+
case 'scatter':
347+
$type = 'corechart';
348+
break;
349+
case 'geo':
350+
$type = 'geochart';
351+
break;
352+
case 'dataTable':
353+
$type = null;
354+
break;
355+
}
356+
if($type != null){
357+
$chart_types.push($type);
358+
}
359+
});
360+
}
361+
328362
objects = {};
329-
google.charts.load("current", {packages: ["corechart", "geochart", "gauge", "table", "timeline"], mapsApiKey: v.map_api_key, 'language' : v.language});
363+
google.charts.load("current", {packages: $chart_types, mapsApiKey: v.map_api_key, 'language' : v.language});
330364
google.charts.setOnLoadCallback(function() {
331365
gv = google.visualization;
332366
all_charts = v.charts;

0 commit comments

Comments
 (0)