fix(plugin-chart-pivot-table): Invalid Formats Date Fields (#20909)

When a custom date field value converted in a string format, some aggregators truncated to the first four digits.
 This is caused by the parseFloat function which converts to first matched number rather than NaN(Not-A-Number) value.
 This commit replaces the parseFloat by Number wrapper to handle this case correctly.
This commit is contained in:
Just[in]Do it!
2022-07-28 22:56:08 -07:00
committed by GitHub
parent d50784dd80
commit 3f124d9d67
3 changed files with 206 additions and 6 deletions

View File

@@ -231,7 +231,7 @@ const baseAggregatorTemplates = {
return {
sum: 0,
push(record) {
if (Number.isNaN(parseFloat(record[attr]))) {
if (Number.isNaN(Number(record[attr]))) {
this.sum = record[attr];
} else {
this.sum += parseFloat(record[attr]);
@@ -259,7 +259,7 @@ const baseAggregatorTemplates = {
push(record) {
const x = record[attr];
if (['min', 'max'].includes(mode)) {
const coercedValue = parseFloat(x);
const coercedValue = Number(x);
if (Number.isNaN(coercedValue)) {
this.val =
!this.val ||
@@ -308,7 +308,7 @@ const baseAggregatorTemplates = {
strMap: {},
push(record) {
const val = record[attr];
const x = parseFloat(val);
const x = Number(val);
if (Number.isNaN(x)) {
this.strMap[val] = (this.strMap[val] || 0) + 1;
@@ -354,7 +354,7 @@ const baseAggregatorTemplates = {
s: 0.0,
strValue: null,
push(record) {
const x = parseFloat(record[attr]);
const x = Number(record[attr]);
if (Number.isNaN(x)) {
this.strValue =
typeof record[attr] === 'string' ? record[attr] : this.strValue;
@@ -405,10 +405,10 @@ const baseAggregatorTemplates = {
sumNum: 0,
sumDenom: 0,
push(record) {
if (!Number.isNaN(parseFloat(record[num]))) {
if (!Number.isNaN(Number(record[num]))) {
this.sumNum += parseFloat(record[num]);
}
if (!Number.isNaN(parseFloat(record[denom]))) {
if (!Number.isNaN(Number(record[denom]))) {
this.sumDenom += parseFloat(record[denom]);
}
},