LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Get plot number in 2D graph where each plot is a single point

Solved!
Go to solution

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.

Lubenhristov_0-1707844004314.png

 

 

I'll appreciate any ideas how I can read the plot index undex the mouse if the plot consists of single point. Thank you.

0 Kudos
Message 1 of 6
(2,169 Views)

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.

0 Kudos
Message 2 of 6
(2,143 Views)
Solution
Accepted by topic author Luben.hristov

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)

 

altenbach_0-1707850114152.png

 

altenbach_1-1707850307014.png

 

Message 3 of 6
(2,130 Views)

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.

0 Kudos
Message 4 of 6
(2,118 Views)

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!

 

altenbach_0-1707853726094.png

 

For context, see also this old idea, now implemented. 😄

 

Message 5 of 6
(2,110 Views)

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. 

0 Kudos
Message 6 of 6
(2,101 Views)