PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.4.8
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.4.8
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-chartjs.js +29 -157 4.0.33.4.8 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 });
@@ -205,8 +154,12 @@
205 154 if(typeof settings['animation'] !== 'undefined' && parseInt(settings['animation']['duration']) === 0){
206 155 settings['animation']['duration'] = 1000;
207 156 }
208 157
158 + if(typeof settings['title'] !== 'undefined' && settings['title']['text'] !== ''){
159 + settings['title']['display'] = true;
160 + }
161 +
209 162 if(typeof settings['tooltip'] !== 'undefined' && typeof settings['tooltip']['intersect'] !== 'undefined'){
210 163 // jshint ignore:line
211 164 settings['tooltip']['intersect'] = settings['tooltip']['intersect'] == true || parseInt(settings['tooltip']['intersect']) === 1; // jshint ignore:line
212 165 }
@@ -211,14 +164,14 @@
211 164 settings['tooltip']['intersect'] = settings['tooltip']['intersect'] == true || parseInt(settings['tooltip']['intersect']) === 1; // jshint ignore:line
212 165 }
213 166
214 167 if(typeof settings['fontName'] !== 'undefined' && settings['fontName'] !== ''){
215 - Chart.defaults.font.family = settings['fontName'];
168 + Chart.defaults.global.defaultFontFamily = settings['fontName'];
216 169 delete settings['fontName'];
217 170 }
218 171
219 172 if(typeof settings['fontSize'] !== 'undefined' && settings['fontSize'] !== ''){
220 - Chart.defaults.font.size = parseInt(settings['fontSize']);
173 + Chart.defaults.global.defaultFontSize = settings['fontSize'];
221 174 delete settings['fontSize'];
222 175 }
223 176
224 177 // handle legend defaults.
@@ -229,19 +182,11 @@
229 182 }
230 183 }
231 184 }
232 185
233 - settings.plugins = {
234 - legend: settings.legend,
235 - };
186 + handleAxes(settings, chart);
236 187
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);
188 + override(settings, chart);
244 189 }
245 190
246 191 function handleAxes(settings, chart){
247 192 if(typeof settings['yAxes'] !== 'undefined' && typeof settings['xAxes'] !== 'undefined'){
@@ -246,27 +191,13 @@
246 191 function handleAxes(settings, chart){
247 192 if(typeof settings['yAxes'] !== 'undefined' && typeof settings['xAxes'] !== 'undefined'){
248 193 // stacking has to be defined on both axes.
249 194 if(typeof settings['yAxes']['stacked_bool'] !== 'undefined'){
250 - settings['yAxes']['stacked_bool'] = 'true';
195 + settings['xAxes']['stacked_bool'] = 'true';
251 196 }
252 197 if(typeof settings['xAxes']['stacked_bool'] !== 'undefined'){
253 - settings['xAxes']['stacked_bool'] = 'true';
198 + settings['yAxes']['stacked_bool'] = 'true';
254 199 }
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 200 }
270 201 configureAxes(settings, 'yAxes', chart);
271 202 configureAxes(settings, 'xAxes', chart);
272 203 }
@@ -278,9 +209,9 @@
278 209 var $o = {};
279 210 if(Array.isArray(settings[axis][i]) || typeof settings[axis][i] === 'object'){
280 211 for(var j in settings[axis][i]){
281 212 var $val = '';
282 - if(j === 'labelString'){
213 + if(j === 'labelString'){
283 214 $o['display'] = true;
284 215 $val = settings[axis][i][j];
285 216 }else if(i === 'ticks'){
286 217 // number values under ticks need to be converted to numbers or the library throws a JS error.
@@ -335,56 +266,8 @@
335 266 }
336 267 var $axis = $scales['scales'][axis];
337 268
338 269 $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 270 $.extend(settings, $scales);
388 271
389 272 // to prevent duplication, indicates that the axis has been set.
390 273 var $custom = {};
@@ -394,24 +277,21 @@
394 277
395 278 // format the axes labels.
396 279 if(typeof settings[axis + '_format'] !== 'undefined' && settings[axis + '_format'] !== ''){
397 280 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 - }
281 + switch(axis){
282 + case 'xAxes':
283 + settings.scales.xAxes[0].ticks.callback = function(value, index, values){
284 + return format_datum(value, format);
285 + };
286 + break;
287 + case 'yAxes':
288 + settings.scales.yAxes[0].ticks.callback = function(value, index, values){
289 + return format_datum(value, format);
290 + };
291 + break;
292 + }
293 + delete settings[axis + '_format'];
414 294 }
415 295 delete settings[axis];
416 296 }
417 297
@@ -448,11 +328,8 @@
448 328 return;
449 329 }
450 330 for(var i in settings.series[j]){
451 331 var $attribute = {};
452 - if ( settings.series[j].backgroundColor == '' ) {
453 - delete settings.series[j].backgroundColor;
454 - }
455 332 $attribute[i] = settings.series[j][i];
456 333 $.extend($attributes, $attribute);
457 334 }
458 335 }
@@ -474,9 +351,9 @@
474 351
475 352 switch(type) {
476 353 case 'number':
477 354 // 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, '');
355 + format = format.replace(/#/g, '0');
479 356 // we also replace all instance of '$' as that is more relevant for ticks.
480 357 if(removeDollar){
481 358 format = format.replace(/\$/g, '');
482 359 }
@@ -493,13 +370,8 @@
493 370
494 371 function format_data(datum, j, settings, series){
495 372 j = j - 1;
496 373 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 374 return format_datum(datum, format, series[j + 1].type);
503 375 }
504 376
505 377 function override(settings, chart) {
@@ -505,9 +377,9 @@
505 377 function override(settings, chart) {
506 378 if (settings.manual) {
507 379 try{
508 380 var options = JSON.parse(settings.manual);
509 - $.extend(true, settings, options);
381 + $.extend(settings, options);
510 382 delete settings.manual;
511 383 }catch(error){
512 384 console.error("Error while adding manual configuration override " + settings.manual);
513 385 }