PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.2.0
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.2.0
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 +24 -106 3.10.153.2.0 View file →
@@ -5,18 +5,10 @@
5 5 var all_charts;
6 6 // so that we know which charts belong to our library.
7 7 var rendered_charts = [];
8 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 -
12 9 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);
10 + renderSpecificChart(id, all_charts[id], v);
19 11 }
20 12
21 13 function renderSpecificChart(id, chart, v) {
22 14 var render, container, series, data, table, settings, i, j, row, date, axis, property, format, formatter, type, rows, cols;
@@ -36,8 +28,9 @@
36 28
37 29 if($('#' + id).find('table.visualizer-data-table').length > 0){
38 30 $('#' + id).empty();
39 31 }
32 + $('#' + id).append($('<table class="dataTable visualizer-data-table table table-striped"></table>'));
40 33
41 34 settings = {
42 35 destroy: true,
43 36 paging: false,
@@ -54,53 +47,25 @@
54 47 },
55 48 dom: 'Bfrtip',
56 49 };
57 50
58 - var $classes = 'dataTable visualizer-data-table table table-striped';
59 -
60 51 if(typeof v.page_type !== 'undefined'){
61 52 switch(v.page_type){
62 53 case 'post':
63 - // fall-through.
64 54 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, {
55 + $.extend( settings, {
71 56 scrollX: 150,
72 - scrollY: (( chart.settings['responsive_bool'] === 'true' ? 0.8 : 0.5 ) * parseInt($(container).css('height').replace('px',''))),
57 + scrollY: 180,
73 58 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 - }
59 + } );
85 60 break;
61 + case 'frontend':
86 62 case 'chart':
87 - delete chart.settings['scrollX']; // jshint ignore:line
88 - // fall-through.
89 - case 'frontend':
90 63 // empty.
91 64 break;
92 65 }
93 66 }
94 67
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 68 var select = {
104 69 info: false
105 70 };
106 71 // we cannot use { select } below because https://github.com/Codeinwp/visualizer/issues/357
@@ -107,15 +72,10 @@
107 72 $.extend( settings, { info: false } ); // jshint ignore:line
108 73
109 74 var stripe = ['', ''];
110 75
111 - if(cssClassNames !== null){
112 - chart.settings['cssClassNames'] = cssClassNames;
113 - }
114 -
115 76 // in preview mode, cssClassNames will not exist when a color is changed.
116 77 if(typeof chart.settings['cssClassNames'] !== 'undefined'){
117 - cssClassNames = chart.settings['cssClassNames'];
118 78 if(typeof chart.settings['cssClassNames']['oddTableRow'] !== 'undefined'){
119 79 stripe[0] = chart.settings['cssClassNames']['oddTableRow'];
120 80 }
121 81
@@ -129,12 +89,8 @@
129 89 } );
130 90 }
131 91 }
132 92
133 - // remove this so that the eval does not fail.
134 - delete chart.settings['internal_title'];
135 -
136 - var additional = [];
137 93 for (i in chart.settings) {
138 94 var valoo = chart.settings[i];
139 95
140 96 // remove the type suffix to get the name of the setting.
@@ -150,11 +106,8 @@
150 106 default:
151 107 if(parseInt(valoo) > 0){
152 108 valoo = parseInt(valoo);
153 109 }
154 - if(i === 'pageLength' && (valoo === '' || parseInt(valoo) < 0)){
155 - valoo = 1;
156 - }
157 110 }
158 111
159 112 // if the setting name has an '_' this means it is a sub-setting e.g. select_items means { select: { items: ... } }.
160 113 var array = i.split('_');
@@ -160,19 +113,14 @@
160 113 var array = i.split('_');
161 114 if(array.length === 2){
162 115 i = eval( array[0] ); // jshint ignore:line
163 116 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 117 }
118 + settings[i] = valoo;
172 119 }
173 - $.extend( settings, additional );
174 120
121 + $.extend( $.fn.dataTable.defaults, settings );
122 +
175 123 cols = [];
176 124 for (j = 0; j < series.length; j++) {
177 125 type = series[j].type;
178 126 switch(type){
@@ -184,8 +132,9 @@
184 132 case 'timeofday':
185 133 type = 'date';
186 134 break;
187 135 }
136 +
188 137 render = addRenderer(series[j].type, settings.series, j);
189 138
190 139 var col = { title: series[j].label, data: series[j].label, type: type, render: render };
191 140 if(typeof chart.settings['cssClassNames'] !== 'undefined' && typeof chart.settings['cssClassNames']['tableCell'] !== 'undefined'){
@@ -198,36 +147,22 @@
198 147 for (i = 0; i < data.length; i++) {
199 148 row = [];
200 149 for (j = 0; j < series.length; j++) {
201 150 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 151 row[ series[j].label ] = datum;
207 152 }
208 153 rows.push(row);
209 154 }
210 155
211 - $.extend( settings, {
156 + // allow user to extend the settings.
157 + $('body').trigger('visualizer:chart:settings:extend', {id: id, chart: chart, settings: settings});
158 +
159 + table = $('#' + id + ' table.visualizer-data-table');
160 + table.DataTable( {
212 161 data: rows,
213 162 columns: cols,
214 163 stripeClasses: stripe,
215 164 } );
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 165 $('.loader').remove();
231 166 }
232 167
233 168 function addRenderer(type, series, index){
@@ -246,13 +181,10 @@
246 181 parts[0] = series.format.thousands;
247 182 }
248 183 if(typeof series.format.decimal !== ''){
249 184 parts[1] = series.format.decimal;
250 - if ( '' === series.format.precision ) {
251 - series.format.precision = 2;
252 - }
253 185 }
254 - if(typeof series.format.precision !== '' && parseInt(series.format.precision) > 0){
186 + if(typeof series.format.precision !== ''){
255 187 parts[2] = series.format.precision;
256 188 }
257 189 if(typeof series.format.prefix !== ''){
258 190 parts[3] = series.format.prefix;
@@ -268,21 +200,10 @@
268 200 if(typeof series.format.to !== 'undefined' && typeof series.format.from !== 'undefined' && series.format.from != '' && series.format.to !== ''){
269 201 render = $.fn.dataTable.render.moment(series.format.from, series.format.to);
270 202 }
271 203 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 204 }
283 205 /* jshint ignore:end */
284 -
285 206 return render;
286 207 }
287 208
288 209 function render(v) {
@@ -290,25 +211,22 @@
290 211 renderChart(id, v);
291 212 }
292 213 }
293 214
215 + if(typeof visualizer !== 'undefined'){
216 + // called while updating the chart.
217 + visualizer.update = function(){
218 + renderChart('canvas', visualizer);
219 + };
220 + }
221 +
294 222 $('body').on('visualizer:render:chart:start', function(event, v){
295 223 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 - }
224 + render(v);
302 225 });
303 226
304 227 $('body').on('visualizer:render:specificchart:start', function(event, v){
305 228 renderSpecificChart(v.id, v.chart, v.v);
306 - });
307 -
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 229 });
312 230
313 231 // front end actions
314 232 $('body').on('visualizer:action:specificchart', function(event, v){