I have a canvas inside which I have a board / grid. When the user selects their mouse over the intersection of the grid, I want it to show where their game pace will go. This worked great when the board was the exact size of the canvas. I made it smaller by x for the whole round.
So, as you can see in the figure below, green shows the canvas, and the grid - the board. I placed my cursor in the lowest right corner of the green color to show when it fires. The only one that works great is average, because no matter how big the board I make, the middle will always be average.
Any simple fix will only be to make an area with a mouseover event, the size of the board instead of the canvas, but the event listener is on the canvas. My code is below the image

Variables
var canvas = document.getElementById("game-canvas");
var context = canvas.getContext("2d");
var boardSize = 13;
var border = canvas.width / 20;
var boardWidth = canvas.width - (border * 2);
var boardHeight = canvas.height - (border * 2);
var cellWidth = boardWidth / (boardSize - 1);
var cellHeight = boardHeight / (boardSize - 1);
var lastX;
var lastY;
Mouse Event:
canvas.addEventListener('mousemove', function(evt)
{
var position = getGridPoint(evt);
if ((position.x != lastX) || (position.y != lastY))
{
placeStone((position.x * cellWidth) + border, (position.y * cellWidth) + border, 'rgba(0, 0, 0, 0.2)');
}
lastX = position.x;
lastY = position.y;
});
Gets a point on the grid and converts it to a number 0 - 13 (in this case)
function getGridPoint(evt)
{
var rect = canvas.getBoundingClientRect();
var x = Math.round((evt.clientX-rect.left)/(rect.right-rect.left)*boardWidth);
var y = Math.round((evt.clientY-rect.top)/(rect.bottom-rect.top)*boardHeight);
var roundX = Math.round(x / cellWidth);
var roundY = Math.round(y / cellHeight);
return {
x: roundX,
y: roundY
};
}
And finally, draws a piece on the board:
function placeStone(x, y, color)
{
var radius = cellWidth / 2;
context.beginPath();
context.arc(x, y, radius, 0, 2 * Math.PI, false);
context.fillStyle = color;
context.fill();
context.lineWidth = 5;
}
I left a couple of bits, like the way the grid is updated, so this is not a series of circles following the mouse, etc., so that it is as short as I can, I was hoping it was just a simple asnwer and no one should recreate it, but if you do, I can enable a function that updates the grid and draws everything. Thanks for any advice.