Skip to content

Commit

Permalink
fix: apply legend to all numeric and boolean types
Browse files Browse the repository at this point in the history
  • Loading branch information
janhenrikoverland committed Jun 27, 2024
1 parent e017683 commit 47fdff1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/components/PivotTable/PivotTableValueCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import PropTypes from 'prop-types'
import React, { useRef } from 'react'
import { applyLegendSet } from '../../modules/pivotTable/applyLegendSet.js'
import { CELL_TYPE_VALUE } from '../../modules/pivotTable/pivotTableConstants.js'
import { VALUE_TYPE_NUMBER } from '../../modules/valueTypes.js'
import {
isNumericValueType,
isBooleanValueType,
} from '../../modules/valueTypes.js'
import { PivotTableCell } from './PivotTableCell.js'
import { PivotTableEmptyCell } from './PivotTableEmptyCell.js'
import { usePivotTableEngine } from './PivotTableEngineContext.js'
Expand Down Expand Up @@ -43,10 +46,10 @@ export const PivotTableValueCell = ({
)
}

// TODO: Add support for 'INTEGER' type (requires server changes)
const legendStyle =
cellContent.cellType === CELL_TYPE_VALUE &&
cellContent.valueType === VALUE_TYPE_NUMBER
(isNumericValueType(cellContent.valueType) ||
isBooleanValueType(cellContent.valueType))
? applyLegendSet(
cellContent.rawValue,
cellContent.dxDimension,
Expand Down
7 changes: 5 additions & 2 deletions src/modules/renderValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
NUMBER_TYPE_ROW_PERCENTAGE,
NUMBER_TYPE_COLUMN_PERCENTAGE,
} from './pivotTable/pivotTableConstants.js'
import { isNumericValueType } from './valueTypes.js'
import { isNumericValueType, isBooleanValueType } from './valueTypes.js'

const trimTrailingZeros = (stringValue) => stringValue.replace(/\.?0+$/, '')

Expand Down Expand Up @@ -53,7 +53,10 @@ const toFixedPrecisionString = (value, skipRounding) => {
}

export const renderValue = (value, valueType, visualization) => {
if (!isNumericValueType(valueType) || value === undefined) {
if (
!(isNumericValueType(valueType) || isBooleanValueType(valueType)) ||
value === undefined
) {
return String(value).replace(/[^\S\n]+/, ' ')
}

Expand Down
3 changes: 3 additions & 0 deletions src/modules/valueTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ const NUMERIC_VALUE_TYPES = [
VALUE_TYPE_INTEGER_ZERO_OR_POSITIVE,
]

const BOOLEAN_VALUE_TYPES = [VALUE_TYPE_BOOLEAN, VALUE_TYPE_TRUE_ONLY]

export const isNumericValueType = (type) => NUMERIC_VALUE_TYPES.includes(type)
export const isBooleanValueType = (type) => BOOLEAN_VALUE_TYPES.includes(type)

0 comments on commit 47fdff1

Please sign in to comment.