From d1e8418c7470409559ce4a974041c7ac83a327f8 Mon Sep 17 00:00:00 2001 From: Ben RUBSON Date: Sat, 15 Oct 2016 08:02:07 +0200 Subject: [PATCH] Correct tooltip timestamp (#6283) Corrects #6275, follows #6211 --- public/app/plugins/panel/graph/graph_tooltip.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/public/app/plugins/panel/graph/graph_tooltip.js b/public/app/plugins/panel/graph/graph_tooltip.js index da0080f0005..5ae03ccf813 100644 --- a/public/app/plugins/panel/graph/graph_tooltip.js +++ b/public/app/plugins/panel/graph/graph_tooltip.js @@ -149,8 +149,6 @@ function ($, _) { seriesHtml = ''; - absoluteTime = dashboard.formatDate(seriesHoverInfo.time, tooltipFormat); - // Dynamically reorder the hovercard for the current time point if the // option is enabled, sort by yaxis by default. if (panel.tooltip.sort === 2) { @@ -161,13 +159,14 @@ function ($, _) { seriesHoverInfo.sort(function(a, b) { return a.value - b.value; }); - } - else { + } else { seriesHoverInfo.sort(function(a, b) { return a.yaxis - b.yaxis; }); } + var distance, time; + for (i = 0; i < seriesHoverInfo.length; i++) { hoverInfo = seriesHoverInfo[i]; @@ -175,6 +174,11 @@ function ($, _) { continue; } + if (! distance || hoverInfo.distance < distance) { + distance = hoverInfo.distance; + time = hoverInfo.time; + } + var highlightClass = ''; if (item && i === item.seriesIndex) { highlightClass = 'graph-tooltip-list-item--highlight'; @@ -190,6 +194,7 @@ function ($, _) { plot.highlight(hoverInfo.index, hoverInfo.hoverIndex); } + absoluteTime = dashboard.formatDate(time, tooltipFormat); self.showTooltip(absoluteTime, seriesHtml, pos); } // single series tooltip