mirror of
https://github.com/apache/superset.git
synced 2026-04-24 18:44:53 +00:00
feat: conditional coloring for big number chart (#23064)
Co-authored-by: Gerold Busch <gerold.busch@valtech.com>
This commit is contained in:
@@ -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}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user