How to reference Bokeh quad values on-select within callback

Viewed 1148

I'm trying to extract values from quads when I click on them using TapTool

The following code works for a hover tool but not for tap.

from bokeh.plotting import figure, show
from bokeh.models import HoverTool, CustomJS, ColumnDataSource

source =  generate_column_data_source()
quad_plot = generate_quad_plot(source )

code = ''' var hovered_ind = cb_data.index['1d'].indices[0];
    var data = source.data
    console.log(hovered_ind)
    if(hovered_ind != undefined){
        console.log('inside', hovered_ind)
        var top = data['top'][hovered_ind]
        var bottom = data['bottom'][hovered_ind]
        var left = data['left'][hovered_ind]
        var right = data['right'][hovered_ind]
        console.log(top, bottom, left, right)
    } '''

callback = CustomJS(code=code, args={'source': source})

quad_plot.add_tools(TapTool( callback=callback))  

show(quad_plot)

It seems that cb_data.index['1d'].indices[0]; exists for hover interactions, but not for tap-selection interactions.

For tap-selection, cb_data has a single attribute named geometry, that gives me x,y,vx,and vypoints.

I do not believe these parameters to be exact enough to guarantee efficient indexing/lookup of values from my source.

Is there any way to get that precise of an index with TapTool?

1 Answers
Related