Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added test to catch cases where the tooltip covers the top point. Clo…

…ses #313.
  • Loading branch information...
commit 0e6c6682ca71fd1bae76bb5badf10782921e4218 1 parent 185aa70
@eolsson eolsson authored
View
6 js/highcharts.src.js
@@ -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};
View
6 js/parts/Utilities.js
@@ -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};
View
13 test/unit/UtilitiesTest.js
@@ -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;
};
@@ -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));
};
/**
Please sign in to comment.
Something went wrong with that request. Please try again.