diff --git a/lib/matplotlib/backends/backend_webagg_core.py b/lib/matplotlib/backends/backend_webagg_core.py index c656c9756daa..42fa6ebaa87e 100644 --- a/lib/matplotlib/backends/backend_webagg_core.py +++ b/lib/matplotlib/backends/backend_webagg_core.py @@ -319,20 +319,15 @@ class NavigationToolbar2WebAgg(backend_bases.NavigationToolbar2): None: None } - def _init_toolbar(self): - # Use the standard toolbar items + download button - toolitems = ( - backend_bases.NavigationToolbar2.toolitems + - (('Download', 'Download plot', 'download', 'download'),) - ) - - NavigationToolbar2WebAgg.toolitems = \ - tuple( - (text, tooltip_text, self._jquery_icon_classes[image_file], - name_of_method) - for text, tooltip_text, image_file, name_of_method - in toolitems if image_file in self._jquery_icon_classes) + # Use the standard toolbar items + download button + toolitems = [(text, tooltip_text, _jquery_icon_classes[image_file], name_of_method) + for text, tooltip_text, image_file, name_of_method + in (backend_bases.NavigationToolbar2.toolitems + + (('Download', 'Download plot', 'download', 'download'),)) + if image_file in _jquery_icon_classes] + + def _init_toolbar(self): self.message = '' self.cursor = 0 diff --git a/lib/matplotlib/backends/web_backend/mpl.js b/lib/matplotlib/backends/web_backend/mpl.js index 89fe97c8b5f7..471ba1aa6866 100644 --- a/lib/matplotlib/backends/web_backend/mpl.js +++ b/lib/matplotlib/backends/web_backend/mpl.js @@ -1,5 +1,5 @@ -/* Put everything inside the mpl namespace */ -var mpl = {}; +/* Put everything inside the global mpl namespace */ +window.mpl = {}; mpl.get_websocket_type = function() { @@ -56,21 +56,15 @@ mpl.figure = function(figure_id, websocket, ondownload, parent_element) { this.waiting = false; - onopen_creator = function(fig) { - return function () { + this.ws.onopen = function () { fig.send_message("supports_binary", {value: fig.supports_binary}); fig.send_message("refresh", {}); } - }; - this.ws.onopen = onopen_creator(fig); - onload_creator = function(fig) { - return function() { + this.imageObj.onload = function() { fig.context.drawImage(fig.imageObj, 0, 0); fig.waiting = false; }; - }; - this.imageObj.onload = onload_creator(fig); this.imageObj.onunload = function() { this.ws.close();