Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5156c10

Browse files
Jason Groutpelson
Jason Grout
authored andcommitted
Small changes to clean up webagg javascript code a bit.
1 parent 24bc071 commit 5156c10

File tree

2 files changed

+12
-23
lines changed

2 files changed

+12
-23
lines changed

lib/matplotlib/backends/backend_webagg_core.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -319,20 +319,15 @@ class NavigationToolbar2WebAgg(backend_bases.NavigationToolbar2):
319319
None: None
320320
}
321321

322-
def _init_toolbar(self):
323-
# Use the standard toolbar items + download button
324-
toolitems = (
325-
backend_bases.NavigationToolbar2.toolitems +
326-
(('Download', 'Download plot', 'download', 'download'),)
327-
)
328-
329-
NavigationToolbar2WebAgg.toolitems = \
330-
tuple(
331-
(text, tooltip_text, self._jquery_icon_classes[image_file],
332-
name_of_method)
333-
for text, tooltip_text, image_file, name_of_method
334-
in toolitems if image_file in self._jquery_icon_classes)
335322

323+
# Use the standard toolbar items + download button
324+
toolitems = [(text, tooltip_text, _jquery_icon_classes[image_file], name_of_method)
325+
for text, tooltip_text, image_file, name_of_method
326+
in (backend_bases.NavigationToolbar2.toolitems +
327+
(('Download', 'Download plot', 'download', 'download'),))
328+
if image_file in _jquery_icon_classes]
329+
330+
def _init_toolbar(self):
336331
self.message = ''
337332
self.cursor = 0
338333

lib/matplotlib/backends/web_backend/mpl.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
/* Put everything inside the mpl namespace */
2-
var mpl = {};
1+
/* Put everything inside the global mpl namespace */
2+
window.mpl = {};
33

44

55
mpl.get_websocket_type = function() {
@@ -56,21 +56,15 @@ mpl.figure = function(figure_id, websocket, ondownload, parent_element) {
5656

5757
this.waiting = false;
5858

59-
onopen_creator = function(fig) {
60-
return function () {
59+
this.ws.onopen = function () {
6160
fig.send_message("supports_binary", {value: fig.supports_binary});
6261
fig.send_message("refresh", {});
6362
}
64-
};
65-
this.ws.onopen = onopen_creator(fig);
6663

67-
onload_creator = function(fig) {
68-
return function() {
64+
this.imageObj.onload = function() {
6965
fig.context.drawImage(fig.imageObj, 0, 0);
7066
fig.waiting = false;
7167
};
72-
};
73-
this.imageObj.onload = onload_creator(fig);
7468

7569
this.imageObj.onunload = function() {
7670
this.ws.close();

0 commit comments

Comments
 (0)