diff --git a/src/components/PivotTable/styles/PivotTable.style.js b/src/components/PivotTable/styles/PivotTable.style.js index 705e95232..769454e98 100644 --- a/src/components/PivotTable/styles/PivotTable.style.js +++ b/src/components/PivotTable/styles/PivotTable.style.js @@ -159,6 +159,7 @@ export const cell = css` text-align: right; } .N_A { + text-align: center; color: ${colors.grey600}; } diff --git a/src/modules/pivotTable/PivotTableEngine.js b/src/modules/pivotTable/PivotTableEngine.js index 0b95d4235..9338f41ee 100644 --- a/src/modules/pivotTable/PivotTableEngine.js +++ b/src/modules/pivotTable/PivotTableEngine.js @@ -43,6 +43,7 @@ import { NUMBER_TYPE_ROW_PERCENTAGE, NUMBER_TYPE_VALUE, VALUE_TYPE_NA, + VALUE_NA, } from './pivotTableConstants.js' const dataFields = [ @@ -247,7 +248,7 @@ const applyTotalAggregationType = ( ) => { switch (overrideTotalAggregationType || totalAggregationType) { case AGGREGATE_TYPE_NA: - return 'N/A' + return VALUE_NA case AGGREGATE_TYPE_AVERAGE: return ( ((numerator || value) * multiplier) / @@ -433,9 +434,12 @@ export class PivotTableEngine { }) if (cumulativeValue !== undefined && cumulativeValue !== null) { - // force to NUMBER for accumulated values + // force to TEXT for N/A (accumulated) values + // force to NUMBER for accumulated values if no valueType present rawCell.valueType = - valueType === undefined || valueType === null + cumulativeValue === VALUE_NA + ? VALUE_TYPE_NA + : valueType === undefined || valueType === null ? VALUE_TYPE_NUMBER : valueType rawCell.empty = false @@ -1087,7 +1091,7 @@ export class PivotTableEngine { // only accumulate numeric (except for PERCENTAGE and UNIT_INTERVAL) and boolean values // accumulating other value types like text values does not make sense - if (isCumulativeValueType(valueType)) { + if (acc !== VALUE_NA && isCumulativeValueType(valueType)) { // initialise to 0 for cumulative types // (||= is not transformed correctly in Babel with the current setup) acc || (acc = 0) @@ -1104,10 +1108,14 @@ export class PivotTableEngine { acc += parseValue(rawValue) } - - this.accumulators.rows[row][column] = acc + } else { + // show N/A from the first non-cumulative type and onwards + // only if a previous value is present (this is to avoid filling empty rows with N/A) + acc = acc ? VALUE_NA : '' } + this.accumulators.rows[row][column] = acc + return acc }, '') }) diff --git a/src/modules/pivotTable/pivotTableConstants.js b/src/modules/pivotTable/pivotTableConstants.js index d3a742960..1ab1b290d 100644 --- a/src/modules/pivotTable/pivotTableConstants.js +++ b/src/modules/pivotTable/pivotTableConstants.js @@ -37,3 +37,5 @@ export const WRAPPED_TEXT_JUSTIFY_BUFFER = 25 export const WRAPPED_TEXT_LINE_HEIGHT = 1.0 export const CLIPPED_AXIS_PARTITION_SIZE_PX = 1000 + +export const VALUE_NA = 'N/A'