mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Colors: fix by-value/hex3 & Single color schemes in Gradient mode (#38656)
This commit is contained in:
parent
4e2516d12a
commit
3c72f1678f
@ -279,10 +279,18 @@ describe('utils/colorManipulator', () => {
|
|||||||
expect(alpha('hsla(0, 100%, 50%, 0.2)', 0.5)).toEqual('hsla(0, 100%, 50%, 0.5)');
|
expect(alpha('hsla(0, 100%, 50%, 0.2)', 0.5)).toEqual('hsla(0, 100%, 50%, 0.5)');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('converts an rgb hex color with the alpha value provided', () => {
|
it('converts an #rrggbb hex color with the alpha value provided', () => {
|
||||||
expect(alpha('#FFFFFF', 0)).toEqual('#FFFFFF00');
|
expect(alpha('#FFFFFF', 0)).toEqual('#FFFFFF00');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('converts an #rgb color with the alpha value provided', () => {
|
||||||
|
expect(alpha('#fff', 0.5)).toEqual('#ffffff80');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('converts an #rgba color with the alpha value provided', () => {
|
||||||
|
expect(alpha('#ffff', 0.5)).toEqual('#ffffff80');
|
||||||
|
});
|
||||||
|
|
||||||
it('throw on invalid colors', () => {
|
it('throw on invalid colors', () => {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
alpha('white', 0.4);
|
alpha('white', 0.4);
|
||||||
|
@ -261,10 +261,16 @@ export function alpha(color: string, value: number) {
|
|||||||
|
|
||||||
value = clamp(value);
|
value = clamp(value);
|
||||||
|
|
||||||
// hex 6, hex 8 (w/alpha)
|
// hex 3, hex 4 (w/alpha), hex 6, hex 8 (w/alpha)
|
||||||
if (color[0] === '#') {
|
if (color[0] === '#') {
|
||||||
if (color.length === 9) {
|
if (color.length === 9) {
|
||||||
color = color.substring(0, 7);
|
color = color.substring(0, 7);
|
||||||
|
} else if (color.length <= 5) {
|
||||||
|
let c = '#';
|
||||||
|
for (let i = 1; i < 4; i++) {
|
||||||
|
c += color[i] + color[i];
|
||||||
|
}
|
||||||
|
color = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -3,6 +3,7 @@ import {
|
|||||||
DataFrameFieldIndex,
|
DataFrameFieldIndex,
|
||||||
FALLBACK_COLOR,
|
FALLBACK_COLOR,
|
||||||
FieldColorMode,
|
FieldColorMode,
|
||||||
|
FieldColorModeId,
|
||||||
GrafanaTheme2,
|
GrafanaTheme2,
|
||||||
ThresholdsConfig,
|
ThresholdsConfig,
|
||||||
} from '@grafana/data';
|
} from '@grafana/data';
|
||||||
@ -139,7 +140,7 @@ export class UPlotSeriesBuilder extends PlotConfigBuilder<SeriesProps, Series> {
|
|||||||
private getLineColor(): Series.Stroke {
|
private getLineColor(): Series.Stroke {
|
||||||
const { lineColor, gradientMode, colorMode, thresholds, theme } = this.props;
|
const { lineColor, gradientMode, colorMode, thresholds, theme } = this.props;
|
||||||
|
|
||||||
if (gradientMode === GraphGradientMode.Scheme) {
|
if (gradientMode === GraphGradientMode.Scheme && colorMode?.id !== FieldColorModeId.Fixed) {
|
||||||
return getScaleGradientFn(1, theme, colorMode, thresholds);
|
return getScaleGradientFn(1, theme, colorMode, thresholds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,7 +163,10 @@ export class UPlotSeriesBuilder extends PlotConfigBuilder<SeriesProps, Series> {
|
|||||||
case GraphGradientMode.Hue:
|
case GraphGradientMode.Hue:
|
||||||
return getHueGradientFn((fillColor ?? lineColor)!, opacityPercent, theme);
|
return getHueGradientFn((fillColor ?? lineColor)!, opacityPercent, theme);
|
||||||
case GraphGradientMode.Scheme:
|
case GraphGradientMode.Scheme:
|
||||||
return getScaleGradientFn(opacityPercent, theme, colorMode, thresholds);
|
if (colorMode?.id !== FieldColorModeId.Fixed) {
|
||||||
|
return getScaleGradientFn(opacityPercent, theme, colorMode, thresholds);
|
||||||
|
}
|
||||||
|
// intentional fall-through to handle Scheme with Fixed color
|
||||||
default:
|
default:
|
||||||
if (opacityPercent > 0) {
|
if (opacityPercent > 0) {
|
||||||
return colorManipulator.alpha(lineColor ?? '', opacityPercent);
|
return colorManipulator.alpha(lineColor ?? '', opacityPercent);
|
||||||
|
Loading…
Reference in New Issue
Block a user