02-13-2024 11:07 AM
Hi,
There is 2D graph and I want to track which plot was hovered by the mouse pointer. Surprisingly if the plot consists of single point the method GetPlotAtPosition never yields the plot number (it always shows -1). See attached example - if you add second element in the X and Y array everything works as expected, but if you press the button <Set to single point> the plot number is always -1. Below is a snapshot from the block diagram.
I'll appreciate any ideas how I can read the plot index undex the mouse if the plot consists of single point. Thank you.
Solved! Go to Solution.
02-13-2024 12:21 PM
It seems the position is taken from the interpolation line, not the points, but if there is only one point, there is no line, of course.
You can easily hover halfway between the two points and get the plot number for that. I would probably do the math instead and for any mouse position find the closest point, then decide if the distance is close enough. This is most easily done if you would use complex arrays instead of clusters, of course.
02-13-2024 12:54 PM
Here is a quick draft. You can easily expand it for multiple plot and get the closest point AND it's plot number, of course. (not shown)
Of course for better visual, I would make sure the graph grid is is square (i.e. same # of pixels per axis unit. Not shown)
02-13-2024 01:33 PM
Thank you for the idea, Altenbach!
It seems like this is an undocumented behaviour of the 2D graph - normally the plots contain plurality of points, but if the plot contains just one point, some of the functions don't work as expected.
I'll use your idea and calculate the distance between the current mouse position and the individual points of the plots - the plot point which has minimum distance to the mouse is more likely the one I'm looking for.
02-13-2024 01:50 PM - edited 02-13-2024 01:52 PM
Finding the plot using the built-in tool can get expensive if there are many plots and points. It needs to iterate over all line segments and find the point<->line distance between segment and cursor. I guess they decided to not expand it to also include the point<->point distance as required if the plot only has one point, as in your case.
Note that I have changed the cursor move event to keep the event history at one and don't lock the panel. This will prevent event queue buildup if you keep moving the mouse around. Highly recommended!
For context, see also this old idea, now implemented. 😄
02-13-2024 01:55 PM - edited 02-13-2024 01:56 PM
Good hint for keeping the panel unlocked! Makes perfect sense to avoid building events before the previous event was not processed - I never paid attention to these fields.