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