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

Skip to content

Commit 94c0721

Browse files
authored
Merge pull request #17086 from QuLogic/no-jquery-ui
MNT: Remove jQuery & jQuery UI
2 parents 7f66d47 + 6e8bda7 commit 94c0721

File tree

11 files changed

+80
-171
lines changed

11 files changed

+80
-171
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,5 @@ lib/z.lib
102102

103103
# Vendored dependencies #
104104
#########################
105-
106-
jquery-ui-*/
107105
lib/matplotlib/backends/web_backend/node_modules/
108106
lib/matplotlib/backends/web_backend/package-lock.json

LICENSE/LICENSE_JQUERY

Lines changed: 0 additions & 61 deletions
This file was deleted.

examples/user_interfaces/embedding_webagg_sgskip.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@ def create_figure():
6060
type="text/css" />
6161
<link rel="stylesheet" href="_static/css/fbm.css" type="text/css" />
6262
<link rel="stylesheet" href="_static/css/mpl.css" type="text/css">
63-
<link rel="stylesheet" href="_static/jquery-ui-1.12.1/jquery-ui.min.css" />
64-
<script src="_static/jquery-ui-1.12.1/external/jquery/jquery.js"></script>
65-
<script src="_static/jquery-ui-1.12.1/jquery-ui.min.js"></script>
6663
<script src="mpl.js"></script>
6764
6865
<script>

lib/matplotlib/backends/backend_webagg_core.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ def handle_resize(self, event):
322322
# canvas size to the figure's new size (which is hopefully
323323
# identical or within a pixel or so).
324324
self._png_is_old = True
325-
self.manager.resize(*fig.bbox.size)
325+
self.manager.resize(*fig.bbox.size, forward=False)
326326
self.resize_event()
327327

328328
def handle_send_image_mode(self, event):
@@ -427,10 +427,11 @@ def _get_toolbar(self, canvas):
427427
toolbar = self.ToolbarCls(canvas)
428428
return toolbar
429429

430-
def resize(self, w, h):
430+
def resize(self, w, h, forward=True):
431431
self._send_event(
432432
'resize',
433-
size=(w / self.canvas._dpi_ratio, h / self.canvas._dpi_ratio))
433+
size=(w / self.canvas._dpi_ratio, h / self.canvas._dpi_ratio),
434+
forward=forward)
434435

435436
def set_window_title(self, title):
436437
self._send_event('figure_label', label=title)

lib/matplotlib/backends/web_backend/all_figures.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
<link rel="stylesheet" href="{{ prefix }}/_static/css/boilerplate.css" type="text/css" />
55
<link rel="stylesheet" href="{{ prefix }}/_static/css/fbm.css" type="text/css" />
66
<link rel="stylesheet" href="{{ prefix }}/_static/css/mpl.css" type="text/css">
7-
<link rel="stylesheet" href="{{ prefix }}/_static/jquery-ui-1.12.1/jquery-ui.min.css" >
8-
<script src="{{ prefix }}/_static/jquery-ui-1.12.1/external/jquery/jquery.js"></script>
9-
<script src="{{ prefix }}/_static/jquery-ui-1.12.1/jquery-ui.min.js"></script>
107
<script src="{{ prefix }}/_static/js/mpl_tornado.js"></script>
118
<script src="{{ prefix }}/js/mpl.js"></script>
129

lib/matplotlib/backends/web_backend/css/mpl.css

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
/* General styling */
2+
.ui-helper-clearfix:before,
3+
.ui-helper-clearfix:after {
4+
content: "";
5+
display: table;
6+
border-collapse: collapse;
7+
}
8+
.ui-helper-clearfix:after {
9+
clear: both;
10+
}
11+
12+
/* Header */
13+
.ui-widget-header {
14+
border: 1px solid #dddddd;
15+
border-top-left-radius: 6px;
16+
border-top-right-radius: 6px;
17+
background: #e9e9e9;
18+
color: #333333;
19+
font-weight: bold;
20+
}
21+
122
/* Toolbar and items */
223
.mpl-toolbar {
324
width: 100%;

lib/matplotlib/backends/web_backend/css/page.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,6 @@ span#login_widget {
7878
#figure-div {
7979
display: inline-block;
8080
margin: 10px;
81+
vertical-align: top;
8182
}
8283

lib/matplotlib/backends/web_backend/js/mpl.js

