[bokeh] Transform tap tool for double tap

Hi,

···

On Sat, Apr 28, 2018 at 12:02 PM, Vincent Konaté [email protected] wrote:

I have been looking to transform the tap tool so that it performs action on double tap.

I found that stackoverflow page, that basically should answer my question:

https://stackoverflow.com/questions/39426158/bokeh-js-callback-when-double-click-on-circle?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa

(Here below the code form that page)

However it renders a blank canvas when I run it.

Could anyone help me find out what’s wrong with it to get me started?

this is very old code and significant changes will be necessary (exports, events, coordinate mapping, selections; so almost everything). Maybe a more productive approach would be to contribute to bokeh and add support to TapTool for configuring the event.

Mateusz

from bokeh.core.properties import Instance
from bokeh.io import output_file, show
from bokeh.models import ColumnDataSource, TapTool, CustomJS, OpenURL
from bokeh.plotting import figure
output_file('tool.html')

JS_CODE = """
p = require "core/properties"
TapTool = require "models/tools/gestures/tap_
tool"
class NewTapToolView extends TapTool.View
_get_canvas_position: (e) ->
canvas = @plot_view.canvas
vx = canvas.sx_to_vx(e.bokeh.sx)
vy = canvas.sy_to_vy([e.bokeh.sy](http://e.bokeh.sy)    )
return [vx, vy]
_tap: (e) ->
console.log('click')
[vx, vy] = @_get_canvas_position(e)
append = e.srcEvent.shiftKey ? false
@_select(vx, vy, true, append)
_doubletap: (e) ->
console.log('double click')
[vx, vy] = @_get_canvas_position(e)
append = false
@_select(vx, vy, true, append)
class NewTapTool extends TapTool.Model
default_view: NewTapToolView
type: "NewTapTool"
tool_name: "New Tap Tool"
@define { source: [ p.Instance ] }
module.exports =
Model: NewTapTool
View: NewTapToolView
"""


class NewTapTool(TapTool):
    __implementation__ = JS_CODE
source = Instance(ColumnDataSource)


x = y = [i for i in range(10)]
source = ColumnDataSource(data=dict(x=x, y=y))

plot = figure(x_range=(0, 10), y_range=(0, 10), tools=[NewTapTool(source=source)])
plot.title.text = "Double click on a dot to test"
plot.circle('x', 'y', source=source, size=10)

newtaptool = plot.select(type=TapTool)
newtaptool.callback = OpenURL(url="[https://en.wikipedia.org/](https://en.wikipedia.org/)")

show(plot)

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/49506c87-d8e1-4827-85a0-de4cb8ac9771%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.