Following is my Code for reference.
- One main image is display on Canvas.
- On that image with dataJSON object I am passing x and y co-ordinates and drawing ball images there.
- Then tooltip is added. (function tooltipFunc)
- But when I am panning image then tooltip is not visible on those balls images on hover.**
- In tooltipFunc function, if code is for default position when page loads first time. And else code is for translate positions when we are panning the image to show the tooltip.
- But after panning, when mousehover on balls images then tooltip is not visible. When I click on those ball images then tooltip is visible but not on the translate position.
Any suggestions?
//Following is Code for reference
var isDown = false;
var startCoords = [];
var last = [0, 0];
canvas.onmousedown = function(e){
isDown = true;
startCoords = [
e.offsetX - last[0],
e.offsetY - last[1]
];
};
canvas.onmouseup = function(e){
isDown = false;
last = [
e.offsetX - startCoords[0], // set last coordinates
e.offsetY - startCoords[1]
];
//tooltipFunc(e);
};
canvas.onmousemove = function(e){
tooltipFunc(e); //tooltip function
if(!isDown) return;
var x = e.offsetX;
var y = e.offsetY;
context.setTransform(1, 0, 0, 1, x - startCoords[0], y - startCoords[1]);
draw1(scaleValue);//redrawing image on canvas while panning image
}
function tooltipFunc(e){
var translationX, translationY;
var r = canvas.getBoundingClientRect(),
x = e.clientX - r.left,
y = e.clientY - r.top,
i = 0,
r,
inTooltip = false;
if((typeof startCoords[0] === 'undefined' || startCoords[0] === 'NaN') && (typeof startCoords[1] === 'undefined' || startCoords[1] === 'NaN')){
for (; r = dataJSON[i]; i++) {
if (x >= parseInt(dataJSON[i].x[0] * scaleValue) + parseInt(scaleValue) && x <= parseInt(dataJSON[i].x[0] * scaleValue) + parseInt(20/scaleValue) && y >= parseInt(dataJSON[i].y[0] * scaleValue) && y <= parseInt(dataJSON[i].y[0] * scaleValue) + parseInt(20/scaleValue)) {
clearTooltip();
showTooltip(e.clientX, e.clientY, i);
inTooltip = true;
}
}
}
else{
for (; r = dataJSON[i]; i++) {
translationX = parseInt(x) - parseInt(startCoords[0]);
translationY = parseInt(y) - parseInt(startCoords[1]);
if (x >= parseInt(dataJSON[i].x[0] * scaleValue) + parseInt(translationX) + parseInt(scaleValue) && x <= parseInt(dataJSON[i].x[0] * scaleValue) + parseInt(translationX) + parseInt(20/scaleValue) && y >= parseInt(dataJSON[i].y[0] * scaleValue) + parseInt(translationY) && y <= parseInt(dataJSON[i].y[0] * scaleValue) + parseInt(translationY) + parseInt(20/scaleValue)) {
clearTooltip();
var newX = e.clientX - translationX;
var newY = e.clientY - translationY
showTooltip(newX, newY, i);
inTooltip = true;
}
}
}
}