From 79953bf39c0ff065a348ecf0981b7405131c35dc Mon Sep 17 00:00:00 2001 From: Jason Grout Date: Thu, 14 Nov 2013 19:10:33 -0600 Subject: [PATCH 1/2] Small changes to clean up webagg javascript code a bit. --- lib/matplotlib/backends/web_backend/mpl.js | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) 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(); From 5b93867188a4dae5a0e5706089b934f1475f159e Mon Sep 17 00:00:00 2001 From: Jason Grout Date: Fri, 15 Nov 2013 04:10:31 -0600 Subject: [PATCH 2/2] Don't wait for _init_toolbar to initialize the toolbar information in the webagg backend This is so that the javascript generation works before any plots have been initialized. --- .../backends/backend_webagg_core.py | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) 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