PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.6.1
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.6.1
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 3.10.4 All 148 releases
← All changes | js/render-google.js +203 -33 3.1.33.6.1 View file →
@@ -11,9 +11,25 @@
11 11 // so that we know which charts belong to our library.
12 12 var rendered_charts = [];
13 13
14 14 function renderChart(id) {
15 - renderSpecificChart(id, all_charts[id]);
15 + var chart = all_charts[id];
16 + var hasAnnotation = false;
17 +
18 + // re-render the chart only if it doesn't have annotations and it is on the front-end
19 + // this is to prevent the chart from showing "All series on a given axis must be of the same data type" during resize.
20 + // remember, some charts do not support annotations so they should not be included in this.
21 + var no_annotation_charts = ['tabular', 'timeline', 'gauge', 'geo', 'bubble', 'candlestick'];
22 + if ( undefined !== chart.settings && undefined !== chart.settings.series && undefined === chart.settings.series.length ) {
23 + chart.settings.series = Object.values( chart.settings.series );
24 + }
25 + if(id !== 'canvas' && typeof chart.series !== 'undefined' && typeof chart.settings.series !== 'undefined' && ! no_annotation_charts.includes(chart.type) ) {
26 + hasAnnotation = chart.series.length - chart.settings.series.length > 1;
27 + }
28 +
29 + if(! hasAnnotation){
30 + renderSpecificChart(id, all_charts[id]);
31 + }
16 32 }
17 33
18 34 function renderSpecificChart(id, chart) {
19 35 var render, container, series, data, table, settings, i, j, row, date, axis, property, format, formatter;
@@ -35,8 +51,11 @@
35 51
36 52 render = objects[id] || null;
37 53 if (!render) {
38 54 switch (chart.type) {
55 + case "tabular":
56 + render = "Table";
57 + break;
39 58 case "gauge":
40 59 case "table":
41 60 case "timeline":
42 61 render = chart.type.charAt(0).toUpperCase() + chart.type.slice(1);
@@ -54,8 +73,47 @@
54 73 settings['animation']['startup'] = true;
55 74 settings['animation']['duration'] = parseInt(settings['animation']['duration']);
56 75 }
57 76
77 + // mark roles for series that have specified a role
78 + // and then remove them from future processing
79 + // and also adjust the indices of the series array so that
80 + // the ones with a role are ignored
81 + // e.g. if there are 6 columns (0-5) out of which 1, 3 and 5 are annotations
82 + // the final series will only include 0, 2, 4 (reindexed as 0, 1, 2)
83 +
84 + // this will capture all the series indexes that became annotations.
85 + var series_annotations = [];
86 + if (settings.series) {
87 + var adjusted_series = [];
88 + for (i = 0; i < settings.series.length; i++) {
89 + if (!series[i + 1] || typeof settings.series[i] === 'undefined') {
90 + continue;
91 + }
92 + if(typeof settings.series[i].role !== 'undefined'){
93 + table.setColumnProperty(i + 1, 'role', settings.series[i].role);
94 + if(settings.series[i].role === '') {
95 + adjusted_series.push(settings.series[i]);
96 + }else{
97 + series_annotations.push(i);
98 + }
99 + }
100 + }
101 + if(adjusted_series.length > 0){
102 + settings.series = adjusted_series;
103 + }
104 + }
105 +
106 + if ( settings['explorer_enabled'] && settings['explorer_enabled'] == 'true' ) { // jshint ignore:line
107 + var $explorer = {};
108 + $explorer['keepInBounds'] = true;
109 +
110 + if ( settings['explorer_actions'] ) {
111 + $explorer['actions'] = settings['explorer_actions'];
112 + }
113 + settings['explorer'] = $explorer;
114 + }
115 +
58 116 switch (chart.type) {
59 117 case 'pie':
60 118 if (settings.slices) {
61 119 for (i in settings.slices) {
@@ -89,8 +147,9 @@
89 147 settings['region'] = 'world';
90 148 }
91 149 break;
92 150 case 'table':
151 + case 'tabular':
93 152 if (parseInt(settings['pagination']) !== 1)
94 153 {
95 154 delete settings['pageSize'];
96 155 }
@@ -96,10 +155,13 @@
96 155 }
97 156 break;
98 157 case 'gauge':
99 158 break;
159 + case 'bubble':
160 + settings.sortBubblesBySize = settings.sortBubblesBySize ? settings.sortBubblesBySize == 1 : false; // jshint ignore:line
161 + break;
100 162 case 'timeline':
101 - settings['timeline'] = [];
163 + settings['timeline'] = {};
102 164 settings['timeline']['groupByRowLabel'] = settings['groupByRowLabel'] ? true : false;
103 165 settings['timeline']['colorByRowLabel'] = settings['colorByRowLabel'] ? true : false;
104 166 settings['timeline']['showRowLabels'] = settings['showRowLabels'] ? true : false;
105 167 if(settings['singleColor'] !== '') {
@@ -176,16 +238,30 @@
176 238
177 239 for (i = 0; i < data.length; i++) {
178 240 row = [];
179 241 for (j = 0; j < series.length; j++) {
180 - if (series[j].type === 'date' || series[j].type === 'datetime') {
181 - date = new Date(data[i][j]);
182 - data[i][j] = null;
183 - if (Object.prototype.toString.call(date) === "[object Date]") {
184 - if (!isNaN(date.getTime())) {
185 - data[i][j] = date;
186 - }
187 - }
242 + switch(series[j].type) {
243 + case 'string':
244 + if(data[i][j] === ''){
245 + data[i][j] = null;
246 + }
247 + break;
248 + case 'boolean':
249 + if (typeof data[i][j] === 'string'){
250 + data[i][j] = data[i][j] === 'true';
251 + }
252 + break;
253 + case 'date':
254 + // fall-through.
255 + case 'datetime':
256 + date = new Date(data[i][j]);
257 + data[i][j] = null;
258 + if (Object.prototype.toString.call(date) === "[object Date]") {
259 + if (!isNaN(date.getTime())) {
260 + data[i][j] = date;
261 + }
262 + }
263 + break;
188 264 }
189 265 row.push(data[i][j]);
190 266 }
191 267 table.addRow(row);
@@ -193,8 +269,9 @@
193 269
194 270 if (settings.series) {
195 271 switch(chart.type){
196 272 case 'table':
273 + case 'tabular':
197 274 for(i in settings.series){
198 275 i = parseInt(i);
199 276 if (!series[i + 1]) {
200 277 continue;
@@ -203,12 +280,20 @@
203 280 }
204 281 break;
205 282 default:
206 283 for (i = 0; i < settings.series.length; i++) {
207 - if (!series[i + 1]) {
284 + if (!series[i + 1] || typeof settings.series[i] === 'undefined') {
208 285 continue;
209 286 }
210 - format_data(id, table, series[i + 1].type, settings.series[i].format, i + 1);
287 + var seriesIndexToUse = i + 1;
288 +
289 + // if an annotation "swallowed" a series, use the following one.
290 + if(series_annotations.includes(i)){
291 + seriesIndexToUse++;
292 + }
293 + if ( series[seriesIndexToUse] ) {
294 + format_data(id, table, series[seriesIndexToUse].type, settings.series[i].format, seriesIndexToUse);
295 + }
211 296 }
212 297 break;
213 298 }
214 299 } else if (chart.type === 'pie' && settings.format && settings.format !== '') {
@@ -213,8 +298,13 @@
213 298 }
214 299 } else if (chart.type === 'pie' && settings.format && settings.format !== '') {
215 300 format_data(id, table, 'number', settings.format, 1);
216 301 }
302 +
303 + if(settings.hAxis && series[0]) {
304 + format_data(id, table, series[0].type, settings.hAxis.format, 0);
305 + }
306 +
217 307 override(settings);
218 308
219 309 gv.events.addListener(render, 'ready', function () {
220 310 var arr = id.split('-');
@@ -222,13 +312,28 @@
222 312 try{
223 313 var img = render.getImageURI();
224 314 __visualizer_chart_images[ arr[0] + '-' + arr[1] ] = img;
225 315 $('body').trigger('visualizer:render:chart', {id: arr[1], image: img});
316 + if ( $( '#chart-img' ).length ) {
317 + $( '#chart-img' ).val( img );
318 + }
226 319 }catch(error){
227 - console.warn('render.getImageURI not defined for ' + arr[0] + '-' + arr[1]);
320 + var canvas = document.getElementById( 'canvas' );
321 + domtoimage.toPng(canvas)
322 + .then(function ( img ) {
323 + __visualizer_chart_images[ arr[0] + '-' + arr[1] ] = img;
324 + $('body').trigger('visualizer:render:chart', {id: arr[1], image: img});
325 + if ( $( '#chart-img' ).length ) {
326 + $( '#chart-img' ).val( img );
327 + }
328 + })
329 + .catch(function (error) {
330 + console.warn('render.getImageURI not defined for ' + arr[0] + '-' + arr[1]);
331 + });
228 332 }
229 333 });
230 334
335 + $('body').trigger('visualizer:chart:settings:extend', {id: id, chart: chart, settings: settings, data: table});
231 336 render.draw(table, settings);
232 337 }
233 338
234 339 function format_data(id, table, type, format, index) {
@@ -270,20 +375,14 @@
270 375 }
271 376
272 377 function render() {
273 378 for (var id in (all_charts || {})) {
274 - renderChart(id);
379 + if (document.getElementById( id ).offsetParent !== null) {
380 + renderChart(id);
381 + }
275 382 }
276 383 }
277 384
278 - if(typeof visualizer !== 'undefined'){
279 - // called while updating the chart.
280 - visualizer.update = function(){
281 - renderChart('canvas');
282 - };
283 - }
284 -
285 -
286 385 var resizeTimeout;
287 386
288 387 $(document).ready(function() {
289 388 $(window).resize(function() {
@@ -291,8 +390,14 @@
291 390 resizeTimeout = setTimeout(render, 100);
292 391 });
293 392
294 393 resizeHiddenContainers(true);
394 +
395 + if ( $( '.visualizer-hidden-container' ).length ) {
396 + setInterval( function() {
397 + $( '.visualizer-hidden-container' ).find(".visualizer-front").resize();
398 + }, 500 );
399 + }
295 400 });
296 401
297 402 $(window).on('load', function(){
298 403 resizeHiddenContainers(true);
@@ -324,14 +429,62 @@
324 429 });
325 430 }
326 431
327 432 $('body').on('visualizer:render:chart:start', function(event, v){
433 + var $chart_types = ['corechart', 'geochart', 'gauge', 'table', 'timeline'];
434 + if(v.is_front == true){ // jshint ignore:line
435 + // check what all chart types to load.
436 + $chart_types = [];
437 + $.each(v.charts, function(i, c){
438 + var $type = c.type;
439 + switch($type){
440 + case 'bar':
441 + case 'column':
442 + case 'line':
443 + case 'area':
444 + case 'stepped area':
445 + case 'bubble':
446 + case 'pie':
447 + case 'donut':
448 + case 'combo':
449 + case 'candlestick':
450 + case 'histogram':
451 + case 'scatter':
452 + case 'bubble':
453 + $type = 'corechart';
454 + break;
455 + case 'geo':
456 + $type = 'geochart';
457 + break;
458 + case 'tabular':
459 + case 'table':
460 + $type = 'table';
461 + break;
462 + case 'dataTable':
463 + case 'polarArea':
464 + case 'radar':
465 + $type = null;
466 + break;
467 + }
468 + if($type != null){
469 + $chart_types.push($type);
470 + }
471 + });
472 + }
473 +
328 474 objects = {};
329 - google.charts.load("current", {packages: ["corechart", "geochart", "gauge", "table", "timeline"], mapsApiKey: v.map_api_key, 'language' : v.language});
330 - google.charts.setOnLoadCallback(function() {
331 - gv = google.visualization;
332 - all_charts = v.charts;
333 - render();
475 + google.load( 'visualization', 'current', {packages: $chart_types, mapsApiKey: v.map_api_key, 'language' : v.language,
476 + callback: function () {
477 + gv = google.visualization;
478 + all_charts = v.charts;
479 + if(v.is_front == true && typeof v.id !== 'undefined'){ // jshint ignore:line
480 + if ( document.getElementById( v.id ).offsetParent !== null ) {
481 + renderChart(v.id);
482 + }
483 + } else {
484 + render();
485 + }
486 + }
334 487 });
335 488 });
336 489
337 490 $('body').on('visualizer:render:specificchart:start', function(event, v){
@@ -339,18 +492,23 @@
339 492 gv = google.visualization;
340 493 renderSpecificChart(v.id, v.chart);
341 494 });
342 495
496 + $('body').on('visualizer:render:currentchart:update', function(event, v){
497 + renderChart('canvas');
498 + });
499 +
343 500 // front end actions
501 + // 'image' is also called from the library
344 502 $('body').on('visualizer:action:specificchart', function(event, v){
503 + var id = v.id;
504 + if(typeof rendered_charts[id] === 'undefined'){
505 + return;
506 + }
507 + var arr = id.split('-');
508 + var img = __visualizer_chart_images[ arr[0] + '-' + arr[1] ];
345 509 switch(v.action){
346 510 case 'print':
347 - var id = v.id;
348 - if(typeof rendered_charts[id] === 'undefined'){
349 - return;
350 - }
351 - var arr = id.split('-');
352 - var img = __visualizer_chart_images[ arr[0] + '-' + arr[1] ];
353 511 // for charts that have no rendered image defined, we print the data instead.
354 512 var html = v.data;
355 513 if(img !== ''){
356 514 html = "<html><body><img src='" + img + "' /></body></html>";
@@ -355,8 +513,20 @@
355 513 if(img !== ''){
356 514 html = "<html><body><img src='" + img + "' /></body></html>";
357 515 }
358 516 $('body').trigger('visualizer:action:specificchart:defaultprint', {data: html});
517 + break;
518 + case 'image':
519 + if(img !== ''){
520 + var $a = $("<a>"); // jshint ignore:line
521 + $a.attr("href", img);
522 + $("body").append($a);
523 + $a.attr("download", v.dataObj.name);
524 + $a[0].click();
525 + $a.remove();
526 + }else{
527 + console.warn("No image generated");
528 + }
359 529 break;
360 530 }
361 531 });
362 532