Skip to content

Commit

Permalink
Hot fix interactive plot
Browse files Browse the repository at this point in the history
  • Loading branch information
QuanticPony committed Apr 4, 2023
1 parent 86aa46d commit 1e2671f
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 96 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<link rel="stylesheet" href="web_backend/css/mpl.css">
<script src="renderer.js"></script>
<script src="web_backend/js/mpl.js"></script>
<!-- <script src="web_backend/js/nbagg_mpl.js"></script> -->
<script src="web_backend/js/nbagg_mpl.js"></script>
</head>

<body class="dark:bg-gray-600">
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "phaseportrait-gui",
"version": "1.0.3",
"version": "1.1.4",
"description": "",
"main": "main.js",
"scripts": {
Expand Down
11 changes: 7 additions & 4 deletions phaseportrait-launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion settings.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"dark":true,"python":"python3"}
{"dark":false,"python":"python3"}
174 changes: 87 additions & 87 deletions web_backend/js/nbagg_mpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'] =
'<img src="' + dataURL + '" width="' + width + '">';
};
// 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'] =
// '<img src="' + dataURL + '" width="' + width + '">';
// };

mpl.figure.prototype.updated_canvas_event = function () {
// Tell IPython that the notebook contents must change.
Expand All @@ -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 = '<i class="fa ' + image + ' fa-lg"></i>';
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 = '<i class="fa fa-power-off icon-remove icon-large"></i>';
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 = '<i class="fa ' + image + ' fa-lg"></i>';
// 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 = '<i class="fa fa-power-off icon-remove icon-large"></i>';
// 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;
Expand Down

0 comments on commit 1e2671f

Please sign in to comment.