Skip to content

Remove jQuery & jQuery UI #17086

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,5 @@ lib/z.lib

# Vendored dependencies #
#########################

jquery-ui-*/
lib/matplotlib/backends/web_backend/node_modules/
lib/matplotlib/backends/web_backend/package-lock.json
61 changes: 0 additions & 61 deletions LICENSE/LICENSE_JQUERY

This file was deleted.

3 changes: 0 additions & 3 deletions examples/user_interfaces/embedding_webagg_sgskip.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ def create_figure():
type="text/css" />
<link rel="stylesheet" href="_static/css/fbm.css" type="text/css" />
<link rel="stylesheet" href="_static/css/mpl.css" type="text/css">
<link rel="stylesheet" href="_static/jquery-ui-1.12.1/jquery-ui.min.css" />
<script src="_static/jquery-ui-1.12.1/external/jquery/jquery.js"></script>
<script src="_static/jquery-ui-1.12.1/jquery-ui.min.js"></script>
<script src="mpl.js"></script>

<script>
Expand Down
7 changes: 4 additions & 3 deletions lib/matplotlib/backends/backend_webagg_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def handle_resize(self, event):
# canvas size to the figure's new size (which is hopefully
# identical or within a pixel or so).
self._png_is_old = True
self.manager.resize(*fig.bbox.size)
self.manager.resize(*fig.bbox.size, forward=False)
self.resize_event()

def handle_send_image_mode(self, event):
Expand Down Expand Up @@ -427,10 +427,11 @@ def _get_toolbar(self, canvas):
toolbar = self.ToolbarCls(canvas)
return toolbar

def resize(self, w, h):
def resize(self, w, h, forward=True):
self._send_event(
'resize',
size=(w / self.canvas._dpi_ratio, h / self.canvas._dpi_ratio))
size=(w / self.canvas._dpi_ratio, h / self.canvas._dpi_ratio),
forward=forward)

def set_window_title(self, title):
self._send_event('figure_label', label=title)
Expand Down
3 changes: 0 additions & 3 deletions lib/matplotlib/backends/web_backend/all_figures.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
<link rel="stylesheet" href="{{ prefix }}/_static/css/boilerplate.css" type="text/css" />
<link rel="stylesheet" href="{{ prefix }}/_static/css/fbm.css" type="text/css" />
<link rel="stylesheet" href="{{ prefix }}/_static/css/mpl.css" type="text/css">
<link rel="stylesheet" href="{{ prefix }}/_static/jquery-ui-1.12.1/jquery-ui.min.css" >
<script src="{{ prefix }}/_static/jquery-ui-1.12.1/external/jquery/jquery.js"></script>
<script src="{{ prefix }}/_static/jquery-ui-1.12.1/jquery-ui.min.js"></script>
<script src="{{ prefix }}/_static/js/mpl_tornado.js"></script>
<script src="{{ prefix }}/js/mpl.js"></script>

Expand Down
21 changes: 21 additions & 0 deletions lib/matplotlib/backends/web_backend/css/mpl.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
/* General styling */
.ui-helper-clearfix:before,
.ui-helper-clearfix:after {
content: "";
display: table;
border-collapse: collapse;
}
.ui-helper-clearfix:after {
clear: both;
}

/* Header */
.ui-widget-header {
border: 1px solid #dddddd;
border-top-left-radius: 6px;
border-top-right-radius: 6px;
background: #e9e9e9;
color: #333333;
font-weight: bold;
}

/* Toolbar and items */
.mpl-toolbar {
width: 100%;
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/backends/web_backend/css/page.css
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,6 @@ span#login_widget {
#figure-div {
display: inline-block;
margin: 10px;
vertical-align: top;
}

