mirror of
https://github.com/grafana/grafana.git
synced 2024-11-22 08:56:43 -06:00
TablePanel/StatPanel: Fix values not being visible when background transparent (#55092)
* TablePanel/StatPanel: Fix values not being visible when background transparent * Maintain backwards compatibility
This commit is contained in:
parent
1e9f5a5080
commit
32c4245efd
@ -4,7 +4,7 @@ import tinycolor from 'tinycolor2';
|
||||
import { formattedValueToString, DisplayValue, FieldConfig, FieldType, VizOrientation } from '@grafana/data';
|
||||
import { GraphDrawStyle, GraphFieldConfig } from '@grafana/schema';
|
||||
|
||||
import { getTextColorForBackground } from '../../utils';
|
||||
import { getTextColorForAlphaBackground } from '../../utils';
|
||||
import { calculateFontSize } from '../../utils/measureText';
|
||||
import { Sparkline } from '../Sparkline/Sparkline';
|
||||
|
||||
@ -67,7 +67,7 @@ export abstract class BigValueLayout {
|
||||
}
|
||||
|
||||
if (this.props.colorMode === BigValueColorMode.Background) {
|
||||
styles.color = getTextColorForBackground(this.valueColor);
|
||||
styles.color = getTextColorForAlphaBackground(this.valueColor, this.props.theme.isDark);
|
||||
}
|
||||
|
||||
return styles;
|
||||
@ -91,7 +91,7 @@ export abstract class BigValueLayout {
|
||||
styles.color = this.valueColor;
|
||||
break;
|
||||
case BigValueColorMode.Background:
|
||||
styles.color = getTextColorForBackground(this.valueColor);
|
||||
styles.color = getTextColorForAlphaBackground(this.valueColor, this.props.theme.isDark);
|
||||
break;
|
||||
case BigValueColorMode.None:
|
||||
styles.color = this.props.theme.colors.text.primary;
|
||||
|
@ -4,7 +4,7 @@ import tinycolor from 'tinycolor2';
|
||||
|
||||
import { DisplayValue, Field, formattedValueToString } from '@grafana/data';
|
||||
|
||||
import { getTextColorForBackground, getCellLinks } from '../../utils';
|
||||
import { getCellLinks, getTextColorForAlphaBackground } from '../../utils';
|
||||
import { DataLinksContextMenu } from '../DataLinks/DataLinksContextMenu';
|
||||
|
||||
import { CellActions } from './CellActions';
|
||||
@ -63,7 +63,7 @@ function getCellStyle(
|
||||
|
||||
if (field.config.custom?.displayMode === TableCellDisplayMode.ColorBackgroundSolid) {
|
||||
const bgColor = tinycolor(displayValue.color);
|
||||
const textColor = getTextColorForBackground(displayValue.color!);
|
||||
const textColor = getTextColorForAlphaBackground(displayValue.color!, tableStyles.theme.isDark);
|
||||
return tableStyles.buildCellContainerStyle(textColor, bgColor.toRgbString(), !disableOverflowOnHover);
|
||||
}
|
||||
|
||||
@ -74,7 +74,7 @@ function getCellStyle(
|
||||
.spin(5)
|
||||
.toRgbString();
|
||||
|
||||
const textColor = getTextColorForBackground(displayValue.color!);
|
||||
const textColor = getTextColorForAlphaBackground(displayValue.color!, tableStyles.theme.isDark);
|
||||
|
||||
return tableStyles.buildCellContainerStyle(
|
||||
textColor,
|
||||
|
@ -114,6 +114,19 @@ function hslToHex(color: tinycolor.ColorFormats.HSLA) {
|
||||
|
||||
export function getTextColorForBackground(color: string) {
|
||||
const b = tinycolor(color).getBrightness();
|
||||
|
||||
return b > 180 ? 'rgb(32, 34, 38)' : 'rgb(247, 248, 250)';
|
||||
}
|
||||
|
||||
export function getTextColorForAlphaBackground(color: string, themeIsDark: boolean) {
|
||||
const tcolor = tinycolor(color);
|
||||
const b = tcolor.getBrightness();
|
||||
const a = tcolor.getAlpha();
|
||||
|
||||
if (a < 0.3) {
|
||||
return themeIsDark ? 'rgb(247, 248, 250)' : 'rgb(32, 34, 38)';
|
||||
}
|
||||
|
||||
return b > 180 ? 'rgb(32, 34, 38)' : 'rgb(247, 248, 250)';
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user