BarGauge: Fix percentage-based thresholds (#32415)

Closes #31756
This commit is contained in:
kay delaney 2021-03-29 15:11:23 +01:00 committed by GitHub
parent 5ec530f3fc
commit 6015432f07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -538,13 +538,19 @@ export function getBarGradient(props: Props, maxSize: number): string {
for (let i = 0; i < thresholds.steps.length; i++) {
const threshold = thresholds.steps[i];
const color = getColorForTheme(threshold.color, props.theme);
const valuePercent = getValuePercent(threshold.value, minValue, maxValue);
const valuePercent =
thresholds.mode === ThresholdsMode.Percentage
? threshold.value / 100
: getValuePercent(threshold.value, minValue, maxValue);
const pos = valuePercent * maxSize;
const offset = Math.round(pos - (pos - lastpos) / 2);
const thresholdValue =
thresholds.mode === ThresholdsMode.Percentage
? minValue + (maxValue - minValue) * valuePercent
: threshold.value;
if (gradient === '') {
gradient = `linear-gradient(${cssDirection}, ${color}, ${color}`;
} else if (value.numeric < threshold.value) {
} else if (value.numeric < thresholdValue) {
break;
} else {
lastpos = pos;