From 865723d56e2ccf1d54da76e54a6dd481ee4cfa0c Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Mon, 28 Feb 2022 17:55:54 -0500 Subject: [PATCH] StateTimeline: fix duration in tooltip (#45955) (#45987) - Fixes duration in StateTimeline appearing incorrectly when "merge consecutive values" is enabled. (cherry picked from commit 5aab0063c7335474582b9a7d17b2fc069270500e) Co-authored-by: Leon Sorokin --- public/app/plugins/panel/state-timeline/utils.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/public/app/plugins/panel/state-timeline/utils.ts b/public/app/plugins/panel/state-timeline/utils.ts index 1b5a7ff3036..5db103c4e61 100644 --- a/public/app/plugins/panel/state-timeline/utils.ts +++ b/public/app/plugins/panel/state-timeline/utils.ts @@ -553,16 +553,18 @@ export function findNextStateIndex(field: Field, datapointIdx: number) { return null; } + const startValue = field.values.get(datapointIdx); + while (end === undefined) { if (rightPointer >= field.values.length) { return null; } const rightValue = field.values.get(rightPointer); - if (rightValue !== undefined) { - end = rightPointer; - } else { + if (rightValue === undefined || rightValue === startValue) { rightPointer++; + } else { + end = rightPointer; } }