mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
StateTimeline: Fix negative infinity legend/tooltip from thresholds (#60279)
This commit is contained in:
parent
4064fa51c6
commit
e0eacf1b04
@ -182,7 +182,7 @@ describe('getThresholdItems', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('prepareTimelineLegendItems', () => {
|
describe('prepareTimelineLegendItems', () => {
|
||||||
it('should return legend items', () => {
|
it('should return legend items without crashing when single (base) threshold', () => {
|
||||||
const frame: any = [
|
const frame: any = [
|
||||||
{
|
{
|
||||||
refId: 'A',
|
refId: 'A',
|
||||||
|
@ -478,10 +478,21 @@ export function getThresholdItems(fieldConfig: FieldConfig, theme: GrafanaTheme2
|
|||||||
|
|
||||||
const fmt = (v: number) => formattedValueToString(disp(v));
|
const fmt = (v: number) => formattedValueToString(disp(v));
|
||||||
|
|
||||||
for (let i = 1; i <= steps.length; i++) {
|
for (let i = 0; i < steps.length; i++) {
|
||||||
const step = steps[i - 1];
|
let step = steps[i];
|
||||||
|
let value = step.value;
|
||||||
|
let pre = '';
|
||||||
|
let suf = '';
|
||||||
|
|
||||||
|
if (value === -Infinity && i < steps.length - 1) {
|
||||||
|
value = steps[i + 1].value;
|
||||||
|
pre = '< ';
|
||||||
|
} else {
|
||||||
|
suf = '+';
|
||||||
|
}
|
||||||
|
|
||||||
items.push({
|
items.push({
|
||||||
label: i === 1 ? `< ${fmt(step.value)}` : `${fmt(step.value)}+`,
|
label: `${pre}${fmt(value)}${suf}`,
|
||||||
color: theme.visualization.getColorByName(step.color),
|
color: theme.visualization.getColorByName(step.color),
|
||||||
yAxis: 1,
|
yAxis: 1,
|
||||||
});
|
});
|
||||||
@ -510,10 +521,9 @@ export function getFieldLegendItem(fields: Field[], theme: GrafanaTheme2): VizLe
|
|||||||
const items: VizLegendItem[] = [];
|
const items: VizLegendItem[] = [];
|
||||||
const fieldConfig = fields[0].config;
|
const fieldConfig = fields[0].config;
|
||||||
const colorMode = fieldConfig.color?.mode ?? FieldColorModeId.Fixed;
|
const colorMode = fieldConfig.color?.mode ?? FieldColorModeId.Fixed;
|
||||||
const thresholds = fieldConfig.thresholds;
|
|
||||||
|
|
||||||
// If thresholds are enabled show each step in the legend
|
// If thresholds are enabled show each step in the legend
|
||||||
if (colorMode === FieldColorModeId.Thresholds && thresholds?.steps && thresholds.steps.length > 1) {
|
if (colorMode === FieldColorModeId.Thresholds) {
|
||||||
return getThresholdItems(fieldConfig, theme);
|
return getThresholdItems(fieldConfig, theme);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user