def _plot_figure(self, idx, fig_format='json'): """ Returns the figure in html format on the first call and """ self.plot.update(idx) if self.embed or fig_format == 'html' or bokeh_lt_011: return self.renderer.html(self.plot, fig_format) else: doc = self.plot.document if hasattr(doc, 'last_comms_handle'): handle = doc.last_comms_handle else: doc.add_root(self.plot.state) handle = _CommsHandle(get_comms(doc.last_comms_target), doc, doc.to_json()) doc.last_comms_handle = handle to_json = doc.to_json() if handle.doc is not doc: msg = dict(doc=to_json) else: msg = Document._compute_patch_between_json(handle.json, to_json) if isinstance(handle._json, dict): handle._json[doc] = to_json else: handle._json = to_json handle.comms.send(json.dumps(msg))
def update(self, ranges): if not self.comms: self.comms = _CommsHandle(get_comms(self.ref), self.doc, self.doc.to_json()) self.redraw_image(ranges) to_json = self.doc.to_json() msg = Document._compute_patch_between_json(self.comms.json, to_json) self.comms._json[self.doc] = to_json self.comms.comms.send(json.dumps(msg))
def serialize(self, models): """ Serializes any Bokeh plot objects passed to it as a list. """ documents = {plot.document for plot in self.plots} for doc in documents: if hasattr(doc, 'last_comms_handle'): handle = doc.last_comms_handle else: handle = _CommsHandle(get_comms(doc.last_comms_target), doc, None) doc.last_comms_handle = handle msg = compute_static_patch(doc, models) handle.comms.send(serialize_json(msg)) return 'Complete'
def update(self, ranges): """ Update the image datasource based on the new ranges, serialize the data to JSON and send to notebook via a new or existing notebook comms handle. Parameters ---------- ranges : dict(xmin=float, xmax=float, ymin=float, ymax=float, h=int, w=int) Dictionary with of x/y-ranges, width and height. """ if not self.comms_handle: self.comms_handle = _CommsHandle(get_comms(self.ref), self.doc, {}) self.update_image(ranges) msg = self.get_update_event() self.comms_handle.comms.send(msg)
def _plot_figure(self, idx, fig_format='json'): """ Returns the figure in html format on the first call and """ self.plot.update(idx) if self.embed or fig_format == 'html': html = self.renderer.html(self.plot, fig_format) return html else: doc = self.plot.document if hasattr(doc, 'last_comms_handle'): handle = doc.last_comms_handle else: handle = _CommsHandle(get_comms(doc.last_comms_target), doc, doc.to_json()) doc.last_comms_handle = handle plotobjects = [h for handles in self.plot.traverse(lambda x: x.current_handles) for h in handles] msg = compute_static_patch(doc, plotobjects) handle.comms.send(json.dumps(msg)) return 'Complete'