Lines changed: 52 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ mpl.figure = function (figure_id, websocket, ondownload, parent_element) {
4646
this.image_mode = 'full';
4747

4848
this.root = document.createElement('div');
49-
this._root_extra_style(this.root);
5049
this.root.setAttribute('style', 'display: inline-block');
50+
this._root_extra_style(this.root);
5151

5252
parent_element.appendChild(this.root);
5353

@@ -112,7 +112,15 @@ mpl.figure.prototype._init_canvas = function () {
112112
var canvas_div = (this.canvas_div = document.createElement('div'));
113113
canvas_div.setAttribute(
114114
'style',
115-
'position: relative; clear: both; outline: 0'
115+
'border: 1px solid #ddd;' +
116+
'box-sizing: content-box;' +
117+
'clear: both;' +
118+
'min-height: 1px;' +
119+
'min-width: 1px;' +
120+
'outline: 0;' +
121+
'overflow: hidden;' +
122+
'position: relative;' +
123+
'resize: both;'
116124
);
117125

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

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

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

@@ -155,29 +163,47 @@ mpl.figure.prototype._init_canvas = function () {
155163
));
156164
rubberband_canvas.setAttribute(
157165
'style',
158-
'position: absolute; left: 0; top: 0; z-index: 1;'
166+
'box-sizing: content-box; position: absolute; left: 0; top: 0; z-index: 1;'
159167
);
160168

161-
var pass_mouse_events = true;
162-
163-
$(canvas_div).resizable({
164-
start: function (_event, _ui) {
165-
pass_mouse_events = false;
166-
},
167-
resize: function (_event, ui) {
168-
fig.request_resize(ui.size.width, ui.size.height);
169-
},
170-
stop: function (_event, ui) {
171-
pass_mouse_events = true;
172-
fig.request_resize(ui.size.width, ui.size.height);
173-
},
169+
var resizeObserver = new ResizeObserver(function (entries) {
170+
var nentries = entries.length;
171+
for (var i = 0; i < nentries; i++) {
172+
var entry = entries[i];
173+
var width, height;
174+
if (entry.contentBoxSize) {
175+
width = entry.contentBoxSize.inlineSize;
176+
height = entry.contentBoxSize.blockSize;
177+
} else {
178+
width = entry.contentRect.width;
179+
height = entry.contentRect.height;
180+
}
181+
182+
// Keep the size of the canvas and rubber band canvas in sync with
183+
// the canvas container.
184+
canvas.setAttribute('width', width * mpl.ratio);
185+
canvas.setAttribute('height', height * mpl.ratio);
186+
canvas.setAttribute(
187+
'style',
188+
'width: ' + width + 'px; height: ' + height + 'px;'
189+
);
190+
191+
rubberband_canvas.setAttribute('width', width);
192+
rubberband_canvas.setAttribute('height', height);
193+
194+
// And update the size in Python. We ignore the initial 0/0 size
195+
// that occurs as the element is placed into the DOM, which should
196+
// otherwise not happen due to the minimum size styling.
197+
if (width != 0 && height != 0) {
198+
fig.request_resize(width, height);
199+
}
200+
}
174201
});
202+
resizeObserver.observe(canvas_div);
175203

176204
function on_mouse_event_closure(name) {
177205
return function (event) {
178-
if (pass_mouse_events) {
179-
return fig.mouse_event(event, name);
180-
}
206+
return fig.mouse_event(event, name);
181207
};
182208
}
183209

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

222-
this._resize_canvas = function (width, height) {
223-
// Keep the size of the canvas, canvas container, and rubber band
224-
// canvas in synch.
225-
canvas_div.style.width = width;
226-
canvas_div.style.height = height;
227-
228-
canvas.setAttribute('width', width * mpl.ratio);
229-
canvas.setAttribute('height', height * mpl.ratio);
230-
canvas.setAttribute(
231-
'style',
232-
'width: ' + width + 'px; height: ' + height + 'px;'
233-
);
234-
235-
rubberband_canvas.setAttribute('width', width);
236-
rubberband_canvas.setAttribute('height', height);
248+
this._resize_canvas = function (width, height, forward) {
249+
if (forward) {
250+
canvas_div.style.width = width + 'px';
251+
canvas_div.style.height = height + 'px';
252+
}
237253
};
238254

239-
// Set the figure to an initial 600x600px, this will subsequently be updated
240-
// upon first draw.
241-
this._resize_canvas(600, 600);
242-
243255
// Disable right mouse context menu.
244256
this.rubberband_canvas.addEventListener('contextmenu', function (_e) {
245257
return false;
@@ -360,7 +372,7 @@ mpl.figure.prototype.handle_save = function (fig, _msg) {
360372
mpl.figure.prototype.handle_resize = function (fig, msg) {
361373
var size = msg['size'];
362374
if (size[0] !== fig.canvas.width || size[1] !== fig.canvas.height) {
363-
fig._resize_canvas(size[0], size[1]);
375+
fig._resize_canvas(size[0], size[1], msg['forward']);
364376
fig.send_message('refresh', {});
365377
}
366378
};

lib/matplotlib/backends/web_backend/js/nbagg_mpl.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ mpl.figure.prototype._remove_fig_handler = function () {
176176
};
177177

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

lib/matplotlib/backends/web_backend/single_figure.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
<link rel="stylesheet" href="{{ prefix }}/_static/css/boilerplate.css" type="text/css" />
55
<link rel="stylesheet" href="{{ prefix }}/_static/css/fbm.css" type="text/css" />
66
<link rel="stylesheet" href="{{ prefix }}/_static/css/mpl.css" type="text/css">
7-
<link rel="stylesheet" href="{{ prefix }}/_static/jquery-ui-1.12.1/jquery-ui.min.css" >
8-
<script src="{{ prefix }}/_static/jquery-ui-1.12.1/external/jquery/jquery.js"></script>
9-
<script src="{{ prefix }}/_static/jquery-ui-1.12.1/jquery-ui.min.js"></script>
107
<script src="{{ prefix }}/_static/js/mpl_tornado.js"></script>
118
<script src="{{ prefix }}/js/mpl.js"></script>
129
<script>

setup.py

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,9 @@
2626
from pathlib import Path
2727
import shutil
2828
import subprocess
29-
from zipfile import ZipFile
3029

3130
from setuptools import setup, find_packages, Extension
3231
from setuptools.command.build_ext import build_ext as BuildExtCommand
33-
from setuptools.command.develop import develop as DevelopCommand
34-
from setuptools.command.install_lib import install_lib as InstallLibCommand
3532
from setuptools.command.test import test as TestCommand
3633

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

5047
import setupext
51-
from setupext import print_raw, print_status, download_or_cache
48+
from setupext import print_raw, print_status
5249

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

184181

185-
def _download_jquery_to(dest):
186-
# Note: When bumping the jquery-ui version, also update the versions in
187-
# single_figure.html and all_figures.html.
188-
url = "https://jqueryui.com/resources/download/jquery-ui-1.12.1.zip"
189-
sha = "f8233674366ab36b2c34c577ec77a3d70cac75d2e387d8587f3836345c0f624d"
190-
name = Path(url).stem
191-
if (dest / name).exists():
192-
return
193-
# If we are installing from an sdist, use the already downloaded jquery-ui.
194-
sdist_src = Path("lib/matplotlib/backends/web_backend", name)
195-
if sdist_src.exists():
196-
shutil.copytree(sdist_src, dest / name)
197-
return
198-
if not (dest / name).exists():
199-
dest.mkdir(parents=True, exist_ok=True)
200-
try:
201-
buff = download_or_cache(url, sha)
202-
except Exception:
203-
raise IOError(
204-
"Failed to download jquery-ui. Please download "
205-
"{url} and extract it to {dest}.".format(url=url, dest=dest))
206-
with ZipFile(buff) as zf:
207-
zf.extractall(dest)
208-
209-
210-
# Relying on versioneer's implementation detail.
211-
class sdist_with_jquery(cmdclass['sdist']):
212-
def make_release_tree(self, base_dir, files):
213-
super().make_release_tree(base_dir, files)
214-
_download_jquery_to(
215-
Path(base_dir, "lib/matplotlib/backends/web_backend/"))
216-
217-
218-
# Affects install and bdist_wheel.
219-
class install_lib_with_jquery(InstallLibCommand):
220-
def run(self):
221-
super().run()
222-
_download_jquery_to(
223-
Path(self.install_dir, "matplotlib/backends/web_backend/"))
224-
225-
226-
class develop_with_jquery(DevelopCommand):
227-
def run(self):
228-
super().run()
229-
_download_jquery_to(Path("lib/matplotlib/backends/web_backend/"))
230-
231-
232-
cmdclass['sdist'] = sdist_with_jquery
233-
cmdclass['install_lib'] = install_lib_with_jquery
234-
cmdclass['develop'] = develop_with_jquery
235-
236-
237182
package_data = {} # Will be filled below by the various components.
238183

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

0 commit comments

Comments
 (0)