Fixed database typo and removed unnecessary class identifier.
This commit is contained in:
parent
00ad49a143
commit
45fb349a7d
5098 changed files with 952558 additions and 85 deletions
|
@ -0,0 +1,32 @@
|
|||
module.exports = {
|
||||
root: true,
|
||||
ignorePatterns: ["jquery-ui-*/", "node_modules/"],
|
||||
env: {
|
||||
browser: true,
|
||||
jquery: true,
|
||||
},
|
||||
extends: ["eslint:recommended", "prettier"],
|
||||
globals: {
|
||||
IPython: "readonly",
|
||||
MozWebSocket: "readonly",
|
||||
},
|
||||
rules: {
|
||||
indent: ["error", 2, { SwitchCase: 1 }],
|
||||
"no-unused-vars": [
|
||||
"error",
|
||||
{
|
||||
argsIgnorePattern: "^_",
|
||||
},
|
||||
],
|
||||
quotes: ["error", "double", { avoidEscape: true }],
|
||||
},
|
||||
overrides: [
|
||||
{
|
||||
files: "js/**/*.js",
|
||||
rules: {
|
||||
indent: ["error", 4, { SwitchCase: 1 }],
|
||||
quotes: ["error", "single", { avoidEscape: true }],
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
|
@ -0,0 +1,7 @@
|
|||
node_modules/
|
||||
|
||||
# Vendored dependencies
|
||||
css/boilerplate.css
|
||||
css/fbm.css
|
||||
css/page.css
|
||||
jquery-ui-*/
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"overrides": [
|
||||
{
|
||||
"files": "js/**/*.js",
|
||||
"options": {
|
||||
"singleQuote": true,
|
||||
"tabWidth": 4,
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="{{ prefix }}/_static/css/page.css" type="text/css">
|
||||
<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">
|
||||
<script src="{{ prefix }}/_static/js/mpl_tornado.js"></script>
|
||||
<script src="{{ prefix }}/js/mpl.js"></script>
|
||||
|
||||
<script>
|
||||
function ready(fn) {
|
||||
if (document.readyState != "loading") {
|
||||
fn();
|
||||
} else {
|
||||
document.addEventListener("DOMContentLoaded", fn);
|
||||
}
|
||||
}
|
||||
|
||||
function figure_ready(fig_id) {
|
||||
return function () {
|
||||
var main_div = document.querySelector("div#figures");
|
||||
var figure_div = document.createElement("div");
|
||||
figure_div.id = "figure-div";
|
||||
main_div.appendChild(figure_div);
|
||||
var websocket_type = mpl.get_websocket_type();
|
||||
var websocket = new websocket_type("{{ ws_uri }}" + fig_id + "/ws");
|
||||
var fig = new mpl.figure(fig_id, websocket, mpl_ondownload, figure_div);
|
||||
|
||||
fig.focus_on_mouseover = true;
|
||||
|
||||
fig.canvas.setAttribute("tabindex", fig_id);
|
||||
}
|
||||
};
|
||||
|
||||
{% for (fig_id, fig_manager) in figures %}
|
||||
ready(figure_ready({{ str(fig_id) }}));
|
||||
{% end %}
|
||||
</script>
|
||||
|
||||
<title>MPL | WebAgg current figures</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div id="mpl-warnings" class="mpl-warnings"></div>
|
||||
|
||||
<div id="figures" style="margin: 10px 10px;"></div>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,77 @@
|
|||
/**
|
||||
* HTML5 ✰ Boilerplate
|
||||
*
|
||||
* style.css contains a reset, font normalization and some base styles.
|
||||
*
|
||||
* Credit is left where credit is due.
|
||||
* Much inspiration was taken from these projects:
|
||||
* - yui.yahooapis.com/2.8.1/build/base/base.css
|
||||
* - camendesign.com/design/
|
||||
* - praegnanz.de/weblog/htmlcssjs-kickstart
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* html5doctor.com Reset Stylesheet (Eric Meyer's Reset Reloaded + HTML5 baseline)
|
||||
* v1.6.1 2010-09-17 | Authors: Eric Meyer & Richard Clark
|
||||
* html5doctor.com/html-5-reset-stylesheet/
|
||||
*/
|
||||
|
||||
html, body, div, span, object, iframe,
|
||||
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
|
||||
abbr, address, cite, code, del, dfn, em, img, ins, kbd, q, samp,
|
||||
small, strong, sub, sup, var, b, i, dl, dt, dd, ol, ul, li,
|
||||
fieldset, form, label, legend,
|
||||
table, caption, tbody, tfoot, thead, tr, th, td,
|
||||
article, aside, canvas, details, figcaption, figure,
|
||||
footer, header, hgroup, menu, nav, section, summary,
|
||||
time, mark, audio, video {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
font-size: 100%;
|
||||
font: inherit;
|
||||
vertical-align: baseline;
|
||||
}
|
||||
|
||||
sup { vertical-align: super; }
|
||||
sub { vertical-align: sub; }
|
||||
|
||||
article, aside, details, figcaption, figure,
|
||||
footer, header, hgroup, menu, nav, section {
|
||||
display: block;
|
||||
}
|
||||
|
||||
blockquote, q { quotes: none; }
|
||||
|
||||
blockquote:before, blockquote:after,
|
||||
q:before, q:after { content: ""; content: none; }
|
||||
|
||||
ins { background-color: #ff9; color: #000; text-decoration: none; }
|
||||
|
||||
mark { background-color: #ff9; color: #000; font-style: italic; font-weight: bold; }
|
||||
|
||||
del { text-decoration: line-through; }
|
||||
|
||||
abbr[title], dfn[title] { border-bottom: 1px dotted; cursor: help; }
|
||||
|
||||
table { border-collapse: collapse; border-spacing: 0; }
|
||||
|
||||
hr { display: block; height: 1px; border: 0; border-top: 1px solid #ccc; margin: 1em 0; padding: 0; }
|
||||
|
||||
input, select { vertical-align: middle; }
|
||||
|
||||
|
||||
/**
|
||||
* Font normalization inspired by YUI Library's fonts.css: developer.yahoo.com/yui/
|
||||
*/
|
||||
|
||||
body { font:13px/1.231 sans-serif; *font-size:small; } /* Hack retained to preserve specificity */
|
||||
select, input, textarea, button { font:99% sans-serif; }
|
||||
|
||||
/* Normalize monospace sizing:
|
||||
en.wikipedia.org/wiki/MediaWiki_talk:Common.css/Archive_11#Teletype_style_fix_for_Chrome */
|
||||
pre, code, kbd, samp { font-family: monospace, sans-serif; }
|
||||
|
||||
em,i { font-style: italic; }
|
||||
b,strong { font-weight: bold; }
|
|
@ -0,0 +1,97 @@
|
|||
|
||||
/* Flexible box model classes */
|
||||
/* Taken from Alex Russell http://infrequently.org/2009/08/css-3-progress/ */
|
||||
|
||||
.hbox {
|
||||
display: -webkit-box;
|
||||
-webkit-box-orient: horizontal;
|
||||
-webkit-box-align: stretch;
|
||||
|
||||
display: -moz-box;
|
||||
-moz-box-orient: horizontal;
|
||||
-moz-box-align: stretch;
|
||||
|
||||
display: box;
|
||||
box-orient: horizontal;
|
||||
box-align: stretch;
|
||||
}
|
||||
|
||||
.hbox > * {
|
||||
-webkit-box-flex: 0;
|
||||
-moz-box-flex: 0;
|
||||
box-flex: 0;
|
||||
}
|
||||
|
||||
.vbox {
|
||||
display: -webkit-box;
|
||||
-webkit-box-orient: vertical;
|
||||
-webkit-box-align: stretch;
|
||||
|
||||
display: -moz-box;
|
||||
-moz-box-orient: vertical;
|
||||
-moz-box-align: stretch;
|
||||
|
||||
display: box;
|
||||
box-orient: vertical;
|
||||
box-align: stretch;
|
||||
}
|
||||
|
||||
.vbox > * {
|
||||
-webkit-box-flex: 0;
|
||||
-moz-box-flex: 0;
|
||||
box-flex: 0;
|
||||
}
|
||||
|
||||
.reverse {
|
||||
-webkit-box-direction: reverse;
|
||||
-moz-box-direction: reverse;
|
||||
box-direction: reverse;
|
||||
}
|
||||
|
||||
.box-flex0 {
|
||||
-webkit-box-flex: 0;
|
||||
-moz-box-flex: 0;
|
||||
box-flex: 0;
|
||||
}
|
||||
|
||||
.box-flex1, .box-flex {
|
||||
-webkit-box-flex: 1;
|
||||
-moz-box-flex: 1;
|
||||
box-flex: 1;
|
||||
}
|
||||
|
||||
.box-flex2 {
|
||||
-webkit-box-flex: 2;
|
||||
-moz-box-flex: 2;
|
||||
box-flex: 2;
|
||||
}
|
||||
|
||||
.box-group1 {
|
||||
-webkit-box-flex-group: 1;
|
||||
-moz-box-flex-group: 1;
|
||||
box-flex-group: 1;
|
||||
}
|
||||
|
||||
.box-group2 {
|
||||
-webkit-box-flex-group: 2;
|
||||
-moz-box-flex-group: 2;
|
||||
box-flex-group: 2;
|
||||
}
|
||||
|
||||
.start {
|
||||
-webkit-box-pack: start;
|
||||
-moz-box-pack: start;
|
||||
box-pack: start;
|
||||
}
|
||||
|
||||
.end {
|
||||
-webkit-box-pack: end;
|
||||
-moz-box-pack: end;
|
||||
box-pack: end;
|
||||
}
|
||||
|
||||
.center {
|
||||
-webkit-box-pack: center;
|
||||
-moz-box-pack: center;
|
||||
box-pack: center;
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
/* 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%;
|
||||
}
|
||||
|
||||
.mpl-toolbar div.mpl-button-group {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.mpl-button-group + .mpl-button-group {
|
||||
margin-left: 0.5em;
|
||||
}
|
||||
|
||||
.mpl-widget {
|
||||
background-color: #fff;
|
||||
border: 1px solid #ccc;
|
||||
display: inline-block;
|
||||
cursor: pointer;
|
||||
color: #333;
|
||||
padding: 6px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.mpl-widget:disabled,
|
||||
.mpl-widget[disabled] {
|
||||
background-color: #ddd;
|
||||
border-color: #ddd !important;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.mpl-widget:disabled img,
|
||||
.mpl-widget[disabled] img {
|
||||
/* Convert black to grey */
|
||||
filter: contrast(0%);
|
||||
}
|
||||
|
||||
.mpl-widget.active img {
|
||||
/* Convert black to tab:blue, approximately */
|
||||
filter: invert(34%) sepia(97%) saturate(468%) hue-rotate(162deg) brightness(96%) contrast(91%);
|
||||
}
|
||||
|
||||
button.mpl-widget:focus,
|
||||
button.mpl-widget:hover {
|
||||
background-color: #ddd;
|
||||
border-color: #aaa;
|
||||
}
|
||||
|
||||
.mpl-button-group button.mpl-widget {
|
||||
margin-left: -1px;
|
||||
}
|
||||
.mpl-button-group button.mpl-widget:first-child {
|
||||
border-top-left-radius: 6px;
|
||||
border-bottom-left-radius: 6px;
|
||||
margin-left: 0px;
|
||||
}
|
||||
.mpl-button-group button.mpl-widget:last-child {
|
||||
border-top-right-radius: 6px;
|
||||
border-bottom-right-radius: 6px;
|
||||
}
|
||||
|
||||
select.mpl-widget {
|
||||
cursor: default;
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
/**
|
||||
* Primary styles
|
||||
*
|
||||
* Author: IPython Development Team
|
||||
*/
|
||||
|
||||
|
||||
body {
|
||||
background-color: white;
|
||||
/* This makes sure that the body covers the entire window and needs to
|
||||
be in a different element than the display: box in wrapper below */
|
||||
position: absolute;
|
||||
left: 0px;
|
||||
right: 0px;
|
||||
top: 0px;
|
||||
bottom: 0px;
|
||||
overflow: visible;
|
||||
}
|
||||
|
||||
|
||||
div#header {
|
||||
/* Initially hidden to prevent FLOUC */
|
||||
display: none;
|
||||
position: relative;
|
||||
height: 40px;
|
||||
padding: 5px;
|
||||
margin: 0px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
span#ipython_notebook {
|
||||
position: absolute;
|
||||
padding: 2px 2px 2px 5px;
|
||||
}
|
||||
|
||||
span#ipython_notebook img {
|
||||
font-family: Verdana, "Helvetica Neue", Arial, Helvetica, Geneva, sans-serif;
|
||||
height: 24px;
|
||||
text-decoration:none;
|
||||
display: inline;
|
||||
color: black;
|
||||
}
|
||||
|
||||
#site {
|
||||
width: 100%;
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* We set the fonts by hand here to override the values in the theme */
|
||||
.ui-widget {
|
||||
font-family: "Lucinda Grande", "Lucinda Sans Unicode", Helvetica, Arial, Verdana, sans-serif;
|
||||
}
|
||||
|
||||
.ui-widget input, .ui-widget select, .ui-widget textarea, .ui-widget button {
|
||||
font-family: "Lucinda Grande", "Lucinda Sans Unicode", Helvetica, Arial, Verdana, sans-serif;
|
||||
}
|
||||
|
||||
/* Smaller buttons */
|
||||
.ui-button .ui-button-text {
|
||||
padding: 0.2em 0.8em;
|
||||
font-size: 77%;
|
||||
}
|
||||
|
||||
input.ui-button {
|
||||
padding: 0.3em 0.9em;
|
||||
}
|
||||
|
||||
span#login_widget {
|
||||
float: right;
|
||||
}
|
||||
|
||||
.border-box-sizing {
|
||||
box-sizing: border-box;
|
||||
-moz-box-sizing: border-box;
|
||||
-webkit-box-sizing: border-box;
|
||||
}
|
||||
|
||||
#figure-div {
|
||||
display: inline-block;
|
||||
margin: 10px;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
<!-- Within the kernel, we don't know the address of the matplotlib
|
||||
websocket server, so we have to get in client-side and fetch our
|
||||
resources that way. -->
|
||||
<script>
|
||||
// We can't proceed until these Javascript files are fetched, so
|
||||
// we fetch them synchronously
|
||||
$.ajaxSetup({async: false});
|
||||
$.getScript("http://" + window.location.hostname + ":{{ port }}{{prefix}}/_static/js/mpl_tornado.js");
|
||||
$.getScript("http://" + window.location.hostname + ":{{ port }}{{prefix}}/js/mpl.js");
|
||||
$.ajaxSetup({async: true});
|
||||
|
||||
function init_figure{{ fig_id }}(e) {
|
||||
$('div.output').off('resize');
|
||||
|
||||
var output_div = e.target.querySelector('div.output_subarea');
|
||||
var websocket_type = mpl.get_websocket_type();
|
||||
var websocket = new websocket_type(
|
||||
"ws://" + window.location.hostname + ":{{ port }}{{ prefix}}/" +
|
||||
{{ repr(str(fig_id)) }} + "/ws");
|
||||
|
||||
var fig = new mpl.figure(
|
||||
{{repr(str(fig_id))}}, websocket, mpl_ondownload, output_div);
|
||||
|
||||
// Fetch the first image
|
||||
fig.context.drawImage(fig.imageObj, 0, 0);
|
||||
|
||||
fig.focus_on_mouseover = true;
|
||||
}
|
||||
|
||||
// We can't initialize the figure contents until our content
|
||||
// has been added to the DOM. This is a bit of hack to get an
|
||||
// event for that.
|
||||
$('div.output').resize(init_figure{{ fig_id }});
|
||||
</script>
|
671
venv/Lib/site-packages/matplotlib/backends/web_backend/js/mpl.js
Normal file
671
venv/Lib/site-packages/matplotlib/backends/web_backend/js/mpl.js
Normal file
|
@ -0,0 +1,671 @@
|
|||
/* Put everything inside the global mpl namespace */
|
||||
/* global mpl */
|
||||
window.mpl = {};
|
||||
|
||||
mpl.get_websocket_type = function () {
|
||||
if (typeof WebSocket !== 'undefined') {
|
||||
return WebSocket;
|
||||
} 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.'
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
mpl.figure = function (figure_id, websocket, ondownload, parent_element) {
|
||||
this.id = figure_id;
|
||||
|
||||
this.ws = websocket;
|
||||
|
||||
this.supports_binary = this.ws.binaryType !== undefined;
|
||||
|
||||
if (!this.supports_binary) {
|
||||
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.';
|
||||
}
|
||||
}
|
||||
|
||||
this.imageObj = new Image();
|
||||
|
||||
this.context = undefined;
|
||||
this.message = undefined;
|
||||
this.canvas = undefined;
|
||||
this.rubberband_canvas = undefined;
|
||||
this.rubberband_context = undefined;
|
||||
this.format_dropdown = undefined;
|
||||
|
||||
this.image_mode = 'full';
|
||||
|
||||
this.root = document.createElement('div');
|
||||
this.root.setAttribute('style', 'display: inline-block');
|
||||
this._root_extra_style(this.root);
|
||||
|
||||
parent_element.appendChild(this.root);
|
||||
|
||||
this._init_header(this);
|
||||
this._init_canvas(this);
|
||||
this._init_toolbar(this);
|
||||
|
||||
var fig = this;
|
||||
|
||||
this.waiting = false;
|
||||
|
||||
this.ws.onopen = function () {
|
||||
fig.send_message('supports_binary', { value: fig.supports_binary });
|
||||
fig.send_message('send_image_mode', {});
|
||||
if (fig.ratio !== 1) {
|
||||
fig.send_message('set_dpi_ratio', { dpi_ratio: fig.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.onunload = function () {
|
||||
fig.ws.close();
|
||||
};
|
||||
|
||||
this.ws.onmessage = this._make_on_message_function(this);
|
||||
|
||||
this.ondownload = ondownload;
|
||||
};
|
||||
|
||||
mpl.figure.prototype._init_header = function () {
|
||||
var titlebar = document.createElement('div');
|
||||
titlebar.classList =
|
||||
'ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix';
|
||||
var titletext = document.createElement('div');
|
||||
titletext.classList = 'ui-dialog-title';
|
||||
titletext.setAttribute(
|
||||
'style',
|
||||
'width: 100%; text-align: center; padding: 3px;'
|
||||
);
|
||||
titlebar.appendChild(titletext);
|
||||
this.root.appendChild(titlebar);
|
||||
this.header = titletext;
|
||||
};
|
||||
|
||||
mpl.figure.prototype._canvas_extra_style = function (_canvas_div) {};
|
||||
|
||||
mpl.figure.prototype._root_extra_style = function (_canvas_div) {};
|
||||
|
||||
mpl.figure.prototype._init_canvas = function () {
|
||||
var fig = this;
|
||||
|
||||
var canvas_div = (this.canvas_div = document.createElement('div'));
|
||||
canvas_div.setAttribute(
|
||||
'style',
|
||||
'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) {
|
||||
return function (event) {
|
||||
return fig.key_event(event, name);
|
||||
};
|
||||
}
|
||||
|
||||
canvas_div.addEventListener(
|
||||
'keydown',
|
||||
on_keyboard_event_closure('key_press')
|
||||
);
|
||||
canvas_div.addEventListener(
|
||||
'keyup',
|
||||
on_keyboard_event_closure('key_release')
|
||||
);
|
||||
|
||||
this._canvas_extra_style(canvas_div);
|
||||
this.root.appendChild(canvas_div);
|
||||
|
||||
var canvas = (this.canvas = document.createElement('canvas'));
|
||||
canvas.classList.add('mpl-canvas');
|
||||
canvas.setAttribute('style', 'box-sizing: content-box;');
|
||||
|
||||
this.context = canvas.getContext('2d');
|
||||
|
||||
var backingStore =
|
||||
this.context.backingStorePixelRatio ||
|
||||
this.context.webkitBackingStorePixelRatio ||
|
||||
this.context.mozBackingStorePixelRatio ||
|
||||
this.context.msBackingStorePixelRatio ||
|
||||
this.context.oBackingStorePixelRatio ||
|
||||
this.context.backingStorePixelRatio ||
|
||||
1;
|
||||
|
||||
this.ratio = (window.devicePixelRatio || 1) / backingStore;
|
||||
if (this.ratio !== 1) {
|
||||
fig.send_message('set_dpi_ratio', { dpi_ratio: this.ratio });
|
||||
}
|
||||
|
||||
var rubberband_canvas = (this.rubberband_canvas = document.createElement(
|
||||
'canvas'
|
||||
));
|
||||
rubberband_canvas.setAttribute(
|
||||
'style',
|
||||
'box-sizing: content-box; position: absolute; left: 0; top: 0; z-index: 1;'
|
||||
);
|
||||
|
||||
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) {
|
||||
if (entry.contentBoxSize instanceof Array) {
|
||||
// Chrome 84 implements new version of spec.
|
||||
width = entry.contentBoxSize[0].inlineSize;
|
||||
height = entry.contentBoxSize[0].blockSize;
|
||||
} else {
|
||||
// Firefox implements old version of spec.
|
||||
width = entry.contentBoxSize.inlineSize;
|
||||
height = entry.contentBoxSize.blockSize;
|
||||
}
|
||||
} else {
|
||||
// Chrome <84 implements even older version of spec.
|
||||
width = entry.contentRect.width;
|
||||
height = entry.contentRect.height;
|
||||
}
|
||||
|
||||
// Keep the size of the canvas and rubber band canvas in sync with
|
||||
// the canvas container.
|
||||
if (entry.devicePixelContentBoxSize) {
|
||||
// Chrome 84 implements new version of spec.
|
||||
canvas.setAttribute(
|
||||
'width',
|
||||
entry.devicePixelContentBoxSize[0].inlineSize
|
||||
);
|
||||
canvas.setAttribute(
|
||||
'height',
|
||||
entry.devicePixelContentBoxSize[0].blockSize
|
||||
);
|
||||
} else {
|
||||
canvas.setAttribute('width', width * fig.ratio);
|
||||
canvas.setAttribute('height', height * fig.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) {
|
||||
return fig.mouse_event(event, name);
|
||||
};
|
||||
}
|
||||
|
||||
rubberband_canvas.addEventListener(
|
||||
'mousedown',
|
||||
on_mouse_event_closure('button_press')
|
||||
);
|
||||
rubberband_canvas.addEventListener(
|
||||
'mouseup',
|
||||
on_mouse_event_closure('button_release')
|
||||
);
|
||||
// Throttle sequential mouse events to 1 every 20ms.
|
||||
rubberband_canvas.addEventListener(
|
||||
'mousemove',
|
||||
on_mouse_event_closure('motion_notify')
|
||||
);
|
||||
|
||||
rubberband_canvas.addEventListener(
|
||||
'mouseenter',
|
||||
on_mouse_event_closure('figure_enter')
|
||||
);
|
||||
rubberband_canvas.addEventListener(
|
||||
'mouseleave',
|
||||
on_mouse_event_closure('figure_leave')
|
||||
);
|
||||
|
||||
canvas_div.addEventListener('wheel', function (event) {
|
||||
if (event.deltaY < 0) {
|
||||
event.step = 1;
|
||||
} else {
|
||||
event.step = -1;
|
||||
}
|
||||
on_mouse_event_closure('scroll')(event);
|
||||
});
|
||||
|
||||
canvas_div.appendChild(canvas);
|
||||
canvas_div.appendChild(rubberband_canvas);
|
||||
|
||||
this.rubberband_context = rubberband_canvas.getContext('2d');
|
||||
this.rubberband_context.strokeStyle = '#000000';
|
||||
|
||||
this._resize_canvas = function (width, height, forward) {
|
||||
if (forward) {
|
||||
canvas_div.style.width = width + 'px';
|
||||
canvas_div.style.height = height + 'px';
|
||||
}
|
||||
};
|
||||
|
||||
// Disable right mouse context menu.
|
||||
this.rubberband_canvas.addEventListener('contextmenu', function (_e) {
|
||||
event.preventDefault();
|
||||
return false;
|
||||
});
|
||||
|
||||
function set_focus() {
|
||||
canvas.focus();
|
||||
canvas_div.focus();
|
||||
}
|
||||
|
||||
window.setTimeout(set_focus, 100);
|
||||
};
|
||||
|
||||
mpl.figure.prototype._init_toolbar = function () {
|
||||
var fig = this;
|
||||
|
||||
var toolbar = document.createElement('div');
|
||||
toolbar.classList = 'mpl-toolbar';
|
||||
this.root.appendChild(toolbar);
|
||||
|
||||
function on_click_closure(name) {
|
||||
return function (_event) {
|
||||
return fig.toolbar_button_onclick(name);
|
||||
};
|
||||
}
|
||||
|
||||
function on_mouseover_closure(tooltip) {
|
||||
return function (event) {
|
||||
if (!event.currentTarget.disabled) {
|
||||
return fig.toolbar_button_onmouseover(tooltip);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
fig.buttons = {};
|
||||
var buttonGroup = document.createElement('div');
|
||||
buttonGroup.classList = 'mpl-button-group';
|
||||
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];
|
||||
var method_name = mpl.toolbar_items[toolbar_ind][3];
|
||||
|
||||
if (!name) {
|
||||
/* Instead of a spacer, we start a new button group. */
|
||||
if (buttonGroup.hasChildNodes()) {
|
||||
toolbar.appendChild(buttonGroup);
|
||||
}
|
||||
buttonGroup = document.createElement('div');
|
||||
buttonGroup.classList = 'mpl-button-group';
|
||||
continue;
|
||||
}
|
||||
|
||||
var button = (fig.buttons[name] = document.createElement('button'));
|
||||
button.classList = 'mpl-widget';
|
||||
button.setAttribute('role', 'button');
|
||||
button.setAttribute('aria-disabled', 'false');
|
||||
button.addEventListener('click', on_click_closure(method_name));
|
||||
button.addEventListener('mouseover', on_mouseover_closure(tooltip));
|
||||
|
||||
var icon_img = document.createElement('img');
|
||||
icon_img.src = '_images/' + image + '.png';
|
||||
icon_img.srcset = '_images/' + image + '_large.png 2x';
|
||||
icon_img.alt = tooltip;
|
||||
button.appendChild(icon_img);
|
||||
|
||||
buttonGroup.appendChild(button);
|
||||
}
|
||||
|
||||
if (buttonGroup.hasChildNodes()) {
|
||||
toolbar.appendChild(buttonGroup);
|
||||
}
|
||||
|
||||
var fmt_picker = document.createElement('select');
|
||||
fmt_picker.classList = 'mpl-widget';
|
||||
toolbar.appendChild(fmt_picker);
|
||||
this.format_dropdown = fmt_picker;
|
||||
|
||||
for (var ind in mpl.extensions) {
|
||||
var fmt = mpl.extensions[ind];
|
||||
var option = document.createElement('option');
|
||||
option.selected = fmt === mpl.default_extension;
|
||||
option.innerHTML = fmt;
|
||||
fmt_picker.appendChild(option);
|
||||
}
|
||||
|
||||
var status_bar = document.createElement('span');
|
||||
status_bar.classList = 'mpl-message';
|
||||
toolbar.appendChild(status_bar);
|
||||
this.message = status_bar;
|
||||
};
|
||||
|
||||
mpl.figure.prototype.request_resize = function (x_pixels, y_pixels) {
|
||||
// Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,
|
||||
// which will in turn request a refresh of the image.
|
||||
this.send_message('resize', { width: x_pixels, height: y_pixels });
|
||||
};
|
||||
|
||||
mpl.figure.prototype.send_message = function (type, properties) {
|
||||
properties['type'] = type;
|
||||
properties['figure_id'] = this.id;
|
||||
this.ws.send(JSON.stringify(properties));
|
||||
};
|
||||
|
||||
mpl.figure.prototype.send_draw_message = function () {
|
||||
if (!this.waiting) {
|
||||
this.waiting = true;
|
||||
this.ws.send(JSON.stringify({ type: 'draw', figure_id: this.id }));
|
||||
}
|
||||
};
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
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], msg['forward']);
|
||||
fig.send_message('refresh', {});
|
||||
}
|
||||
};
|
||||
|
||||
mpl.figure.prototype.handle_rubberband = function (fig, msg) {
|
||||
var x0 = msg['x0'] / fig.ratio;
|
||||
var y0 = (fig.canvas.height - msg['y0']) / fig.ratio;
|
||||
var x1 = msg['x1'] / fig.ratio;
|
||||
var y1 = (fig.canvas.height - msg['y1']) / fig.ratio;
|
||||
x0 = Math.floor(x0) + 0.5;
|
||||
y0 = Math.floor(y0) + 0.5;
|
||||
x1 = Math.floor(x1) + 0.5;
|
||||
y1 = Math.floor(y1) + 0.5;
|
||||
var min_x = Math.min(x0, x1);
|
||||
var min_y = Math.min(y0, y1);
|
||||
var width = Math.abs(x1 - x0);
|
||||
var height = Math.abs(y1 - y0);
|
||||
|
||||
fig.rubberband_context.clearRect(
|
||||
0,
|
||||
0,
|
||||
fig.canvas.width / fig.ratio,
|
||||
fig.canvas.height / fig.ratio
|
||||
);
|
||||
|
||||
fig.rubberband_context.strokeRect(min_x, min_y, width, height);
|
||||
};
|
||||
|
||||
mpl.figure.prototype.handle_figure_label = function (fig, msg) {
|
||||
// Updates the figure title.
|
||||
fig.header.textContent = msg['label'];
|
||||
};
|
||||
|
||||
mpl.figure.prototype.handle_cursor = function (fig, msg) {
|
||||
var cursor = msg['cursor'];
|
||||
switch (cursor) {
|
||||
case 0:
|
||||
cursor = 'pointer';
|
||||
break;
|
||||
case 1:
|
||||
cursor = 'default';
|
||||
break;
|
||||
case 2:
|
||||
cursor = 'crosshair';
|
||||
break;
|
||||
case 3:
|
||||
cursor = 'move';
|
||||
break;
|
||||
}
|
||||
fig.rubberband_canvas.style.cursor = cursor;
|
||||
};
|
||||
|
||||
mpl.figure.prototype.handle_message = function (fig, msg) {
|
||||
fig.message.textContent = msg['message'];
|
||||
};
|
||||
|
||||
mpl.figure.prototype.handle_draw = function (fig, _msg) {
|
||||
// Request the server to send over a new figure.
|
||||
fig.send_draw_message();
|
||||
};
|
||||
|
||||
mpl.figure.prototype.handle_image_mode = function (fig, msg) {
|
||||
fig.image_mode = msg['mode'];
|
||||
};
|
||||
|
||||
mpl.figure.prototype.handle_history_buttons = function (fig, msg) {
|
||||
for (var key in msg) {
|
||||
if (!(key in fig.buttons)) {
|
||||
continue;
|
||||
}
|
||||
fig.buttons[key].disabled = !msg[key];
|
||||
fig.buttons[key].setAttribute('aria-disabled', !msg[key]);
|
||||
}
|
||||
};
|
||||
|
||||
mpl.figure.prototype.handle_navigate_mode = function (fig, msg) {
|
||||
if (msg['mode'] === 'PAN') {
|
||||
fig.buttons['Pan'].classList.add('active');
|
||||
fig.buttons['Zoom'].classList.remove('active');
|
||||
} else if (msg['mode'] === 'ZOOM') {
|
||||
fig.buttons['Pan'].classList.remove('active');
|
||||
fig.buttons['Zoom'].classList.add('active');
|
||||
} else {
|
||||
fig.buttons['Pan'].classList.remove('active');
|
||||
fig.buttons['Zoom'].classList.remove('active');
|
||||
}
|
||||
};
|
||||
|
||||
mpl.figure.prototype.updated_canvas_event = function () {
|
||||
// Called whenever the canvas gets updated.
|
||||
this.send_message('ack', {});
|
||||
};
|
||||
|
||||
// A function to construct a web socket function for onmessage handling.
|
||||
// Called in the figure constructor.
|
||||
mpl.figure.prototype._make_on_message_function = function (fig) {
|
||||
return function socket_on_message(evt) {
|
||||
if (evt.data instanceof Blob) {
|
||||
/* FIXME: We get "Resource interpreted as Image but
|
||||
* transferred with MIME type text/plain:" errors on
|
||||
* Chrome. But how to set the MIME type? It doesn't seem
|
||||
* to be part of the websocket stream */
|
||||
evt.data.type = 'image/png';
|
||||
|
||||
/* Free the memory for the previous frames */
|
||||
if (fig.imageObj.src) {
|
||||
(window.URL || window.webkitURL).revokeObjectURL(
|
||||
fig.imageObj.src
|
||||
);
|
||||
}
|
||||
|
||||
fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(
|
||||
evt.data
|
||||
);
|
||||
fig.updated_canvas_event();
|
||||
fig.waiting = false;
|
||||
return;
|
||||
} else if (
|
||||
typeof evt.data === 'string' &&
|
||||
evt.data.slice(0, 21) === 'data:image/png;base64'
|
||||
) {
|
||||
fig.imageObj.src = evt.data;
|
||||
fig.updated_canvas_event();
|
||||
fig.waiting = false;
|
||||
return;
|
||||
}
|
||||
|
||||
var msg = JSON.parse(evt.data);
|
||||
var msg_type = msg['type'];
|
||||
|
||||
// Call the "handle_{type}" callback, which takes
|
||||
// the figure and JSON message as its only arguments.
|
||||
try {
|
||||
var callback = fig['handle_' + msg_type];
|
||||
} catch (e) {
|
||||
console.log(
|
||||
"No handler for the '" + msg_type + "' message type: ",
|
||||
msg
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (callback) {
|
||||
try {
|
||||
// console.log("Handling '" + msg_type + "' message: ", msg);
|
||||
callback(fig, msg);
|
||||
} catch (e) {
|
||||
console.log(
|
||||
"Exception inside the 'handler_" + msg_type + "' callback:",
|
||||
e,
|
||||
e.stack,
|
||||
msg
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// from http://stackoverflow.com/questions/1114465/getting-mouse-location-in-canvas
|
||||
mpl.findpos = function (e) {
|
||||
//this section is from http://www.quirksmode.org/js/events_properties.html
|
||||
var targ;
|
||||
if (!e) {
|
||||
e = window.event;
|
||||
}
|
||||
if (e.target) {
|
||||
targ = e.target;
|
||||
} else if (e.srcElement) {
|
||||
targ = e.srcElement;
|
||||
}
|
||||
if (targ.nodeType === 3) {
|
||||
// defeat Safari bug
|
||||
targ = targ.parentNode;
|
||||
}
|
||||
|
||||
// pageX,Y are the mouse positions relative to the document
|
||||
var boundingRect = targ.getBoundingClientRect();
|
||||
var x = e.pageX - (boundingRect.left + document.body.scrollLeft);
|
||||
var y = e.pageY - (boundingRect.top + document.body.scrollTop);
|
||||
|
||||
return { x: x, y: y };
|
||||
};
|
||||
|
||||
/*
|
||||
* return a copy of an object with only non-object keys
|
||||
* we need this to avoid circular references
|
||||
* http://stackoverflow.com/a/24161582/3208463
|
||||
*/
|
||||
function simpleKeys(original) {
|
||||
return Object.keys(original).reduce(function (obj, key) {
|
||||
if (typeof original[key] !== 'object') {
|
||||
obj[key] = original[key];
|
||||
}
|
||||
return obj;
|
||||
}, {});
|
||||
}
|
||||
|
||||
mpl.figure.prototype.mouse_event = function (event, name) {
|
||||
var canvas_pos = mpl.findpos(event);
|
||||
|
||||
if (name === 'button_press') {
|
||||
this.canvas.focus();
|
||||
this.canvas_div.focus();
|
||||
}
|
||||
|
||||
var x = canvas_pos.x * this.ratio;
|
||||
var y = canvas_pos.y * this.ratio;
|
||||
|
||||
this.send_message(name, {
|
||||
x: x,
|
||||
y: y,
|
||||
button: event.button,
|
||||
step: event.step,
|
||||
guiEvent: simpleKeys(event),
|
||||
});
|
||||
|
||||
/* This prevents the web browser from automatically changing to
|
||||
* the text insertion cursor when the button is pressed. We want
|
||||
* to control all of the cursor setting manually through the
|
||||
* 'cursor' event from matplotlib */
|
||||
event.preventDefault();
|
||||
return false;
|
||||
};
|
||||
|
||||
mpl.figure.prototype._key_event_extra = function (_event, _name) {
|
||||
// Handle any extra behaviour associated with a key event
|
||||
};
|
||||
|
||||
mpl.figure.prototype.key_event = function (event, name) {
|
||||
// Prevent repeat events
|
||||
if (name === 'key_press') {
|
||||
if (event.which === this._key) {
|
||||
return;
|
||||
} else {
|
||||
this._key = event.which;
|
||||
}
|
||||
}
|
||||
if (name === 'key_release') {
|
||||
this._key = null;
|
||||
}
|
||||
|
||||
var value = '';
|
||||
if (event.ctrlKey && event.which !== 17) {
|
||||
value += 'ctrl+';
|
||||
}
|
||||
if (event.altKey && event.which !== 18) {
|
||||
value += 'alt+';
|
||||
}
|
||||
if (event.shiftKey && event.which !== 16) {
|
||||
value += 'shift+';
|
||||
}
|
||||
|
||||
value += 'k';
|
||||
value += event.which.toString();
|
||||
|
||||
this._key_event_extra(event, name);
|
||||
|
||||
this.send_message(name, { key: value, guiEvent: simpleKeys(event) });
|
||||
return false;
|
||||
};
|
||||
|
||||
mpl.figure.prototype.toolbar_button_onclick = function (name) {
|
||||
if (name === 'download') {
|
||||
this.handle_save(this, null);
|
||||
} else {
|
||||
this.send_message('toolbar_button', { name: name });
|
||||
}
|
||||
};
|
||||
|
||||
mpl.figure.prototype.toolbar_button_onmouseover = function (tooltip) {
|
||||
this.message.textContent = tooltip;
|
||||
};
|
|
@ -0,0 +1,8 @@
|
|||
/* This .js file contains functions for matplotlib's built-in
|
||||
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');
|
||||
}
|
|
@ -0,0 +1,256 @@
|
|||
/* 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
|
||||
// socket, so there is still some room for performance tuning.
|
||||
var ws = {};
|
||||
|
||||
ws.close = function () {
|
||||
comm.close();
|
||||
};
|
||||
ws.send = function (m) {
|
||||
//console.log('sending', m);
|
||||
comm.send(m);
|
||||
};
|
||||
// Register the callback with on_msg.
|
||||
comm.on_msg(function (msg) {
|
||||
//console.log('receiving', msg['content']['data'], msg);
|
||||
// Pass the mpl event to the overridden (by mpl) onmessage function.
|
||||
ws.onmessage(msg['content']['data']);
|
||||
});
|
||||
return ws;
|
||||
};
|
||||
|
||||
mpl.mpl_figure_comm = function (comm, msg) {
|
||||
// This is the function which gets called when the mpl process
|
||||
// starts-up an IPython Comm through the "matplotlib" channel.
|
||||
|
||||
var id = msg.content.data.id;
|
||||
// Get hold of the div created by the display call when the Comm
|
||||
// socket was opened in Python.
|
||||
var element = document.getElementById(id);
|
||||
var ws_proxy = comm_websocket_adapter(comm);
|
||||
|
||||
function ondownload(figure, _format) {
|
||||
window.open(figure.canvas.toDataURL());
|
||||
}
|
||||
|
||||
var fig = new mpl.figure(id, ws_proxy, ondownload, element);
|
||||
|
||||
// Call onopen now - mpl needs it, as it is assuming we've passed it a real
|
||||
// web socket which is closed, not our websocket->open comm proxy.
|
||||
ws_proxy.onopen();
|
||||
|
||||
fig.parent_element = element;
|
||||
fig.cell_info = mpl.find_output_cell("<div id='" + id + "'></div>");
|
||||
if (!fig.cell_info) {
|
||||
console.error('Failed to find cell for figure', id, fig);
|
||||
return;
|
||||
}
|
||||
fig.cell_info[0].output_area.element.one(
|
||||
'cleared',
|
||||
{ fig: fig },
|
||||
fig._remove_fig_handler
|
||||
);
|
||||
};
|
||||
|
||||
mpl.figure.prototype.handle_close = function (fig, msg) {
|
||||
var width = fig.canvas.width / fig.ratio;
|
||||
fig.cell_info[0].output_area.element.off(
|
||||
'cleared',
|
||||
fig._remove_fig_handler
|
||||
);
|
||||
|
||||
// Update the output cell to use the data from the current canvas.
|
||||
fig.push_to_output();
|
||||
var dataURL = fig.canvas.toDataURL();
|
||||
// Re-enable the keyboard manager in IPython - without this line, in FF,
|
||||
// the notebook keyboard shortcuts fail.
|
||||
IPython.keyboard_manager.enable();
|
||||
fig.parent_element.innerHTML =
|
||||
'<img src="' + dataURL + '" width="' + width + '">';
|
||||
fig.close_ws(fig, msg);
|
||||
};
|
||||
|
||||
mpl.figure.prototype.close_ws = function (fig, msg) {
|
||||
fig.send_message('closing', msg);
|
||||
// fig.ws.close()
|
||||
};
|
||||
|
||||
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 / this.ratio;
|
||||
var dataURL = this.canvas.toDataURL();
|
||||
this.cell_info[1]['text/html'] =
|
||||
'<img src="' + dataURL + '" width="' + width + '">';
|
||||
};
|
||||
|
||||
mpl.figure.prototype.updated_canvas_event = function () {
|
||||
// Tell IPython that the notebook contents must change.
|
||||
IPython.notebook.set_dirty(true);
|
||||
this.send_message('ack', {});
|
||||
var fig = this;
|
||||
// Wait a second, then push the new image to the DOM so
|
||||
// that it is saved nicely (might be nice to debounce this).
|
||||
setTimeout(function () {
|
||||
fig.push_to_output();
|
||||
}, 1000);
|
||||
};
|
||||
|
||||
mpl.figure.prototype._init_toolbar = function () {
|
||||
var fig = this;
|
||||
|
||||
var toolbar = document.createElement('div');
|
||||
toolbar.classList = 'btn-toolbar';
|
||||
this.root.appendChild(toolbar);
|
||||
|
||||
function on_click_closure(name) {
|
||||
return function (_event) {
|
||||
return fig.toolbar_button_onclick(name);
|
||||
};
|
||||
}
|
||||
|
||||
function on_mouseover_closure(tooltip) {
|
||||
return function (event) {
|
||||
if (!event.currentTarget.disabled) {
|
||||
return fig.toolbar_button_onmouseover(tooltip);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
fig.buttons = {};
|
||||
var buttonGroup = document.createElement('div');
|
||||
buttonGroup.classList = 'btn-group';
|
||||
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];
|
||||
var image = mpl.toolbar_items[toolbar_ind][2];
|
||||
var method_name = mpl.toolbar_items[toolbar_ind][3];
|
||||
|
||||
if (!name) {
|
||||
/* Instead of a spacer, we start a new button group. */
|
||||
if (buttonGroup.hasChildNodes()) {
|
||||
toolbar.appendChild(buttonGroup);
|
||||
}
|
||||
buttonGroup = document.createElement('div');
|
||||
buttonGroup.classList = 'btn-group';
|
||||
continue;
|
||||
}
|
||||
|
||||
button = fig.buttons[name] = document.createElement('button');
|
||||
button.classList = 'btn btn-default';
|
||||
button.href = '#';
|
||||
button.title = name;
|
||||
button.innerHTML = '<i class="fa ' + image + ' fa-lg"></i>';
|
||||
button.addEventListener('click', on_click_closure(method_name));
|
||||
button.addEventListener('mouseover', on_mouseover_closure(tooltip));
|
||||
buttonGroup.appendChild(button);
|
||||
}
|
||||
|
||||
if (buttonGroup.hasChildNodes()) {
|
||||
toolbar.appendChild(buttonGroup);
|
||||
}
|
||||
|
||||
// Add the status bar.
|
||||
var status_bar = document.createElement('span');
|
||||
status_bar.classList = 'mpl-message pull-right';
|
||||
toolbar.appendChild(status_bar);
|
||||
this.message = status_bar;
|
||||
|
||||
// Add the close button to the window.
|
||||
var buttongrp = document.createElement('div');
|
||||
buttongrp.classList = 'btn-group inline pull-right';
|
||||
button = document.createElement('button');
|
||||
button.classList = 'btn btn-mini btn-primary';
|
||||
button.href = '#';
|
||||
button.title = 'Stop Interaction';
|
||||
button.innerHTML = '<i class="fa fa-power-off icon-remove icon-large"></i>';
|
||||
button.addEventListener('click', function (_evt) {
|
||||
fig.handle_close(fig, {});
|
||||
});
|
||||
button.addEventListener(
|
||||
'mouseover',
|
||||
on_mouseover_closure('Stop Interaction')
|
||||
);
|
||||
buttongrp.appendChild(button);
|
||||
var titlebar = this.root.querySelector('.ui-dialog-titlebar');
|
||||
titlebar.insertBefore(buttongrp, titlebar.firstChild);
|
||||
};
|
||||
|
||||
mpl.figure.prototype._remove_fig_handler = function (event) {
|
||||
var fig = event.data.fig;
|
||||
fig.close_ws(fig, {});
|
||||
};
|
||||
|
||||
mpl.figure.prototype._root_extra_style = function (el) {
|
||||
el.style.boxSizing = 'content-box'; // override notebook setting of border-box.
|
||||
};
|
||||
|
||||
mpl.figure.prototype._canvas_extra_style = function (el) {
|
||||
// this is important to make the div 'focusable
|
||||
el.setAttribute('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 {
|
||||
// location in version 2
|
||||
IPython.keyboard_manager.register_events(el);
|
||||
}
|
||||
};
|
||||
|
||||
mpl.figure.prototype._key_event_extra = function (event, _name) {
|
||||
var manager = IPython.notebook.keyboard_manager;
|
||||
if (!manager) {
|
||||
manager = IPython.keyboard_manager;
|
||||
}
|
||||
|
||||
// Check for shift+enter
|
||||
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]);
|
||||
IPython.notebook.select(index + 1);
|
||||
}
|
||||
};
|
||||
|
||||
mpl.figure.prototype.handle_save = function (fig, _msg) {
|
||||
fig.ondownload(fig, null);
|
||||
};
|
||||
|
||||
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 < ncells; i++) {
|
||||
var cell = cells[i];
|
||||
if (cell.cell_type === 'code') {
|
||||
for (var j = 0; j < cell.output_area.outputs.length; j++) {
|
||||
var data = cell.output_area.outputs[j];
|
||||
if (data.data) {
|
||||
// IPython >= 3 moved mimebundle to data attribute of output
|
||||
data = data.data;
|
||||
}
|
||||
if (data['text/html'] === html_output) {
|
||||
return [cell, data, j];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 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
|
||||
);
|
||||
}
|
|
@ -0,0 +1,639 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from imp import reload"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## UAT for NbAgg backend.\n",
|
||||
"\n",
|
||||
"The first line simply reloads matplotlib, uses the nbagg backend and then reloads the backend, just to ensure we have the latest modification to the backend code. Note: The underlying JavaScript will not be updated by this process, so a refresh of the browser after clearing the output and saving is necessary to clear everything fully."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import matplotlib\n",
|
||||
"reload(matplotlib)\n",
|
||||
"\n",
|
||||
"matplotlib.use('nbagg')\n",
|
||||
"\n",
|
||||
"import matplotlib.backends.backend_nbagg\n",
|
||||
"reload(matplotlib.backends.backend_nbagg)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### UAT 1 - Simple figure creation using pyplot\n",
|
||||
"\n",
|
||||
"Should produce a figure window which is interactive with the pan and zoom buttons. (Do not press the close button, but any others may be used)."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import matplotlib.backends.backend_webagg_core\n",
|
||||
"reload(matplotlib.backends.backend_webagg_core)\n",
|
||||
"\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"plt.interactive(False)\n",
|
||||
"\n",
|
||||
"fig1 = plt.figure()\n",
|
||||
"plt.plot(range(10))\n",
|
||||
"\n",
|
||||
"plt.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### UAT 2 - Creation of another figure, without the need to do plt.figure.\n",
|
||||
"\n",
|
||||
"As above, a new figure should be created."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"plt.plot([3, 2, 1])\n",
|
||||
"plt.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### UAT 3 - Connection info\n",
|
||||
"\n",
|
||||
"The printout should show that there are two figures which have active CommSockets, and no figures pending show."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"print(matplotlib.backends.backend_nbagg.connection_info())"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### UAT 4 - Closing figures\n",
|
||||
"\n",
|
||||
"Closing a specific figure instance should turn the figure into a plain image - the UI should have been removed. In this case, scroll back to the first figure and assert this is the case."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"plt.close(fig1)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### UAT 5 - No show without plt.show in non-interactive mode\n",
|
||||
"\n",
|
||||
"Simply doing a plt.plot should not show a new figure, nor indeed update an existing one (easily verified in UAT 6).\n",
|
||||
"The output should simply be a list of Line2D instances."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"plt.plot(range(10))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### UAT 6 - Connection information\n",
|
||||
"\n",
|
||||
"We just created a new figure, but didn't show it. Connection info should no longer have \"Figure 1\" (as we closed it in UAT 4) and should have figure 2 and 3, with Figure 3 without any connections. There should be 1 figure pending."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"print(matplotlib.backends.backend_nbagg.connection_info())"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### UAT 7 - Show of previously created figure\n",
|
||||
"\n",
|
||||
"We should be able to show a figure we've previously created. The following should produce two figure windows."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"plt.show()\n",
|
||||
"plt.figure()\n",
|
||||
"plt.plot(range(5))\n",
|
||||
"plt.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### UAT 8 - Interactive mode\n",
|
||||
"\n",
|
||||
"In interactive mode, creating a line should result in a figure being shown."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"plt.interactive(True)\n",
|
||||
"plt.figure()\n",
|
||||
"plt.plot([3, 2, 1])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Subsequent lines should be added to the existing figure, rather than creating a new one."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"plt.plot(range(3))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Calling connection_info in interactive mode should not show any pending figures."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"print(matplotlib.backends.backend_nbagg.connection_info())"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Disable interactive mode again."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"plt.interactive(False)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### UAT 9 - Multiple shows\n",
|
||||
"\n",
|
||||
"Unlike most of the other matplotlib backends, we may want to see a figure multiple times (with or without synchronisation between the views, though the former is not yet implemented). Assert that plt.gcf().canvas.manager.reshow() results in another figure window which is synchronised upon pan & zoom."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"plt.gcf().canvas.manager.reshow()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### UAT 10 - Saving notebook\n",
|
||||
"\n",
|
||||
"Saving the notebook (with CTRL+S or File->Save) should result in the saved notebook having static versions of the figues embedded within. The image should be the last update from user interaction and interactive plotting. (check by converting with ``ipython nbconvert <notebook>``)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### UAT 11 - Creation of a new figure on second show\n",
|
||||
"\n",
|
||||
"Create a figure, show it, then create a new axes and show it. The result should be a new figure.\n",
|
||||
"\n",
|
||||
"**BUG: Sometimes this doesn't work - not sure why (@pelson).**"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"fig = plt.figure()\n",
|
||||
"plt.axes()\n",
|
||||
"plt.show()\n",
|
||||
"\n",
|
||||
"plt.plot([1, 2, 3])\n",
|
||||
"plt.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### UAT 12 - OO interface\n",
|
||||
"\n",
|
||||
"Should produce a new figure and plot it."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from matplotlib.backends.backend_nbagg import new_figure_manager,show\n",
|
||||
"\n",
|
||||
"manager = new_figure_manager(1000)\n",
|
||||
"fig = manager.canvas.figure\n",
|
||||
"ax = fig.add_subplot(1,1,1)\n",
|
||||
"ax.plot([1,2,3])\n",
|
||||
"fig.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## UAT 13 - Animation\n",
|
||||
"\n",
|
||||
"The following should generate an animated line:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import matplotlib.animation as animation\n",
|
||||
"import numpy as np\n",
|
||||
"\n",
|
||||
"fig, ax = plt.subplots()\n",
|
||||
"\n",
|
||||
"x = np.arange(0, 2*np.pi, 0.01) # x-array\n",
|
||||
"line, = ax.plot(x, np.sin(x))\n",
|
||||
"\n",
|
||||
"def animate(i):\n",
|
||||
" line.set_ydata(np.sin(x+i/10.0)) # update the data\n",
|
||||
" return line,\n",
|
||||
"\n",
|
||||
"#Init only required for blitting to give a clean slate.\n",
|
||||
"def init():\n",
|
||||
" line.set_ydata(np.ma.array(x, mask=True))\n",
|
||||
" return line,\n",
|
||||
"\n",
|
||||
"ani = animation.FuncAnimation(fig, animate, np.arange(1, 200), init_func=init,\n",
|
||||
" interval=32., blit=True)\n",
|
||||
"plt.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### UAT 14 - Keyboard shortcuts in IPython after close of figure\n",
|
||||
"\n",
|
||||
"After closing the previous figure (with the close button above the figure) the IPython keyboard shortcuts should still function.\n",
|
||||
"\n",
|
||||
"### UAT 15 - Figure face colours\n",
|
||||
"\n",
|
||||
"The nbagg honours all colours apart from that of the figure.patch. The two plots below should produce a figure with a red background. There should be no yellow figure."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import matplotlib\n",
|
||||
"matplotlib.rcParams.update({'figure.facecolor': 'red',\n",
|
||||
" 'savefig.facecolor': 'yellow'})\n",
|
||||
"plt.figure()\n",
|
||||
"plt.plot([3, 2, 1])\n",
|
||||
"\n",
|
||||
"plt.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### UAT 16 - Events\n",
|
||||
"\n",
|
||||
"Pressing any keyboard key or mouse button (or scrolling) should cycle the line line while the figure has focus. The figure should have focus by default when it is created and re-gain it by clicking on the canvas. Clicking anywhere outside of the figure should release focus, but moving the mouse out of the figure should not release focus."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import itertools\n",
|
||||
"fig, ax = plt.subplots()\n",
|
||||
"x = np.linspace(0,10,10000)\n",
|
||||
"y = np.sin(x)\n",
|
||||
"ln, = ax.plot(x,y)\n",
|
||||
"evt = []\n",
|
||||
"colors = iter(itertools.cycle(['r', 'g', 'b', 'k', 'c']))\n",
|
||||
"def on_event(event):\n",
|
||||
" if event.name.startswith('key'):\n",
|
||||
" fig.suptitle('%s: %s' % (event.name, event.key))\n",
|
||||
" elif event.name == 'scroll_event':\n",
|
||||
" fig.suptitle('%s: %s' % (event.name, event.step))\n",
|
||||
" else:\n",
|
||||
" fig.suptitle('%s: %s' % (event.name, event.button))\n",
|
||||
" evt.append(event)\n",
|
||||
" ln.set_color(next(colors))\n",
|
||||
" fig.canvas.draw()\n",
|
||||
" fig.canvas.draw_idle()\n",
|
||||
"\n",
|
||||
"fig.canvas.mpl_connect('button_press_event', on_event)\n",
|
||||
"fig.canvas.mpl_connect('button_release_event', on_event)\n",
|
||||
"fig.canvas.mpl_connect('scroll_event', on_event)\n",
|
||||
"fig.canvas.mpl_connect('key_press_event', on_event)\n",
|
||||
"fig.canvas.mpl_connect('key_release_event', on_event)\n",
|
||||
"\n",
|
||||
"plt.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### UAT 17 - Timers\n",
|
||||
"\n",
|
||||
"Single-shot timers follow a completely different code path in the nbagg backend than regular timers (such as those used in the animation example above.) The next set of tests ensures that both \"regular\" and \"single-shot\" timers work properly.\n",
|
||||
"\n",
|
||||
"The following should show a simple clock that updates twice a second:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import time\n",
|
||||
"\n",
|
||||
"fig, ax = plt.subplots()\n",
|
||||
"text = ax.text(0.5, 0.5, '', ha='center')\n",
|
||||
"\n",
|
||||
"def update(text):\n",
|
||||
" text.set(text=time.ctime())\n",
|
||||
" text.axes.figure.canvas.draw()\n",
|
||||
" \n",
|
||||
"timer = fig.canvas.new_timer(500, [(update, [text], {})])\n",
|
||||
"timer.start()\n",
|
||||
"plt.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"However, the following should only update once and then stop:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"fig, ax = plt.subplots()\n",
|
||||
"text = ax.text(0.5, 0.5, '', ha='center') \n",
|
||||
"timer = fig.canvas.new_timer(500, [(update, [text], {})])\n",
|
||||
"\n",
|
||||
"timer.single_shot = True\n",
|
||||
"timer.start()\n",
|
||||
"\n",
|
||||
"plt.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"And the next two examples should never show any visible text at all:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"fig, ax = plt.subplots()\n",
|
||||
"text = ax.text(0.5, 0.5, '', ha='center')\n",
|
||||
"timer = fig.canvas.new_timer(500, [(update, [text], {})])\n",
|
||||
"\n",
|
||||
"timer.start()\n",
|
||||
"timer.stop()\n",
|
||||
"\n",
|
||||
"plt.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"fig, ax = plt.subplots()\n",
|
||||
"text = ax.text(0.5, 0.5, '', ha='center')\n",
|
||||
"timer = fig.canvas.new_timer(500, [(update, [text], {})])\n",
|
||||
"\n",
|
||||
"timer.single_shot = True\n",
|
||||
"timer.start()\n",
|
||||
"timer.stop()\n",
|
||||
"\n",
|
||||
"plt.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### UAT17 - stopping figure when removed from DOM\n",
|
||||
"\n",
|
||||
"When the div that contains from the figure is removed from the DOM the figure should shut down it's comm, and if the python-side figure has no more active comms, it should destroy the figure. Repeatedly running the cell below should always have the same figure number"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"fig, ax = plt.subplots()\n",
|
||||
"ax.plot(range(5))\n",
|
||||
"plt.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Running the cell below will re-show the figure. After this, re-running the cell above should result in a new figure number."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"fig.canvas.manager.reshow()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.4.3"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 0
|
||||
}
|
|
@ -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}\""
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="{{ prefix }}/_static/css/page.css" type="text/css">
|
||||
<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">
|
||||
<script src="{{ prefix }}/_static/js/mpl_tornado.js"></script>
|
||||
<script src="{{ prefix }}/js/mpl.js"></script>
|
||||
<script>
|
||||
function ready(fn) {
|
||||
if (document.readyState != "loading") {
|
||||
fn();
|
||||
} else {
|
||||
document.addEventListener("DOMContentLoaded", fn);
|
||||
}
|
||||
}
|
||||
|
||||
ready(
|
||||
function () {
|
||||
var websocket_type = mpl.get_websocket_type();
|
||||
var websocket = new websocket_type(
|
||||
"{{ ws_uri }}" + {{ str(fig_id) }} + "/ws");
|
||||
var fig = new mpl.figure(
|
||||
{{ str(fig_id) }}, websocket, mpl_ondownload,
|
||||
document.getElementById("figure"));
|
||||
}
|
||||
);
|
||||
</script>
|
||||
|
||||
<title>matplotlib</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="mpl-warnings" class="mpl-warnings"></div>
|
||||
<div id="figure" style="margin: 10px 10px;"></div>
|
||||
</body>
|
||||
</html>
|
Loading…
Add table
Add a link
Reference in a new issue