Skip to content

Commit 1e2671f

Browse files
committed
Hot fix interactive plot
1 parent 86aa46d commit 1e2671f

6 files changed

Lines changed: 99 additions & 96 deletions

File tree

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<link rel="stylesheet" href="web_backend/css/mpl.css">
1616
<script src="renderer.js"></script>
1717
<script src="web_backend/js/mpl.js"></script>
18-
<!-- <script src="web_backend/js/nbagg_mpl.js"></script> -->
18+
<script src="web_backend/js/nbagg_mpl.js"></script>
1919
</head>
2020

2121
<body class="dark:bg-gray-600">

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "phaseportrait-gui",
3-
"version": "1.0.3",
3+
"version": "1.1.4",
44
"description": "",
55
"main": "main.js",
66
"scripts": {

phaseportrait-launcher.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818

1919
import matplotlib as mpl
2020
from matplotlib import pyplot as plt
21-
from matplotlib.backends.backend_webagg_core import \
22-
new_figure_manager_given_figure
21+
from matplotlib.backends.backend_webagg import \
22+
FigureManagerWebAgg, new_figure_manager_given_figure
2323

2424
files_path = '/'.join(__file__.split('\\')[:-1])
2525

@@ -110,8 +110,11 @@ def on_message(self, message):
110110
except Exception as e:
111111
print(e, flush=True, end='')
112112
self.logger(e)
113-
self._prev_ = message.get('name', None)
114-
manager.handle_json(message)
113+
self._prev_ = message.get('type', None)
114+
try:
115+
manager.handle_json(message)
116+
except Exception as e:
117+
self.logger(e)
115118

116119

117120
def send_json(self, content):

settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"dark":true,"python":"python3"}
1+
{"dark":false,"python":"python3"}

web_backend/js/nbagg_mpl.js

Lines changed: 87 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ mpl.figure.prototype.close_ws = function (fig, msg) {
9898
// fig.ws.close()
9999
};
100100

101-
mpl.figure.prototype.push_to_output = function (_remove_interactive) {
102-
// Turn the data on the canvas into data in the output cell.
103-
var width = this.canvas.width / this.ratio;
104-
var dataURL = this.canvas.toDataURL();
105-
this.cell_info[1]['text/html'] =
106-
'<img src="' + dataURL + '" width="' + width + '">';
107-
};
101+
// mpl.figure.prototype.push_to_output = function (_remove_interactive) {
102+
// // Turn the data on the canvas into data in the output cell.
103+
// var width = this.canvas.width / this.ratio;
104+
// var dataURL = this.canvas.toDataURL();
105+
// this.cell_info[1]['text/html'] =
106+
// '<img src="' + dataURL + '" width="' + width + '">';
107+
// };
108108

109109
mpl.figure.prototype.updated_canvas_event = function () {
110110
// Tell IPython that the notebook contents must change.
@@ -118,86 +118,86 @@ mpl.figure.prototype.updated_canvas_event = function () {
118118
}, 1000);
119119
};
120120

