At this point, you have all tools at hands to implement a hover. Now, you will need to make it happen. To wire it all up, you need to do the following steps:
- Listen to mousemoves on the main Canvas.
- Translate these coordinates to positions on the hidden Canvas.
- Pick the color from that position.
- Strip out the color value that represents the data array index for your data.
- Lean back and think of ways to use it.
Listening on mousemove is easy; you just need to perform the following command:
canvas.on('mousemove', highlightPicking);
Done. The first thing we will do in highlightPicking() is translate the mouse position on the main Canvas to the coordinates on the hidden Canvas:
function highlightPicking() { var pos = d3.mouse(this); ...