Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def modify_doc(doc):
source = ColumnDataSource(dict(xs=[[1, 2]], ys=[[1, 1]]))
plot = Plot(plot_height=400, plot_width=400, x_range=Range1d(0, 3), y_range=Range1d(0, 3), min_border=0)
renderer = plot.add_glyph(source, MultiLine(xs='xs', ys='ys'))
tool = PolyDrawTool(renderers=[renderer])
plot.add_tools(tool)
plot.toolbar.active_multi = tool
div = Div(text='False')
def cb(attr, old, new):
if cds_data_almost_equal(new, expected):
div.text = 'True'
source.on_change('data', cb)
code = RECORD("matches", "div.text")
plot.add_tools(CustomAction(callback=CustomJS(args=dict(div=div), code=code)))
doc.add_root(column(plot, div))
return modify_doc
def test_clicking_resets_selection(self, single_plot_page):
source = ColumnDataSource(dict(x=[1, 2], y=[1, 1]))
source.selected.indices = [0]
source.selected.line_indices = [0]
# XXX (bev) string key for multiline_indices seems questionable
source.selected.multiline_indices = {"0": [0]}
plot = Plot(plot_height=400, plot_width=400, x_range=Range1d(0, 1), y_range=Range1d(0, 1), min_border=0)
plot.add_glyph(source, Circle(x='x', y='y', size=20))
plot.add_tools(ResetTool())
code = \
RECORD("indices", "s.selected.indices") + \
RECORD("line_indices", "s.selected.line_indices") + \
RECORD("multiline_indices", "s.selected.multiline_indices")
plot.add_tools(CustomAction(callback=CustomJS(args=dict(s=source), code=code)))
plot.toolbar_sticky = False
page = single_plot_page(plot)
# Verify selections are non empty
page.click_custom_action()
results = page.results
assert results['indices'] == [0]
assert results['line_indices'] == [0]
assert results['multiline_indices'] == {"0": [0]} # XXX (bev) string key
# Click the reset tool and check the selections are restored
button = page.get_toolbar_button('reset')
button.click()
def _make_plot():
source = ColumnDataSource(dict(x=[1, 2], y=[1, 1]))
r = Range1d(start=0.4, end=0.6)
plot = Plot(plot_height=400, plot_width=1100, x_range=Range1d(0, 1), y_range=Range1d(0, 1), min_border=0)
plot.add_glyph(source, Rect(x='x', y='y', width=0.9, height=0.9))
tool = RangeTool(x_range=r)
plot.add_tools(tool)
plot.min_border_right = 100
code = RECORD("start", "t.x_range.start", final=False) + RECORD("end", "t.x_range.end")
plot.add_tools(CustomAction(callback=CustomJS(args=dict(t=tool), code=code)))
plot.toolbar_sticky = False
return plot
def _make_plot(dimensions="both", num_objects=0):
source = ColumnDataSource(dict(x=[1, 2], y=[1, 1], width=[0.5, 0.5], height=[0.5, 0.5]))
plot = Plot(plot_height=400, plot_width=400, x_range=Range1d(0, 3), y_range=Range1d(0, 3), min_border=0)
renderer = plot.add_glyph(source, Rect(x='x', y='y', width='width', height='height'))
tool = BoxEditTool(dimensions=dimensions, num_objects=num_objects, renderers=[renderer])
plot.add_tools(tool)
plot.toolbar.active_multi = tool
code = RECORD("x", "source.data.x", final=False) + \
RECORD("y", "source.data.y", final=False) + \
RECORD("width", "source.data.width", final=False) + \
RECORD("height", "source.data.height")
plot.add_tools(CustomAction(callback=CustomJS(args=dict(source=source), code=code)))
plot.toolbar_sticky = False
return plot
def test_callback_property_executes(self, bokeh_model_page):
group = CheckboxGroup(labels=LABELS, css_classes=["foo"])
group.callback = CustomJS(code=RECORD("active", "cb_obj.active"))
page = bokeh_model_page(group)
el = page.driver.find_element_by_css_selector('.foo input[value="2"]')
el.click()
results = page.results
assert results['active'] == [2]
el = page.driver.find_element_by_css_selector('.foo input[value="0"]')
el.click()
results = page.results
assert results['active'] == [0, 2]
el = page.driver.find_element_by_css_selector('.foo input[value="2"]')
def modify_doc(doc):
source = ColumnDataSource(dict(x=[1, 2], y=[1, 1]))
plot = Plot(plot_height=400, plot_width=400, x_range=Range1d(0, 1), y_range=Range1d(0, 1), min_border=0)
plot.add_glyph(source, Circle(x='x', y='y', size=20))
plot.add_tools(CustomAction(callback=CustomJS(args=dict(s=source), code=RECORD("data", "s.data"))))
button = Toggle(css_classes=['foo'])
def cb(value):
if value:
source.data=dict(x=[10, 20], y=[10, 10])
else:
source.data=dict(x=[100, 200], y=[100, 100])
button.on_click(cb)
doc.add_root(column(button, plot))
def _make_plot(tool):
source = ColumnDataSource(dict(x=[1, 2], y=[1, 1]))
plot = Plot(plot_height=400, plot_width=450, min_border_right=50, x_range=Range1d(0, 1), y_range=Range1d(0, 1), min_border=0)
plot.add_glyph(source, Rect(x='x', y='y', width=0.9, height=0.9))
plot.add_tools(tool)
code = RECORD("xrstart", "p.x_range.start", final=False) + \
RECORD("xrend", "p.x_range.end", final=False) + \
RECORD("yrstart", "p.y_range.start", final=False) + \
RECORD("yrend", "p.y_range.end")
plot.add_tools(CustomAction(callback=CustomJS(args=dict(p=plot), code=code)))
plot.toolbar_sticky = False
return plot
def _make_plot():
source = ColumnDataSource(dict(x=[1, 2], y=[1, 1]))
plot = Plot(plot_height=400, plot_width=400, x_range=Range1d(0, 1), y_range=Range1d(0, 1), min_border=0)
plot.add_glyph(source, Rect(x='x', y='y', width=0.9, height=0.9))
plot.add_tools(ZoomOutTool())
code = RECORD("xrstart", "p.x_range.start", final=False) + \
RECORD("xrend", "p.x_range.end", final=False) + \
RECORD("yrstart", "p.y_range.start", final=False) + \
RECORD("yrend", "p.y_range.end")
plot.add_tools(CustomAction(callback=CustomJS(args=dict(p=plot), code=code)))
plot.toolbar_sticky = False
return plot
def _make_plot(dimensions="both", num_objects=0):
source = ColumnDataSource(dict(x=[1, 2], y=[1, 1], width=[0.5, 0.5], height=[0.5, 0.5]))
plot = Plot(plot_height=400, plot_width=400, x_range=Range1d(0, 3), y_range=Range1d(0, 3), min_border=0)
renderer = plot.add_glyph(source, Rect(x='x', y='y', width='width', height='height'))
tool = BoxEditTool(dimensions=dimensions, num_objects=num_objects, renderers=[renderer])
plot.add_tools(tool)
plot.toolbar.active_multi = tool
code = RECORD("x", "source.data.x", final=False) + \
RECORD("y", "source.data.y", final=False) + \
RECORD("width", "source.data.width", final=False) + \
RECORD("height", "source.data.height")
plot.add_tools(CustomAction(callback=CustomJS(args=dict(source=source), code=code)))
plot.toolbar_sticky = False
return plot
def test_callback_property_executes(self, single_plot_page):
source = ColumnDataSource(dict(x=[1, 2], y=[1, 1]))
plot = Plot(plot_height=400, plot_width=400, x_range=Range1d(0, 1), y_range=Range1d(0, 1), min_border=0)
plot.add_glyph(source, Circle(x='x', y='y', size=20))
spinner = Spinner(css_classes=['foo'], step=1, value=0)
spinner.callback = CustomJS(code=RECORD("value", "cb_obj.value"))
page = single_plot_page(column(spinner, plot))
el = page.driver.find_element_by_css_selector('.foo input')
enter_value_in_spinner(page.driver, el, 4)
results = page.results
assert results['value'] == 4
enter_value_in_spinner(page.driver, el, -5.1)
results = page.results
assert results['value'] == -5
assert page.has_no_console_errors()