highslide-software/highcharts.com — Issue #529: placeBox subtracts boxHeight twice for tooltips that are too far to the right
Author: dvogel
Created: 2011-10-26 16:36:54+00:00
State: open

This is causing tooltips with line breaks in the text to "float" upward by their height if they are too far to the right. The y coordinate should really be moved up by the height of a one-text-line tooltip in this code block:

```
// Test to see if the tooltip is to far to the right,
// if it is, move it back to be inside and then up to not cover the point.
if ((x + boxWidth) > (outerLeft + outerWidth)) {
x -= (x + boxWidth) - (outerLeft + outerWidth);
y -= boxHeight;
alignedRight = true;
}
```

Here's the entire function as it exists today:

```
/**
* Utility method extracted from Tooltip code that places a tooltip in a chart without spilling over
* and not covering the point it self.
*/
function placeBox(boxWidth, boxHeight, outerLeft, outerTop, outerWidth, outerHeight, point) {
// keep the box within the chart area
var pointX = point.x,
pointY = point.y,
x = pointX - boxWidth + outerLeft - 25,
y = pointY - boxHeight + outerTop + 10,
alignedRight;

// it is too far to the left, adjust it
if (x < 7) {
x = outerLeft + pointX + 15;
}

// Test to see if the tooltip is to far to the right,
// if it is, move it back to be inside and then up to not cover the point.
if ((x + boxWidth) > (outerLeft + outerWidth)) {
x -= (x + boxWidth) - (outerLeft + outerWidth);
y -= boxHeight;
alignedRight = true;
}

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

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

return {x: x, y: y};
}
```