From f7124f1638913feba6fddf552ec10d31f90d59e9 Mon Sep 17 00:00:00 2001 From: Ben RUBSON Date: Tue, 11 Oct 2016 13:53:49 +0200 Subject: [PATCH] Patch: 4 tooltip bugs (#6211) * Order tooltip by yaxis by default solves #6174 * typo * Avoid sorting multiple times and evaluate series.yaxis.n as it may not exist. * typo * typo * typo * Tooltip values loose their format when reordered solves #6208 * Hover the correct point * Make tooltip sort happy with hidden series --- .../app/plugins/panel/graph/graph_tooltip.js | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/public/app/plugins/panel/graph/graph_tooltip.js b/public/app/plugins/panel/graph/graph_tooltip.js index cd3bddf41ef..da0080f0005 100644 --- a/public/app/plugins/panel/graph/graph_tooltip.js +++ b/public/app/plugins/panel/graph/graph_tooltip.js @@ -41,7 +41,7 @@ function ($, _) { }; this.getMultiSeriesPlotHoverInfo = function(seriesList, pos) { - var value, i, series, hoverIndex, hoverDistance, pointTime; + var value, i, series, hoverIndex, hoverDistance, pointTime, yaxis; var results = []; //now we know the current X (j) position for X and Y values @@ -51,12 +51,12 @@ function ($, _) { series = seriesList[i]; if (!series.data.length || (panel.legend.hideEmpty && series.allIsNull)) { - results.push({ hidden: true }); + results.push({ hidden: true, value: 0, yaxis: 0 }); continue; } if (!series.data.length || (panel.legend.hideZero && series.allIsZero)) { - results.push({ hidden: true }); + results.push({ hidden: true, value: 0, yaxis: 0 }); continue; } @@ -85,13 +85,20 @@ function ($, _) { hoverIndex = this.findHoverIndexFromDataPoints(pos.x, series, hoverIndex); } + yaxis = 0; + if (series.yaxis) { + yaxis = series.yaxis.n; + } + results.push({ value: value, hoverIndex: hoverIndex, color: series.color, label: series.label, time: pointTime, - distance: hoverDistance + distance: hoverDistance, + yaxis: yaxis, + index: i }); } @@ -145,7 +152,7 @@ function ($, _) { absoluteTime = dashboard.formatDate(seriesHoverInfo.time, tooltipFormat); // Dynamically reorder the hovercard for the current time point if the - // option is enabled. + // option is enabled, sort by yaxis by default. if (panel.tooltip.sort === 2) { seriesHoverInfo.sort(function(a, b) { return b.value - a.value; @@ -155,6 +162,11 @@ function ($, _) { return a.value - b.value; }); } + else { + seriesHoverInfo.sort(function(a, b) { + return a.yaxis - b.yaxis; + }); + } for (i = 0; i < seriesHoverInfo.length; i++) { hoverInfo = seriesHoverInfo[i]; @@ -168,14 +180,14 @@ function ($, _) { highlightClass = 'graph-tooltip-list-item--highlight'; } - series = seriesList[i]; + series = seriesList[hoverInfo.index]; value = series.formatValue(hoverInfo.value); seriesHtml += '
'; seriesHtml += ' ' + hoverInfo.label + ':
'; seriesHtml += '
' + value + '
'; - plot.highlight(i, hoverInfo.hoverIndex); + plot.highlight(hoverInfo.index, hoverInfo.hoverIndex); } self.showTooltip(absoluteTime, seriesHtml, pos);