def __init__(self, bokeh_plot, callback, delay=200, timeout=2000, throttle=None, **kwargs): self.p = bokeh_plot self.callback = callback self.kwargs = kwargs self.ref = str(uuid.uuid4()) self.comms_handle = None self.delay = delay self.timeout = timeout if throttle: print( "Warning: throttle parameter no longer supported; will not be accepted in future versions" ) # Initialize the image and callback self.ds, self.renderer = self._init_image() callback = self._init_callback() self.p.x_range.callback = callback self.p.y_range.callback = callback # Initialize document doc_handler = add_to_document(self.p) with doc_handler: self.doc = doc_handler._doc self.div = notebook_div(self.p, self.ref)
def figure_data(self, plot, fmt='html', **kwargs): doc_handler = add_to_document(plot.state) with doc_handler: doc = doc_handler._doc comm_id = plot.comm.id if plot.comm else None div = notebook_div(plot.state, comm_id) plot.document = doc doc.add_root(plot.state) return div
def figure_data(self, plot, fmt='html', **kwargs): doc_handler = add_to_document(plot.state) with doc_handler: doc = doc_handler._doc comms_target = str(uuid.uuid4()) doc.last_comms_target = comms_target div = notebook_div(plot.state, comms_target) plot.document = doc doc.add_root(plot.state) return div
def __init__(self, bokeh_plot, callback, throttle=100, **kwargs): """ The callback function should have the signature: fn(x_range=(xmin, xmax), y_range=(ymin, ymax), w, h, **kwargs) and return a PIL image object. Any kwargs provided here will be passed to the callback each time. The throttle parameter allows control over how many times the callback will get executed when there are frequent closely spaced events. """ self.p = bokeh_plot self.callback = callback self.kwargs = kwargs # Initialize RGBA image glyph and datasource w, h = self.p.plot_width, self.p.plot_height xmin, xmax = self.p.x_range.start, self.p.x_range.end ymin, ymax = self.p.y_range.start, self.p.y_range.end dw, dh = xmax-xmin, ymax-ymin image = self.callback(x_range=(xmin, xmax), y_range=(ymin, ymax), w=w, h=h, **self.kwargs) self.ds = ColumnDataSource(data=dict(image=[image.data], x=[xmin], y=[ymin], dw=[dw], dh=[dh])) self.p.image_rgba(source=self.ds, image='image', x='x', y='y', dw='dw', dh='dh', dilate=False) # Register callback on the class with unique reference cls = type(self) self.ref = str(uuid.uuid4()) cls._callbacks[self.ref] = self # Generate python callback command cmd = cls.cmd_template.format(module=cls.__module__, cls=cls.__name__, ref=self.ref) # Initialize callback cb_code = cls.jscode.format(plot_id=self.p._id, cmd=cmd, ref=self.ref.replace('-', '_'), throttle=throttle) cb_args = dict(x_range=self.p.x_range, y_range=self.p.y_range) callback = CustomJS(args=cb_args, code=cb_code) self.p.x_range.callback = callback self.p.y_range.callback = callback # Initialize document doc_handler = add_to_document(self.p) with doc_handler: self.doc = doc_handler._doc self.div = notebook_div(self.p, self.ref) self.comms = None
def __init__(self, bokeh_plot, callback, throttle=500, **kwargs): self.p = bokeh_plot self.callback = callback self.kwargs = kwargs self.ref = str(uuid.uuid4()) self.comms_handle = None self.throttle = throttle # Initialize the image and callback self.ds, self.renderer = self._init_image() callback = self._init_callback() self.p.x_range.callback = callback self.p.y_range.callback = callback # Initialize document doc_handler = add_to_document(self.p) with doc_handler: self.doc = doc_handler._doc self.div = notebook_div(self.p, self.ref)
def __init__(self, bokeh_plot, callback, throttle=100, **kwargs): self.p = bokeh_plot self.callback = callback self.kwargs = kwargs # Initialize RGBA image glyph and datasource w, h = self.p.plot_width, self.p.plot_height xmin, xmax = self.p.x_range.start, self.p.x_range.end ymin, ymax = self.p.y_range.start, self.p.y_range.end dw, dh = xmax-xmin, ymax-ymin image = self.callback((xmin, xmax), (ymin, ymax), w, h, **self.kwargs) self.ds = ColumnDataSource(data=dict(image=[image.img], x=[xmin], y=[ymin], dw=[dw], dh=[dh])) self.p.image_rgba(source=self.ds, image='image', x='x', y='y', dw='dw', dh='dh', dilate=False) # Register callback on the class with unique reference cls = type(self) self.ref = str(uuid.uuid4()) cls._callbacks[self.ref] = self # Generate python callback command cmd = cls.cmd_template.format(module=cls.__module__, cls=cls.__name__, ref=self.ref) # Initialize callback cb_code = cls.jscode.format(plot_id=self.p._id, cmd=cmd, ref=self.ref.replace('-', '_'), throttle=throttle) cb_args = dict(x_range=self.p.x_range, y_range=self.p.y_range) callback = CustomJS(args=cb_args, code=cb_code) self.p.x_range.callback = callback self.p.y_range.callback = callback # Initialize document doc_handler = add_to_document(self.p) with doc_handler: self.doc = doc_handler._doc self.div = notebook_div(self.p, self.ref) self.comms = None
def __init__(self, bokeh_plot, callback, delay=200, timeout=2000, throttle=None, **kwargs): self.p = bokeh_plot self.callback = callback self.kwargs = kwargs self.ref = str(uuid.uuid4()) self.comms_handle = None self.delay = delay self.timeout = timeout if throttle: print("Warning: throttle parameter no longer supported; will not be accepted in future versions") # Initialize the image and callback self.ds, self.renderer = self._init_image() callback = self._init_callback() self.p.x_range.callback = callback self.p.y_range.callback = callback # Initialize document doc_handler = add_to_document(self.p) with doc_handler: self.doc = doc_handler._doc self.div = notebook_div(self.p, self.ref)