09-09-2024 08:58 AM
I want to show a cursor on the point nearest to the mouse cursor. This will be used to select datapoints on an XY graph. It seems simple, just use the Map Coords to XY method and get the distance of this XY position to each graph point and take the minimum. The x-axis is on log scale, so I take the log base 10 on the x-values.
The subvi:
It almost works, it's just a little off. In the below example, clearly the nearest point is not selected.
Is my calculation wrong? Am I missing something else?
09-10-2024 01:01 AM - edited 09-10-2024 01:05 AM
I didn't analyze your code (for instance, I don't know what happens when you do an Array Max and Min on complex numbers. You might need to check the actual distance, for example by converting to polar), but what you can do is set the cursor to snap rather than being free dragging and then you just need to use the XY value you got from the method and set the cursor position to that value and it will snap to the nearest point on the plots it's defined to snap to.
09-10-2024 03:08 AM
Looks like you are finding the nearest "Y" position instead of absolute. If you want to select range then maybe you could just do the calculations on X axis and ignore the Y.
09-10-2024 03:51 AM - edited 09-10-2024 03:56 AM
@tst ha scritto:
I didn't analyze your code (for instance, I don't know what happens when you do an Array Max and Min on complex numbers. You might need to check the actual distance, for example by converting to polar), but what you can do is set the cursor to snap rather than being free dragging and then you just need to use the XY value you got from the method and set the cursor position to that value and it will snap to the nearest point on the plots it's defined to snap to.
Array Max Min was done on the absolute (i.e. distance) of the complex number.
Setting the cursor to snap works well. It even works with multiple plots! It automatically snaps to the correct plot, I didn't know this was possible.
Anyway, I still need the distance to show the cursor only when the mouse is near a plot. I forgot to take into account the range of the axes. The x-axis doesn't start from 0, this caused an offset in the distances. When taking this into account, the distance is very similar (not exactly the same for some reason) to the snapping method.
Here is the updated and cleaned-up version in case someone is interested.