Detect mouseover of certain points within an HTML canvas?

前端 未结 7 1167
予麋鹿
予麋鹿 2020-12-02 14:45

I\'ve built an analytical data visualization engine for Canvas and have been requested to add tooltip-like hover over data elements to display detailed metrics for the data

7条回答
  •  生来不讨喜
    2020-12-02 14:55

    I needed to do detect mouse clicks for a grid of squares (like cells of an excel spreadsheet). To speed it up, I divided the grid into regions recursively halving until a small number of cells remained, for example for a 100x100 grid, the first 4 regions could be the 50x50 grids comprising the four quadrants. Then these could be divided into another 4 each (hence giving 16 regions of 25x25 each). This requires a small number of comparisons and finally the 25x25 grid could be tested for each cell (625 comparisons in this example).

提交回复
热议问题