From 91d66413269b6bcdcf4de24005aa311b705a088c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 19 Nov 2014 16:01:04 +0100 Subject: [PATCH] Graph: fixed issue with shared tooltip when one or more series is hidden, Fixes #1094 --- src/app/panels/graph/graph.tooltip.js | 19 +++++++++++++----- src/test/specs/graph-tooltip-specs.js | 28 +++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/app/panels/graph/graph.tooltip.js b/src/app/panels/graph/graph.tooltip.js index e0fede2f62d..4c5f727f919 100644 --- a/src/app/panels/graph/graph.tooltip.js +++ b/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') { diff --git a/src/test/specs/graph-tooltip-specs.js b/src/test/specs/graph-tooltip-specs.js index 6d1b9a40a58..b7def74ac89 100644 --- a/src/test/specs/graph-tooltip-specs.js +++ b/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 = [