Просмотр исходного кода

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
Ben RUBSON 9 лет назад
Родитель
Сommit
f7124f1638
1 измененных файлов с 19 добавлено и 7 удалено
  1. 19 7
      public/app/plugins/panel/graph/graph_tooltip.js

+ 19 - 7
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 += '<div class="graph-tooltip-list-item ' + highlightClass + '"><div class="graph-tooltip-series-name">';
           seriesHtml += '<i class="fa fa-minus" style="color:' + hoverInfo.color +';"></i> ' + hoverInfo.label + ':</div>';
           seriesHtml += '<div class="graph-tooltip-value">' + value + '</div></div>';
-          plot.highlight(i, hoverInfo.hoverIndex);
+          plot.highlight(hoverInfo.index, hoverInfo.hoverIndex);
         }
 
         self.showTooltip(absoluteTime, seriesHtml, pos);