From 1e2671f12d6faf595d1666bf10873b1787815997 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Unai=20Ler=C3=ADa=20Fortea?= Date: Tue, 4 Apr 2023 19:12:48 +0200 Subject: [PATCH] Hot fix interactive plot --- index.html | 2 +- package-lock.json | 4 +- package.json | 2 +- phaseportrait-launcher.py | 11 ++- settings.json | 2 +- web_backend/js/nbagg_mpl.js | 174 ++++++++++++++++++------------------ 6 files changed, 99 insertions(+), 96 deletions(-) diff --git a/index.html b/index.html index 4fc5a72..46bf211 100644 --- a/index.html +++ b/index.html @@ -15,7 +15,7 @@ - + diff --git a/package-lock.json b/package-lock.json index eb4196f..482656a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "phaseportrait-gui", - "version": "1.0.3", + "version": "1.1.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "phaseportrait-gui", - "version": "1.0.3", + "version": "1.1.4", "license": "MIT", "dependencies": { "codemirror": "^5.65.1", diff --git a/package.json b/package.json index 16c41dc..9591ee3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "phaseportrait-gui", - "version": "1.0.3", + "version": "1.1.4", "description": "", "main": "main.js", "scripts": { diff --git a/phaseportrait-launcher.py b/phaseportrait-launcher.py index 67acd7b..eb6b0c6 100644 --- a/phaseportrait-launcher.py +++ b/phaseportrait-launcher.py @@ -18,8 +18,8 @@ import matplotlib as mpl from matplotlib import pyplot as plt -from matplotlib.backends.backend_webagg_core import \ - new_figure_manager_given_figure +from matplotlib.backends.backend_webagg import \ + FigureManagerWebAgg, new_figure_manager_given_figure files_path = '/'.join(__file__.split('\\')[:-1]) @@ -110,8 +110,11 @@ def on_message(self, message): except Exception as e: print(e, flush=True, end='') self.logger(e) - self._prev_ = message.get('name', None) - manager.handle_json(message) + self._prev_ = message.get('type', None) + try: + manager.handle_json(message) + except Exception as e: + self.logger(e) def send_json(self, content): diff --git a/settings.json b/settings.json index 01e1453..1ae9e90 100644 --- a/settings.json +++ b/settings.json @@ -1 +1 @@ -{"dark":true,"python":"python3"} \ No newline at end of file +{"dark":false,"python":"python3"} \ No newline at end of file diff --git a/web_backend/js/nbagg_mpl.js b/web_backend/js/nbagg_mpl.js index debebcf..a06810b 100644 --- a/web_backend/js/nbagg_mpl.js +++ b/web_backend/js/nbagg_mpl.js @@ -98,13 +98,13 @@ mpl.figure.prototype.close_ws = function (fig, msg) { // fig.ws.close() }; -mpl.figure.prototype.push_to_output = function (_remove_interactive) { - // Turn the data on the canvas into data in the output cell. - var width = this.canvas.width / this.ratio; - var dataURL = this.canvas.toDataURL(); - this.cell_info[1]['text/html'] = - ''; -}; +// mpl.figure.prototype.push_to_output = function (_remove_interactive) { +// // Turn the data on the canvas into data in the output cell. +// var width = this.canvas.width / this.ratio; +// var dataURL = this.canvas.toDataURL(); +// this.cell_info[1]['text/html'] = +// ''; +// }; mpl.figure.prototype.updated_canvas_event = function () { // Tell IPython that the notebook contents must change. @@ -118,86 +118,86 @@ mpl.figure.prototype.updated_canvas_event = function () { }, 1000); }; -mpl.figure.prototype._init_toolbar = function () { - var fig = this; - - var toolbar = document.createElement('div'); - toolbar.classList = 'btn-toolbar'; - this.root.appendChild(toolbar); - - function on_click_closure(name) { - return function (_event) { - return fig.toolbar_button_onclick(name); - }; - } - - function on_mouseover_closure(tooltip) { - return function (event) { - if (!event.currentTarget.disabled) { - return fig.toolbar_button_onmouseover(tooltip); - } - }; - } - - fig.buttons = {}; - var buttonGroup = document.createElement('div'); - buttonGroup.classList = 'btn-group'; - var button; - for (var toolbar_ind in mpl.toolbar_items) { - var name = mpl.toolbar_items[toolbar_ind][0]; - var tooltip = mpl.toolbar_items[toolbar_ind][1]; - var image = mpl.toolbar_items[toolbar_ind][2]; - var method_name = mpl.toolbar_items[toolbar_ind][3]; - - if (!name) { - /* Instead of a spacer, we start a new button group. */ - if (buttonGroup.hasChildNodes()) { - toolbar.appendChild(buttonGroup); - } - buttonGroup = document.createElement('div'); - buttonGroup.classList = 'btn-group'; - continue; - } - - button = fig.buttons[name] = document.createElement('button'); - button.classList = 'btn btn-default'; - button.href = '#'; - button.title = name; - button.innerHTML = ''; - button.addEventListener('click', on_click_closure(method_name)); - button.addEventListener('mouseover', on_mouseover_closure(tooltip)); - buttonGroup.appendChild(button); - } - - if (buttonGroup.hasChildNodes()) { - toolbar.appendChild(buttonGroup); - } - - // Add the status bar. - var status_bar = document.createElement('span'); - status_bar.classList = 'mpl-message pull-right'; - toolbar.appendChild(status_bar); - this.message = status_bar; - - // Add the close button to the window. - var buttongrp = document.createElement('div'); - buttongrp.classList = 'btn-group inline pull-right'; - button = document.createElement('button'); - button.classList = 'btn btn-mini btn-primary'; - button.href = '#'; - button.title = 'Stop Interaction'; - button.innerHTML = ''; - button.addEventListener('click', function (_evt) { - fig.handle_close(fig, {}); - }); - button.addEventListener( - 'mouseover', - on_mouseover_closure('Stop Interaction') - ); - buttongrp.appendChild(button); - var titlebar = this.root.querySelector('.ui-dialog-titlebar'); - titlebar.insertBefore(buttongrp, titlebar.firstChild); -}; +// mpl.figure.prototype._init_toolbar = function () { +// var fig = this; + +// var toolbar = document.createElement('div'); +// toolbar.classList = 'btn-toolbar'; +// this.root.appendChild(toolbar); + +// function on_click_closure(name) { +// return function (_event) { +// return fig.toolbar_button_onclick(name); +// }; +// } + +// function on_mouseover_closure(tooltip) { +// return function (event) { +// if (!event.currentTarget.disabled) { +// return fig.toolbar_button_onmouseover(tooltip); +// } +// }; +// } + +// fig.buttons = {}; +// var buttonGroup = document.createElement('div'); +// buttonGroup.classList = 'btn-group'; +// var button; +// for (var toolbar_ind in mpl.toolbar_items) { +// var name = mpl.toolbar_items[toolbar_ind][0]; +// var tooltip = mpl.toolbar_items[toolbar_ind][1]; +// var image = mpl.toolbar_items[toolbar_ind][2]; +// var method_name = mpl.toolbar_items[toolbar_ind][3]; + +// if (!name) { +// /* Instead of a spacer, we start a new button group. */ +// if (buttonGroup.hasChildNodes()) { +// toolbar.appendChild(buttonGroup); +// } +// buttonGroup = document.createElement('div'); +// buttonGroup.classList = 'btn-group'; +// continue; +// } + +// button = fig.buttons[name] = document.createElement('button'); +// button.classList = 'btn btn-default'; +// button.href = '#'; +// button.title = name; +// button.innerHTML = ''; +// button.addEventListener('click', on_click_closure(method_name)); +// button.addEventListener('mouseover', on_mouseover_closure(tooltip)); +// buttonGroup.appendChild(button); +// } + +// if (buttonGroup.hasChildNodes()) { +// toolbar.appendChild(buttonGroup); +// } + +// // Add the status bar. +// var status_bar = document.createElement('span'); +// status_bar.classList = 'mpl-message pull-right'; +// toolbar.appendChild(status_bar); +// this.message = status_bar; + +// // Add the close button to the window. +// var buttongrp = document.createElement('div'); +// buttongrp.classList = 'btn-group inline pull-right'; +// button = document.createElement('button'); +// button.classList = 'btn btn-mini btn-primary'; +// button.href = '#'; +// button.title = 'Stop Interaction'; +// button.innerHTML = ''; +// button.addEventListener('click', function (_evt) { +// fig.handle_close(fig, {}); +// }); +// button.addEventListener( +// 'mouseover', +// on_mouseover_closure('Stop Interaction') +// ); +// buttongrp.appendChild(button); +// var titlebar = this.root.querySelector('.ui-dialog-titlebar'); +// titlebar.insertBefore(buttongrp, titlebar.firstChild); +// }; mpl.figure.prototype._remove_fig_handler = function (event) { var fig = event.data.fig;