121-
mpl.figure.prototype._init_toolbar = function () {
122-
var fig = this;
123-
124-
var toolbar = document.createElement('div');
125-
toolbar.classList = 'btn-toolbar';
126-
this.root.appendChild(toolbar);
127-
128-
function on_click_closure(name) {
129-
return function (_event) {
130-
return fig.toolbar_button_onclick(name);
131-
};
132-
}
133-
134-
function on_mouseover_closure(tooltip) {
135-
return function (event) {
136-
if (!event.currentTarget.disabled) {
137-
return fig.toolbar_button_onmouseover(tooltip);
138-
}
139-
};
140-
}
141-
142-
fig.buttons = {};
143-
var buttonGroup = document.createElement('div');
144-
buttonGroup.classList = 'btn-group';
145-
var button;
146-
for (var toolbar_ind in mpl.toolbar_items) {
147-
var name = mpl.toolbar_items[toolbar_ind][0];
148-
var tooltip = mpl.toolbar_items[toolbar_ind][1];
149-
var image = mpl.toolbar_items[toolbar_ind][2];
150-
var method_name = mpl.toolbar_items[toolbar_ind][3];
151-
152-
if (!name) {
153-
/* Instead of a spacer, we start a new button group. */
154-
if (buttonGroup.hasChildNodes()) {
155-
toolbar.appendChild(buttonGroup);
156-
}
157-
buttonGroup = document.createElement('div');
158-
buttonGroup.classList = 'btn-group';
159-
continue;
160-
}
161-
162-
button = fig.buttons[name] = document.createElement('button');
163-
button.classList = 'btn btn-default';
164-
button.href = '#';
165-
button.title = name;
166-
button.innerHTML = '<i class="fa ' + image + ' fa-lg"></i>';
167-
button.addEventListener('click', on_click_closure(method_name));
168-
button.addEventListener('mouseover', on_mouseover_closure(tooltip));
169-
buttonGroup.appendChild(button);
170-
}
171-
172-
if (buttonGroup.hasChildNodes()) {
173-
toolbar.appendChild(buttonGroup);
174-
}
175-
176-
// Add the status bar.
177-
var status_bar = document.createElement('span');
178-
status_bar.classList = 'mpl-message pull-right';
179-
toolbar.appendChild(status_bar);
180-
this.message = status_bar;
181-
182-
// Add the close button to the window.
183-
var buttongrp = document.createElement('div');
184-
buttongrp.classList = 'btn-group inline pull-right';
185-
button = document.createElement('button');
186-
button.classList = 'btn btn-mini btn-primary';
187-
button.href = '#';
188-
button.title = 'Stop Interaction';
189-
button.innerHTML = '<i class="fa fa-power-off icon-remove icon-large"></i>';
190-
button.addEventListener('click', function (_evt) {
191-
fig.handle_close(fig, {});
192-
});
193-
button.addEventListener(
194-
'mouseover',
195-
on_mouseover_closure('Stop Interaction')
196-
);
197-
buttongrp.appendChild(button);
198-
var titlebar = this.root.querySelector('.ui-dialog-titlebar');
199-
titlebar.insertBefore(buttongrp, titlebar.firstChild);
200-
};
121+
// mpl.figure.prototype._init_toolbar = function () {
122+
// var fig = this;
123+
124+
// var toolbar = document.createElement('div');
125+
// toolbar.classList = 'btn-toolbar';
126+
// this.root.appendChild(toolbar);
127+
128+
// function on_click_closure(name) {
129+
// return function (_event) {
130+
// return fig.toolbar_button_onclick(name);
131+
// };
132+
// }
133+
134+
// function on_mouseover_closure(tooltip) {
135+
// return function (event) {
136+
// if (!event.currentTarget.disabled) {
137+
// return fig.toolbar_button_onmouseover(tooltip);
138+
// }
139+
// };
140+
// }
141+
142+
// fig.buttons = {};
143+
// var buttonGroup = document.createElement('div');
144+
// buttonGroup.classList = 'btn-group';
145+
// var button;
146+
// for (var toolbar_ind in mpl.toolbar_items) {
147+
// var name = mpl.toolbar_items[toolbar_ind][0];
148+
// var tooltip = mpl.toolbar_items[toolbar_ind][1];
149+
// var image = mpl.toolbar_items[toolbar_ind][2];
150+
// var method_name = mpl.toolbar_items[toolbar_ind][3];
151+
152+
// if (!name) {
153+
// /* Instead of a spacer, we start a new button group. */
154+
// if (buttonGroup.hasChildNodes()) {
155+
// toolbar.appendChild(buttonGroup);
156+
// }
157+
// buttonGroup = document.createElement('div');
158+
// buttonGroup.classList = 'btn-group';
159+
// continue;
160+
// }
161+
162+
// button = fig.buttons[name] = document.createElement('button');
163+
// button.classList = 'btn btn-default';
164+
// button.href = '#';
165+
// button.title = name;
166+
// button.innerHTML = '<i class="fa ' + image + ' fa-lg"></i>';
167+
// button.addEventListener('click', on_click_closure(method_name));
168+
// button.addEventListener('mouseover', on_mouseover_closure(tooltip));
169+
// buttonGroup.appendChild(button);
170+
// }
171+
172+
// if (buttonGroup.hasChildNodes()) {
173+
// toolbar.appendChild(buttonGroup);
174+
// }
175+
176+
// // Add the status bar.
177+
// var status_bar = document.createElement('span');
178+
// status_bar.classList = 'mpl-message pull-right';
179+
// toolbar.appendChild(status_bar);
180+
// this.message = status_bar;
181+
182+
// // Add the close button to the window.
183+
// var buttongrp = document.createElement('div');
184+
// buttongrp.classList = 'btn-group inline pull-right';
185+
// button = document.createElement('button');
186+
// button.classList = 'btn btn-mini btn-primary';
187+
// button.href = '#';
188+
// button.title = 'Stop Interaction';
189+
// button.innerHTML = '<i class="fa fa-power-off icon-remove icon-large"></i>';
190+
// button.addEventListener('click', function (_evt) {
191+
// fig.handle_close(fig, {});
192+
// });
193+
// button.addEventListener(
194+
// 'mouseover',
195+
// on_mouseover_closure('Stop Interaction')
196+
// );
197+
// buttongrp.appendChild(button);
198+
// var titlebar = this.root.querySelector('.ui-dialog-titlebar');
199+
// titlebar.insertBefore(buttongrp, titlebar.firstChild);
200+
// };
201201

202202
mpl.figure.prototype._remove_fig_handler = function (event) {
203203
var fig = event.data.fig;

0 commit comments

Comments
 (0)