From ba840a56b726bbcb3614b3ada0f0ec37e3a5cdac Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Fri, 3 Apr 2020 23:33:41 -0400 Subject: [PATCH 1/3] STY: Add eslint and prettier config. These are setup similar to ipywidgets, but with slightly less newer things, as our JavaScript parts are much older. --- .gitignore | 2 ++ .../backends/web_backend/.eslintrc.js | 21 +++++++++++++++++++ .../backends/web_backend/.prettierignore | 7 +++++++ .../backends/web_backend/.prettierrc | 11 ++++++++++ lib/matplotlib/backends/web_backend/js/mpl.js | 19 +++++++++-------- .../backends/web_backend/js/mpl_tornado.js | 1 + .../backends/web_backend/js/nbagg_mpl.js | 21 +++++++++---------- .../backends/web_backend/package.json | 15 +++++++++++++ 8 files changed, 77 insertions(+), 20 deletions(-) create mode 100644 lib/matplotlib/backends/web_backend/.eslintrc.js create mode 100644 lib/matplotlib/backends/web_backend/.prettierignore create mode 100644 lib/matplotlib/backends/web_backend/.prettierrc create mode 100644 lib/matplotlib/backends/web_backend/package.json diff --git a/.gitignore b/.gitignore index bbd62a042419..491c72e229b5 100644 --- a/.gitignore +++ b/.gitignore @@ -104,3 +104,5 @@ lib/z.lib ######################### jquery-ui-*/ +lib/matplotlib/backends/web_backend/node_modules/ +lib/matplotlib/backends/web_backend/package-lock.json diff --git a/lib/matplotlib/backends/web_backend/.eslintrc.js b/lib/matplotlib/backends/web_backend/.eslintrc.js new file mode 100644 index 000000000000..f073e7fa3dc0 --- /dev/null +++ b/lib/matplotlib/backends/web_backend/.eslintrc.js @@ -0,0 +1,21 @@ +module.exports = { + root: true, + ignorePatterns: ["jquery-ui-*/", "node_modules/"], + env: { + browser: true, + jquery: true, + }, + extends: ["eslint:recommended", "prettier"], + globals: { + IPython: "readonly", + MozWebSocket: "readonly", + }, + rules: { + "no-unused-vars": [ + "error", + { + argsIgnorePattern: "^_", + }, + ], + }, +}; diff --git a/lib/matplotlib/backends/web_backend/.prettierignore b/lib/matplotlib/backends/web_backend/.prettierignore new file mode 100644 index 000000000000..06a29c66e0fc --- /dev/null +++ b/lib/matplotlib/backends/web_backend/.prettierignore @@ -0,0 +1,7 @@ +node_modules/ + +# Vendored dependencies +css/boilerplate.css +css/fbm.css +css/page.css +jquery-ui-*/ diff --git a/lib/matplotlib/backends/web_backend/.prettierrc b/lib/matplotlib/backends/web_backend/.prettierrc new file mode 100644 index 000000000000..fe8d711065d6 --- /dev/null +++ b/lib/matplotlib/backends/web_backend/.prettierrc @@ -0,0 +1,11 @@ +{ + "overrides": [ + { + "files": "js/**/*.js", + "options": { + "singleQuote": true, + "tabWidth": 4, + } + } + ] +} diff --git a/lib/matplotlib/backends/web_backend/js/mpl.js b/lib/matplotlib/backends/web_backend/js/mpl.js index 7c774b4a16d0..5d927c1d241f 100644 --- a/lib/matplotlib/backends/web_backend/js/mpl.js +++ b/lib/matplotlib/backends/web_backend/js/mpl.js @@ -1,4 +1,5 @@ /* Put everything inside the global mpl namespace */ +/* global mpl */ window.mpl = {}; @@ -99,12 +100,12 @@ mpl.figure.prototype._init_header = function() { -mpl.figure.prototype._canvas_extra_style = function(canvas_div) { +mpl.figure.prototype._canvas_extra_style = function(_canvas_div) { } -mpl.figure.prototype._root_extra_style = function(canvas_div) { +mpl.figure.prototype._root_extra_style = function(_canvas_div) { } @@ -147,13 +148,13 @@ mpl.figure.prototype._init_canvas = function() { var pass_mouse_events = true; canvas_div.resizable({ - start: function(event, ui) { + start: function(_event, _ui) { pass_mouse_events = false; }, - resize: function(event, ui) { + resize: function(_event, ui) { fig.request_resize(ui.size.width, ui.size.height); }, - stop: function(event, ui) { + stop: function(_event, ui) { pass_mouse_events = true; fig.request_resize(ui.size.width, ui.size.height); }, @@ -210,7 +211,7 @@ mpl.figure.prototype._init_canvas = function() { this._resize_canvas(600, 600); // Disable right mouse context menu. - $(this.rubberband_canvas).bind("contextmenu",function(e){ + $(this.rubberband_canvas).bind("contextmenu",function(_e){ return false; }); @@ -316,7 +317,7 @@ mpl.figure.prototype.send_draw_message = function() { } -mpl.figure.prototype.handle_save = function(fig, msg) { +mpl.figure.prototype.handle_save = function(fig, _msg) { var format_dropdown = fig.format_dropdown; var format = format_dropdown.options[format_dropdown.selectedIndex].value; fig.ondownload(fig, format); @@ -380,7 +381,7 @@ mpl.figure.prototype.handle_message = function(fig, msg) { fig.message.textContent = msg['message']; } -mpl.figure.prototype.handle_draw = function(fig, msg) { +mpl.figure.prototype.handle_draw = function(fig, _msg) { // Request the server to send over a new figure. fig.send_draw_message(); } @@ -506,7 +507,7 @@ mpl.figure.prototype.mouse_event = function(event, name) { return false; } -mpl.figure.prototype._key_event_extra = function(event, name) { +mpl.figure.prototype._key_event_extra = function(_event, _name) { // Handle any extra behaviour associated with a key event } diff --git a/lib/matplotlib/backends/web_backend/js/mpl_tornado.js b/lib/matplotlib/backends/web_backend/js/mpl_tornado.js index 8eb5eedb506a..b3cab8b7b906 100644 --- a/lib/matplotlib/backends/web_backend/js/mpl_tornado.js +++ b/lib/matplotlib/backends/web_backend/js/mpl_tornado.js @@ -2,6 +2,7 @@ tornado-based server, that are not relevant when embedding WebAgg in another web application. */ +/* exported mpl_ondownload */ function mpl_ondownload(figure, format) { window.open(figure.id + '/download.' + format, '_blank'); } diff --git a/lib/matplotlib/backends/web_backend/js/nbagg_mpl.js b/lib/matplotlib/backends/web_backend/js/nbagg_mpl.js index a66e450cd90c..bdbaab6bf8e0 100644 --- a/lib/matplotlib/backends/web_backend/js/nbagg_mpl.js +++ b/lib/matplotlib/backends/web_backend/js/nbagg_mpl.js @@ -1,3 +1,5 @@ +/* global mpl */ + var comm_websocket_adapter = function(comm) { // Create a "websocket"-like object which calls the given IPython comm // object with the appropriate methods. Currently this is a non binary @@ -30,7 +32,7 @@ mpl.mpl_figure_comm = function(comm, msg) { var element = $("#" + id); var ws_proxy = comm_websocket_adapter(comm) - function ondownload(figure, format) { + function ondownload(figure, _format) { window.open(figure.imageObj.src); } @@ -48,10 +50,6 @@ mpl.mpl_figure_comm = function(comm, msg) { console.error("Failed to find cell for figure", id, fig); return; } - - var output_index = fig.cell_info[2] - var cell = fig.cell_info[0]; - }; mpl.figure.prototype.handle_close = function(fig, msg) { @@ -73,7 +71,7 @@ mpl.figure.prototype.close_ws = function(fig, msg){ // fig.ws.close() } -mpl.figure.prototype.push_to_output = function(remove_interactive) { +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/mpl.ratio var dataURL = this.canvas.toDataURL(); @@ -105,6 +103,7 @@ mpl.figure.prototype._init_toolbar = function() { return fig.toolbar_button_onmouseover(event['data']); } + 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]; @@ -113,7 +112,7 @@ mpl.figure.prototype._init_toolbar = function() { if (!name) { continue; }; - var button = $(''); + button = $(''); button.click(method_name, toolbar_event); button.mouseover(tooltip, toolbar_mouse_event); nav_element.append(button); @@ -126,8 +125,8 @@ mpl.figure.prototype._init_toolbar = function() { // Add the close button to the window. var buttongrp = $('
'); - var button = $(''); - button.click(function (evt) { fig.handle_close(fig, {}); } ); + button = $(''); + button.click(function (_evt) { fig.handle_close(fig, {}); } ); button.mouseover('Stop Interaction', toolbar_mouse_event); buttongrp.append(button); var titlebar = this.root.find($('.ui-dialog-titlebar')); @@ -158,7 +157,7 @@ mpl.figure.prototype._canvas_extra_style = function(el){ } -mpl.figure.prototype._key_event_extra = function(event, name) { +mpl.figure.prototype._key_event_extra = function(event, _name) { var manager = IPython.notebook.keyboard_manager; if (!manager) manager = IPython.keyboard_manager; @@ -172,7 +171,7 @@ mpl.figure.prototype._key_event_extra = function(event, name) { } } -mpl.figure.prototype.handle_save = function(fig, msg) { +mpl.figure.prototype.handle_save = function(fig, _msg) { fig.ondownload(fig, null); } diff --git a/lib/matplotlib/backends/web_backend/package.json b/lib/matplotlib/backends/web_backend/package.json new file mode 100644 index 000000000000..e2a4009a971b --- /dev/null +++ b/lib/matplotlib/backends/web_backend/package.json @@ -0,0 +1,15 @@ +{ + "devDependencies": { + "eslint": "^6.8.0", + "eslint-config-prettier": "^6.10.1", + "prettier": "^2.0.2" + }, + "scripts": { + "eslint": "eslint . --fix", + "eslint:check": "eslint .", + "lint": "npm run prettier && npm run eslint", + "lint:check": "npm run prettier:check && npm run eslint:check", + "prettier": "prettier --write \"**/*{.ts,.tsx,.js,.jsx,.css,.json}\"", + "prettier:check": "prettier --check \"**/*{.ts,.tsx,.js,.jsx,.css,.json}\"" + } +} From 9d791dab9a48cd1e3c2c9c624a227dc4294059d6 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sat, 4 Apr 2020 00:11:26 -0400 Subject: [PATCH 2/3] STY: Format JavaScript code with prettier. --- lib/matplotlib/backends/web_backend/js/mpl.js | 405 ++++++++++-------- .../backends/web_backend/js/nbagg_mpl.js | 140 +++--- 2 files changed, 299 insertions(+), 246 deletions(-) diff --git a/lib/matplotlib/backends/web_backend/js/mpl.js b/lib/matplotlib/backends/web_backend/js/mpl.js index 5d927c1d241f..b350cd52a630 100644 --- a/lib/matplotlib/backends/web_backend/js/mpl.js +++ b/lib/matplotlib/backends/web_backend/js/mpl.js @@ -2,34 +2,35 @@ /* global mpl */ window.mpl = {}; - -mpl.get_websocket_type = function() { - if (typeof(WebSocket) !== 'undefined') { +mpl.get_websocket_type = function () { + if (typeof WebSocket !== 'undefined') { return WebSocket; - } else if (typeof(MozWebSocket) !== 'undefined') { + } else if (typeof MozWebSocket !== 'undefined') { return MozWebSocket; } else { - alert('Your browser does not have WebSocket support. ' + - 'Please try Chrome, Safari or Firefox ≥ 6. ' + - 'Firefox 4 and 5 are also supported but you ' + - 'have to enable WebSockets in about:config.'); - }; -} + alert( + 'Your browser does not have WebSocket support. ' + + 'Please try Chrome, Safari or Firefox ≥ 6. ' + + 'Firefox 4 and 5 are also supported but you ' + + 'have to enable WebSockets in about:config.' + ); + } +}; -mpl.figure = function(figure_id, websocket, ondownload, parent_element) { +mpl.figure = function (figure_id, websocket, ondownload, parent_element) { this.id = figure_id; this.ws = websocket; - this.supports_binary = (this.ws.binaryType != undefined); + this.supports_binary = this.ws.binaryType != undefined; if (!this.supports_binary) { - var warnings = document.getElementById("mpl-warnings"); + var warnings = document.getElementById('mpl-warnings'); if (warnings) { warnings.style.display = 'block'; - warnings.textContent = ( - "This browser does not support binary websocket messages. " + - "Performance may be slow."); + warnings.textContent = + 'This browser does not support binary websocket messages. ' + + 'Performance may be slow.'; } } @@ -45,7 +46,7 @@ mpl.figure = function(figure_id, websocket, ondownload, parent_element) { this.image_mode = 'full'; this.root = $('
'); - this._root_extra_style(this.root) + this._root_extra_style(this.root); this.root.attr('style', 'display: inline-block'); $(parent_element).append(this.root); @@ -58,58 +59,53 @@ mpl.figure = function(figure_id, websocket, ondownload, parent_element) { this.waiting = false; - this.ws.onopen = function () { - fig.send_message("supports_binary", {value: fig.supports_binary}); - fig.send_message("send_image_mode", {}); - if (mpl.ratio != 1) { - fig.send_message("set_dpi_ratio", {'dpi_ratio': mpl.ratio}); - } - fig.send_message("refresh", {}); + this.ws.onopen = function () { + fig.send_message('supports_binary', { value: fig.supports_binary }); + fig.send_message('send_image_mode', {}); + if (mpl.ratio != 1) { + fig.send_message('set_dpi_ratio', { dpi_ratio: mpl.ratio }); } + fig.send_message('refresh', {}); + }; - this.imageObj.onload = function() { - if (fig.image_mode == 'full') { - // Full images could contain transparency (where diff images - // almost always do), so we need to clear the canvas so that - // there is no ghosting. - fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height); - } - fig.context.drawImage(fig.imageObj, 0, 0); - }; + this.imageObj.onload = function () { + if (fig.image_mode == 'full') { + // Full images could contain transparency (where diff images + // almost always do), so we need to clear the canvas so that + // there is no ghosting. + fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height); + } + fig.context.drawImage(fig.imageObj, 0, 0); + }; - this.imageObj.onunload = function() { + this.imageObj.onunload = function () { fig.ws.close(); - } + }; this.ws.onmessage = this._make_on_message_function(this); this.ondownload = ondownload; -} +}; -mpl.figure.prototype._init_header = function() { +mpl.figure.prototype._init_header = function () { var titlebar = $( '
'); + 'ui-helper-clearfix"/>' + ); var titletext = $( '
'); - titlebar.append(titletext) + 'text-align: center; padding: 3px;"/>' + ); + titlebar.append(titletext); this.root.append(titlebar); this.header = titletext[0]; -} - - - -mpl.figure.prototype._canvas_extra_style = function(_canvas_div) { - -} - +}; -mpl.figure.prototype._root_extra_style = function(_canvas_div) { +mpl.figure.prototype._canvas_extra_style = function (_canvas_div) {}; -} +mpl.figure.prototype._root_extra_style = function (_canvas_div) {}; -mpl.figure.prototype._init_canvas = function() { +mpl.figure.prototype._init_canvas = function () { var fig = this; var canvas_div = $('
'); @@ -122,47 +118,53 @@ mpl.figure.prototype._init_canvas = function() { canvas_div.keydown('key_press', canvas_keyboard_event); canvas_div.keyup('key_release', canvas_keyboard_event); - this.canvas_div = canvas_div - this._canvas_extra_style(canvas_div) + this.canvas_div = canvas_div; + this._canvas_extra_style(canvas_div); this.root.append(canvas_div); var canvas = $(''); canvas.addClass('mpl-canvas'); - canvas.attr('style', "left: 0; top: 0; z-index: 0; outline: 0") + canvas.attr('style', 'left: 0; top: 0; z-index: 0; outline: 0'); this.canvas = canvas[0]; - this.context = canvas[0].getContext("2d"); + this.context = canvas[0].getContext('2d'); - var backingStore = this.context.backingStorePixelRatio || - this.context.webkitBackingStorePixelRatio || - this.context.mozBackingStorePixelRatio || - this.context.msBackingStorePixelRatio || - this.context.oBackingStorePixelRatio || - this.context.backingStorePixelRatio || 1; + var backingStore = + this.context.backingStorePixelRatio || + this.context.webkitBackingStorePixelRatio || + this.context.mozBackingStorePixelRatio || + this.context.msBackingStorePixelRatio || + this.context.oBackingStorePixelRatio || + this.context.backingStorePixelRatio || + 1; mpl.ratio = (window.devicePixelRatio || 1) / backingStore; var rubberband = $(''); - rubberband.attr('style', "position: absolute; left: 0; top: 0; z-index: 1;") + rubberband.attr( + 'style', + 'position: absolute; left: 0; top: 0; z-index: 1;' + ); var pass_mouse_events = true; canvas_div.resizable({ - start: function(_event, _ui) { + start: function (_event, _ui) { pass_mouse_events = false; }, - resize: function(_event, ui) { + resize: function (_event, ui) { fig.request_resize(ui.size.width, ui.size.height); }, - stop: function(_event, ui) { + stop: function (_event, ui) { pass_mouse_events = true; fig.request_resize(ui.size.width, ui.size.height); }, }); function mouse_event_fn(event) { - if (pass_mouse_events) + if (pass_mouse_events) { return fig.mouse_event(event, event['data']); + } } rubberband.mousedown('button_press', mouse_event_fn); @@ -173,9 +175,9 @@ mpl.figure.prototype._init_canvas = function() { rubberband.mouseenter('figure_enter', mouse_event_fn); rubberband.mouseleave('figure_leave', mouse_event_fn); - canvas_div.on("wheel", function (event) { + canvas_div.on('wheel', function (event) { event = event.originalEvent; - event['data'] = 'scroll' + event['data'] = 'scroll'; if (event.deltaY < 0) { event.step = 1; } else { @@ -189,41 +191,44 @@ mpl.figure.prototype._init_canvas = function() { this.rubberband = rubberband; this.rubberband_canvas = rubberband[0]; - this.rubberband_context = rubberband[0].getContext("2d"); - this.rubberband_context.strokeStyle = "#000000"; + this.rubberband_context = rubberband[0].getContext('2d'); + this.rubberband_context.strokeStyle = '#000000'; - this._resize_canvas = function(width, height) { + this._resize_canvas = function (width, height) { // Keep the size of the canvas, canvas container, and rubber band // canvas in synch. - canvas_div.css('width', width) - canvas_div.css('height', height) + canvas_div.css('width', width); + canvas_div.css('height', height); canvas.attr('width', width * mpl.ratio); canvas.attr('height', height * mpl.ratio); - canvas.attr('style', 'width: ' + width + 'px; height: ' + height + 'px;'); + canvas.attr( + 'style', + 'width: ' + width + 'px; height: ' + height + 'px;' + ); rubberband.attr('width', width); rubberband.attr('height', height); - } + }; // Set the figure to an initial 600x600px, this will subsequently be updated // upon first draw. this._resize_canvas(600, 600); // Disable right mouse context menu. - $(this.rubberband_canvas).bind("contextmenu",function(_e){ + $(this.rubberband_canvas).bind('contextmenu', function (_e) { return false; }); - function set_focus () { + function set_focus() { canvas.focus(); canvas_div.focus(); } window.setTimeout(set_focus, 100); -} +}; -mpl.figure.prototype._init_toolbar = function() { +mpl.figure.prototype._init_toolbar = function () { var fig = this; var nav_element = $('
'); @@ -238,7 +243,7 @@ mpl.figure.prototype._init_toolbar = function() { return fig.toolbar_button_onmouseover(event['data']); } - for(var toolbar_ind in mpl.toolbar_items) { + 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]; @@ -249,8 +254,10 @@ mpl.figure.prototype._init_toolbar = function() { continue; } var button = $(''); + button = $( + '' + ); button.click(method_name, toolbar_event); button.mouseover(tooltip, toolbar_mouse_event); nav_element.append(button); } // Add the status bar. - var status_bar = $(''); + var status_bar = $( + '' + ); nav_element.append(status_bar); this.message = status_bar[0]; // Add the close button to the window. var buttongrp = $('
'); - button = $(''); - button.click(function (_evt) { fig.handle_close(fig, {}); } ); + button = $( + '' + ); + button.click(function (_evt) { + fig.handle_close(fig, {}); + }); button.mouseover('Stop Interaction', toolbar_mouse_event); buttongrp.append(button); var titlebar = this.root.find($('.ui-dialog-titlebar')); titlebar.prepend(buttongrp); -} +}; -mpl.figure.prototype._root_extra_style = function(el){ - var fig = this - el.on("remove", function(){ - fig.close_ws(fig, {}); +mpl.figure.prototype._root_extra_style = function (el) { + var fig = this; + el.on('remove', function () { + fig.close_ws(fig, {}); }); -} +}; -mpl.figure.prototype._canvas_extra_style = function(el){ +mpl.figure.prototype._canvas_extra_style = function (el) { // this is important to make the div 'focusable - el.attr('tabindex', 0) + el.attr('tabindex', 0); // reach out to IPython and tell the keyboard manager to turn it's self // off when our div gets focus // location in version 3 if (IPython.notebook.keyboard_manager) { IPython.notebook.keyboard_manager.register_events(el); - } - else { + } else { // location in version 2 IPython.keyboard_manager.register_events(el); } +}; -} - -mpl.figure.prototype._key_event_extra = function(event, _name) { +mpl.figure.prototype._key_event_extra = function (event, _name) { var manager = IPython.notebook.keyboard_manager; - if (!manager) + if (!manager) { manager = IPython.keyboard_manager; + } // Check for shift+enter if (event.shiftKey && event.which == 13) { @@ -169,24 +185,23 @@ mpl.figure.prototype._key_event_extra = function(event, _name) { var index = IPython.notebook.find_cell_index(this.cell_info[0]); IPython.notebook.select(index + 1); } -} +}; -mpl.figure.prototype.handle_save = function(fig, _msg) { +mpl.figure.prototype.handle_save = function (fig, _msg) { fig.ondownload(fig, null); -} - +}; -mpl.find_output_cell = function(html_output) { +mpl.find_output_cell = function (html_output) { // Return the cell and output element which can be found *uniquely* in the notebook. // Note - this is a bit hacky, but it is done because the "notebook_saving.Notebook" // IPython event is triggered only after the cells have been serialised, which for // our purposes (turning an active figure into a static one), is too late. var cells = IPython.notebook.get_cells(); var ncells = cells.length; - for (var i=0; i= 3 moved mimebundle to data attribute of output @@ -198,10 +213,13 @@ mpl.find_output_cell = function(html_output) { } } } -} +}; // Register the function which deals with the matplotlib target/channel. // The kernel may be null if the page has been refreshed. if (IPython.notebook.kernel != null) { - IPython.notebook.kernel.comm_manager.register_target('matplotlib', mpl.mpl_figure_comm); + IPython.notebook.kernel.comm_manager.register_target( + 'matplotlib', + mpl.mpl_figure_comm + ); } From 33d496b37f07c5f12f46a006379587804eb13928 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sat, 4 Apr 2020 01:13:37 -0400 Subject: [PATCH 3/3] Use strict equality in JS files. --- lib/matplotlib/backends/web_backend/js/mpl.js | 24 +++++++++---------- .../backends/web_backend/js/nbagg_mpl.js | 6 ++--- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/matplotlib/backends/web_backend/js/mpl.js b/lib/matplotlib/backends/web_backend/js/mpl.js index b350cd52a630..4986680f5f2b 100644 --- a/lib/matplotlib/backends/web_backend/js/mpl.js +++ b/lib/matplotlib/backends/web_backend/js/mpl.js @@ -22,7 +22,7 @@ mpl.figure = function (figure_id, websocket, ondownload, parent_element) { this.ws = websocket; - this.supports_binary = this.ws.binaryType != undefined; + this.supports_binary = this.ws.binaryType !== undefined; if (!this.supports_binary) { var warnings = document.getElementById('mpl-warnings'); @@ -62,14 +62,14 @@ mpl.figure = function (figure_id, websocket, ondownload, parent_element) { this.ws.onopen = function () { fig.send_message('supports_binary', { value: fig.supports_binary }); fig.send_message('send_image_mode', {}); - if (mpl.ratio != 1) { + if (mpl.ratio !== 1) { fig.send_message('set_dpi_ratio', { dpi_ratio: mpl.ratio }); } fig.send_message('refresh', {}); }; this.imageObj.onload = function () { - if (fig.image_mode == 'full') { + if (fig.image_mode === 'full') { // Full images could contain transparency (where diff images // almost always do), so we need to clear the canvas so that // there is no ghosting. @@ -336,7 +336,7 @@ mpl.figure.prototype.handle_save = function (fig, _msg) { mpl.figure.prototype.handle_resize = function (fig, msg) { var size = msg['size']; - if (size[0] != fig.canvas.width || size[1] != fig.canvas.height) { + if (size[0] !== fig.canvas.width || size[1] !== fig.canvas.height) { fig._resize_canvas(size[0], size[1]); fig.send_message('refresh', {}); } @@ -434,7 +434,7 @@ mpl.figure.prototype._make_on_message_function = function (fig) { return; } else if ( typeof evt.data === 'string' && - evt.data.slice(0, 21) == 'data:image/png;base64' + evt.data.slice(0, 21) === 'data:image/png;base64' ) { fig.imageObj.src = evt.data; fig.updated_canvas_event(); @@ -485,7 +485,7 @@ mpl.findpos = function (e) { } else if (e.srcElement) { targ = e.srcElement; } - if (targ.nodeType == 3) { + if (targ.nodeType === 3) { // defeat Safari bug targ = targ.parentNode; } @@ -546,25 +546,25 @@ mpl.figure.prototype._key_event_extra = function (_event, _name) { mpl.figure.prototype.key_event = function (event, name) { // Prevent repeat events - if (name == 'key_press') { + if (name === 'key_press') { if (event.which === this._key) { return; } else { this._key = event.which; } } - if (name == 'key_release') { + if (name === 'key_release') { this._key = null; } var value = ''; - if (event.ctrlKey && event.which != 17) { + if (event.ctrlKey && event.which !== 17) { value += 'ctrl+'; } - if (event.altKey && event.which != 18) { + if (event.altKey && event.which !== 18) { value += 'alt+'; } - if (event.shiftKey && event.which != 16) { + if (event.shiftKey && event.which !== 16) { value += 'shift+'; } @@ -578,7 +578,7 @@ mpl.figure.prototype.key_event = function (event, name) { }; mpl.figure.prototype.toolbar_button_onclick = function (name) { - if (name == 'download') { + if (name === 'download') { this.handle_save(this, null); } else { this.send_message('toolbar_button', { name: name }); diff --git a/lib/matplotlib/backends/web_backend/js/nbagg_mpl.js b/lib/matplotlib/backends/web_backend/js/nbagg_mpl.js index fdcc157cc9f3..6461bfca6479 100644 --- a/lib/matplotlib/backends/web_backend/js/nbagg_mpl.js +++ b/lib/matplotlib/backends/web_backend/js/nbagg_mpl.js @@ -179,7 +179,7 @@ mpl.figure.prototype._key_event_extra = function (event, _name) { } // Check for shift+enter - if (event.shiftKey && event.which == 13) { + if (event.shiftKey && event.which === 13) { this.canvas_div.blur(); // select the cell after this one var index = IPython.notebook.find_cell_index(this.cell_info[0]); @@ -207,7 +207,7 @@ mpl.find_output_cell = function (html_output) { // IPython >= 3 moved mimebundle to data attribute of output data = data.data; } - if (data['text/html'] == html_output) { + if (data['text/html'] === html_output) { return [cell, data, j]; } } @@ -217,7 +217,7 @@ mpl.find_output_cell = function (html_output) { // Register the function which deals with the matplotlib target/channel. // The kernel may be null if the page has been refreshed. -if (IPython.notebook.kernel != null) { +if (IPython.notebook.kernel !== null) { IPython.notebook.kernel.comm_manager.register_target( 'matplotlib', mpl.mpl_figure_comm