Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for HTML export after moving to MIME bundle #2574

Merged
merged 5 commits into from Apr 17, 2018
Merged
Diff settings

Always

Just for now

@@ -24,7 +24,11 @@ var BokehMethods = {
}
var data = this.frames[current];
if (data !== undefined) {
var doc = HoloViews.plot_index[data.root].model.document;
if (data.root in HoloViews.plot_index) {
var doc = HoloViews.plot_index[data.root].model.document;
} else {
var doc = Bokeh.index[data.root].model.document;
}
doc.apply_json_patch(data.content);
}
},
@@ -37,7 +41,11 @@ var BokehMethods = {
return HoloViewsWidget.prototype.init_comms.call(this);
},
process_msg : function(msg) {
var doc = HoloViews.plot_index[this.plot_id].model.document;
if (this.plot_id in HoloViews.plot_index) {
var doc = HoloViews.plot_index[this.plot_id].model.document;
} else {
var doc = Bokeh.index[this.plot_id].model.document;
}
if (this.receiver === null) { return }
var receiver = this.receiver;
if (msg.buffers.length > 0) {
@@ -34,15 +34,20 @@

# Following JS block becomes body of the message handler callback
bokeh_msg_handler = """
var plot = HoloViews.plot_index["{plot_id}"];
if ("{plot_id}" in HoloViews.receivers) {{
var receiver = HoloViews.receivers["{plot_id}"];
var plot_id = "{plot_id}";
if (plot_id in HoloViews.plot_index) {
var doc = HoloViews.plot_index[plot_id];
} else {
var doc = 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;
HoloViews.receivers[plot_id] = receiver;
}}
if (buffers.length > 0) {{
Copy path View file
@@ -69,6 +69,17 @@
</html>
"""

embed_js = """

This comment has been minimized.

Copy link
@jlstevens

jlstevens Apr 17, 2018

Contributor

I suggest leaving a comment pointing to this PR where we can explain why such a nasty thing exists.

This comment has been minimized.

Copy link
@philippjfr

philippjfr Apr 17, 2018

Author Contributor

Agreed, don't want anyone blaming us for this.

if (!(document.getElementById('{plot_id}')) && !(document.getElementById('_anim_img{element_id}'))) {{
var htmlObject = document.createElement('div');
htmlObject.innerHTML = `{html}`;
var scriptTags = document.getElementsByTagName('script');
var parentTag = scriptTags[scriptTags.length-1].parentNode;
parentTag.append(htmlObject)
}}
"""


class Renderer(Exporter):
"""
The job of a Renderer is to turn the plotting state held within
@@ -311,6 +322,7 @@ def components(self, obj, fmt=None, comm=True, **kwargs):
if isinstance(plot, NdWidget):
js, html = plot(as_script=True)
plot_id = plot.plot_id
element_id = plot.id
else:
html, js = self._figure_data(plot, fmt, as_script=True, **kwargs)
plot_id = plot.id
@@ -322,7 +334,10 @@ def components(self, obj, fmt=None, comm=True, **kwargs):
comm_id=plot.comm.id,
plot_id=plot_id)
js = '\n'.join([js, comm_js])
html = "<div style='display: table; margin: 0 auto;'>%s</div>" % html
element_id = plot_id
html = "<div id='%s' style='display: table; margin: 0 auto;'>%s</div>" % (element_id, html)
if not os.environ.get('HV_DOC_HTML', False) and js is not None:
js = embed_js.format(element_id=element_id, plot_id=plot_id, html=html) + js

This comment has been minimized.

Copy link
@jlstevens

jlstevens Apr 17, 2018

Contributor

Why define element_id if you can just replace this with plot.id (or plot_id)?

This comment has been minimized.

Copy link
@jlstevens

jlstevens Apr 17, 2018

Contributor

Nevermind, I see it now. Though isn't it plot.id in both branches?

This comment has been minimized.

Copy link
@philippjfr

philippjfr Apr 17, 2018

Author Contributor

Bit confusing but in the widget case they aren't identical, in that case plot variable is actually the widget and the two are different. I might just call it widget_id instead of element_id and then default it to None in the non-widget case.

This comment has been minimized.

Copy link
@jlstevens

jlstevens Apr 17, 2018

Contributor

Ok. If it can be made clearer, then great!


data['text/html'] = html
if js:
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.