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

tap tool on bokeh server does not select data points with a custom callback #6707

Closed
EmperorDali opened this issue Aug 1, 2017 · 7 comments

Comments

@EmperorDali
Copy link

EmperorDali commented Aug 1, 2017

Versions: Firefox 54.0.1 (64-bit) on macOS Sierra, 0.12.6

Expected behavior: With the tap tool, the user can select a data point and the specified callback will fire

Observed behavior: Callback fires intermittently with incorrect parameters, or does not fire at all

mwe.py:

from bokeh import plotting as bplt
from bokeh import layouts as blayouts
from bokeh import models as bmodels
from bokeh import io as bio

fig = bplt.figure(tools="tap")

source = bmodels.ColumnDataSource(dict(x=[0,1], y=[0,1]))

r = fig.circle('x', 'y', source=source, size=4)

def handler(attr, old, new):
    print('attr: {} old: {} new: {}'.format(attr, old, new))

r.data_source.on_change('selected', handler)

bio.curdoc().add_root(blayouts.layout([[fig]]))

bokeh serve --show mwe.py

Steps to reproduce

  1. Run bokeh serve --show mwe.py as above
  2. Click one of the circles
  3. Observe that either i) no output is printed, or ii) the following is printed, indicating the callback fired with incorrect empty arguments:

attr: selected old: {'0d': {'glyph': None, 'indices': []}, '1d': {'indices': []}, '2d': {'indices': {}}} new: {'0d': {'glyph': None, 'get_view': {}, 'indices': []}, '1d': {'indices': []}, '2d': {'indices': {}}}

@bryevdv
Copy link
Member

bryevdv commented Aug 1, 2017

I can reproduce this on firefox, but not on safari.

@bryevdv
Copy link
Member

bryevdv commented Aug 1, 2017

FYI the callback being fired with empty args is equivalent to "unselection", and is expected any time things are unselected. The callback fires based on the value of the selection, not based on just clicking or even hit-testing positive after a click. E.g. If something is already selected, and you click it again, there will be no selection change, and hence no callback. Or if you click in outside any glyph or hit esc to unselect, that changes to an empty selection, so there will be a callback with empty data.

That said, it seems to be ignoring valid mouse hits on FF.

@EmperorDali
Copy link
Author

I'm also encountering the bug in Safari: did you try clicking more than once? Sometimes intermittently one of the circles will select if you're clicking a lot. This happened to me once with Safari, but then I deselected and the other circle wouldn't select.

@p-himik
Copy link
Contributor

p-himik commented Aug 1, 2017

I can reproduce on Google Chrome.
A couple of things that I notice:

  1. You should increase size - otherwise, it's way too easy to miss a point
  2. The very first tap on an empty space (so, nothing was and nothing is selected) generates the output in the description - the difference is in get_view. Probably it's a function that gets added to the selection result dynamically, resulting in this diff
  3. If the very first tap is on a dot, the diff includes both get_view and the correct dot index
  4. In either case, subsequent taps don't cause the callback to be called if the selection doesn't change

@EmperorDali
Copy link
Author

EmperorDali commented Aug 1, 2017

Update:

Good call @p-himik, with size = 20 the bug seems to NOT occur on firefox. I can reliably select either circle, back and forth.

Something with hit detection?

Also, since whether or not the bug occurs depends on the size of the glyphs, reproducing might depend on the resolution of the display.

@bryevdv
Copy link
Member

bryevdv commented Aug 1, 2017

I'm also encountering the bug in Safari: did you try clicking more than once?

Yes I clicked each circle several dozen times in various orders and it always triggered appropriately

@bryevdv bryevdv modified the milestones: 0.13.x, short-term Sep 11, 2018
@bryevdv
Copy link
Member

bryevdv commented Mar 8, 2019

I updated the code to the current standard usage:

r.data_source.selected.on_change('indices', handler)

and tested on Chrome, FF, and Safari. The circles were a bit hard to hit (because they are tiny) but in every case the callback printed exactly what is expected. There were lots of issues previously with both the "dict" for selections, and also with Bokeh itself replacing whole Selection objects. My guess is this issue was related to those things as well (neither of them exists anymore)

@bryevdv bryevdv closed this as completed Mar 8, 2019
@bryevdv bryevdv modified the milestones: short-term, 1.1 Mar 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants