diff --git a/src/tooltip.js b/src/tooltip.js index 3a98ad8..1abd0b3 100644 --- a/src/tooltip.js +++ b/src/tooltip.js @@ -154,8 +154,13 @@ window.nv.tooltip.* also has various helper methods. svgOffset.top = Math.abs(svgBound.top - chartBound.top); svgOffset.left = Math.abs(svgBound.left - chartBound.left); } - left += chartContainer.offsetLeft + svgOffset.left; - top += chartContainer.offsetTop + svgOffset.top; + + //If the parent container is an overflow
with scrollbars, subtract the scroll offsets. + //You need to also add any offset between the element and its containing
+ //Finally, add any offset of the containing
on the whole page. + left += chartContainer.offsetLeft + svgOffset.left - 2*chartContainer.scrollLeft; + top += chartContainer.offsetTop + svgOffset.top - 2*chartContainer.scrollTop; + } if (snapDistance && snapDistance > 0) { @@ -264,6 +269,7 @@ window.nv.tooltip.* also has various helper methods. //Original tooltip.show function. Kept for backward compatibility. + // pos = [left,top] nv.tooltip.show = function(pos, content, gravity, dist, parentContainer, classes) { //Create new tooltip div if it doesn't exist on DOM. @@ -281,7 +287,10 @@ window.nv.tooltip.* also has various helper methods. container.style.opacity = 0; container.innerHTML = content; body.appendChild(container); - + + //If the parent container is an overflow
with scrollbars, subtract the scroll offsets. + pos[0] = pos[0] - parentContainer.scrollLeft; + pos[1] = pos[1] - parentContainer.scrollTop; nv.tooltip.calcTooltipPosition(pos, gravity, dist, container); }; @@ -320,7 +329,7 @@ window.nv.tooltip.* also has various helper methods. }; //Global utility function to render a tooltip on the DOM. - //pos = [X,Y] coordinates of where to place the tooltip, relative to the SVG chart container. + //pos = [left,top] coordinates of where to place the tooltip, relative to the SVG chart container. //gravity = how to orient the tooltip //dist = how far away from the mouse to place tooltip //container = tooltip DIV diff --git a/test/lineChartTest.html b/test/lineChartTest.html index b75f0e5..f8921ca 100644 --- a/test/lineChartTest.html +++ b/test/lineChartTest.html @@ -4,13 +4,13 @@