From 807bc5eb473eb0cc8d079c36a8de3733b6829731 Mon Sep 17 00:00:00 2001 From: benrubson Date: Sun, 16 Oct 2016 01:09:00 +0200 Subject: [PATCH] Add time back to result array --- .../app/plugins/panel/graph/graph_tooltip.js | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/public/app/plugins/panel/graph/graph_tooltip.js b/public/app/plugins/panel/graph/graph_tooltip.js index f777ba15402..f160c55663f 100644 --- a/public/app/plugins/panel/graph/graph_tooltip.js +++ b/public/app/plugins/panel/graph/graph_tooltip.js @@ -48,6 +48,8 @@ function ($) { //now we know the current X (j) position for X and Y values var last_value = 0; //needed for stacked values + var minDistance, minTime; + for (i = 0; i < seriesList.length; i++) { series = seriesList[i]; @@ -65,6 +67,13 @@ function ($) { hoverDistance = pos.x - series.data[hoverIndex][0]; pointTime = series.data[hoverIndex][0]; + if (! minDistance + || (hoverDistance >=0 && (hoverDistance < minDistance || minDistance < 0)) + || (hoverDistance < 0 && hoverDistance > minDistance)) { + minDistance = hoverDistance; + minTime = pointTime; + } + if (series.stack) { if (panel.tooltip.value_type === 'individual') { value = series.data[hoverIndex][1]; @@ -103,6 +112,9 @@ function ($) { }); } + // Find point which closer to pointer + results.time = minTime; + return results; }; @@ -147,6 +159,8 @@ 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) { @@ -163,8 +177,6 @@ function ($) { }); } - var distance, time; - for (i = 0; i < seriesHoverInfo.length; i++) { hoverInfo = seriesHoverInfo[i]; @@ -172,13 +184,6 @@ function ($) { continue; } - if (! distance - || (hoverInfo.distance >=0 && (hoverInfo.distance < distance || distance < 0)) - || (hoverInfo.distance < 0 && hoverInfo.distance > distance)) { - distance = hoverInfo.distance; - time = hoverInfo.time; - } - var highlightClass = ''; if (item && i === item.seriesIndex) { highlightClass = 'graph-tooltip-list-item--highlight'; @@ -194,7 +199,6 @@ function ($) { plot.highlight(hoverInfo.index, hoverInfo.hoverIndex); } - absoluteTime = dashboard.formatDate(time, tooltipFormat); self.showTooltip(absoluteTime, seriesHtml, pos); } // single series tooltip