Perhaps
going forward I will just check in
any notebooks or scripts into the
repo so they are at least available
there for anyone that wants them.
Thanks,
Bryan
> On Nov 28, 2017, at
10:14, Bryan Van de ven <[email protected] >
wrote:
>
> Hi,
>
> I have not done a good
job of sharing the code behind
the blog posts. I find that
the posts read better with
snippets. I’d like to find a
way to link to or include the
full code behind a scroller or
something but I have not had
the opportunity yet. However,
the code for that example is
roughly below (it may be
missing some imports as it was
scattered across a notebook
with other examples).
>
>
> import numpy as np
>
> from bokeh.events
import *
> from [bokeh.io](http://bokeh.io)
import output_notebook, show
> from bokeh.models
import ColumnDataSource,
CustomJS
> from bokeh.plotting
import figure
>
> output_notebook()
>
> p =
figure(x_range=(0,10),
y_range=(0,10),
x_axis_location=None,
y_axis_location=None,
tools=“”,
toolbar_location=None)
> p.plot_height = 300
> p.title.text = 'Drag
to draw lines, Tap to drop
Circles, Double Tap to reset’
> p.grid.grid_line_color
= None
>
p.background_fill_color =
‘#f5f5f5’
>
> s1 =
ColumnDataSource(data=dict(x=[ ],
y=, c=))
> p.circle('x', 'y',
color=‘c’, size=20, alpha=0.4,
source=s1)
>
> s2 =
ColumnDataSource(data=dict(x0= ,
y0=, x1=, y1=))
> p.segment(x0='x0',
y0=‘y0’, x1=‘x1’, y1=‘y1’,
line_dash=“dashed”,
line_width=2, source=s2)
>
> p.js_on_event(Tap,
CustomJS(args=dict(s=s1),
code=“”"
>
s.data.x.push(cb_obj.x)
>
s.data.y.push(cb_obj.y)
> s.data.c.push('#'
s.trigger(‘change’)
> """))
>
>
p.js_on_event(PanStart,
CustomJS(code=“”"
> window._p0 = {x:
cb_obj.x, y: cb_obj.y}
> """))
>
> p.js_on_event(Pan,
CustomJS(args=dict(s=s2),
code=“”"
> if (window._p0 !=
null) {
>
s.data.x0.push(window._p0.x);
>
s.data.y0.push(window._p0.y);
>
s.data.x1.push(cb_obj.x);
>
s.data.y1.push(cb_obj.y);
> window._p0 =
null;
> } else {
>
s.data.x1[s.data.x1.length-1]
= cb_obj.x
>
s.data.y1[s.data.y1.length-1]
= cb_obj.y
> }
>
s.trigger(‘change’)
> """))
>
>
p.js_on_event(DoubleTap,
CustomJS(args=dict(s1=s1,
s2=s2), code=“”"
> s1.data.x = []
> s1.data.y = []
> s1.data.c = []
>
s1.trigger(‘change’)
> s2.data.x0 = []
> s2.data.y0 = []
> s2.data.x1 = []
> s2.data.y1 = []
>
s2.trigger(‘change’)
> """))
>
> show(p)
>