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 +35 -180 3.10.23.3.4 View file →
@@ -46,10 +46,9 @@
46 46 case 'column':
47 47 type = 'bar';
48 48 break;
49 49 case 'bar':
50 - type = 'bar';
51 - settings.indexAxis = 'y';
50 + type = 'horizontalBar';
52 51 break;
53 52 case 'pie':
54 53 // donut is not a setting but a separate chart type.
55 54 if(typeof settings['custom'] !== 'undefined' && settings['custom']['donut'] === 'true'){
@@ -64,9 +63,9 @@
64 63
65 64 for (i = 0; i < data.length; i++) {
66 65 row = [];
67 66 for (j = 0; j < series.length; j++) {
68 - if (series[j].type === 'date' || series[j].type === 'datetime') {
67 + if (series[j].type === 'date' || series[j].type === 'datetime') {
69 68 date = new Date(data[i][j]);
70 69 data[i][j] = null;
71 70 if (Object.prototype.toString.call(date) === "[object Date]") {
72 71 if (!isNaN(date.getTime())) {
@@ -112,42 +111,8 @@
112 111 }
113 112
114 113 handleSettings(settings, chart);
115 114
116 - const getChart = Chart.getChart(context);
117 - if ( getChart ) {
118 - return;
119 - }
120 -
121 - // Format series label.
122 - settings.plugins.tooltip = {
123 - callbacks: {
124 - label: function(context) {
125 - var label = '';
126 - if ( 'object' === typeof context.dataset.label ) {
127 - label = context.label || '';
128 - } else {
129 - label = context.dataset.label || '';
130 - }
131 - if ( label ) {
132 - label += ': ';
133 - }
134 - var format = context.dataset.format || '';
135 - if ( format ) {
136 - label += format_datum( context.formattedValue, format );
137 - } else {
138 - format = 'undefined' !== typeof context.chart.config._config.options.format ? context.chart.config._config.options.format : '';
139 - if ( format ) {
140 - label += format_datum( context.formattedValue, format );
141 - } else {
142 - label += context.formattedValue;
143 - }
144 - }
145 - return label;
146 - }
147 - }
148 - };
149 -
150 115 var chartjs = new Chart(context, {
151 116 type: type,
152 117 data: {
153 118 labels: labels,
@@ -152,17 +117,9 @@
152 117 data: {
153 118 labels: labels,
154 119 datasets: datasets
155 120 },
156 - options: settings,
157 - plugins: [{
158 - afterRender: function () {
159 - var canvas = $( 'canvas' )[0];
160 - if ( $( '#chart-img' ).length ) {
161 - $( '#chart-img' ).val( canvas.toDataURL() );
162 - }
163 - }
164 - }],
121 + options: settings
165 122 });
166 123
167 124 // this line needs to be included twice. This is not an error.
168 125 $.extend(settings, { responsive: true, maintainAspectRatio: false });
@@ -169,18 +126,10 @@
169 126
170 127 // chart area
171 128 if(v.is_front == true){ // jshint ignore:line
172 129 $('#' + id).css('position', 'relative');
173 - var height = settings.height.indexOf('%') === -1 ? ( settings.height + 'px' ) : settings.height;
174 - var width = settings.width.indexOf('%') === -1 ? ( settings.width + 'px' ) : settings.width;
175 - if(settings.height){
176 - chartjs.canvas.parentNode.style.height = height;
177 - $('#' + id + ' canvas').css('height', height);
178 - }
179 - if(settings.width){
180 - chartjs.canvas.parentNode.style.width = width;
181 - $('#' + id + ' canvas').css('width', width);
182 - }
130 + chartjs.canvas.parentNode.style.height = settings.height;
131 + chartjs.canvas.parentNode.style.width = settings.width;
183 132 }
184 133
185 134 // allow user to extend the settings.
186 135 $('body').trigger('visualizer:chart:settings:extend', {id: id, chart: chart, settings: settings});
@@ -207,14 +156,14 @@
207 156 settings['tooltip']['intersect'] = settings['tooltip']['intersect'] == true || parseInt(settings['tooltip']['intersect']) === 1; // jshint ignore:line
208 157 }
209 158
210 159 if(typeof settings['fontName'] !== 'undefined' && settings['fontName'] !== ''){
211 - Chart.defaults.font.family = settings['fontName'];
160 + Chart.defaults.global.defaultFontFamily = settings['fontName'];
212 161 delete settings['fontName'];
213 162 }
214 163
215 164 if(typeof settings['fontSize'] !== 'undefined' && settings['fontSize'] !== ''){
216 - Chart.defaults.font.size = parseInt(settings['fontSize']);
165 + Chart.defaults.global.defaultFontSize = settings['fontSize'];
217 166 delete settings['fontSize'];
218 167 }
219 168
220 169 // handle legend defaults.
@@ -225,12 +174,8 @@
225 174 }
226 175 }
227 176 }
228 177
229 - settings.plugins = {
230 - legend: settings.legend,
231 - };
232 -
233 178 handleAxes(settings, chart);
234 179
235 180 override(settings, chart);
236 181 }
@@ -238,27 +183,13 @@
238 183 function handleAxes(settings, chart){
239 184 if(typeof settings['yAxes'] !== 'undefined' && typeof settings['xAxes'] !== 'undefined'){
240 185 // stacking has to be defined on both axes.
241 186 if(typeof settings['yAxes']['stacked_bool'] !== 'undefined'){
242 - settings['yAxes']['stacked_bool'] = 'true';
187 + settings['xAxes']['stacked_bool'] = 'true';
243 188 }
244 189 if(typeof settings['xAxes']['stacked_bool'] !== 'undefined'){
245 - settings['xAxes']['stacked_bool'] = 'true';
190 + settings['yAxes']['stacked_bool'] = 'true';
246 191 }
247 - // Bar percentage.
248 - if (typeof settings['yAxes']['barPercentage_int'] !=='undefined' && ''!== settings['yAxes']['barPercentage_int']){
249 - settings['barPercentage'] = settings['yAxes']['barPercentage_int'];
250 - }
251 - if (typeof settings['xAxes']['barPercentage_int'] !=='undefined' && ''!== settings['xAxes']['barPercentage_int']){
252 - settings['barPercentage'] = settings['xAxes']['barPercentage_int'];
253 - }
254 - // Bar thickness.
255 - if (typeof settings['yAxes']['barThickness'] !=='undefined' && ''!== settings['yAxes']['barThickness']){
256 - settings['barThickness'] = settings['yAxes']['barThickness'];
257 - }
258 - if (typeof settings['xAxes']['barThickness'] !=='undefined' && ''!== settings['xAxes']['barThickness']){
259 - settings['barThickness'] = settings['xAxes']['barThickness'];
260 - }
261 192 }
262 193 configureAxes(settings, 'yAxes', chart);
263 194 configureAxes(settings, 'xAxes', chart);
264 195 }
@@ -327,56 +258,8 @@
327 258 }
328 259 var $axis = $scales['scales'][axis];
329 260
330 261 $axis.push($features);
331 - // Migrate xAxes settings to v3.0+
332 - if ( $scales.scales && $scales.scales.xAxes ) {
333 - for (var x in $scales.scales.xAxes) {
334 - $scales.scales.x = {
335 - display: $scales.scales.xAxes[x].scaleLabel.display,
336 - title: {
337 - display:true,
338 - text: $scales.scales.xAxes[x].scaleLabel.labelString,
339 - color: $scales.scales.xAxes[x].scaleLabel.fontColor,
340 - font: {
341 - family: $scales.scales.xAxes[x].scaleLabel.fontFamily,
342 - size: $scales.scales.xAxes[x].scaleLabel.fontSize
343 - }
344 - },
345 - suggestedMax: $scales.scales.xAxes[x].ticks.suggestedMax || '',
346 - suggestedMin: $scales.scales.xAxes[x].ticks.suggestedMin || '',
347 - ticks: {
348 - maxTicksLimit: $scales.scales.xAxes[x].ticks.maxTicksLimit
349 - },
350 - stacked: $scales.scales.xAxes[x].stacked || false
351 - }
352 - }
353 - delete $scales.scales.xAxes;
354 - }
355 - // Migrate yAxes settings to v3.0+
356 - if ( $scales.scales && $scales.scales.yAxes ) {
357 - for (var y in $scales.scales.yAxes) {
358 - $scales.scales.y = {
359 - display: $scales.scales.yAxes[y].scaleLabel.display,
360 - title: {
361 - display:true,
362 - text: $scales.scales.yAxes[y].scaleLabel.labelString,
363 - color: $scales.scales.yAxes[y].scaleLabel.fontColor,
364 - font: {
365 - family: $scales.scales.yAxes[y].scaleLabel.fontFamily,
366 - size: $scales.scales.yAxes[y].scaleLabel.fontSize
367 - }
368 - },
369 - suggestedMax: $scales.scales.yAxes[y].ticks.suggestedMax || '',
370 - suggestedMin: $scales.scales.yAxes[y].ticks.suggestedMin || '',
371 - ticks: {
372 - maxTicksLimit: $scales.scales.yAxes[y].ticks.maxTicksLimit
373 - },
374 - stacked: $scales.scales.yAxes[y].stacked || false
375 - }
376 - }
377 - delete $scales.scales.yAxes;
378 - }
379 262 $.extend(settings, $scales);
380 263
381 264 // to prevent duplication, indicates that the axis has been set.
382 265 var $custom = {};
@@ -386,24 +269,21 @@
386 269
387 270 // format the axes labels.
388 271 if(typeof settings[axis + '_format'] !== 'undefined' && settings[axis + '_format'] !== ''){
389 272 var format = settings[axis + '_format'];
390 - var isDateFormat = moment( moment().format( format ),format, true ).isValid();
391 - if ( ! isDateFormat ) {
392 - switch(axis){
393 - case 'xAxes':
394 - settings.scales.x.ticks.callback = function(value, index, values){
395 - return format_datum(value, format);
396 - };
397 - break;
398 - case 'yAxes':
399 - settings.scales.y.ticks.callback = function(value, index, values){
400 - return format_datum(value, format);
401 - };
402 - break;
403 - }
404 - delete settings[axis + '_format'];
405 - }
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'];
406 286 }
407 287 delete settings[axis];
408 288 }
409 289
@@ -440,11 +320,8 @@
440 320 return;
441 321 }
442 322 for(var i in settings.series[j]){
443 323 var $attribute = {};
444 - if ( settings.series[j].backgroundColor == '' ) {
445 - delete settings.series[j].backgroundColor;
446 - }
447 324 $attribute[i] = settings.series[j][i];
448 325 $.extend($attributes, $attribute);
449 326 }
450 327 }
@@ -485,13 +362,8 @@
485 362
486 363 function format_data(datum, j, settings, series){
487 364 j = j - 1;
488 365 var format = typeof settings.series !== 'undefined' && typeof settings.series[j] !== 'undefined' ? settings.series[j].format : '';
489 - if ( '' === format && typeof settings.yAxes_format !== 'undefined' ) {
490 - format = settings.yAxes_format;
491 - } else if ( '' === format && typeof settings.xAxes_format !== 'undefined' ) {
492 - format = settings.xAxes_format;
493 - }
494 366 return format_datum(datum, format, series[j + 1].type);
495 367 }
496 368
497 369 function override(settings, chart) {
@@ -512,17 +384,19 @@
512 384 renderChart(id, v);
513 385 }
514 386 }
515 387
388 + if(typeof visualizer !== 'undefined'){
389 + // called while updating the chart.
390 + visualizer.update = function(){
391 + renderChart('canvas', visualizer);
392 + };
393 + }
394 +
516 395 $('body').on('visualizer:render:chart:start', function(event, v){
517 396 all_charts = v.charts;
397 + render(v);
518 398
519 - if(v.is_front == true && typeof v.id !== 'undefined'){ // jshint ignore:line
520 - renderChart(v.id, v);
521 - } else {
522 - render(v);
523 - }
524 -
525 399 // for some reason this needs to be introduced here for dynamic preview updates to work.
526 400 v.update = function(){
527 401 renderChart('canvas', v);
528 402 };
@@ -532,40 +406,21 @@
532 406 $('body').on('visualizer:render:specificchart:start', function(event, v){
533 407 renderSpecificChart(v.id, v.chart, v.v);
534 408 });
535 409
536 - $('body').on('visualizer:render:currentchart:update', function(event, v){
537 - var data = v || event.detail;
538 - renderChart('canvas', data.visualizer);
539 - });
540 -
541 410 // front end actions
542 - // 'image' is also called from the library
543 411 $('body').on('visualizer:action:specificchart', function(event, v){
544 - var id = v.id;
545 - if(typeof rendered_charts[id] === 'undefined'){
546 - return;
547 - }
548 - var canvas = $('#' + id + ' canvas');
549 412 switch(v.action){
550 413 case 'print':
414 + var id = v.id;
415 + if(typeof rendered_charts[id] === 'undefined'){
416 + return;
417 + }
418 + var canvas = $('#' + id + ' canvas');
551 419 var win = window.open();
552 420 win.document.write("<br><img src='" + canvas[0].toDataURL() + "'/>");
553 421 win.document.close();
554 422 win.onload = function () { win.print(); setTimeout(win.close, 500); };
555 - break;
556 - case 'image':
557 - var img = canvas[0].toDataURL();
558 - if(img !== ''){
559 - var $a = $("<a>"); // jshint ignore:line
560 - $a.attr("href", img);
561 - $("body").append($a);
562 - $a.attr("download", v.dataObj.name);
563 - $a[0].click();
564 - $a.remove();
565 - }else{
566 - console.warn("No image generated");
567 - }
568 423 break;
569 424 }
570 425 });
571 426