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") + RECORD("y", "source.data.y") + RECORD("width", "source.data.width") + 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_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() page.click_custom_action() results = page.results assert results['indices'] == [] assert results['line_indices'] == [] assert results['multiline_indices'] == {} assert page.has_no_console_errors()
def test_updates_when_visibility_is_toggled(self, single_plot_page) -> None: source = ColumnDataSource(dict(x=[1, 2], y1=[0, 1], y2=[10, 11])) plot = Plot(plot_height=400, plot_width=400, x_range=DataRange1d(), y_range=DataRange1d(only_visible=True), min_border=0) plot.add_glyph(source, Circle(x='x', y='y1')) glyph = plot.add_glyph(source, Circle(x='x', y='y2')) code = 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 button = Button(css_classes=['foo']) button.js_on_click( CustomJS(args=dict(glyph=glyph), code="glyph.visible=false")) page = single_plot_page(column(plot, button)) page.click_custom_action() results = page.results assert results['yrstart'] <= 0 assert results['yrend'] >= 11 button = page.driver.find_element_by_css_selector('.foo .bk-btn') button.click() page.click_custom_action() results = page.results assert results['yrstart'] <= 0 assert results['yrend'] < 5 assert page.has_no_console_errors()
def test_ranges_update(self, single_plot_page) -> None: 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(WheelZoomTool()) code = RECORD("event_name", "cb_obj.event_name", final=False) + \ RECORD("x0", "cb_obj.x0", final=False) + \ RECORD("x1", "cb_obj.x1", final=False) + \ RECORD("y0", "cb_obj.y0", final=False) + \ RECORD("y1", "cb_obj.y1") plot.js_on_event(RangesUpdate, CustomJS(code=code)) plot.add_tools(CustomAction(callback=CustomJS(code=""))) plot.toolbar_sticky = False page = single_plot_page(plot) button = page.get_toolbar_button('wheel-zoom') button.click() page.driver.execute_script(SCROLL(-200)) page.click_custom_action() results = page.results assert results['event_name'] == "rangesupdate" assert results['x0'] > 0 assert results['x1'] < 1 assert results['y0'] > 0 assert results['y1'] < 1 assert page.has_no_console_errors()
def modify_doc(doc): plot = Plot(height=400, 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 = PolyEditTool(renderers=[renderer]) psource = ColumnDataSource(dict(x=[], y=[])) prenderer = plot.add_glyph(psource, Circle(x='x', y='y', size=10)) tool.vertex_renderer = prenderer plot.add_tools(tool) plot.toolbar.active_multi = tool plot.toolbar_sticky = False div = Div(text='False') def cb(attr, old, new): try: if cds_data_almost_equal(new, expected): div.text = 'True' except ValueError: return 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))
def test_ranges_update(self, single_plot_page: SinglePlotPage) -> None: source = ColumnDataSource(dict(x=[1, 2], y=[1, 1])) plot = Plot(height=400, 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(PanTool()) code = RECORD("event_name", "cb_obj.event_name", final=False) + \ RECORD("x0", "cb_obj.x0", final=False) + \ RECORD("x1", "cb_obj.x1", final=False) + \ RECORD("y0", "cb_obj.y0", final=False) + \ RECORD("y1", "cb_obj.y1") plot.js_on_event(RangesUpdate, CustomJS(code=code)) plot.tags.append(CustomJS(name="custom-action", code="")) plot.toolbar_sticky = False page = single_plot_page(plot) page.drag_canvas_at_position(plot, 100, 100, 20, 20) page.eval_custom_action() results = page.results assert results['event_name'] == "rangesupdate" assert results['x0'] < 0 assert results['x1'] < 1 assert results['y0'] > 0 assert results['y1'] > 1 assert page.has_no_console_errors()
def _make_plot(num_objects=0): source = ColumnDataSource(dict(xs=[], ys=[])) 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 = FreehandDrawTool(num_objects=num_objects, renderers=[renderer]) plot.add_tools(tool) plot.toolbar.active_multi = tool code = RECORD("xs", "source.data.xs") + RECORD("ys", "source.data.ys") plot.add_tools(CustomAction(callback=CustomJS(args=dict(source=source), code=code))) plot.toolbar_sticky = False return plot
def _make_plot(num_objects=0, add=True, drag=True): source = ColumnDataSource(dict(x=[1, 2], y=[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, Circle(x='x', y='y')) tool = PointDrawTool(num_objects=num_objects, add=add, drag=drag, renderers=[renderer]) plot.add_tools(tool) plot.toolbar.active_multi = tool code = RECORD("x", "source.data.x") + RECORD("y", "source.data.y") plot.add_tools(CustomAction(callback=CustomJS(args=dict(source=source), code=code))) plot.toolbar_sticky = False return plot
def _make_plot(): source = ColumnDataSource(dict(x=[1, 2], y=[1, 1])) r = Range1d(start=0.4, end=0.6) plot = Plot(height=400, 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.tags.append(CustomJS(name="custom-action", args=dict(t=tool), code=code)) plot.toolbar_sticky = False return plot
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") + 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(tool): source = ColumnDataSource(dict(x=[1, 2], y=[1, 1])) plot = Plot(height=400, 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.tags.append(CustomJS(name="custom-action", args=dict(p=plot), code=code)) plot.toolbar_sticky = False return plot
def _make_plot(num_objects=0, drag=True, vertices=False): 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(num_objects=num_objects, drag=drag, renderers=[renderer]) if vertices: psource = ColumnDataSource(dict(x=[], y=[])) prenderer = plot.add_glyph(psource, Circle(x='x', y='y', size=10)) tool.vertex_renderer = prenderer plot.add_tools(tool) plot.toolbar.active_multi = tool code = RECORD("xs", "source.data.xs", final=False) + RECORD("ys", "source.data.ys") plot.add_tools(CustomAction(callback=CustomJS(args=dict(source=source), code=code))) plot.toolbar_sticky = False return plot
def _make_plot(num_objects=0, drag=True, vertices=False): 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(num_objects=num_objects, drag=drag, renderers=[renderer]) if vertices: psource = ColumnDataSource(dict(x=[], y=[])) prenderer = plot.add_glyph(psource, Circle(x='x', y='y', size=10)) tool.vertex_renderer = prenderer plot.add_tools(tool) plot.toolbar.active_multi = tool code = RECORD("xs", "source.data.xs") + RECORD("ys", "source.data.ys") plot.add_tools(CustomAction(callback=CustomJS(args=dict(source=source), code=code))) plot.toolbar_sticky = False return plot
def _make_plot(): data = {"xs": [[1, 2], [1.6, 2.45]], "ys": [[1, 1], [1.5, 0.75]]} source = ColumnDataSource(data) 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', line_width=10)) tool = PolyEditTool(renderers=[renderer]) psource = ColumnDataSource(dict(x=[], y=[])) prenderer = plot.add_glyph(psource, Circle(x='x', y='y', size=10)) tool.vertex_renderer = prenderer plot.add_tools(tool) plot.toolbar.active_multi = tool code = RECORD("xs", "source.data.xs") + RECORD("ys", "source.data.ys") plot.add_tools(CustomAction(callback=CustomJS(args=dict(source=source), code=code))) plot.toolbar_sticky = False return plot
def _make_plot(**kw): source = ColumnDataSource(dict(x=[1, 2], y1=[0, 1], y2=[10, 11])) plot = Plot(plot_height=400, plot_width=400, x_range=DataRange1d(), y_range=DataRange1d(**kw), min_border=0) plot.add_glyph(source, Circle(x='x', y='y1')) glyph = plot.add_glyph(source, Circle(x='x', y='y2')) glyph.visible = False code = 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, glyph
def test_clicking_resets_selection(self, single_plot_page) -> None: 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(height=400, 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() page.click_custom_action() results = page.results assert results['indices'] == [] assert results['line_indices'] == [] assert results['multiline_indices'] == {} assert page.has_no_console_errors()
def _make_plot(dimensions="both", num_objects: int = 0) -> Plot: source = ColumnDataSource( dict(x=[1, 2], y=[1, 1], width=[0.5, 0.5], height=[0.5, 0.5])) plot = Plot(height=400, 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.tags.append( CustomJS(name="custom-action", args=dict(source=source), code=code)) plot.toolbar_sticky = False return plot
def test_updates_when_visibility_is_toggled( self, single_plot_page: SinglePlotPage) -> None: source = ColumnDataSource(dict(x=[1, 2], y1=[0, 1], y2=[10, 11])) plot = Plot(height=400, width=400, x_range=DataRange1d(), y_range=DataRange1d(only_visible=True), min_border=0) plot.add_glyph(source, Circle(x='x', y='y1')) glyph = plot.add_glyph(source, Circle(x='x', y='y2')) code = RECORD("yrstart", "p.y_range.start", final=False) + RECORD( "yrend", "p.y_range.end") plot.tags.append( CustomJS(name="custom-action", args=dict(p=plot), code=code)) plot.toolbar_sticky = False button = Button() button.js_on_click( CustomJS(args=dict(glyph=glyph), code="glyph.visible=false")) page = single_plot_page(column(plot, button)) page.eval_custom_action() results = page.results assert results['yrstart'] <= 0 assert results['yrend'] >= 11 button = find_element_for(page.driver, button, ".bk-btn") button.click() page.eval_custom_action() results = page.results assert results['yrstart'] <= 0 assert results['yrend'] < 5 assert page.has_no_console_errors()
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") + RECORD("xrend", "p.x_range.end") + RECORD("yrstart", "p.y_range.start") + RECORD("yrend", "p.y_range.end") plot.add_tools(CustomAction(callback=CustomJS(args=dict(p=plot), code=code))) plot.toolbar_sticky = False return plot