Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capturing background clicks with coordinates #973

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

joders
Copy link
Contributor

@joders joders commented Nov 19, 2019

*Issue number of the reported bug or feature request: #972

Changes
I added a default click event to scatter plots which is triggered whenever the click interactions on the mark is set to neither 'add', 'delete' nor 'select'. The mark now has a further handler registration function called .on_background_click_with_coordinates().

This implementation might not be ideal as it doesn't tie in with the present background click handling and also it doesn't have its own click interaction on the mark.

Testing performed
I only manually observed the events emitted by the mark to confirm that the desired information is present.

@joders
Copy link
Contributor Author

joders commented Nov 19, 2019

This also fixes #653

@joders
Copy link
Contributor Author

joders commented Nov 21, 2019

to test:

from bqplot import *

xs=LinearScale(min=0,max=1)
ys=LinearScale(min=0,max=1)
xa=Axis(scale=xs)
ya=Axis(scale=ys,orientation='vertical')
mark=Scatter(scales={'x':xs,'y':ys},interactions={'click':''})   #  <-- IMPORTANT
fig=Figure(marks=[mark],axes=[xa,ya])

def background_click_handler(mark, event):
    print(event['point'])
mark.on_background_click_with_coordinates(background_click_handler)

fig

Copy link
Member

@martinRenou martinRenou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we not enhance the current on_background_click with the coordinates instead of adding a new Python method?

@martinRenou
Copy link
Member

Thanks for the PR anyway! This is super useful :)

@joders
Copy link
Contributor Author

joders commented Jan 14, 2020

Should we not enhance the current on_background_click with the coordinates instead of adding a new Python method?

I did have a look at that but as far as I can remember there is no easy way to do that (or it's impossible). On the other hand the background_click_with_coordinates could also serve the ordinary background click function though from what I remember this might have performance implications.

Thanks for the PR anyway! This is super useful :)

Thanks :)

@jfraymond
Copy link

This is a very useful addition.
I spent hours looking the the documentation for this feature.
It would be perfect it it was available for all types of plots, not only scatter plots.

@maartenbreddels
Copy link
Member

Hi joders,

thanks, I think this could be very useful, even apart from #1066 which listens to all mouse events / clicks. I think there are many cases where we'd like to capture clicks that are not on a mark. However, I don't think the place should be in a Mark since it does not make sense in the case of multiple marks, do you agree? I think the best place would be in Figure.ts, which is actually the originator of the events (ctrl-f for bg_clicked in that file).

Regards,

aarten

@joders
Copy link
Contributor Author

joders commented Apr 9, 2020

Hello,
I currently don't understand the architecture well enough to answer this and forgot quite a few things in the last months. I thought you can have multiple axes in one direction (in which case outputting a single coordinate for that direction isn't enough). I would definitely agree if axes in one direction are always aligned. Maybe I'm confusing scales and axes. Also, I guess it would fulfill @jfraymond 's needs.
Cheers,
Jonathan

@Mathemmagician
Copy link

Hello from the future,

Was anything like this ever merged? Especially interested in getting mouse coordinates for the bq.Map

@maartenbreddels
Copy link
Member

Hi, you could maybe take a look at glue-viz/bqplot-image-gl#57 instead

@Mathemmagician
Copy link

Not sure that would work since Map allows for various zoom ins. I think the approach above works for stationary widgets. Cool library though

@maartenbreddels
Copy link
Member

Not sure

not sure either, try it out :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants