PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.4.4
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.4.4
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 All 149 releases
← All changes | js/render-google.js +158 -19 3.1.03.4.4 View file →
@@ -7,10 +7,22 @@
7 7
8 8 (function($) {
9 9 var gv;
10 10 var all_charts, objects;
11 + // so that we know which charts belong to our library.
12 + var rendered_charts = [];
11 13
12 14 function renderChart(id) {
15 + var chart = all_charts[id];
16 + var hasAnnotation = false;
17 + if(id !== 'canvas' && typeof chart.series !== 'undefined' && typeof chart.settings.series !== 'undefined'){
18 + hasAnnotation = chart.series.length - chart.settings.series.length > 1;
19 + }
20 + // re-render the chart only if it doesn't have annotations and it is on the front-end
21 + // this is to prevent the chart from showing "All series on a given axis must be of the same data type" during resize.
22 + if(hasAnnotation){
23 + return;
24 + }
13 25 renderSpecificChart(id, all_charts[id]);
14 26 }
15 27
16 28 function renderSpecificChart(id, chart) {
@@ -18,8 +30,9 @@
18 30
19 31 if(chart.library !== 'google'){
20 32 return;
21 33 }
34 + rendered_charts[id] = 'yes';
22 35
23 36 series = chart.series;
24 37 data = chart.data;
25 38 settings = chart.settings;
@@ -51,8 +64,42 @@
51 64 settings['animation']['startup'] = true;
52 65 settings['animation']['duration'] = parseInt(settings['animation']['duration']);
53 66 }
54 67
68 + // mark roles for series that have specified a role
69 + // and then remove them from future processing
70 + // and also adjust the indices of the series array so that
71 + // the ones with a role are ignored
72 + // e.g. if there are 6 columns (0-5) out of which 1, 3 and 5 are annotations
73 + // the final series will only include 0, 2, 4 (reindexed as 0, 1, 2)
74 + if (settings.series) {
75 + var adjusted_series = [];
76 + for (i = 0; i < settings.series.length; i++) {
77 + if (!series[i + 1] || typeof settings.series[i] === 'undefined') {
78 + continue;
79 + }
80 + if(typeof settings.series[i].role !== 'undefined'){
81 + table.setColumnProperty(i + 1, 'role', settings.series[i].role);
82 + if(settings.series[i].role === '') {
83 + adjusted_series.push(settings.series[i]);
84 + }
85 + }
86 + }
87 + if(adjusted_series.length > 0){
88 + settings.series = adjusted_series;
89 + }
90 + }
91 +
92 + if ( settings['explorer_enabled'] && settings['explorer_enabled'] == 'true' ) { // jshint ignore:line
93 + var $explorer = {};
94 + $explorer['keepInBounds'] = true;
95 +
96 + if ( settings['explorer_actions'] ) {
97 + $explorer['actions'] = settings['explorer_actions'];
98 + }
99 + settings['explorer'] = $explorer;
100 + }
101 +
55 102 switch (chart.type) {
56 103 case 'pie':
57 104 if (settings.slices) {
58 105 for (i in settings.slices) {
@@ -93,8 +140,11 @@
93 140 }
94 141 break;
95 142 case 'gauge':
96 143 break;
144 + case 'bubble':
145 + settings.sortBubblesBySize = settings.sortBubblesBySize ? settings.sortBubblesBySize == 1 : false; // jshint ignore:line
146 + break;
97 147 case 'timeline':
98 148 settings['timeline'] = [];
99 149 settings['timeline']['groupByRowLabel'] = settings['groupByRowLabel'] ? true : false;
100 150 settings['timeline']['colorByRowLabel'] = settings['colorByRowLabel'] ? true : false;
@@ -131,8 +181,9 @@
131 181 case 'area':
132 182 case 'scatter':
133 183 case 'candlestick':
134 184 case 'column':
185 + case 'combo':
135 186 axis = settings.hAxis;
136 187 break;
137 188 case 'bar':
138 189 axis = settings.vAxis;
@@ -172,16 +223,30 @@
172 223
173 224 for (i = 0; i < data.length; i++) {
174 225 row = [];
175 226 for (j = 0; j < series.length; j++) {
176 - if (series[j].type === 'date' || series[j].type === 'datetime') {
177 - date = new Date(data[i][j]);
178 - data[i][j] = null;
179 - if (Object.prototype.toString.call(date) === "[object Date]") {
180 - if (!isNaN(date.getTime())) {
181 - data[i][j] = date;
182 - }
183 - }
227 + switch(series[j].type) {
228 + case 'string':
229 + if(data[i][j] === ''){
230 + data[i][j] = null;
231 + }
232 + break;
233 + case 'boolean':
234 + if (typeof data[i][j] === 'string'){
235 + data[i][j] = data[i][j] === 'true';
236 + }
237 + break;
238 + case 'date':
239 + // fall-through.
240 + case 'datetime':
241 + date = new Date(data[i][j]);
242 + data[i][j] = null;
243 + if (Object.prototype.toString.call(date) === "[object Date]") {
244 + if (!isNaN(date.getTime())) {
245 + data[i][j] = date;
246 + }
247 + }
248 + break;
184 249 }
185 250 row.push(data[i][j]);
186 251 }
187 252 table.addRow(row);
@@ -199,9 +264,9 @@
199 264 }
200 265 break;
201 266 default:
202 267 for (i = 0; i < settings.series.length; i++) {
203 - if (!series[i + 1]) {
268 + if (!series[i + 1] || typeof settings.series[i] === 'undefined') {
204 269 continue;
205 270 }
206 271 format_data(id, table, series[i + 1].type, settings.series[i].format, i + 1);
207 272 }
@@ -209,12 +274,18 @@
209 274 }
210 275 } else if (chart.type === 'pie' && settings.format && settings.format !== '') {
211 276 format_data(id, table, 'number', settings.format, 1);
212 277 }
278 +
279 + if(settings.hAxis && series[0]) {
280 + format_data(id, table, series[0].type, settings.hAxis.format, 0);
281 + }
282 +
213 283 override(settings);
214 284
215 285 gv.events.addListener(render, 'ready', function () {
216 286 var arr = id.split('-');
287 + __visualizer_chart_images[ arr[0] + '-' + arr[1] ] = '';
217 288 try{
218 289 var img = render.getImageURI();
219 290 __visualizer_chart_images[ arr[0] + '-' + arr[1] ] = img;
220 291 $('body').trigger('visualizer:render:chart', {id: arr[1], image: img});
@@ -222,8 +293,10 @@
222 293 console.warn('render.getImageURI not defined for ' + arr[0] + '-' + arr[1]);
223 294 }
224 295 });
225 296
297 + $('body').trigger('visualizer:chart:settings:extend', {id: id, chart: chart, settings: settings, data: table});
298 +
226 299 render.draw(table, settings);
227 300 }
228 301
229 302 function format_data(id, table, type, format, index) {
@@ -269,16 +342,8 @@
269 342 renderChart(id);
270 343 }
271 344 }
272 345
273 - if(typeof visualizer !== 'undefined'){
274 - // called while updating the chart.
275 - visualizer.update = function(){
276 - renderChart('canvas');
277 - };
278 - }
279 -
280 -
281 346 var resizeTimeout;
282 347
283 348 $(document).ready(function() {
284 349 $(window).resize(function() {
@@ -288,9 +353,9 @@
288 353
289 354 resizeHiddenContainers(true);
290 355 });
291 356
292 - $(window).load(function(){
357 + $(window).on('load', function(){
293 358 resizeHiddenContainers(true);
294 359 });
295 360
296 361 function resizeHiddenContainers(everytime){
@@ -319,10 +384,47 @@
319 384 });
320 385 }
321 386
322 387 $('body').on('visualizer:render:chart:start', function(event, v){
388 + var $chart_types = ['corechart', 'geochart', 'gauge', 'table', 'timeline'];
389 + if(v.is_front == true){ // jshint ignore:line
390 + // check what all chart types to load.
391 + $chart_types = [];
392 + $.each(v.charts, function(i, c){
393 + var $type = c.type;
394 + switch($type){
395 + case 'bar':
396 + case 'column':
397 + case 'line':
398 + case 'area':
399 + case 'stepped area':
400 + case 'bubble':
401 + case 'pie':
402 + case 'donut':
403 + case 'combo':
404 + case 'candlestick':
405 + case 'histogram':
406 + case 'scatter':
407 + case 'bubble':
408 + $type = 'corechart';
409 + break;
410 + case 'geo':
411 + $type = 'geochart';
412 + break;
413 + case 'dataTable':
414 + case 'polarArea':
415 + case 'radar':
416 + $type = null;
417 + break;
418 + }
419 + if($type != null){
420 + $chart_types.push($type);
421 + }
422 + });
423 + }
424 +
323 425 objects = {};
324 - google.charts.load("current", {packages: ["corechart", "geochart", "gauge", "table", "timeline"], mapsApiKey: v.map_api_key, 'language' : v.language});
426 + google.charts.load("current", {packages: $chart_types, mapsApiKey: v.map_api_key, 'language' : v.language});
325 427 google.charts.setOnLoadCallback(function() {
326 428 gv = google.visualization;
327 429 all_charts = v.charts;
328 430 render();
@@ -332,7 +434,44 @@
332 434 $('body').on('visualizer:render:specificchart:start', function(event, v){
333 435 objects = {};
334 436 gv = google.visualization;
335 437 renderSpecificChart(v.id, v.chart);
438 + });
439 +
440 + $('body').on('visualizer:render:currentchart:update', function(event, v){
441 + renderChart('canvas');
442 + });
443 +
444 + // front end actions
445 + // 'image' is also called from the library
446 + $('body').on('visualizer:action:specificchart', function(event, v){
447 + var id = v.id;
448 + if(typeof rendered_charts[id] === 'undefined'){
449 + return;
450 + }
451 + var arr = id.split('-');
452 + var img = __visualizer_chart_images[ arr[0] + '-' + arr[1] ];
453 + switch(v.action){
454 + case 'print':
455 + // for charts that have no rendered image defined, we print the data instead.
456 + var html = v.data;
457 + if(img !== ''){
458 + html = "<html><body><img src='" + img + "' /></body></html>";
459 + }
460 + $('body').trigger('visualizer:action:specificchart:defaultprint', {data: html});
461 + break;
462 + case 'image':
463 + if(img !== ''){
464 + var $a = $("<a>"); // jshint ignore:line
465 + $a.attr("href", img);
466 + $("body").append($a);
467 + $a.attr("download", v.dataObj.name);
468 + $a[0].click();
469 + $a.remove();
470 + }else{
471 + console.warn("No image generated");
472 + }
473 + break;
474 + }
336 475 });
337 476
338 477 })(jQuery);