Commit 7c5ef2c7 by Torkel Ödegaard

Merge branch 'connection-reset-shared_tooltip'

parents 23eab81c 28f890e4
...@@ -34,13 +34,22 @@ function ($, core) { ...@@ -34,13 +34,22 @@ function ($, core) {
}; };
this.findHoverIndexFromData = function(posX, series) { this.findHoverIndexFromData = function(posX, series) {
var len = series.data.length; var lower = 0;
for (var j = 0; j < len; j++) { var upper = series.data.length - 1;
if (series.data[j][0] > posX) { var middle;
return Math.max(j - 1, 0); while (true) {
if (lower > upper) {
return Math.max(upper, 0);
}
middle = Math.floor((lower + upper) / 2);
if (series.data[middle][0] === posX) {
return middle;
} else if (series.data[middle][0] < posX) {
lower = middle + 1;
} else {
upper = middle - 1;
} }
} }
return j - 1;
}; };
this.renderAndShow = function(absoluteTime, innerHtml, pos, xMode) { this.renderAndShow = function(absoluteTime, innerHtml, pos, xMode) {
...@@ -156,6 +165,7 @@ function ($, core) { ...@@ -156,6 +165,7 @@ function ($, core) {
this.clear = function(plot) { this.clear = function(plot) {
$tooltip.detach(); $tooltip.detach();
plot.clearCrosshair(); plot.clearCrosshair();
plot.unhighlight();
}; };
this.show = function(pos, item) { this.show = function(pos, item) {
...@@ -171,12 +181,17 @@ function ($, core) { ...@@ -171,12 +181,17 @@ function ($, core) {
// get pageX from position on x axis and pageY from relative position in original panel // get pageX from position on x axis and pageY from relative position in original panel
if (pos.panelRelY) { if (pos.panelRelY) {
var pointOffset = plot.pointOffset({x: pos.x}); var pointOffset = plot.pointOffset({x: pos.x});
if (Number.isNaN(pointOffset.left) || pointOffset.left < 0) { if (Number.isNaN(pointOffset.left) || pointOffset.left < 0 || pointOffset.left > elem.width()) {
$tooltip.detach(); self.clear(plot);
return; return;
} }
pos.pageX = elem.offset().left + pointOffset.left; pos.pageX = elem.offset().left + pointOffset.left;
pos.pageY = elem.offset().top + elem.height() * pos.panelRelY; pos.pageY = elem.offset().top + elem.height() * pos.panelRelY;
var isVisible = pos.pageY >= $(window).scrollTop() && pos.pageY <= $(window).innerHeight() + $(window).scrollTop();
if (!isVisible) {
self.clear(plot);
return;
}
plot.setCrosshair(pos); plot.setCrosshair(pos);
allSeriesMode = true; allSeriesMode = true;
......
...@@ -40,6 +40,31 @@ function describeSharedTooltip(desc, fn) { ...@@ -40,6 +40,31 @@ function describeSharedTooltip(desc, fn) {
}); });
} }
describe("findHoverIndexFromData", function() {
var tooltip = new GraphTooltip(elem, dashboard, scope);
var series = { data: [[100, 0], [101, 0], [102, 0], [103, 0], [104, 0], [105, 0], [106, 0], [107, 0]] };
it("should return 0 if posX out of lower bounds", function() {
var posX = 99;
expect(tooltip.findHoverIndexFromData(posX, series)).to.be(0);
});
it("should return n - 1 if posX out of upper bounds", function() {
var posX = 108;
expect(tooltip.findHoverIndexFromData(posX, series)).to.be(series.data.length - 1);
});
it("should return i if posX in series", function() {
var posX = 104;
expect(tooltip.findHoverIndexFromData(posX, series)).to.be(4);
});
it("should return i if posX not in series and i + 1 > posX", function() {
var posX = 104.9;
expect(tooltip.findHoverIndexFromData(posX, series)).to.be(4);
});
});
describeSharedTooltip("steppedLine false, stack false", function(ctx) { describeSharedTooltip("steppedLine false, stack false", function(ctx) {
ctx.setup(function() { ctx.setup(function() {
ctx.data = [ ctx.data = [
...@@ -168,6 +193,3 @@ describeSharedTooltip("steppedLine false, stack true, individual true", function ...@@ -168,6 +193,3 @@ describeSharedTooltip("steppedLine false, stack true, individual true", function
expect(ctx.results[1].value).to.be(2); expect(ctx.results[1].value).to.be(2);
}); });
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment