forked from chartjs/Chart.js
-
Notifications
You must be signed in to change notification settings - Fork 72
Closed
Description
In the changes proposed by @peachananr in #2 there was a small problem. If you scroll on Firefox and IE, the tooltips does not appear or with some shift. After some search, it seems that e.scrollTop property is not supported if a doctype is present.
I replaced :
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);
}
}
}
with this
function getPosition(e) {
var xPosition = 0;
var yPosition = 0;
while(e) {
xPosition += (e.offsetLeft - window.pageXOffset + e.clientLeft);
yPosition += (e.offsetTop - window.pageYOffset + 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.clientX) - position.x - window.pageXOffset,
my = (e.clientY) - position.y - window.pageYOffset;
if(chart.tooltips[i].inRange(mx,my)) {
chart.tooltips[i].render(mx,my);
rendered++;
}
}
if(rendered == 0) {
context.putImageData(chart.savedState,0,0);
}
}
}
Hope it help.
Cheers.
Val
Metadata
Metadata
Assignees
Labels
No labels