Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StateTimeline: Fix negative infinity legend/tooltip from thresholds #60279

Merged
merged 3 commits into from Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion public/app/plugins/panel/state-timeline/utils.test.ts
Expand Up @@ -182,7 +182,7 @@ describe('getThresholdItems', () => {
});

describe('prepareTimelineLegendItems', () => {
it('should return legend items', () => {
it('should return legend items without crashing when single (base) threshold', () => {
const frame: any = [
{
refId: 'A',
Expand Down
20 changes: 15 additions & 5 deletions public/app/plugins/panel/state-timeline/utils.ts
Expand Up @@ -478,10 +478,21 @@ export function getThresholdItems(fieldConfig: FieldConfig, theme: GrafanaTheme2

const fmt = (v: number) => formattedValueToString(disp(v));

for (let i = 1; i <= steps.length; i++) {
const step = steps[i - 1];
for (let i = 0; i < steps.length; i++) {
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({
label: i === 1 ? `< ${fmt(step.value)}` : `${fmt(step.value)}+`,
label: `${pre}${fmt(value)}${suf}`,
color: theme.visualization.getColorByName(step.color),
yAxis: 1,
});
Expand Down Expand Up @@ -510,10 +521,9 @@ export function getFieldLegendItem(fields: Field[], theme: GrafanaTheme2): VizLe
const items: VizLegendItem[] = [];
const fieldConfig = fields[0].config;
const colorMode = fieldConfig.color?.mode ?? FieldColorModeId.Fixed;
const thresholds = fieldConfig.thresholds;

// 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);
}

Expand Down