Skip to content

Commit 0893e63

Browse files
add support for boolean data type in table charts
1 parent fb3bfce commit 0893e63

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

classes/Visualizer/Render/Sidebar/Type/DataTable/DataTable.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,22 @@ protected function _renderFormatField( $index = 0 ) {
477477
'YYYY-MM-DD'
478478
);
479479
break;
480+
case 'boolean':
481+
self::_renderTextItem(
482+
esc_html__( 'Truthy value', 'visualizer' ),
483+
'series[' . $index . '][format][truthy]',
484+
isset( $this->series[ $index ]['format']['truthy'] ) ? $this->series[ $index ]['format']['truthy'] : '',
485+
sprintf( esc_html__( 'Provide the ASCII/HTML entity code for the value the table should display when the value of the column is true. e.g. %1$s (Code: %2$s) instead of true', 'visualizer' ), '✔', '✔' ),
486+
''
487+
);
488+
self::_renderTextItem(
489+
esc_html__( 'Falsy value', 'visualizer' ),
490+
'series[' . $index . '][format][falsy]',
491+
isset( $this->series[ $index ]['format']['falsy'] ) ? $this->series[ $index ]['format']['falsy'] : '',
492+
sprintf( esc_html__( 'Provide the ASCII/HTML entity code for the value the table should display when the value of the column is false. e.g. %1$s (Code: %2$s) instead of true', 'visualizer' ), '✖', '✖' ),
493+
''
494+
);
495+
break;
480496
}
481497
}
482498

classes/Visualizer/Source.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@ protected function _normalizeData( $data ) {
215215
$data[ $i ] = ( is_numeric( $data[ $i ] ) ) ? floatval( $data[ $i ] ) : ( is_numeric( str_replace( ',', '', $data[ $i ] ) ) ? floatval( str_replace( ',', '', $data[ $i ] ) ) : null );
216216
break;
217217
case 'boolean':
218-
error_log("aaya ");
219218
$datum = trim( strval( $data[ $i ] ) );
220219
$data[ $i ] = in_array( $datum, array( 'true', 'yes', '1' ), true ) ? 'true' : 'false';
221220
break;
@@ -244,8 +243,6 @@ protected function _normalizeData( $data ) {
244243
}
245244
}
246245

247-
error_log("gaya " . print_r($data,true));
248-
249246
return apply_filters( 'visualizer_format_data', $data, $this->_series );
250247
}
251248

js/render-datatables.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
series = chart.series;
3030
data = chart.data;
3131

32-
console.log(series);
33-
3432
container = document.getElementById(id);
3533
if (container == null) {
3634
return;
@@ -175,7 +173,6 @@
175173
$.extend( settings, additional );
176174

177175
cols = [];
178-
console.log(series);
179176
for (j = 0; j < series.length; j++) {
180177
type = series[j].type;
181178
switch(type){
@@ -188,7 +185,6 @@
188185
type = 'date';
189186
break;
190187
}
191-
192188
render = addRenderer(series[j].type, settings.series, j);
193189

194190
var col = { title: series[j].label, data: series[j].label, type: type, render: render };
@@ -222,7 +218,6 @@
222218
$('body').trigger('visualizer:chart:settings:extend', {id: id, chart: chart, settings: settings});
223219

224220
table = $('#' + id + ' table.visualizer-data-table');
225-
console.log("showing table");
226221
table.DataTable( settings );
227222

228223
// header row is handled here as the class is added dynamically to it (after the table is rendered).
@@ -272,15 +267,18 @@
272267
}
273268
break;
274269
default:
275-
console.log("yahan aaya");
276-
render = $.fn.dataTable.render.extra = function ( from, to, locale ) {
277-
console.log("andar aaya");
278-
return from;
279-
}
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;
273+
}
274+
if((data === false || data === 'false') && typeof series.format !== 'undefined' && series.format.falsy !== ''){
275+
data = series.format.falsy;
276+
}
277+
return data;
278+
}
280279
}
281280
/* jshint ignore:end */
282281

283-
284282
return render;
285283
}
286284

0 commit comments

Comments
 (0)