On Nov 30, 2017, at 06:24, Andrea Tagliabue <[email protected]> wrote:
Wow really thanks for the quick answer. In order to avoid me bothering you for other issues, is there any doc regarding these custom tools? They looks to me pretty complex in terms of multiple options.
Many thanks again
Andrea
On 30 November 2017 at 13:18, Eugene Pakhomov <[email protected]> wrote:
Hi Andrea,
You almost got it. Here's the working version. The things that needed to be fixed: wrong function name (must be "_tap" instead of "_pan"), wrong "default_view" (must be TapBBToolView), extra data field for the data source (you'd get an error about inconsistent column lengths).
I also realized that TapTool is not needed because all it can provide you if just a single field "event_type", so I used a more general GestureTool instead.
import bokeh.util.compiler
bokeh.util.compiler._npmjs = 'npm.cmd'
from bokeh.core.properties import Instance
from bokeh.io import output_file, show
from bokeh.io.state import curstate
from bokeh.models import ColumnDataSource, Tool
from bokeh.plotting import figure
output_file('tool.html')
curstate().file['resources'].minified = False
JS_CODE = """
import * as p from "core/properties"
import {GestureTool, GestureToolView} from "models/tools/gestures/gesture_tool"
export class TapBBToolView extends GestureToolView
# this is executed on subsequent mouse/touch moves
_tap: (e) ->
frame = @plot_model.frame
{sx, sy} = e.bokeh
if not frame.bbox.contains(sx, sy)
return null
x = frame.xscales['default'].invert(sx)
y = frame.yscales['default'].invert(sy)
source = @model.source
source.data.x.push(x)
source.data.y.push(y)
source.change.emit()
export class TapBBTool extends GestureTool
default_view: TapBBToolView
type: "TapTool"
event_type: "tap"
tool_name: "H Line"
icon: "bk-tool-icon-arrow-right"
default_order: 12
@define { source: [ p.Instance ] }
"""
class TapBBTool(Tool):
__implementation__ = JS_CODE
source = Instance(ColumnDataSource)
source_HorizontalRay = ColumnDataSource(data=dict(x=, y=))
plot = figure(x_range=(0, 10), y_range=(0, 10),
tools=[TapBBTool(source=source_HorizontalRay)])
plot.title.text = "Tap to draw on the plot"
plot.ray(x='x', y='y', angle=0, length=0, line_dash="solid", line_width=2,
source=source_HorizontalRay)
show(plot)
Regards,
Eugene
On Thursday, November 30, 2017 at 6:58:10 PM UTC+7, Andrea Tagliabue wrote:
Hi all,
i am trying to implement a custom tool for drawing rays on tap event. I have implemented it via js_on_event and works fine but i need it as a tool since i want to give the ability of drawing rays, segments or lines and hence multiple custom tools are needed.
This code gets the plot displayed in the browser but when tapping nothing happens. I am struggling to understand what i am missing.
Would you mind to help me out?
Many thanks andrea
import bokeh.util.compiler
bokeh.util.compiler._npmjs = 'npm.cmd'
from bokeh.core.properties import Instance
from bokeh.io import output_file, show
from bokeh.models import ColumnDataSource, Tool
from bokeh.models.tools import Tap
from bokeh.plotting import figure
output_file('tool.html')
JS_CODE = """
import * as p from "core/properties"
import {TapTool, TapToolView} from "models/tools/gestures/tap_tool"
export class TapBBToolView extends TapToolView
# this is executed on subsequent mouse/touch moves
_pan: (e) ->
frame = @plot_model.frame
{sx, sy} = e.bokeh
if not frame.bbox.contains(sx, sy)
return null
x = frame.xscales['default'].invert(sx)
y = frame.yscales['default'].invert(sy)
source = @model.source
source.data.x.push(x)
source.data.y.push(y)
source.change.emit()
export class TapBBTool extends TapTool
default_view: TapToolView
type: "TapTool"
tool_name: "H Line"
icon: "bk-tool-icon-arrow-right"
event_type: "tap"
default_order: 12
@define { source: [ p.Instance ] }
"""
class TapBBTool(Tool):
__implementation__ = JS_CODE
source = Instance(ColumnDataSource)
source_HorizontalRay = ColumnDataSource(data=dict(x=, y=, angle=))
plot = figure(x_range=(0,10), y_range=(0,10), tools=[TapBBTool(source=source_HorizontalRay)])
plot.title.text ="Tap to draw on the plot"
plot.ray(x='x', y='y', angle = 0, length=0, line_dash="solid", line_width=2, source=source_HorizontalRay)
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/ac17d835-5909-4ac2-a552-9b94d3dba436%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.
--
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/CAKUye6BUwhPJOh-asYXsxK4YSkdogZCE_qFU4JNf8t3hFQfMHA%40mail.gmail.com\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.