92 changes: 52 additions & 40 deletions lib/matplotlib/backends/web_backend/js/mpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ mpl.figure = function (figure_id, websocket, ondownload, parent_element) {
this.image_mode = 'full';

this.root = document.createElement('div');
this._root_extra_style(this.root);
this.root.setAttribute('style', 'display: inline-block');
this._root_extra_style(this.root);

parent_element.appendChild(this.root);

Expand Down Expand Up @@ -112,7 +112,15 @@ mpl.figure.prototype._init_canvas = function () {
var canvas_div = (this.canvas_div = document.createElement('div'));
canvas_div.setAttribute(
'style',
'position: relative; clear: both; outline: 0'
'border: 1px solid #ddd;' +
'box-sizing: content-box;' +
'clear: both;' +
'min-height: 1px;' +
'min-width: 1px;' +
'outline: 0;' +
'overflow: hidden;' +
'position: relative;' +
'resize: both;'
);

function on_keyboard_event_closure(name) {
Expand All @@ -135,7 +143,7 @@ mpl.figure.prototype._init_canvas = function () {

var canvas = (this.canvas = document.createElement('canvas'));
canvas.classList.add('mpl-canvas');
canvas.setAttribute('style', 'left: 0; top: 0; z-index: 0; outline: 0');
canvas.setAttribute('style', 'box-sizing: content-box;');

this.context = canvas.getContext('2d');

Expand All @@ -155,29 +163,47 @@ mpl.figure.prototype._init_canvas = function () {
));
rubberband_canvas.setAttribute(
'style',
'position: absolute; left: 0; top: 0; z-index: 1;'
'box-sizing: content-box; position: absolute; left: 0; top: 0; z-index: 1;'
);

var pass_mouse_events = true;

$(canvas_div).resizable({
start: function (_event, _ui) {
pass_mouse_events = false;
},
resize: function (_event, ui) {
fig.request_resize(ui.size.width, ui.size.height);
},
stop: function (_event, ui) {
pass_mouse_events = true;
fig.request_resize(ui.size.width, ui.size.height);
},
var resizeObserver = new ResizeObserver(function (entries) {
var nentries = entries.length;
for (var i = 0; i < nentries; i++) {
var entry = entries[i];
var width, height;
if (entry.contentBoxSize) {
width = entry.contentBoxSize.inlineSize;
height = entry.contentBoxSize.blockSize;
} else {
width = entry.contentRect.width;
height = entry.contentRect.height;
}

// Keep the size of the canvas and rubber band canvas in sync with
// the canvas container.
canvas.setAttribute('width', width * mpl.ratio);
canvas.setAttribute('height', height * mpl.ratio);
canvas.setAttribute(
'style',
'width: ' + width + 'px; height: ' + height + 'px;'
);

rubberband_canvas.setAttribute('width', width);
rubberband_canvas.setAttribute('height', height);

// And update the size in Python. We ignore the initial 0/0 size
// that occurs as the element is placed into the DOM, which should
// otherwise not happen due to the minimum size styling.
if (width != 0 && height != 0) {
fig.request_resize(width, height);
}
}
});
resizeObserver.observe(canvas_div);

function on_mouse_event_closure(name) {
return function (event) {
if (pass_mouse_events) {
return fig.mouse_event(event, name);
}
return fig.mouse_event(event, name);
};
}

Expand Down Expand Up @@ -219,27 +245,13 @@ mpl.figure.prototype._init_canvas = function () {
this.rubberband_context = rubberband_canvas.getContext('2d');
this.rubberband_context.strokeStyle = '#000000';

this._resize_canvas = function (width, height) {
// Keep the size of the canvas, canvas container, and rubber band
// canvas in synch.
canvas_div.style.width = width;
canvas_div.style.height = height;

canvas.setAttribute('width', width * mpl.ratio);
canvas.setAttribute('height', height * mpl.ratio);
canvas.setAttribute(
'style',
'width: ' + width + 'px; height: ' + height + 'px;'
);

rubberband_canvas.setAttribute('width', width);
rubberband_canvas.setAttribute('height', height);
this._resize_canvas = function (width, height, forward) {
if (forward) {
canvas_div.style.width = width + 'px';
canvas_div.style.height = height + 'px';
}
};

// 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.addEventListener('contextmenu', function (_e) {
return false;
Expand Down Expand Up @@ -360,7 +372,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) {
fig._resize_canvas(size[0], size[1]);
fig._resize_canvas(size[0], size[1], msg['forward']);
fig.send_message('refresh', {});
}
};
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/backends/web_backend/js/nbagg_mpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ mpl.figure.prototype._remove_fig_handler = function () {
};

mpl.figure.prototype._root_extra_style = function (el) {
el.style.boxSizing = 'content-box'; // override notebook setting of border-box.
el.addEventListener('remove', this._remove_fig_handler);
};

Expand Down
3 changes: 0 additions & 3 deletions lib/matplotlib/backends/web_backend/single_figure.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
<link rel="stylesheet" href="{{ prefix }}/_static/css/boilerplate.css" type="text/css" />
<link rel="stylesheet" href="{{ prefix }}/_static/css/fbm.css" type="text/css" />
<link rel="stylesheet" href="{{ prefix }}/_static/css/mpl.css" type="text/css">
<link rel="stylesheet" href="{{ prefix }}/_static/jquery-ui-1.12.1/jquery-ui.min.css" >
<script src="{{ prefix }}/_static/jquery-ui-1.12.1/external/jquery/jquery.js"></script>
<script src="{{ prefix }}/_static/jquery-ui-1.12.1/jquery-ui.min.js"></script>
<script src="{{ prefix }}/_static/js/mpl_tornado.js"></script>
<script src="{{ prefix }}/js/mpl.js"></script>
<script>
Expand Down
57 changes: 1 addition & 56 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,9 @@
from pathlib import Path
import shutil
import subprocess
from zipfile import ZipFile

from setuptools import setup, find_packages, Extension
from setuptools.command.build_ext import build_ext as BuildExtCommand
from setuptools.command.develop import develop as DevelopCommand
from setuptools.command.install_lib import install_lib as InstallLibCommand
from setuptools.command.test import test as TestCommand

# The setuptools version of sdist adds a setup.cfg file to the tree.
Expand All @@ -48,7 +45,7 @@
from distutils.dist import Distribution

import setupext
from setupext import print_raw, print_status, download_or_cache
from setupext import print_raw, print_status

# Get the version from versioneer
import versioneer
Expand Down Expand Up @@ -182,58 +179,6 @@ def build_extensions(self):
cmdclass['build_ext'] = BuildExtraLibraries


def _download_jquery_to(dest):
# Note: When bumping the jquery-ui version, also update the versions in
# single_figure.html and all_figures.html.
url = "https://jqueryui.com/resources/download/jquery-ui-1.12.1.zip"
sha = "f8233674366ab36b2c34c577ec77a3d70cac75d2e387d8587f3836345c0f624d"
name = Path(url).stem
if (dest / name).exists():
return
# If we are installing from an sdist, use the already downloaded jquery-ui.
sdist_src = Path("lib/matplotlib/backends/web_backend", name)
if sdist_src.exists():
shutil.copytree(sdist_src, dest / name)
return
if not (dest / name).exists():
dest.mkdir(parents=True, exist_ok=True)
try:
buff = download_or_cache(url, sha)
except Exception:
raise IOError(
"Failed to download jquery-ui. Please download "
"{url} and extract it to {dest}.".format(url=url, dest=dest))
with ZipFile(buff) as zf:
zf.extractall(dest)


# Relying on versioneer's implementation detail.
class sdist_with_jquery(cmdclass['sdist']):
def make_release_tree(self, base_dir, files):
super().make_release_tree(base_dir, files)
_download_jquery_to(
Path(base_dir, "lib/matplotlib/backends/web_backend/"))


# Affects install and bdist_wheel.
class install_lib_with_jquery(InstallLibCommand):
def run(self):
super().run()
_download_jquery_to(
Path(self.install_dir, "matplotlib/backends/web_backend/"))


class develop_with_jquery(DevelopCommand):
def run(self):
super().run()
_download_jquery_to(Path("lib/matplotlib/backends/web_backend/"))


cmdclass['sdist'] = sdist_with_jquery
cmdclass['install_lib'] = install_lib_with_jquery
cmdclass['develop'] = develop_with_jquery


package_data = {} # Will be filled below by the various components.

# If the user just queries for information, don't bother figuring out which
Expand Down