Skip to content

Commit

Permalink
Added test to catch cases where the tooltip covers the top point. Closes
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Olsson committed Aug 11, 2011
1 parent 185aa70 commit 0e6c668
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
6 changes: 5 additions & 1 deletion js/highcharts.src.js
Expand Up @@ -499,9 +499,13 @@ function placeBox(boxWidth, boxHeight, outerLeft, outerTop, outerWidth, outerHei

if (y < 5) {
y = 5; // above

// If the tooltip is still covering the point, move it below instead
if (point.y >= y && point.y <= (y + boxHeight)) {
y = point.y + boxHeight - 5; // below
}
} else if (y + boxHeight > outerHeight) {
y = outerHeight - boxHeight - 5; // below
y = outerHeight - boxHeight - 5; // below
}

return {x: x, y: y};
Expand Down
6 changes: 5 additions & 1 deletion js/parts/Utilities.js
Expand Up @@ -384,9 +384,13 @@ function placeBox(boxWidth, boxHeight, outerLeft, outerTop, outerWidth, outerHei

if (y < 5) {
y = 5; // above

// If the tooltip is still covering the point, move it below instead
if (point.y >= y && point.y <= (y + boxHeight)) {
y = point.y + boxHeight - 5; // below
}
} else if (y + boxHeight > outerHeight) {
y = outerHeight - boxHeight - 5; // below
y = outerHeight - boxHeight - 5; // below
}

return {x: x, y: y};
Expand Down
13 changes: 12 additions & 1 deletion test/unit/UtilitiesTest.js
Expand Up @@ -111,9 +111,12 @@ UtilTest.prototype.testLin2Log = function () {

/**
* Tests if a point is inside a rectangle
* The rectangle coordinate system is: x and y specifies the _top_ left corner width is the width and height is the height.
*/
UtilTest.prototype.pointInRect = function (x, y, rect) {
var inside = x >= rect.x && x <= (rect.x + rect.width) && y >= rect.y && y <= (rect.y + rect.height)
var inside =
x >= rect.x && x <= (rect.x + rect.width) &&
y >= rect.y && y <= (rect.y + rect.height)
return inside;
};

Expand Down Expand Up @@ -155,6 +158,14 @@ UtilTest.prototype.testPlaceBox = function () {
extend(boxPoint, tooltipSize);
assertTrue('Mid rectInRect chart', this.rectInRect(boxPoint, chartRect));
assertFalse('Mid tooltip cover point', this.pointInRect(dataPoint.x, dataPoint.y, boxPoint));

dataPoint.x = 75;
dataPoint.y = 5;
boxPoint = placeBox(tooltipSize.width, tooltipSize.height, chartRect.x, chartRect.y, chartRect.width, chartRect.height, dataPoint);
extend(boxPoint, tooltipSize);
jstestdriver.console.log(boxPoint.x + ',' + boxPoint.y + ', ' + boxPoint.width + ',' + boxPoint.height);
assertTrue('TopRight rectInRect chart', this.rectInRect(boxPoint, chartRect));
assertFalse('TopRight tooltip cover point', this.pointInRect(dataPoint.x, dataPoint.y, boxPoint));
};

/**
Expand Down

0 comments on commit 0e6c668

Please sign in to comment.