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

Graph: fixed issue with shared tooltip when one or more series is hidden, Fixes #1094

Torkel Ödegaard 11 лет назад
Родитель
Сommit
91d6641326
2 измененных файлов с 42 добавлено и 5 удалено
  1. 14 5
      src/app/panels/graph/graph.tooltip.js
  2. 28 0
      src/test/specs/graph-tooltip-specs.js

+ 14 - 5
src/app/panels/graph/graph.tooltip.js

@@ -38,18 +38,26 @@ function ($) {
     };
 
     this.getMultiSeriesPlotHoverInfo = function(seriesList, pos) {
-      var value, i, series, hoverIndex;
+      var value, i, series, hoverIndex, seriesTmp;
       var results = [];
 
-      var pointCount = seriesList[0].data.length;
-      for (i = 1; i < seriesList.length; i++) {
-        if (seriesList[i].data.length !== pointCount) {
+      var pointCount;
+      for (i = 0; i < seriesList.length; i++) {
+        seriesTmp = seriesList[i];
+        if (!seriesTmp.data.length) { continue; }
+
+        if (!pointCount) {
+          series = seriesTmp;
+          pointCount = series.data.length;
+          continue;
+        }
+
+        if (seriesTmp.data.length !== pointCount) {
           results.pointCountMismatch = true;
           return results;
         }
       }
 
-      series = seriesList[0];
       hoverIndex = this.findHoverIndexFromData(pos.x, series);
       var lasthoverIndex = 0;
       if(!scope.panel.steppedLine) {
@@ -62,6 +70,7 @@ function ($) {
 
       for (i = 0; i < seriesList.length; i++) {
         series = seriesList[i];
+        if (!series.data.length) { continue; }
 
         if (scope.panel.stack) {
           if (scope.panel.tooltip.value_type === 'individual') {

+ 28 - 0
src/test/specs/graph-tooltip-specs.js

@@ -59,6 +59,34 @@ define([
     });
   });
 
+  describeSharedTooltip("point count missmatch", function(ctx) {
+    ctx.setup(function() {
+      ctx.data = [
+        { data: [[10, 15], [12, 20]], },
+        { data: [[10, 2]] }
+      ];
+      ctx.pos = { x: 11 };
+    });
+
+    it('should set pointCountMismatch to true', function() {
+      expect(ctx.results.pointCountMismatch).to.be(true);
+    });
+  });
+
+  describeSharedTooltip("one series is hidden", function(ctx) {
+    ctx.setup(function() {
+      ctx.data = [
+        { data: [[10, 15], [12, 20]], },
+        { data: [] }
+      ];
+      ctx.pos = { x: 11 };
+    });
+
+    it('should set pointCountMismatch to false', function() {
+      expect(ctx.results.pointCountMismatch).to.be(undefined);
+    });
+  });
+
   describeSharedTooltip("steppedLine false, stack true, individual false", function(ctx) {
     ctx.setup(function() {
       ctx.data = [