Skip to content

Commit

Permalink
Merge b6229d9 into 2b16eb0
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Dec 2, 2018
2 parents 2b16eb0 + b6229d9 commit f59b81d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 37 deletions.
36 changes: 3 additions & 33 deletions holoviews/plotting/bokeh/renderer.py
Expand Up @@ -8,6 +8,7 @@
import param
import bokeh

from pyviz_comms import bokeh_msg_handler
from param.parameterized import bothmethod
from bokeh.application.handlers import FunctionHandler
from bokeh.application import Application
Expand All @@ -34,36 +35,6 @@
</script>
"""

# Following JS block becomes body of the message handler callback
bokeh_msg_handler = """
var plot_id = "{plot_id}";
if (plot_id in HoloViews.plot_index) {{
var plot = HoloViews.plot_index[plot_id];
}} else {{
var plot = Bokeh.index[plot_id];
}}
if (plot_id in HoloViews.receivers) {{
var receiver = HoloViews.receivers[plot_id];
}} else if (Bokeh.protocol === undefined) {{
return;
}} else {{
var receiver = new Bokeh.protocol.Receiver();
HoloViews.receivers[plot_id] = receiver;
}}
if (buffers.length > 0) {{
receiver.consume(buffers[0].buffer)
}} else {{
receiver.consume(msg)
}}
const comm_msg = receiver.message;
if (comm_msg != null) {{
plot.model.document.apply_json_patch(comm_msg.content, comm_msg.buffers)
}}
"""

default_theme = Theme(json={
'attrs': {
'Title': {'text_color': 'black', 'text_font_size': '12pt'}
Expand Down Expand Up @@ -114,7 +85,7 @@ class BokehRenderer(Renderer):
_loaded = False

# Define the handler for updating bokeh plots
comm_msg_handler = bokeh_msg_handler if bokeh_version > '0.12.14' else None
comm_msg_handler = bokeh_msg_handler

def __call__(self, obj, fmt=None, doc=None):
"""
Expand Down Expand Up @@ -296,7 +267,6 @@ def _figure_data(self, plot, fmt='html', doc=None, as_script=False, **kwargs):
doc.theme = self.theme
doc.add_root(model)

comm_id = plot.comm.id if plot.comm else None
# Bokeh raises warnings about duplicate tools and empty subplots
# but at the holoviews level these are not issues
logger = logging.getLogger(bokeh.core.validation.check.__file__)
Expand All @@ -316,7 +286,7 @@ def _figure_data(self, plot, fmt='html', doc=None, as_script=False, **kwargs):
js = ''
else:
try:
js, div, _ = notebook_content(model, comm_id)
js, div, _ = notebook_content(model)
html = NOTEBOOK_DIV.format(plot_script=js, plot_div=div)
data = encode_utf8(html)
doc.hold()
Expand Down
22 changes: 18 additions & 4 deletions holoviews/plotting/widgets/widgets.js
Expand Up @@ -72,11 +72,11 @@ HoloViewsWidget.prototype.update = function(current){

HoloViewsWidget.prototype.init_comms = function() {
var that = this
HoloViews.comm_manager.register_target(this.plot_id, this.id, function (msg) { that.process_msg(msg) })
HoloViews.comm_manager.register_target(this.plot_id, this.id, function (msg) { that.msg_handler(msg) })
if (!this.cached || this.dynamic) {
function ack_callback(msg) {
msg = JSON.parse(msg.content.data);
var comm_id = msg["comm_id"]
var msg = msg.metadata;
var comm_id = msg.comm_id;
var comm_status = HoloViews.comm_status[comm_id];
if (that.queue.length > 0) {
that.time = Date.now();
Expand All @@ -88,14 +88,28 @@ HoloViewsWidget.prototype.init_comms = function() {
if ((msg.msg_type == "Ready") && msg.content) {
console.log("Python callback returned following output:", msg.content);
} else if (msg.msg_type == "Error") {
console.log("Python failed with the following traceback:", msg['traceback'])
console.log("Python failed with the following traceback:", msg.traceback)
}
}
var comm = HoloViews.comm_manager.get_client_comm(this.plot_id, this.id+'_client', ack_callback);
return comm
}
}

HoloViewsWidget.prototype.msg_handler = function(msg) {
var metadata = msg.metadata;
if ((metadata.msg_type == "Ready")) {
if (metadata.content) {
console.log("Python callback returned following output:", metadata.content);
}
return;
} else if (metadata.msg_type == "Error") {
console.log("Python failed with the following traceback:", metadata.traceback)
return
}
this.process_msg(msg)
}

HoloViewsWidget.prototype.process_msg = function(msg) {
}

Expand Down

0 comments on commit f59b81d

Please sign in to comment.