Skip to content

Commit

Permalink
Fixed issues in notebook plot cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Apr 5, 2018
1 parent 31fc82b commit fb74ef7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
8 changes: 5 additions & 3 deletions holoviews/ipython/__init__.py
Expand Up @@ -140,7 +140,8 @@ def __call__(self, *args, **params):
'between %r' % p.display_formats)
display(HTML('<b>Warning</b>: %s' % msg))

if notebook_extension._loaded == False:
loaded = notebook_extension._loaded
if loaded == False:
param_ext.load_ipython_extension(ip, verbose=False)
load_magics(ip)
Store.output_settings.initialize(list(Store.renderers.keys()))
Expand All @@ -161,8 +162,9 @@ def __call__(self, *args, **params):
Renderer.load_nb()
for r in [r for r in resources if r != 'holoviews']:
Store.renderers[r].load_nb(inline=p.inline)
if hasattr(ip, 'kernel'):
Renderer.comm_manager.get_client_comm(self._process_comm_msg,

if hasattr(ip, 'kernel') and not loaded:
Renderer.comm_manager.get_client_comm(notebook_extension._process_comm_msg,
"hv-extension-comm")

# Create a message for the logo (if shown)
Expand Down
18 changes: 12 additions & 6 deletions holoviews/plotting/widgets/widgets.js
Expand Up @@ -522,8 +522,6 @@ function init_dropdown(id, plot_id, dim, vals, value, next_vals, labels, next_di

if (window.HoloViews === undefined) {
window.HoloViews = {}
} else {
delete HoloViews.comms["hv-extension-comm"]
}

var _namespace = {
Expand All @@ -532,6 +530,7 @@ var _namespace = {
comms: {},
comm_status: {},
index: {},
plot_index: {},
kernels: {},
receivers: {}
}
Expand Down Expand Up @@ -567,29 +566,35 @@ function handle_add_output(event, handle) {
}
var toinsert = output_area.element.find("." + CLASS_NAME.split(' ')[0]);
if (output.metadata[EXEC_MIME_TYPE]["id"] !== undefined) {
var id = output.metadata[EXEC_MIME_TYPE]["id"];
toinsert[0].firstChild.textContent = output.data[JS_MIME_TYPE];
output_area._hv_plot_id = output.metadata[EXEC_MIME_TYPE]["id"];
output_area._hv_plot_id = id;
HoloViews.plot_index[id] = output_area;
}
}

/**
* Handle when an output is cleared or removed
*/


function handle_clear_output(event, handle) {
var id = handle.cell.output_area._hv_plot_id;
if (id === undefined) { return; }
if ((id === undefined) || !(id in HoloViews.plot_index)) { return; }
var comm = window.HoloViews.comm_manager.get_client_comm("hv-extension-comm", "hv-extension-comm", function () {});
if (comm !== null) {
comm.send({event_type: 'delete', 'id': id});
}
delete HoloViews.plot_index[id];
if ((window.Bokeh !== undefined) & (id in window.Bokeh.index)) {
window.Bokeh.index[id].model.document.clear();
delete Bokeh.index[id];
}
}

function handle_kernel_cleanup(event, handle) {
delete HoloViews.comms["hv-extension-comm"];
window.HoloViews.plot_index = {}
}

function register_renderer(events, OutputArea) {
function append_mime(data, metadata, element) {
// create a DOM node to render to
Expand All @@ -609,6 +614,7 @@ function register_renderer(events, OutputArea) {
events.on('output_added.OutputArea', handle_add_output);
events.on('clear_output.CodeCell', handle_clear_output);
events.on('delete.Cell', handle_clear_output);
events.on('kernel_ready.Kernel', handle_kernel_cleanup);

OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {
safe: true,
Expand Down

0 comments on commit fb74ef7

Please sign in to comment.