forked from chartjs/Chart.js
-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tooltip doesn't seems to work when parent div position is relative. #2
Comments
I've found a solution that might help you solve this. I replaced: context.canvas.onmousemove = function(e) {
if(chart.tooltips.length > 0) {
chart.savedState = chart.savedState == null ? context.getImageData(0,0,context.canvas.width,context.canvas.height) : chart.savedState;
var rendered = 0;
for(var i in chart.tooltips) {
var mx = e.x-context.canvas.offsetLeft,
my = e.y-context.canvas.offsetTop;
if(chart.tooltips[i].inRange(mx,my)) {
chart.tooltips[i].render(mx,my);
rendered++;
}
}
if(rendered == 0) {
context.putImageData(chart.savedState,0,0);
}
}
} with this function getPosition(e) {
var xPosition = 0;
var yPosition = 0;
while(e) {
xPosition += (e.offsetLeft - e.scrollLeft + e.clientLeft);
yPosition += (e.offsetTop - e.scrollTop + e.clientTop);
e = e.offsetParent;
}
return { x: xPosition, y: yPosition };
}
context.canvas.onmousemove = function(e) {
if(chart.tooltips.length > 0) {
chart.savedState = chart.savedState == null ? context.getImageData(0,0,context.canvas.width,context.canvas.height) : chart.savedState;
var rendered = 0;
for(var i in chart.tooltips) {
var position = getPosition(context.canvas),
mx = e.x - position.x,
my = e.y - position.y;
if(chart.tooltips[i].inRange(mx,my)) {
chart.tooltips[i].render(mx,my);
rendered++;
}
}
if(rendered == 0) {
context.putImageData(chart.savedState,0,0);
}
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If I wrap the canvas with relative positioned div, the tooltip no longer show up. When I remove position:relative, the tooltip works again. Can you replicate this as well?
Thanks
The text was updated successfully, but these errors were encountered: