So, GR offers the samplelocator()
function which returns current x, y coordinates and the clicked mouse button.
Here is a MWE:
using GR
plot(rand(10,2))
x, y, button = samplelocator()
while button == 0
@show x,y,button = samplelocator()
sleep(.01)
end
The output would be something like this:
(x, y, button) = samplelocator() = (0.9119601328903655, 0.2168141592920354, 0)
(x, y, button) = samplelocator() = (0.8903654485049833, 0.25442477876106195, 0)
(x, y, button) = samplelocator() = (0.8754152823920266, 0.2743362831858407, 0)
(x, y, button) = samplelocator() = (0.8504983388704319, 0.3075221238938053, 0)
(x, y, button) = samplelocator() = (0.8239202657807309, 0.331858407079646, 0)
(x, y, button) = samplelocator() = (0.813953488372093, 0.3407079646017699, 0)
(x, y, button) = samplelocator() = (0.7940199335548173, 0.3517699115044248, 0)
(x, y, button) = samplelocator() = (0.7558139534883721, 0.36283185840707965, 0)
(x, y, button) = samplelocator() = (0.739202657807309, 0.36283185840707965, 0)
(x, y, button) = samplelocator() = (0.7325581395348837, 0.36283185840707965, 0)
(x, y, button) = samplelocator() = (0.7325581395348837, 0.36283185840707965, 0)
(x, y, button) = samplelocator() = (0.707641196013289, 0.3561946902654868, 0)
This is a nice to have raw functionality, but it still falls short of being a proper mouse/click events handler. E.g., it would be hard to capture a click on a data point in the plot using samplelocator()
.
I wonder if there are some other solutions.