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