def test_bkwidget_bkplot_links(document, comm): from bokeh.models import Slider bokeh_widget = Slider(value=5, start=1, end=10, step=1e-1) bokeh_fig = figure() scatter = bokeh_fig.scatter([1, 2, 3], [1, 2, 3]) Link(bokeh_widget, scatter, properties={'value': 'glyph.size'}) row = Row(bokeh_fig, bokeh_widget) row.get_root(document, comm=comm) slider = bokeh_widget link_customjs = slider.js_property_callbacks['change:value'][-1] assert link_customjs.args['source'] is slider assert link_customjs.args['target'] is scatter.glyph code = """ value = source['value']; value = value; value = value; try { property = target.properties['size']; if (property !== undefined) { property.validate(value); } } catch(err) { console.log('WARNING: Could not set size on target, raised error: ' + err); return; } try { target['size'] = value; } catch(err) { console.log(err) } """ assert link_customjs.code == code
def test_bkwidget_hvplot_links(document, comm): from bokeh.models import Slider bokeh_widget = Slider(value=5, start=1, end=10, step=1e-1) points1 = hv.Points([1, 2, 3]) Link(bokeh_widget, points1, properties={'value': 'glyph.size'}) row = Row(points1, bokeh_widget) model = row.get_root(document, comm=comm) hv_views = row.select(HoloViews) assert len(hv_views) == 1 slider = bokeh_widget scatter = hv_views[0]._plots[model.ref['id']][0].handles['glyph'] link_customjs = slider.js_property_callbacks['change:value'][-1] assert link_customjs.args['source'] is slider assert link_customjs.args['target'] is scatter code = ( "value = source['value'];" "try { property = target.properties['size'];" "if (property !== undefined) { property.validate(value); } }" "catch(err) { console.log('WARNING: Could not set size on target, raised error: ' + err); return; }" "target['size'] = value") assert link_customjs.code == code