From 71b841fa9bfbc02f40f23a98d0490577603aba02 Mon Sep 17 00:00:00 2001 From: Nathan Marrs Date: Tue, 1 Aug 2023 20:54:56 +0200 Subject: [PATCH] StatusHistory: Support legend decimals based on field overrides (#72486) --- public/app/core/components/TimelineChart/utils.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/public/app/core/components/TimelineChart/utils.ts b/public/app/core/components/TimelineChart/utils.ts index 102200fe8fb..ecbf7c8d46f 100644 --- a/public/app/core/components/TimelineChart/utils.ts +++ b/public/app/core/components/TimelineChart/utils.ts @@ -525,9 +525,10 @@ export function getThresholdItems(fieldConfig: FieldConfig, theme: GrafanaTheme2 } const steps = thresholds.steps; - const disp = getValueFormat(thresholds.mode === ThresholdsMode.Percentage ? 'percent' : fieldConfig.unit ?? ''); + const getDisplay = getValueFormat(thresholds.mode === ThresholdsMode.Percentage ? 'percent' : fieldConfig.unit ?? ''); - const fmt = (v: number) => formattedValueToString(disp(v)); + // `undefined` value for decimals will use `auto` + const format = (value: number) => formattedValueToString(getDisplay(value, fieldConfig.decimals ?? undefined)); for (let i = 0; i < steps.length; i++) { let step = steps[i]; @@ -543,7 +544,7 @@ export function getThresholdItems(fieldConfig: FieldConfig, theme: GrafanaTheme2 } items.push({ - label: `${pre}${fmt(value)}${suf}`, + label: `${pre}${format(value)}${suf}`, color: theme.visualization.getColorByName(step.color), yAxis: 1, });