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-datatables.js +128 -25 3.1.13.6.1 View file →
@@ -2,11 +2,21 @@
2 2 /* global visualizer */
3 3
4 4 (function($) {
5 5 var all_charts;
6 + // so that we know which charts belong to our library.
7 + var rendered_charts = [];
6 8
9 + // save the settings corresponding to cssClassNames so that when a table is being edited, they stripes etc. don't get reset
10 + var cssClassNames;
11 +
7 12 function renderChart(id, v) {
8 - renderSpecificChart(id, all_charts[id], v);
13 + var chart = all_charts[id];
14 + if(chart.library !== 'datatables'){
15 + return;
16 + }
17 + cssClassNames = null;
18 + renderSpecificChart(id, chart, v);
9 19 }
10 20
11 21 function renderSpecificChart(id, chart, v) {
12 22 var render, container, series, data, table, settings, i, j, row, date, axis, property, format, formatter, type, rows, cols;
@@ -13,8 +23,9 @@
13 23
14 24 if(chart.library !== 'datatables'){
15 25 return;
16 26 }
27 + rendered_charts[id] = 'yes';
17 28
18 29 series = chart.series;
19 30 data = chart.data;
20 31
@@ -25,9 +36,8 @@
25 36
26 37 if($('#' + id).find('table.visualizer-data-table').length > 0){
27 38 $('#' + id).empty();
28 39 }
29 - $('#' + id).append($('<table class="dataTable visualizer-data-table table table-striped"></table>'));
30 40
31 41 settings = {
32 42 destroy: true,
33 43 paging: false,
@@ -34,36 +44,78 @@
34 44 searching: false,
35 45 ordering: true,
36 46 select: false,
37 47 lengthChange: false,
48 + buttons: {
49 + buttons: [{
50 + extend: 'print',
51 + text: '',
52 + title: ''
53 + }]
54 + },
55 + dom: 'Bfrtip',
38 56 };
39 57
58 + var $classes = 'dataTable visualizer-data-table table table-striped';
59 +
40 60 if(typeof v.page_type !== 'undefined'){
41 61 switch(v.page_type){
42 62 case 'post':
63 + // fall-through.
43 64 case 'library':
44 - $.extend( settings, {
65 + // for smaller screens...
66 + if(window.innerWidth < 1500){
67 + delete chart.settings['scrollX'];
68 + delete chart.settings['scrollY'];
69 + delete chart.settings['scrollY_int'];
70 + $.extend( settings, {
45 71 scrollX: 150,
72 + scrollY: (( chart.settings['responsive_bool'] === 'true' ? 0.8 : 0.5 ) * parseInt($(container).css('height').replace('px',''))),
73 + scrollCollapse: true
74 + } );
75 + }else{
76 + if(parseInt(chart.settings['scrollY_int']) > 180){
77 + chart.settings['scrollY_int'];
78 + }
79 + delete chart.settings['scrollX'];
80 + $.extend( settings, {
81 + scrollX: 150,
46 82 scrollY: 180,
47 - scrollCollapse: true
48 - } );
83 + } );
84 + }
49 85 break;
86 + case 'chart':
87 + delete chart.settings['scrollX']; // jshint ignore:line
88 + // fall-through.
50 89 case 'frontend':
51 - case 'chart':
52 90 // empty.
53 91 break;
54 92 }
55 93 }
56 94
95 + if(typeof chart.settings['scrollX'] !== 'undefined'){
96 + if(chart.settings['scrollX'] == 'true'){ // jshint ignore:line
97 + $classes = $classes + ' nowrap';
98 + }
99 + }
100 +
101 + $('#' + id).append($('<table class="' + $classes + '"></table>'));
102 +
57 103 var select = {
58 104 info: false
59 105 };
60 - $.extend( settings, { select } ); // jshint ignore:line
106 + // we cannot use { select } below because https://github.com/Codeinwp/visualizer/issues/357
107 + $.extend( settings, { info: false } ); // jshint ignore:line
61 108
62 109 var stripe = ['', ''];
63 110
111 + if(cssClassNames !== null){
112 + chart.settings['cssClassNames'] = cssClassNames;
113 + }
114 +
64 115 // in preview mode, cssClassNames will not exist when a color is changed.
65 116 if(typeof chart.settings['cssClassNames'] !== 'undefined'){
117 + cssClassNames = chart.settings['cssClassNames'];
66 118 if(typeof chart.settings['cssClassNames']['oddTableRow'] !== 'undefined'){
67 119 stripe[0] = chart.settings['cssClassNames']['oddTableRow'];
68 120 }
69 121
@@ -77,8 +129,12 @@
77 129 } );
78 130 }
79 131 }
80 132
133 + // remove this so that the eval does not fail.
134 + delete chart.settings['internal_title'];
135 +
136 + var additional = [];
81 137 for (i in chart.settings) {
82 138 var valoo = chart.settings[i];
83 139
84 140 // remove the type suffix to get the name of the setting.
@@ -94,8 +150,11 @@
94 150 default:
95 151 if(parseInt(valoo) > 0){
96 152 valoo = parseInt(valoo);
97 153 }
154 + if(i === 'pageLength' && (valoo === '' || parseInt(valoo) < 0)){
155 + valoo = 1;
156 + }
98 157 }
99 158
100 159 // if the setting name has an '_' this means it is a sub-setting e.g. select_items means { select: { items: ... } }.
101 160 var array = i.split('_');
@@ -101,14 +160,19 @@
101 160 var array = i.split('_');
102 161 if(array.length === 2){
103 162 i = eval( array[0] ); // jshint ignore:line
104 163 i[ array[1] ] = valoo;
164 + additional[ array[0] ] = i;
165 + if(array[0] === 'select' && array[1] === 'info' ){
166 + // enable main info or the selection info will not show.
167 + $.extend( settings, {info: true} );
168 + }
169 + } else {
170 + settings[i] = valoo;
105 171 }
106 - settings[i] = valoo;
107 172 }
173 + $.extend( settings, additional );
108 174
109 - $.extend( $.fn.dataTable.defaults, settings );
110 -
111 175 cols = [];
112 176 for (j = 0; j < series.length; j++) {
113 177 type = series[j].type;
114 178 switch(type){
@@ -120,9 +184,8 @@
120 184 case 'timeofday':
121 185 type = 'date';
122 186 break;
123 187 }
124 -
125 188 render = addRenderer(series[j].type, settings.series, j);
126 189
127 190 var col = { title: series[j].label, data: series[j].label, type: type, render: render };
128 191 if(typeof chart.settings['cssClassNames'] !== 'undefined' && typeof chart.settings['cssClassNames']['tableCell'] !== 'undefined'){
@@ -135,22 +198,36 @@
135 198 for (i = 0; i < data.length; i++) {
136 199 row = [];
137 200 for (j = 0; j < series.length; j++) {
138 201 var datum = data[i][j];
202 + // datum could be undefined for dynamic data (e.g. through json).
203 + if(typeof datum === 'undefined'){
204 + datum = data[i][series[j].label];
205 + }
139 206 row[ series[j].label ] = datum;
140 207 }
141 208 rows.push(row);
142 209 }
143 210
211 + $.extend( settings, {
212 + data: rows,
213 + columns: cols,
214 + stripeClasses: stripe,
215 + } );
216 +
144 217 // allow user to extend the settings.
145 218 $('body').trigger('visualizer:chart:settings:extend', {id: id, chart: chart, settings: settings});
146 219
147 220 table = $('#' + id + ' table.visualizer-data-table');
148 - table.DataTable( {
149 - data: rows,
150 - columns: cols,
151 - stripeClasses: stripe,
152 - } );
221 + table.DataTable( settings );
222 +
223 + // header row is handled here as the class is added dynamically to it (after the table is rendered).
224 + if(typeof chart.settings['cssClassNames'] !== 'undefined'){
225 + if(typeof chart.settings['cssClassNames']['headerRow'] !== 'undefined'){
226 + $('#' + id + ' table thead tr').addClass( chart.settings['cssClassNames']['headerRow'] );
227 + }
228 + }
229 +
153 230 $('.loader').remove();
154 231 }
155 232
156 233 function addRenderer(type, series, index){
@@ -170,9 +247,9 @@
170 247 }
171 248 if(typeof series.format.decimal !== ''){
172 249 parts[1] = series.format.decimal;
173 250 }
174 - if(typeof series.format.precision !== ''){
251 + if(typeof series.format.precision !== '' && parseInt(series.format.precision) > 0){
175 252 parts[2] = series.format.precision;
176 253 }
177 254 if(typeof series.format.prefix !== ''){
178 255 parts[3] = series.format.prefix;
@@ -188,10 +265,21 @@
188 265 if(typeof series.format.to !== 'undefined' && typeof series.format.from !== 'undefined' && series.format.from != '' && series.format.to !== ''){
189 266 render = $.fn.dataTable.render.moment(series.format.from, series.format.to);
190 267 }
191 268 break;
269 + default:
270 + render = $.fn.dataTable.render.extra = function ( data, type, row ) {
271 + if((data === true || data === 'true') && typeof series.format !== 'undefined' && series.format.truthy !== ''){
272 + data = series.format.truthy.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '');
273 + }
274 + if((data === false || data === 'false') && typeof series.format !== 'undefined' && series.format.falsy !== ''){
275 + data = series.format.falsy.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '');
276 + }
277 + return data;
278 + }
192 279 }
193 280 /* jshint ignore:end */
281 +
194 282 return render;
195 283 }
196 284
197 285 function render(v) {
@@ -199,18 +287,16 @@
199 287 renderChart(id, v);
200 288 }
201 289 }
202 290
203 - if(typeof visualizer !== 'undefined'){
204 - // called while updating the chart.
205 - visualizer.update = function(){
206 - renderChart('canvas', visualizer);
207 - };
208 - }
209 -
210 291 $('body').on('visualizer:render:chart:start', function(event, v){
211 292 all_charts = v.charts;
212 - render(v);
293 +
294 + if(v.is_front == true && typeof v.id !== 'undefined'){ // jshint ignore:line
295 + renderChart(v.id, v);
296 + } else {
297 + render(v);
298 + }
213 299 });
214 300
215 301 $('body').on('visualizer:render:specificchart:start', function(event, v){
216 302 renderSpecificChart(v.id, v.chart, v.v);
@@ -215,8 +301,25 @@
215 301 $('body').on('visualizer:render:specificchart:start', function(event, v){
216 302 renderSpecificChart(v.id, v.chart, v.v);
217 303 });
218 304
305 + $('body').on('visualizer:render:currentchart:update', function(event, v){
306 + var data = v || event.detail;
307 + renderSpecificChart('canvas', all_charts['canvas'], data.visualizer);
308 + });
309 +
310 + // front end actions
311 + $('body').on('visualizer:action:specificchart', function(event, v){
312 + switch(v.action){
313 + case 'print':
314 + var id = v.id;
315 + if(typeof rendered_charts[id] === 'undefined'){
316 + return;
317 + }
318 + $('#' + id + ' .buttons-print').trigger('click');
319 + break;
320 + }
321 + });
219 322
220 323 })(jQuery);
221 324
222 325