feat: conditional coloring for big number chart (#23064)

Co-authored-by: Gerold Busch <gerold.busch@valtech.com>
This commit is contained in:
Gerold Busch
2023-05-01 17:44:46 +02:00
committed by GitHub
parent fd3030fc14
commit 61d8a0bd12
7 changed files with 111 additions and 9 deletions

View File

@@ -128,10 +128,29 @@ class BigNumberVis extends React.PureComponent<BigNumberVizProps> {
}
renderHeader(maxHeight: number) {
const { bigNumber, headerFormatter, width } = this.props;
const { bigNumber, headerFormatter, width, colorThresholdFormatters } =
this.props;
// @ts-ignore
const text = bigNumber === null ? t('No data') : headerFormatter(bigNumber);
const hasThresholdColorFormatter =
Array.isArray(colorThresholdFormatters) &&
colorThresholdFormatters.length > 0;
let numberColor;
if (hasThresholdColorFormatter) {
colorThresholdFormatters!.forEach(formatter => {
const formatterResult = bigNumber
? formatter.getColorFromValue(bigNumber as number)
: false;
if (formatterResult) {
numberColor = formatterResult;
}
});
} else {
numberColor = 'black';
}
const container = this.createTemporaryContainer();
document.body.append(container);
const fontSize = computeMaxFontSize({
@@ -156,6 +175,7 @@ class BigNumberVis extends React.PureComponent<BigNumberVizProps> {
style={{
fontSize,
height: maxHeight,
color: numberColor,
}}
onContextMenu={onContextMenu}
>