PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.3.4
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.3.4
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-chartjs.js +44 -197 4.0.43.3.4 View file →
@@ -18,13 +18,8 @@
18 18
19 19 if(chart.library !== 'chartjs'){
20 20 return;
21 21 }
22 -
23 - // Bail if the chart is already rendered or is being rendered.
24 - if ( ! window.isResizeRequest && ( $('#' + id).hasClass('visualizer-chart-loaded') || ( 'canvas' !== id && $('#' + id).children( ':not(.loader, style)' ).length > 0 ) ) ) {
25 - return;
26 - }
27 22 rendered_charts[id] = 'yes';
28 23
29 24 series = chart.series;
30 25 data = chart.data;
@@ -51,10 +46,9 @@
51 46 case 'column':
52 47 type = 'bar';
53 48 break;
54 49 case 'bar':
55 - type = 'bar';
56 - settings.indexAxis = 'y';
50 + type = 'horizontalBar';
57 51 break;
58 52 case 'pie':
59 53 // donut is not a setting but a separate chart type.
60 54 if(typeof settings['custom'] !== 'undefined' && settings['custom']['donut'] === 'true'){
@@ -69,9 +63,9 @@
69 63
70 64 for (i = 0; i < data.length; i++) {
71 65 row = [];
72 66 for (j = 0; j < series.length; j++) {
73 - if (series[j].type === 'date' || series[j].type === 'datetime') {
67 + if (series[j].type === 'date' || series[j].type === 'datetime') {
74 68 date = new Date(data[i][j]);
75 69 data[i][j] = null;
76 70 if (Object.prototype.toString.call(date) === "[object Date]") {
77 71 if (!isNaN(date.getTime())) {
@@ -117,45 +111,8 @@
117 111 }
118 112
119 113 handleSettings(settings, chart);
120 114
121 - const getChart = Chart.getChart(context);
122 - if ( getChart ) {
123 - return;
124 - }
125 -
126 - // Format series label.
127 - settings.plugins.tooltip = {
128 - callbacks: {
129 - label: function(context) {
130 - var label = '';
131 - if ( 'object' === typeof context.dataset.label ) {
132 - label = context.label || '';
133 - } else {
134 - label = context.dataset.label || '';
135 - }
136 - if ( label ) {
137 - label += ': ';
138 - }
139 - var format = context.dataset.format || '';
140 - if ( format ) {
141 - var lastSuffix = numeral(context.formattedValue).format(format).replace(/[0-9]/g, '');
142 - label += context.formattedValue + lastSuffix;
143 - } else {
144 - format = 'undefined' !== typeof context.chart.config._config.options.format ? context.chart.config._config.options.format : '';
145 - if ( format ) {
146 - label += format_datum( context.formattedValue, format );
147 - } else {
148 - label += context.formattedValue;
149 - }
150 - }
151 - return label;
152 - }
153 - }
154 - };
155 -
156 - override(settings, chart);
157 -
158 115 var chartjs = new Chart(context, {
159 116 type: type,
160 117 data: {
161 118 labels: labels,
@@ -160,17 +117,9 @@
160 117 data: {
161 118 labels: labels,
162 119 datasets: datasets
163 120 },
164 - options: settings,
165 - plugins: [{
166 - afterRender: function () {
167 - var canvas = $( 'canvas' )[0];
168 - if ( $( '#chart-img' ).length ) {
169 - $( '#chart-img' ).val( canvas.toDataURL() );
170 - }
171 - }
172 - }],
121 + options: settings
173 122 });
174 123
175 124 // this line needs to be included twice. This is not an error.
176 125 $.extend(settings, { responsive: true, maintainAspectRatio: false });
@@ -177,18 +126,10 @@
177 126
178 127 // chart area
179 128 if(v.is_front == true){ // jshint ignore:line
180 129 $('#' + id).css('position', 'relative');
181 - var height = settings.height.indexOf('%') === -1 ? ( settings.height + 'px' ) : settings.height;
182 - var width = settings.width.indexOf('%') === -1 ? ( settings.width + 'px' ) : settings.width;
183 - if(settings.height){
184 - chartjs.canvas.parentNode.style.height = height;
185 - $('#' + id + ' canvas').css('height', height);
186 - }
187 - if(settings.width){
188 - chartjs.canvas.parentNode.style.width = width;
189 - $('#' + id + ' canvas').css('width', width);
190 - }
130 + chartjs.canvas.parentNode.style.height = settings.height;
131 + chartjs.canvas.parentNode.style.width = settings.width;
191 132 }
192 133
193 134 // allow user to extend the settings.
194 135 $('body').trigger('visualizer:chart:settings:extend', {id: id, chart: chart, settings: settings});
@@ -205,8 +146,12 @@
205 146 if(typeof settings['animation'] !== 'undefined' && parseInt(settings['animation']['duration']) === 0){
206 147 settings['animation']['duration'] = 1000;
207 148 }
208 149
150 + if(typeof settings['title'] !== 'undefined' && settings['title']['text'] !== ''){
151 + settings['title']['display'] = true;
152 + }
153 +
209 154 if(typeof settings['tooltip'] !== 'undefined' && typeof settings['tooltip']['intersect'] !== 'undefined'){
210 155 // jshint ignore:line
211 156 settings['tooltip']['intersect'] = settings['tooltip']['intersect'] == true || parseInt(settings['tooltip']['intersect']) === 1; // jshint ignore:line
212 157 }
@@ -211,14 +156,14 @@
211 156 settings['tooltip']['intersect'] = settings['tooltip']['intersect'] == true || parseInt(settings['tooltip']['intersect']) === 1; // jshint ignore:line
212 157 }
213 158
214 159 if(typeof settings['fontName'] !== 'undefined' && settings['fontName'] !== ''){
215 - Chart.defaults.font.family = settings['fontName'];
160 + Chart.defaults.global.defaultFontFamily = settings['fontName'];
216 161 delete settings['fontName'];
217 162 }
218 163
219 164 if(typeof settings['fontSize'] !== 'undefined' && settings['fontSize'] !== ''){
220 - Chart.defaults.font.size = parseInt(settings['fontSize']);
165 + Chart.defaults.global.defaultFontSize = settings['fontSize'];
221 166 delete settings['fontSize'];
222 167 }
223 168
224 169 // handle legend defaults.
@@ -229,19 +174,11 @@
229 174 }
230 175 }
231 176 }
232 177
233 - settings.plugins = {
234 - legend: settings.legend,
235 - };
178 + handleAxes(settings, chart);
236 179
237 - if(typeof settings['title'] !== 'undefined' && settings['title']['text'] !== ''){
238 - settings.plugins['title'] = {};
239 - settings.plugins['title']['display'] = true;
240 - settings.plugins['title']['text'] = settings['title']['text'];
241 - }
242 -
243 - handleAxes(settings, chart);
180 + override(settings, chart);
244 181 }
245 182
246 183 function handleAxes(settings, chart){
247 184 if(typeof settings['yAxes'] !== 'undefined' && typeof settings['xAxes'] !== 'undefined'){
@@ -246,27 +183,13 @@
246 183 function handleAxes(settings, chart){
247 184 if(typeof settings['yAxes'] !== 'undefined' && typeof settings['xAxes'] !== 'undefined'){
248 185 // stacking has to be defined on both axes.
249 186 if(typeof settings['yAxes']['stacked_bool'] !== 'undefined'){
250 - settings['yAxes']['stacked_bool'] = 'true';
187 + settings['xAxes']['stacked_bool'] = 'true';
251 188 }
252 189 if(typeof settings['xAxes']['stacked_bool'] !== 'undefined'){
253 - settings['xAxes']['stacked_bool'] = 'true';
190 + settings['yAxes']['stacked_bool'] = 'true';
254 191 }
255 - // Bar percentage.
256 - if (typeof settings['yAxes']['barPercentage_int'] !=='undefined' && ''!== settings['yAxes']['barPercentage_int']){
257 - settings['barPercentage'] = settings['yAxes']['barPercentage_int'];
258 - }
259 - if (typeof settings['xAxes']['barPercentage_int'] !=='undefined' && ''!== settings['xAxes']['barPercentage_int']){
260 - settings['barPercentage'] = settings['xAxes']['barPercentage_int'];
261 - }
262 - // Bar thickness.
263 - if (typeof settings['yAxes']['barThickness'] !=='undefined' && ''!== settings['yAxes']['barThickness']){
264 - settings['barThickness'] = settings['yAxes']['barThickness'];
265 - }
266 - if (typeof settings['xAxes']['barThickness'] !=='undefined' && ''!== settings['xAxes']['barThickness']){
267 - settings['barThickness'] = settings['xAxes']['barThickness'];
268 - }
269 192 }
270 193 configureAxes(settings, 'yAxes', chart);
271 194 configureAxes(settings, 'xAxes', chart);
272 195 }
@@ -278,9 +201,9 @@
278 201 var $o = {};
279 202 if(Array.isArray(settings[axis][i]) || typeof settings[axis][i] === 'object'){
280 203 for(var j in settings[axis][i]){
281 204 var $val = '';
282 - if(j === 'labelString'){
205 + if(j === 'labelString'){
283 206 $o['display'] = true;
284 207 $val = settings[axis][i][j];
285 208 }else if(i === 'ticks'){
286 209 // number values under ticks need to be converted to numbers or the library throws a JS error.
@@ -335,56 +258,8 @@
335 258 }
336 259 var $axis = $scales['scales'][axis];
337 260
338 261 $axis.push($features);
339 - // Migrate xAxes settings to v3.0+
340 - if ( $scales.scales && $scales.scales.xAxes ) {
341 - for (var x in $scales.scales.xAxes) {
342 - $scales.scales.x = {
343 - display: $scales.scales.xAxes[x].scaleLabel.display,
344 - title: {
345 - display:true,
346 - text: $scales.scales.xAxes[x].scaleLabel.labelString,
347 - color: $scales.scales.xAxes[x].scaleLabel.fontColor,
348 - font: {
349 - family: $scales.scales.xAxes[x].scaleLabel.fontFamily,
350 - size: $scales.scales.xAxes[x].scaleLabel.fontSize
351 - }
352 - },
353 - suggestedMax: $scales.scales.xAxes[x].ticks.suggestedMax || '',
354 - suggestedMin: $scales.scales.xAxes[x].ticks.suggestedMin || '',
355 - ticks: {
356 - maxTicksLimit: $scales.scales.xAxes[x].ticks.maxTicksLimit
357 - },
358 - stacked: $scales.scales.xAxes[x].stacked || false
359 - }
360 - }
361 - delete $scales.scales.xAxes;
362 - }
363 - // Migrate yAxes settings to v3.0+
364 - if ( $scales.scales && $scales.scales.yAxes ) {
365 - for (var y in $scales.scales.yAxes) {
366 - $scales.scales.y = {
367 - display: $scales.scales.yAxes[y].scaleLabel.display,
368 - title: {
369 - display:true,
370 - text: $scales.scales.yAxes[y].scaleLabel.labelString,
371 - color: $scales.scales.yAxes[y].scaleLabel.fontColor,
372 - font: {
373 - family: $scales.scales.yAxes[y].scaleLabel.fontFamily,
374 - size: $scales.scales.yAxes[y].scaleLabel.fontSize
375 - }
376 - },
377 - suggestedMax: $scales.scales.yAxes[y].ticks.suggestedMax || '',
378 - suggestedMin: $scales.scales.yAxes[y].ticks.suggestedMin || '',
379 - ticks: {
380 - maxTicksLimit: $scales.scales.yAxes[y].ticks.maxTicksLimit
381 - },
382 - stacked: $scales.scales.yAxes[y].stacked || false
383 - }
384 - }
385 - delete $scales.scales.yAxes;
386 - }
387 262 $.extend(settings, $scales);
388 263
389 264 // to prevent duplication, indicates that the axis has been set.
390 265 var $custom = {};
@@ -394,24 +269,21 @@
394 269
395 270 // format the axes labels.
396 271 if(typeof settings[axis + '_format'] !== 'undefined' && settings[axis + '_format'] !== ''){
397 272 var format = settings[axis + '_format'];
398 - var isDateFormat = moment( moment().format( format ),format, true ).isValid();
399 - if ( ! isDateFormat ) {
400 - switch(axis){
401 - case 'xAxes':
402 - settings.scales.x.ticks.callback = function(value, index, values){
403 - return format_datum(value, format);
404 - };
405 - break;
406 - case 'yAxes':
407 - settings.scales.y.ticks.callback = function(value, index, values){
408 - return format_datum(value, format);
409 - };
410 - break;
411 - }
412 - delete settings[axis + '_format'];
413 - }
273 + switch(axis){
274 + case 'xAxes':
275 + settings.scales.xAxes[0].ticks.callback = function(value, index, values){
276 + return format_datum(value, format);
277 + };
278 + break;
279 + case 'yAxes':
280 + settings.scales.yAxes[0].ticks.callback = function(value, index, values){
281 + return format_datum(value, format);
282 + };
283 + break;
284 + }
285 + delete settings[axis + '_format'];
414 286 }
415 287 delete settings[axis];
416 288 }
417 289
@@ -448,11 +320,8 @@
448 320 return;
449 321 }
450 322 for(var i in settings.series[j]){
451 323 var $attribute = {};
452 - if ( settings.series[j].backgroundColor == '' ) {
453 - delete settings.series[j].backgroundColor;
454 - }
455 324 $attribute[i] = settings.series[j][i];
456 325 $.extend($attributes, $attribute);
457 326 }
458 327 }
@@ -474,9 +343,9 @@
474 343
475 344 switch(type) {
476 345 case 'number':
477 346 // numeral.js works on 0 instead of # so we just replace that in the ICU pattern set.
478 - format = format.replace(/#/g, '0').replace(/%/g, '');
347 + format = format.replace(/#/g, '0');
479 348 // we also replace all instance of '$' as that is more relevant for ticks.
480 349 if(removeDollar){
481 350 format = format.replace(/\$/g, '');
482 351 }
@@ -493,13 +362,8 @@
493 362
494 363 function format_data(datum, j, settings, series){
495 364 j = j - 1;
496 365 var format = typeof settings.series !== 'undefined' && typeof settings.series[j] !== 'undefined' ? settings.series[j].format : '';
497 - if ( '' === format && typeof settings.yAxes_format !== 'undefined' ) {
498 - format = settings.yAxes_format;
499 - } else if ( '' === format && typeof settings.xAxes_format !== 'undefined' ) {
500 - format = settings.xAxes_format;
501 - }
502 366 return format_datum(datum, format, series[j + 1].type);
503 367 }
504 368
505 369 function override(settings, chart) {
@@ -505,9 +369,9 @@
505 369 function override(settings, chart) {
506 370 if (settings.manual) {
507 371 try{
508 372 var options = JSON.parse(settings.manual);
509 - $.extend(true, settings, options);
373 + $.extend(settings, options);
510 374 delete settings.manual;
511 375 }catch(error){
512 376 console.error("Error while adding manual configuration override " + settings.manual);
513 377 }
@@ -520,17 +384,19 @@
520 384 renderChart(id, v);
521 385 }
522 386 }
523 387
388 + if(typeof visualizer !== 'undefined'){
389 + // called while updating the chart.
390 + visualizer.update = function(){
391 + renderChart('canvas', visualizer);
392 + };
393 + }
394 +
524 395 $('body').on('visualizer:render:chart:start', function(event, v){
525 396 all_charts = v.charts;
397 + render(v);
526 398
527 - if(v.is_front == true && typeof v.id !== 'undefined'){ // jshint ignore:line
528 - renderChart(v.id, v);
529 - } else {
530 - render(v);
531 - }
532 -
533 399 // for some reason this needs to be introduced here for dynamic preview updates to work.
534 400 v.update = function(){
535 401 renderChart('canvas', v);
536 402 };
@@ -540,40 +406,21 @@
540 406 $('body').on('visualizer:render:specificchart:start', function(event, v){
541 407 renderSpecificChart(v.id, v.chart, v.v);
542 408 });
543 409
544 - $('body').on('visualizer:render:currentchart:update', function(event, v){
545 - var data = v || event.detail;
546 - renderChart('canvas', data.visualizer);
547 - });
548 -
549 410 // front end actions
550 - // 'image' is also called from the library
551 411 $('body').on('visualizer:action:specificchart', function(event, v){
552 - var id = v.id;
553 - if(typeof rendered_charts[id] === 'undefined'){
554 - return;
555 - }
556 - var canvas = $('#' + id + ' canvas');
557 412 switch(v.action){
558 413 case 'print':
414 + var id = v.id;
415 + if(typeof rendered_charts[id] === 'undefined'){
416 + return;
417 + }
418 + var canvas = $('#' + id + ' canvas');
559 419 var win = window.open();
560 420 win.document.write("<br><img src='" + canvas[0].toDataURL() + "'/>");
561 421 win.document.close();
562 422 win.onload = function () { win.print(); setTimeout(win.close, 500); };
563 - break;
564 - case 'image':
565 - var img = canvas[0].toDataURL();
566 - if(img !== ''){
567 - var $a = $("<a>"); // jshint ignore:line
568 - $a.attr("href", img);
569 - $("body").append($a);
570 - $a.attr("download", v.dataObj.name);
571 - $a[0].click();
572 - $a.remove();
573 - }else{
574 - console.warn("No image generated");
575 - }
576 423 break;
577 424 }
578 425 });
579 426