fix(charts): Hide Values greater than Max Y Axis Bound on Mixed Time Series with Bar series (#21015)

* Mixed TimeSeries:

- When Bar chart is used as serie type, we need to hide values that are greater than the max Y Axis Bound.

* Mixed Time Series:

- Simplify logic for getOverMaxHiddenFormatter

* Mixed Time Series:

- Add tests for new getOverMaxHiddenFormatter util func
This commit is contained in:
Antonio Rivero Martinez
2022-08-22 11:55:09 -03:00
committed by GitHub
parent d44202f03c
commit bdcc0a9bcf
4 changed files with 97 additions and 46 deletions

View File

@@ -24,6 +24,7 @@ import {
DTTM_ALIAS,
ensureIsArray,
GenericDataType,
NumberFormats,
NumberFormatter,
TimeFormatter,
} from '@superset-ui/core';
@@ -326,3 +327,24 @@ export function getAxisType(dataType?: GenericDataType): AxisType {
}
return 'category';
}
export function getOverMaxHiddenFormatter(
config: {
max?: number;
formatter?: NumberFormatter;
} = {},
) {
const { max, formatter } = config;
// Only apply this logic if there's a MAX set in the controls
const shouldHideIfOverMax = !!max || max === 0;
return new NumberFormatter({
formatFunc: value =>
`${
shouldHideIfOverMax && value > max
? ''
: formatter?.format(value) || value
}`,
id: NumberFormats.OVER_MAX_HIDDEN,
});
}