开发者

Flot mousehover algorithm to detect purely based on x location?

开发者 https://www.devze.com 2023-01-11 16:20 出处:网络
Using jQuery\'s flot, there\'s a way to allow items to be selected by hovering over them. 开发者_如何学CIn the options, grid[mouseActiveRadius] may be set to a number to indicate the desired length of

Using jQuery's flot, there's a way to allow items to be selected by hovering over them. 开发者_如何学CIn the options, grid[mouseActiveRadius] may be set to a number to indicate the desired length of the radius of the selection circle.

For instance, if you set it to 10, then any mouse hover event will highlight the closest point in a 10 pixel radius circle.

However, I wish to instead tell flot to hover the point that's the closest in the x direction (instead of the closest point period).

EG in this example: point 1 is obviously a lot closer to x than point 2, but I still want flot to select point 2 since it is closer in the x direction.

           x
1







          2

Is there a way to do this with plugins/built in functionality, or do I need to write a function extending flot's default behavior?


The only way I found is to change the source. (it sucks ok, but it's often better a well commented hack than a un-maintainable workaround)

Find this code: (function findNearbyItem(), on line 2278 on my revision)

if (s.lines.show || s.points.show) {
                    for (j = 0; j < points.length; j += ps) {
                        var x = points[j], points[j + 1];
                        if (x == null)
                            continue;

Change to:

if (s.lines.show || s.points.show) {
                    for (j = 0; j < points.length; j += ps) {
                        var x = points[j], y =0; // points[j + 1];
                        if (x == null)
                            continue;

Hope this answer will help anybody with the same problem.


y = 0 will not work for large y-values. y = axisy.datamin fixes the problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消