Skip to content

Commit a46543f

Browse files
1 parent 07c5860 commit a46543f

File tree

5 files changed

+47
-45
lines changed

5 files changed

+47
-45
lines changed

classes/Visualizer/Gutenberg/build/block.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

classes/Visualizer/Gutenberg/src/Components/DataTable.js

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class DataTables extends Component {
6565
title: i.label,
6666
data: i.label,
6767
type: type,
68-
render: this.dataRenderer( data, type, index )
68+
render: this.dataRenderer( type, index )
6969
};
7070
});
7171

@@ -94,9 +94,9 @@ class DataTables extends Component {
9494
pagingType: settings.pagingType,
9595
ordering: 'false' === settings.ordering_bool ? false : true,
9696
fixedHeader: 'true' === settings.fixedHeader_bool ? true : false,
97-
scrollCollapse: this.props.chartsScreen && true || 'true' === settings.scrollCollapse_bool ? true : false,
97+
scrollCollapse: !! this.props.chartsScreen || 'true' === settings.scrollCollapse_bool ? true : false,
9898
scrollY: this.props.chartsScreen && 180 || ( 'true' === settings.scrollCollapse_bool && Number( settings.scrollY_int ) || false ),
99-
responsive: this.props.chartsScreen && true || 'true' === settings.responsive_bool ? true : false,
99+
responsive: !! this.props.chartsScreen || 'true' === settings.responsive_bool ? true : false,
100100
searching: false,
101101
select: false,
102102
lengthChange: false,
@@ -105,48 +105,47 @@ class DataTables extends Component {
105105
});
106106
}
107107

108-
dataRenderer( data, type, index ) {
108+
dataRenderer( type, index ) {
109109
const settings = this.props.options;
110110

111-
if ( undefined === settings.series[index]) {
112-
return data;
113-
}
114-
115-
if ( 'date' === type || 'datetime' === type || 'timeofday' === type ) {
116-
if ( settings.series[index].format && settings.series[index].format.from && settings.series[index].format.to ) {
117-
return jQuery.fn.dataTable.render.moment( settings.series[index].format.from, settings.series[index].format.to );
118-
}
119-
120-
return jQuery.fn.dataTable.render.moment( 'MM-DD-YYYY' );
121-
}
122-
123-
if ( 'num' === type ) {
124-
const parts = [ '', '', '', '', '' ];
125-
126-
if ( settings.series[index].format.thousands ) {
127-
parts[0] = settings.series[index].format.thousands;
128-
}
129-
130-
if ( settings.series[index].format.decimal ) {
131-
parts[1] = settings.series[index].format.decimal;
132-
}
133-
134-
if ( settings.series[index].format.precision ) {
135-
parts[2] = settings.series[index].format.precision;
136-
}
137-
138-
if ( settings.series[index].format.prefix ) {
139-
parts[3] = settings.series[index].format.prefix;
140-
}
141-
142-
if ( settings.series[index].format.suffix ) {
143-
parts[4] = settings.series[index].format.suffix;
144-
}
111+
let renderer = null;
112+
if ( 'undefined' === typeof settings.series[index] || 'undefined' === typeof settings.series[index].format ) {
113+
return renderer;
114+
}
115+
116+
switch ( type ) {
117+
case 'date':
118+
case 'datetime':
119+
case 'timeofday':
120+
if ( settings.series[index].format && settings.series[index].format.from && settings.series[index].format.to ) {
121+
renderer = jQuery.fn.dataTable.render.moment( settings.series[index].format.from, settings.series[index].format.to );
122+
} else {
123+
renderer = jQuery.fn.dataTable.render.moment( 'MM-DD-YYYY' );
124+
}
125+
break;
126+
case 'num':
127+
const parts = [ '', '', '', '', '' ];
145128

146-
return jQuery.fn.dataTable.render.number( ...parts );
147-
}
129+
if ( settings.series[index].format.thousands ) {
130+
parts[0] = settings.series[index].format.thousands;
131+
}
132+
if ( settings.series[index].format.decimal ) {
133+
parts[1] = settings.series[index].format.decimal;
134+
}
135+
if ( settings.series[index].format.precision && '0' != settings.series[index].format.precision ) {
136+
parts[2] = settings.series[index].format.precision;
137+
}
138+
if ( settings.series[index].format.prefix ) {
139+
parts[3] = settings.series[index].format.prefix;
140+
}
141+
if ( settings.series[index].format.suffix ) {
142+
parts[4] = settings.series[index].format.suffix;
143+
}
144+
renderer = jQuery.fn.dataTable.render.number( ...parts );
145+
break;
146+
}
148147

149-
return data;
148+
return renderer;
150149
}
151150

152151
render() {

classes/Visualizer/Gutenberg/src/Components/Sidebar/ColumnSettings.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ class ColumnSettings extends Component {
129129
help={ __( 'Round values to how many decimal places?' ) }
130130
value={ settings.series[i].format ? settings.series[i].format.precision : '' }
131131
type="number"
132+
min="0"
132133
onChange={ e => {
133134
if ( 100 < e ) {
134135
return;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,9 @@ protected function _renderFormatField( $index = 0 ) {
442442
'series[' . $index . '][format][precision]',
443443
isset( $this->series[ $index ]['format']['precision'] ) ? $this->series[ $index ]['format']['precision'] : '',
444444
esc_html__( 'Round values to how many decimal places?', 'visualizer' ),
445-
''
445+
'',
446+
'number',
447+
array( 'min' => 0 )
446448
);
447449
self::_renderTextItem(
448450
esc_html__( 'Prefix', 'visualizer' ),

js/render-datatables.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@
249249
if(typeof series.format.decimal !== ''){
250250
parts[1] = series.format.decimal;
251251
}
252-
if(typeof series.format.precision !== ''){
252+
if(typeof series.format.precision !== '' && series.format.precision != '0'){
253253
parts[2] = series.format.precision;
254254
}
255255
if(typeof series.format.prefix !== ''){

0 commit comments

Comments
 (0)