def test_widget_bkplot_link(document, comm): widget = ColorPicker(value='#ff00ff') bokeh_fig = figure() scatter = bokeh_fig.scatter([1, 2, 3], [1, 2, 3]) widget.jslink(scatter.glyph, value='fill_color') row = Row(bokeh_fig, widget) model = row.get_root(document, comm=comm) link_customjs = model.children[1].js_property_callbacks['change:color'][-1] assert link_customjs.args['source'] is model.children[1] assert link_customjs.args['target'] is scatter.glyph assert scatter.glyph.fill_color == '#ff00ff' code = """ value = source['color']; value = value; value = value; try { property = target.properties['fill_color']; if (property !== undefined) { property.validate(value); } } catch(err) { console.log('WARNING: Could not set fill_color on target, raised error: ' + err); return; } try { target['fill_color'] = value; } catch(err) { console.log(err) } """ assert link_customjs.code == code
def test_widget_jscallback_args_scalar(document, comm): widget = ColorPicker(value='#ff00ff') widget.jscallback(value='some_code', args={'scalar': 1}) model = widget.get_root(document, comm=comm) customjs = model.js_property_callbacks['change:color'][-1] assert customjs.args['scalar'] == 1
def test_widget_jscallback(document, comm): widget = ColorPicker(value='#ff00ff') widget.jscallback(value='some_code') model = widget.get_root(document, comm=comm) customjs = model.js_property_callbacks['change:color'][-1] assert customjs.args['source'] is model assert customjs.code == "try { some_code } catch(err) { console.log(err) }"
def test_widget_jscallback_args_model(document, comm): widget = ColorPicker(value='#ff00ff') widget2 = ColorPicker(value='#ff00ff') widget.jscallback(value='some_code', args={'widget': widget2}) model = Row(widget, widget2).get_root(document, comm=comm) customjs = model.children[0].js_property_callbacks['change:color'][-1] assert customjs.args['source'] is model.children[0] assert customjs.args['widget'] is model.children[1] assert customjs.code == "try { some_code } catch(err) { console.log(err) }"