5815 lines
630 KiB
Text
5815 lines
630 KiB
Text
|
{
|
|||
|
"cells": [
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 1,
|
|||
|
"id": "c0c52617",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"import pandas as pd\n",
|
|||
|
"import matplotlib.pyplot as plt\n",
|
|||
|
"import numpy as np\n",
|
|||
|
"from ipywidgets import widgets\n",
|
|||
|
"from IPython.display import display\n",
|
|||
|
"\n",
|
|||
|
"%matplotlib notebook"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 2,
|
|||
|
"id": "d20f8fbf",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"posts = pd.read_sql_table('post', 'sqlite:///db6.sqlite')\n",
|
|||
|
"likes = pd.read_sql_table('like', 'sqlite:///db6.sqlite')\n",
|
|||
|
"reposts = pd.read_sql_table('repost', 'sqlite:///db6.sqlite')\n",
|
|||
|
"follows = pd.read_sql_table('follow', 'sqlite:///db6.sqlite')\n"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 3,
|
|||
|
"id": "7140b9bd",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"application/vnd.jupyter.widget-view+json": {
|
|||
|
"model_id": "cf35045c14b246bfb0405f9e42c5d5ab",
|
|||
|
"version_major": 2,
|
|||
|
"version_minor": 0
|
|||
|
},
|
|||
|
"text/plain": [
|
|||
|
"Tab(children=(Output(), Output(), Output(), Output()))"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"tabs = []\n",
|
|||
|
"for tab in (posts, likes, reposts, follows):\n",
|
|||
|
" widg = widgets.Output()\n",
|
|||
|
" with widg:\n",
|
|||
|
" display(tab)\n",
|
|||
|
" tabs.append(widg)\n",
|
|||
|
" \n",
|
|||
|
"tab = widgets.Tab(children=tabs, titles = ['posts', 'likes', 'reposts', 'follows'])\n",
|
|||
|
"tab"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "bc1b5a30",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"Basic Summaries\n"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 4,
|
|||
|
"id": "689b5e00",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"\n",
|
|||
|
"Timespan: 0 days 13:44:19.205000\n",
|
|||
|
"Posting Accounts: 53772\n",
|
|||
|
"Liking Accounts: 70198\n",
|
|||
|
"Accounts that only posted: 13218\n",
|
|||
|
"Accounts that only liked: 29644\n",
|
|||
|
"Accounts that posted and liked: 40554\n",
|
|||
|
"\n"
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"posts['indexedAt'] = pd.to_datetime(posts['indexedAt'])\n",
|
|||
|
"span = posts['indexedAt'].max() - posts['indexedAt'].min()\n",
|
|||
|
"posting_accounts = set(posts['authorDid'])\n",
|
|||
|
"liking_accounts = set(likes['authorDid'])\n",
|
|||
|
"posters_only = posting_accounts - liking_accounts\n",
|
|||
|
"likers_only = liking_accounts - posting_accounts\n",
|
|||
|
"posts_and_likes = posting_accounts.intersection(liking_accounts)\n",
|
|||
|
"\n",
|
|||
|
"print(f\"\"\"\n",
|
|||
|
"Timespan: {span}\n",
|
|||
|
"Posting Accounts: {len(posting_accounts)}\n",
|
|||
|
"Liking Accounts: {len(liking_accounts)}\n",
|
|||
|
"Accounts that only posted: {len(posters_only)}\n",
|
|||
|
"Accounts that only liked: {len(likers_only)}\n",
|
|||
|
"Accounts that posted and liked: {len(posts_and_likes)}\n",
|
|||
|
"\"\"\")"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "040f4a01",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"# Interaction Distributions\n",
|
|||
|
"\n",
|
|||
|
"Likes per post"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 5,
|
|||
|
"id": "3c6a03ff",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/html": [
|
|||
|
"<div>\n",
|
|||
|
"<style scoped>\n",
|
|||
|
" .dataframe tbody tr th:only-of-type {\n",
|
|||
|
" vertical-align: middle;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" .dataframe tbody tr th {\n",
|
|||
|
" vertical-align: top;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" .dataframe thead th {\n",
|
|||
|
" text-align: right;\n",
|
|||
|
" }\n",
|
|||
|
"</style>\n",
|
|||
|
"<table border=\"1\" class=\"dataframe\">\n",
|
|||
|
" <thead>\n",
|
|||
|
" <tr style=\"text-align: right;\">\n",
|
|||
|
" <th></th>\n",
|
|||
|
" <th>cid</th>\n",
|
|||
|
" <th>likes</th>\n",
|
|||
|
" </tr>\n",
|
|||
|
" </thead>\n",
|
|||
|
" <tbody>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>0</th>\n",
|
|||
|
" <td>bafyreia2227oeicmtf4xigxvt7pyu4vjskwx4ybt6qs6l...</td>\n",
|
|||
|
" <td>1</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>1</th>\n",
|
|||
|
" <td>bafyreia222rmtxxi6r32jvpv6ztvnf6okg4actj5kguum...</td>\n",
|
|||
|
" <td>1</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>2</th>\n",
|
|||
|
" <td>bafyreia223ok3xtiywatui6vhz4wnj27dmr5axhcfrmax...</td>\n",
|
|||
|
" <td>84</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>3</th>\n",
|
|||
|
" <td>bafyreia224dtxpar5micqm5alflbadh7afpvw67tflq55...</td>\n",
|
|||
|
" <td>1</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>4</th>\n",
|
|||
|
" <td>bafyreia225p3me54nwasphscagmwhgixjuj2ozutf4xyg...</td>\n",
|
|||
|
" <td>60</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>...</th>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>237072</th>\n",
|
|||
|
" <td>bafyreihzzscebwopuvgkagaizjiyn7akm3bpnrzpjqes6...</td>\n",
|
|||
|
" <td>1</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>237073</th>\n",
|
|||
|
" <td>bafyreihzzsv7g3fiqxke7xsvfb2lq6sjfeg5jwrxm4lxn...</td>\n",
|
|||
|
" <td>2</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>237074</th>\n",
|
|||
|
" <td>bafyreihzztj6ztbyworzjigzy7muq63hrq4kdafc6nzqr...</td>\n",
|
|||
|
" <td>2</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>237075</th>\n",
|
|||
|
" <td>bafyreihzzwsbv3xt5uowdtlcbbn2qlr7rrotyt4zp6v4s...</td>\n",
|
|||
|
" <td>1</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>237076</th>\n",
|
|||
|
" <td>bafyreihzzwxykcadm64n4wbin5xsvmggoxpynxc53r3ns...</td>\n",
|
|||
|
" <td>2</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" </tbody>\n",
|
|||
|
"</table>\n",
|
|||
|
"<p>237077 rows × 2 columns</p>\n",
|
|||
|
"</div>"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
" cid likes\n",
|
|||
|
"0 bafyreia2227oeicmtf4xigxvt7pyu4vjskwx4ybt6qs6l... 1\n",
|
|||
|
"1 bafyreia222rmtxxi6r32jvpv6ztvnf6okg4actj5kguum... 1\n",
|
|||
|
"2 bafyreia223ok3xtiywatui6vhz4wnj27dmr5axhcfrmax... 84\n",
|
|||
|
"3 bafyreia224dtxpar5micqm5alflbadh7afpvw67tflq55... 1\n",
|
|||
|
"4 bafyreia225p3me54nwasphscagmwhgixjuj2ozutf4xyg... 60\n",
|
|||
|
"... ... ...\n",
|
|||
|
"237072 bafyreihzzscebwopuvgkagaizjiyn7akm3bpnrzpjqes6... 1\n",
|
|||
|
"237073 bafyreihzzsv7g3fiqxke7xsvfb2lq6sjfeg5jwrxm4lxn... 2\n",
|
|||
|
"237074 bafyreihzztj6ztbyworzjigzy7muq63hrq4kdafc6nzqr... 2\n",
|
|||
|
"237075 bafyreihzzwsbv3xt5uowdtlcbbn2qlr7rrotyt4zp6v4s... 1\n",
|
|||
|
"237076 bafyreihzzwxykcadm64n4wbin5xsvmggoxpynxc53r3ns... 2\n",
|
|||
|
"\n",
|
|||
|
"[237077 rows x 2 columns]"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 5,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"post_likes = likes.groupby('subjectCid'\n",
|
|||
|
" ).agg(likes=('uri', 'count')\n",
|
|||
|
" ).reset_index(\n",
|
|||
|
" ).rename(columns={'subjectCid':'cid'})\n",
|
|||
|
"post_likes"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 6,
|
|||
|
"id": "ff9773ef",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"posts = posts.merge(post_likes, left_on='cid', right_on='cid', how='left')\n",
|
|||
|
"posts.loc[posts['likes'].isna(), 'likes'] = 0"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 7,
|
|||
|
"id": "2523ba0a",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"application/javascript": [
|
|||
|
"/* Put everything inside the global mpl namespace */\n",
|
|||
|
"/* global mpl */\n",
|
|||
|
"window.mpl = {};\n",
|
|||
|
"\n",
|
|||
|
"mpl.get_websocket_type = function () {\n",
|
|||
|
" if (typeof WebSocket !== 'undefined') {\n",
|
|||
|
" return WebSocket;\n",
|
|||
|
" } else if (typeof MozWebSocket !== 'undefined') {\n",
|
|||
|
" return MozWebSocket;\n",
|
|||
|
" } else {\n",
|
|||
|
" alert(\n",
|
|||
|
" 'Your browser does not have WebSocket support. ' +\n",
|
|||
|
" 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n",
|
|||
|
" 'Firefox 4 and 5 are also supported but you ' +\n",
|
|||
|
" 'have to enable WebSockets in about:config.'\n",
|
|||
|
" );\n",
|
|||
|
" }\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure = function (figure_id, websocket, ondownload, parent_element) {\n",
|
|||
|
" this.id = figure_id;\n",
|
|||
|
"\n",
|
|||
|
" this.ws = websocket;\n",
|
|||
|
"\n",
|
|||
|
" this.supports_binary = this.ws.binaryType !== undefined;\n",
|
|||
|
"\n",
|
|||
|
" if (!this.supports_binary) {\n",
|
|||
|
" var warnings = document.getElementById('mpl-warnings');\n",
|
|||
|
" if (warnings) {\n",
|
|||
|
" warnings.style.display = 'block';\n",
|
|||
|
" warnings.textContent =\n",
|
|||
|
" 'This browser does not support binary websocket messages. ' +\n",
|
|||
|
" 'Performance may be slow.';\n",
|
|||
|
" }\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" this.imageObj = new Image();\n",
|
|||
|
"\n",
|
|||
|
" this.context = undefined;\n",
|
|||
|
" this.message = undefined;\n",
|
|||
|
" this.canvas = undefined;\n",
|
|||
|
" this.rubberband_canvas = undefined;\n",
|
|||
|
" this.rubberband_context = undefined;\n",
|
|||
|
" this.format_dropdown = undefined;\n",
|
|||
|
"\n",
|
|||
|
" this.image_mode = 'full';\n",
|
|||
|
"\n",
|
|||
|
" this.root = document.createElement('div');\n",
|
|||
|
" this.root.setAttribute('style', 'display: inline-block');\n",
|
|||
|
" this._root_extra_style(this.root);\n",
|
|||
|
"\n",
|
|||
|
" parent_element.appendChild(this.root);\n",
|
|||
|
"\n",
|
|||
|
" this._init_header(this);\n",
|
|||
|
" this._init_canvas(this);\n",
|
|||
|
" this._init_toolbar(this);\n",
|
|||
|
"\n",
|
|||
|
" var fig = this;\n",
|
|||
|
"\n",
|
|||
|
" this.waiting = false;\n",
|
|||
|
"\n",
|
|||
|
" this.ws.onopen = function () {\n",
|
|||
|
" fig.send_message('supports_binary', { value: fig.supports_binary });\n",
|
|||
|
" fig.send_message('send_image_mode', {});\n",
|
|||
|
" if (fig.ratio !== 1) {\n",
|
|||
|
" fig.send_message('set_device_pixel_ratio', {\n",
|
|||
|
" device_pixel_ratio: fig.ratio,\n",
|
|||
|
" });\n",
|
|||
|
" }\n",
|
|||
|
" fig.send_message('refresh', {});\n",
|
|||
|
" };\n",
|
|||
|
"\n",
|
|||
|
" this.imageObj.onload = function () {\n",
|
|||
|
" if (fig.image_mode === 'full') {\n",
|
|||
|
" // Full images could contain transparency (where diff images\n",
|
|||
|
" // almost always do), so we need to clear the canvas so that\n",
|
|||
|
" // there is no ghosting.\n",
|
|||
|
" fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n",
|
|||
|
" }\n",
|
|||
|
" fig.context.drawImage(fig.imageObj, 0, 0);\n",
|
|||
|
" };\n",
|
|||
|
"\n",
|
|||
|
" this.imageObj.onunload = function () {\n",
|
|||
|
" fig.ws.close();\n",
|
|||
|
" };\n",
|
|||
|
"\n",
|
|||
|
" this.ws.onmessage = this._make_on_message_function(this);\n",
|
|||
|
"\n",
|
|||
|
" this.ondownload = ondownload;\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._init_header = function () {\n",
|
|||
|
" var titlebar = document.createElement('div');\n",
|
|||
|
" titlebar.classList =\n",
|
|||
|
" 'ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix';\n",
|
|||
|
" var titletext = document.createElement('div');\n",
|
|||
|
" titletext.classList = 'ui-dialog-title';\n",
|
|||
|
" titletext.setAttribute(\n",
|
|||
|
" 'style',\n",
|
|||
|
" 'width: 100%; text-align: center; padding: 3px;'\n",
|
|||
|
" );\n",
|
|||
|
" titlebar.appendChild(titletext);\n",
|
|||
|
" this.root.appendChild(titlebar);\n",
|
|||
|
" this.header = titletext;\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._canvas_extra_style = function (_canvas_div) {};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._root_extra_style = function (_canvas_div) {};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._init_canvas = function () {\n",
|
|||
|
" var fig = this;\n",
|
|||
|
"\n",
|
|||
|
" var canvas_div = (this.canvas_div = document.createElement('div'));\n",
|
|||
|
" canvas_div.setAttribute(\n",
|
|||
|
" 'style',\n",
|
|||
|
" 'border: 1px solid #ddd;' +\n",
|
|||
|
" 'box-sizing: content-box;' +\n",
|
|||
|
" 'clear: both;' +\n",
|
|||
|
" 'min-height: 1px;' +\n",
|
|||
|
" 'min-width: 1px;' +\n",
|
|||
|
" 'outline: 0;' +\n",
|
|||
|
" 'overflow: hidden;' +\n",
|
|||
|
" 'position: relative;' +\n",
|
|||
|
" 'resize: both;'\n",
|
|||
|
" );\n",
|
|||
|
"\n",
|
|||
|
" function on_keyboard_event_closure(name) {\n",
|
|||
|
" return function (event) {\n",
|
|||
|
" return fig.key_event(event, name);\n",
|
|||
|
" };\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" canvas_div.addEventListener(\n",
|
|||
|
" 'keydown',\n",
|
|||
|
" on_keyboard_event_closure('key_press')\n",
|
|||
|
" );\n",
|
|||
|
" canvas_div.addEventListener(\n",
|
|||
|
" 'keyup',\n",
|
|||
|
" on_keyboard_event_closure('key_release')\n",
|
|||
|
" );\n",
|
|||
|
"\n",
|
|||
|
" this._canvas_extra_style(canvas_div);\n",
|
|||
|
" this.root.appendChild(canvas_div);\n",
|
|||
|
"\n",
|
|||
|
" var canvas = (this.canvas = document.createElement('canvas'));\n",
|
|||
|
" canvas.classList.add('mpl-canvas');\n",
|
|||
|
" canvas.setAttribute('style', 'box-sizing: content-box;');\n",
|
|||
|
"\n",
|
|||
|
" this.context = canvas.getContext('2d');\n",
|
|||
|
"\n",
|
|||
|
" var backingStore =\n",
|
|||
|
" this.context.backingStorePixelRatio ||\n",
|
|||
|
" this.context.webkitBackingStorePixelRatio ||\n",
|
|||
|
" this.context.mozBackingStorePixelRatio ||\n",
|
|||
|
" this.context.msBackingStorePixelRatio ||\n",
|
|||
|
" this.context.oBackingStorePixelRatio ||\n",
|
|||
|
" this.context.backingStorePixelRatio ||\n",
|
|||
|
" 1;\n",
|
|||
|
"\n",
|
|||
|
" this.ratio = (window.devicePixelRatio || 1) / backingStore;\n",
|
|||
|
"\n",
|
|||
|
" var rubberband_canvas = (this.rubberband_canvas = document.createElement(\n",
|
|||
|
" 'canvas'\n",
|
|||
|
" ));\n",
|
|||
|
" rubberband_canvas.setAttribute(\n",
|
|||
|
" 'style',\n",
|
|||
|
" 'box-sizing: content-box; position: absolute; left: 0; top: 0; z-index: 1;'\n",
|
|||
|
" );\n",
|
|||
|
"\n",
|
|||
|
" // Apply a ponyfill if ResizeObserver is not implemented by browser.\n",
|
|||
|
" if (this.ResizeObserver === undefined) {\n",
|
|||
|
" if (window.ResizeObserver !== undefined) {\n",
|
|||
|
" this.ResizeObserver = window.ResizeObserver;\n",
|
|||
|
" } else {\n",
|
|||
|
" var obs = _JSXTOOLS_RESIZE_OBSERVER({});\n",
|
|||
|
" this.ResizeObserver = obs.ResizeObserver;\n",
|
|||
|
" }\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" this.resizeObserverInstance = new this.ResizeObserver(function (entries) {\n",
|
|||
|
" var nentries = entries.length;\n",
|
|||
|
" for (var i = 0; i < nentries; i++) {\n",
|
|||
|
" var entry = entries[i];\n",
|
|||
|
" var width, height;\n",
|
|||
|
" if (entry.contentBoxSize) {\n",
|
|||
|
" if (entry.contentBoxSize instanceof Array) {\n",
|
|||
|
" // Chrome 84 implements new version of spec.\n",
|
|||
|
" width = entry.contentBoxSize[0].inlineSize;\n",
|
|||
|
" height = entry.contentBoxSize[0].blockSize;\n",
|
|||
|
" } else {\n",
|
|||
|
" // Firefox implements old version of spec.\n",
|
|||
|
" width = entry.contentBoxSize.inlineSize;\n",
|
|||
|
" height = entry.contentBoxSize.blockSize;\n",
|
|||
|
" }\n",
|
|||
|
" } else {\n",
|
|||
|
" // Chrome <84 implements even older version of spec.\n",
|
|||
|
" width = entry.contentRect.width;\n",
|
|||
|
" height = entry.contentRect.height;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" // Keep the size of the canvas and rubber band canvas in sync with\n",
|
|||
|
" // the canvas container.\n",
|
|||
|
" if (entry.devicePixelContentBoxSize) {\n",
|
|||
|
" // Chrome 84 implements new version of spec.\n",
|
|||
|
" canvas.setAttribute(\n",
|
|||
|
" 'width',\n",
|
|||
|
" entry.devicePixelContentBoxSize[0].inlineSize\n",
|
|||
|
" );\n",
|
|||
|
" canvas.setAttribute(\n",
|
|||
|
" 'height',\n",
|
|||
|
" entry.devicePixelContentBoxSize[0].blockSize\n",
|
|||
|
" );\n",
|
|||
|
" } else {\n",
|
|||
|
" canvas.setAttribute('width', width * fig.ratio);\n",
|
|||
|
" canvas.setAttribute('height', height * fig.ratio);\n",
|
|||
|
" }\n",
|
|||
|
" canvas.setAttribute(\n",
|
|||
|
" 'style',\n",
|
|||
|
" 'width: ' + width + 'px; height: ' + height + 'px;'\n",
|
|||
|
" );\n",
|
|||
|
"\n",
|
|||
|
" rubberband_canvas.setAttribute('width', width);\n",
|
|||
|
" rubberband_canvas.setAttribute('height', height);\n",
|
|||
|
"\n",
|
|||
|
" // And update the size in Python. We ignore the initial 0/0 size\n",
|
|||
|
" // that occurs as the element is placed into the DOM, which should\n",
|
|||
|
" // otherwise not happen due to the minimum size styling.\n",
|
|||
|
" if (fig.ws.readyState == 1 && width != 0 && height != 0) {\n",
|
|||
|
" fig.request_resize(width, height);\n",
|
|||
|
" }\n",
|
|||
|
" }\n",
|
|||
|
" });\n",
|
|||
|
" this.resizeObserverInstance.observe(canvas_div);\n",
|
|||
|
"\n",
|
|||
|
" function on_mouse_event_closure(name) {\n",
|
|||
|
" return function (event) {\n",
|
|||
|
" return fig.mouse_event(event, name);\n",
|
|||
|
" };\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" rubberband_canvas.addEventListener(\n",
|
|||
|
" 'mousedown',\n",
|
|||
|
" on_mouse_event_closure('button_press')\n",
|
|||
|
" );\n",
|
|||
|
" rubberband_canvas.addEventListener(\n",
|
|||
|
" 'mouseup',\n",
|
|||
|
" on_mouse_event_closure('button_release')\n",
|
|||
|
" );\n",
|
|||
|
" rubberband_canvas.addEventListener(\n",
|
|||
|
" 'dblclick',\n",
|
|||
|
" on_mouse_event_closure('dblclick')\n",
|
|||
|
" );\n",
|
|||
|
" // Throttle sequential mouse events to 1 every 20ms.\n",
|
|||
|
" rubberband_canvas.addEventListener(\n",
|
|||
|
" 'mousemove',\n",
|
|||
|
" on_mouse_event_closure('motion_notify')\n",
|
|||
|
" );\n",
|
|||
|
"\n",
|
|||
|
" rubberband_canvas.addEventListener(\n",
|
|||
|
" 'mouseenter',\n",
|
|||
|
" on_mouse_event_closure('figure_enter')\n",
|
|||
|
" );\n",
|
|||
|
" rubberband_canvas.addEventListener(\n",
|
|||
|
" 'mouseleave',\n",
|
|||
|
" on_mouse_event_closure('figure_leave')\n",
|
|||
|
" );\n",
|
|||
|
"\n",
|
|||
|
" canvas_div.addEventListener('wheel', function (event) {\n",
|
|||
|
" if (event.deltaY < 0) {\n",
|
|||
|
" event.step = 1;\n",
|
|||
|
" } else {\n",
|
|||
|
" event.step = -1;\n",
|
|||
|
" }\n",
|
|||
|
" on_mouse_event_closure('scroll')(event);\n",
|
|||
|
" });\n",
|
|||
|
"\n",
|
|||
|
" canvas_div.appendChild(canvas);\n",
|
|||
|
" canvas_div.appendChild(rubberband_canvas);\n",
|
|||
|
"\n",
|
|||
|
" this.rubberband_context = rubberband_canvas.getContext('2d');\n",
|
|||
|
" this.rubberband_context.strokeStyle = '#000000';\n",
|
|||
|
"\n",
|
|||
|
" this._resize_canvas = function (width, height, forward) {\n",
|
|||
|
" if (forward) {\n",
|
|||
|
" canvas_div.style.width = width + 'px';\n",
|
|||
|
" canvas_div.style.height = height + 'px';\n",
|
|||
|
" }\n",
|
|||
|
" };\n",
|
|||
|
"\n",
|
|||
|
" // Disable right mouse context menu.\n",
|
|||
|
" this.rubberband_canvas.addEventListener('contextmenu', function (_e) {\n",
|
|||
|
" event.preventDefault();\n",
|
|||
|
" return false;\n",
|
|||
|
" });\n",
|
|||
|
"\n",
|
|||
|
" function set_focus() {\n",
|
|||
|
" canvas.focus();\n",
|
|||
|
" canvas_div.focus();\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" window.setTimeout(set_focus, 100);\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._init_toolbar = function () {\n",
|
|||
|
" var fig = this;\n",
|
|||
|
"\n",
|
|||
|
" var toolbar = document.createElement('div');\n",
|
|||
|
" toolbar.classList = 'mpl-toolbar';\n",
|
|||
|
" this.root.appendChild(toolbar);\n",
|
|||
|
"\n",
|
|||
|
" function on_click_closure(name) {\n",
|
|||
|
" return function (_event) {\n",
|
|||
|
" return fig.toolbar_button_onclick(name);\n",
|
|||
|
" };\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" function on_mouseover_closure(tooltip) {\n",
|
|||
|
" return function (event) {\n",
|
|||
|
" if (!event.currentTarget.disabled) {\n",
|
|||
|
" return fig.toolbar_button_onmouseover(tooltip);\n",
|
|||
|
" }\n",
|
|||
|
" };\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" fig.buttons = {};\n",
|
|||
|
" var buttonGroup = document.createElement('div');\n",
|
|||
|
" buttonGroup.classList = 'mpl-button-group';\n",
|
|||
|
" for (var toolbar_ind in mpl.toolbar_items) {\n",
|
|||
|
" var name = mpl.toolbar_items[toolbar_ind][0];\n",
|
|||
|
" var tooltip = mpl.toolbar_items[toolbar_ind][1];\n",
|
|||
|
" var image = mpl.toolbar_items[toolbar_ind][2];\n",
|
|||
|
" var method_name = mpl.toolbar_items[toolbar_ind][3];\n",
|
|||
|
"\n",
|
|||
|
" if (!name) {\n",
|
|||
|
" /* Instead of a spacer, we start a new button group. */\n",
|
|||
|
" if (buttonGroup.hasChildNodes()) {\n",
|
|||
|
" toolbar.appendChild(buttonGroup);\n",
|
|||
|
" }\n",
|
|||
|
" buttonGroup = document.createElement('div');\n",
|
|||
|
" buttonGroup.classList = 'mpl-button-group';\n",
|
|||
|
" continue;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" var button = (fig.buttons[name] = document.createElement('button'));\n",
|
|||
|
" button.classList = 'mpl-widget';\n",
|
|||
|
" button.setAttribute('role', 'button');\n",
|
|||
|
" button.setAttribute('aria-disabled', 'false');\n",
|
|||
|
" button.addEventListener('click', on_click_closure(method_name));\n",
|
|||
|
" button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n",
|
|||
|
"\n",
|
|||
|
" var icon_img = document.createElement('img');\n",
|
|||
|
" icon_img.src = '_images/' + image + '.png';\n",
|
|||
|
" icon_img.srcset = '_images/' + image + '_large.png 2x';\n",
|
|||
|
" icon_img.alt = tooltip;\n",
|
|||
|
" button.appendChild(icon_img);\n",
|
|||
|
"\n",
|
|||
|
" buttonGroup.appendChild(button);\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" if (buttonGroup.hasChildNodes()) {\n",
|
|||
|
" toolbar.appendChild(buttonGroup);\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" var fmt_picker = document.createElement('select');\n",
|
|||
|
" fmt_picker.classList = 'mpl-widget';\n",
|
|||
|
" toolbar.appendChild(fmt_picker);\n",
|
|||
|
" this.format_dropdown = fmt_picker;\n",
|
|||
|
"\n",
|
|||
|
" for (var ind in mpl.extensions) {\n",
|
|||
|
" var fmt = mpl.extensions[ind];\n",
|
|||
|
" var option = document.createElement('option');\n",
|
|||
|
" option.selected = fmt === mpl.default_extension;\n",
|
|||
|
" option.innerHTML = fmt;\n",
|
|||
|
" fmt_picker.appendChild(option);\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" var status_bar = document.createElement('span');\n",
|
|||
|
" status_bar.classList = 'mpl-message';\n",
|
|||
|
" toolbar.appendChild(status_bar);\n",
|
|||
|
" this.message = status_bar;\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.request_resize = function (x_pixels, y_pixels) {\n",
|
|||
|
" // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,\n",
|
|||
|
" // which will in turn request a refresh of the image.\n",
|
|||
|
" this.send_message('resize', { width: x_pixels, height: y_pixels });\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.send_message = function (type, properties) {\n",
|
|||
|
" properties['type'] = type;\n",
|
|||
|
" properties['figure_id'] = this.id;\n",
|
|||
|
" this.ws.send(JSON.stringify(properties));\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.send_draw_message = function () {\n",
|
|||
|
" if (!this.waiting) {\n",
|
|||
|
" this.waiting = true;\n",
|
|||
|
" this.ws.send(JSON.stringify({ type: 'draw', figure_id: this.id }));\n",
|
|||
|
" }\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_save = function (fig, _msg) {\n",
|
|||
|
" var format_dropdown = fig.format_dropdown;\n",
|
|||
|
" var format = format_dropdown.options[format_dropdown.selectedIndex].value;\n",
|
|||
|
" fig.ondownload(fig, format);\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_resize = function (fig, msg) {\n",
|
|||
|
" var size = msg['size'];\n",
|
|||
|
" if (size[0] !== fig.canvas.width || size[1] !== fig.canvas.height) {\n",
|
|||
|
" fig._resize_canvas(size[0], size[1], msg['forward']);\n",
|
|||
|
" fig.send_message('refresh', {});\n",
|
|||
|
" }\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_rubberband = function (fig, msg) {\n",
|
|||
|
" var x0 = msg['x0'] / fig.ratio;\n",
|
|||
|
" var y0 = (fig.canvas.height - msg['y0']) / fig.ratio;\n",
|
|||
|
" var x1 = msg['x1'] / fig.ratio;\n",
|
|||
|
" var y1 = (fig.canvas.height - msg['y1']) / fig.ratio;\n",
|
|||
|
" x0 = Math.floor(x0) + 0.5;\n",
|
|||
|
" y0 = Math.floor(y0) + 0.5;\n",
|
|||
|
" x1 = Math.floor(x1) + 0.5;\n",
|
|||
|
" y1 = Math.floor(y1) + 0.5;\n",
|
|||
|
" var min_x = Math.min(x0, x1);\n",
|
|||
|
" var min_y = Math.min(y0, y1);\n",
|
|||
|
" var width = Math.abs(x1 - x0);\n",
|
|||
|
" var height = Math.abs(y1 - y0);\n",
|
|||
|
"\n",
|
|||
|
" fig.rubberband_context.clearRect(\n",
|
|||
|
" 0,\n",
|
|||
|
" 0,\n",
|
|||
|
" fig.canvas.width / fig.ratio,\n",
|
|||
|
" fig.canvas.height / fig.ratio\n",
|
|||
|
" );\n",
|
|||
|
"\n",
|
|||
|
" fig.rubberband_context.strokeRect(min_x, min_y, width, height);\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_figure_label = function (fig, msg) {\n",
|
|||
|
" // Updates the figure title.\n",
|
|||
|
" fig.header.textContent = msg['label'];\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_cursor = function (fig, msg) {\n",
|
|||
|
" fig.rubberband_canvas.style.cursor = msg['cursor'];\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_message = function (fig, msg) {\n",
|
|||
|
" fig.message.textContent = msg['message'];\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_draw = function (fig, _msg) {\n",
|
|||
|
" // Request the server to send over a new figure.\n",
|
|||
|
" fig.send_draw_message();\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_image_mode = function (fig, msg) {\n",
|
|||
|
" fig.image_mode = msg['mode'];\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_history_buttons = function (fig, msg) {\n",
|
|||
|
" for (var key in msg) {\n",
|
|||
|
" if (!(key in fig.buttons)) {\n",
|
|||
|
" continue;\n",
|
|||
|
" }\n",
|
|||
|
" fig.buttons[key].disabled = !msg[key];\n",
|
|||
|
" fig.buttons[key].setAttribute('aria-disabled', !msg[key]);\n",
|
|||
|
" }\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_navigate_mode = function (fig, msg) {\n",
|
|||
|
" if (msg['mode'] === 'PAN') {\n",
|
|||
|
" fig.buttons['Pan'].classList.add('active');\n",
|
|||
|
" fig.buttons['Zoom'].classList.remove('active');\n",
|
|||
|
" } else if (msg['mode'] === 'ZOOM') {\n",
|
|||
|
" fig.buttons['Pan'].classList.remove('active');\n",
|
|||
|
" fig.buttons['Zoom'].classList.add('active');\n",
|
|||
|
" } else {\n",
|
|||
|
" fig.buttons['Pan'].classList.remove('active');\n",
|
|||
|
" fig.buttons['Zoom'].classList.remove('active');\n",
|
|||
|
" }\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.updated_canvas_event = function () {\n",
|
|||
|
" // Called whenever the canvas gets updated.\n",
|
|||
|
" this.send_message('ack', {});\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"// A function to construct a web socket function for onmessage handling.\n",
|
|||
|
"// Called in the figure constructor.\n",
|
|||
|
"mpl.figure.prototype._make_on_message_function = function (fig) {\n",
|
|||
|
" return function socket_on_message(evt) {\n",
|
|||
|
" if (evt.data instanceof Blob) {\n",
|
|||
|
" var img = evt.data;\n",
|
|||
|
" if (img.type !== 'image/png') {\n",
|
|||
|
" /* FIXME: We get \"Resource interpreted as Image but\n",
|
|||
|
" * transferred with MIME type text/plain:\" errors on\n",
|
|||
|
" * Chrome. But how to set the MIME type? It doesn't seem\n",
|
|||
|
" * to be part of the websocket stream */\n",
|
|||
|
" img.type = 'image/png';\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" /* Free the memory for the previous frames */\n",
|
|||
|
" if (fig.imageObj.src) {\n",
|
|||
|
" (window.URL || window.webkitURL).revokeObjectURL(\n",
|
|||
|
" fig.imageObj.src\n",
|
|||
|
" );\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(\n",
|
|||
|
" img\n",
|
|||
|
" );\n",
|
|||
|
" fig.updated_canvas_event();\n",
|
|||
|
" fig.waiting = false;\n",
|
|||
|
" return;\n",
|
|||
|
" } else if (\n",
|
|||
|
" typeof evt.data === 'string' &&\n",
|
|||
|
" evt.data.slice(0, 21) === 'data:image/png;base64'\n",
|
|||
|
" ) {\n",
|
|||
|
" fig.imageObj.src = evt.data;\n",
|
|||
|
" fig.updated_canvas_event();\n",
|
|||
|
" fig.waiting = false;\n",
|
|||
|
" return;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" var msg = JSON.parse(evt.data);\n",
|
|||
|
" var msg_type = msg['type'];\n",
|
|||
|
"\n",
|
|||
|
" // Call the \"handle_{type}\" callback, which takes\n",
|
|||
|
" // the figure and JSON message as its only arguments.\n",
|
|||
|
" try {\n",
|
|||
|
" var callback = fig['handle_' + msg_type];\n",
|
|||
|
" } catch (e) {\n",
|
|||
|
" console.log(\n",
|
|||
|
" \"No handler for the '\" + msg_type + \"' message type: \",\n",
|
|||
|
" msg\n",
|
|||
|
" );\n",
|
|||
|
" return;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" if (callback) {\n",
|
|||
|
" try {\n",
|
|||
|
" // console.log(\"Handling '\" + msg_type + \"' message: \", msg);\n",
|
|||
|
" callback(fig, msg);\n",
|
|||
|
" } catch (e) {\n",
|
|||
|
" console.log(\n",
|
|||
|
" \"Exception inside the 'handler_\" + msg_type + \"' callback:\",\n",
|
|||
|
" e,\n",
|
|||
|
" e.stack,\n",
|
|||
|
" msg\n",
|
|||
|
" );\n",
|
|||
|
" }\n",
|
|||
|
" }\n",
|
|||
|
" };\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"// from https://stackoverflow.com/questions/1114465/getting-mouse-location-in-canvas\n",
|
|||
|
"mpl.findpos = function (e) {\n",
|
|||
|
" //this section is from http://www.quirksmode.org/js/events_properties.html\n",
|
|||
|
" var targ;\n",
|
|||
|
" if (!e) {\n",
|
|||
|
" e = window.event;\n",
|
|||
|
" }\n",
|
|||
|
" if (e.target) {\n",
|
|||
|
" targ = e.target;\n",
|
|||
|
" } else if (e.srcElement) {\n",
|
|||
|
" targ = e.srcElement;\n",
|
|||
|
" }\n",
|
|||
|
" if (targ.nodeType === 3) {\n",
|
|||
|
" // defeat Safari bug\n",
|
|||
|
" targ = targ.parentNode;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" // pageX,Y are the mouse positions relative to the document\n",
|
|||
|
" var boundingRect = targ.getBoundingClientRect();\n",
|
|||
|
" var x = e.pageX - (boundingRect.left + document.body.scrollLeft);\n",
|
|||
|
" var y = e.pageY - (boundingRect.top + document.body.scrollTop);\n",
|
|||
|
"\n",
|
|||
|
" return { x: x, y: y };\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"/*\n",
|
|||
|
" * return a copy of an object with only non-object keys\n",
|
|||
|
" * we need this to avoid circular references\n",
|
|||
|
" * https://stackoverflow.com/a/24161582/3208463\n",
|
|||
|
" */\n",
|
|||
|
"function simpleKeys(original) {\n",
|
|||
|
" return Object.keys(original).reduce(function (obj, key) {\n",
|
|||
|
" if (typeof original[key] !== 'object') {\n",
|
|||
|
" obj[key] = original[key];\n",
|
|||
|
" }\n",
|
|||
|
" return obj;\n",
|
|||
|
" }, {});\n",
|
|||
|
"}\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.mouse_event = function (event, name) {\n",
|
|||
|
" var canvas_pos = mpl.findpos(event);\n",
|
|||
|
"\n",
|
|||
|
" if (name === 'button_press') {\n",
|
|||
|
" this.canvas.focus();\n",
|
|||
|
" this.canvas_div.focus();\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" var x = canvas_pos.x * this.ratio;\n",
|
|||
|
" var y = canvas_pos.y * this.ratio;\n",
|
|||
|
"\n",
|
|||
|
" this.send_message(name, {\n",
|
|||
|
" x: x,\n",
|
|||
|
" y: y,\n",
|
|||
|
" button: event.button,\n",
|
|||
|
" step: event.step,\n",
|
|||
|
" guiEvent: simpleKeys(event),\n",
|
|||
|
" });\n",
|
|||
|
"\n",
|
|||
|
" /* This prevents the web browser from automatically changing to\n",
|
|||
|
" * the text insertion cursor when the button is pressed. We want\n",
|
|||
|
" * to control all of the cursor setting manually through the\n",
|
|||
|
" * 'cursor' event from matplotlib */\n",
|
|||
|
" event.preventDefault();\n",
|
|||
|
" return false;\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._key_event_extra = function (_event, _name) {\n",
|
|||
|
" // Handle any extra behaviour associated with a key event\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.key_event = function (event, name) {\n",
|
|||
|
" // Prevent repeat events\n",
|
|||
|
" if (name === 'key_press') {\n",
|
|||
|
" if (event.key === this._key) {\n",
|
|||
|
" return;\n",
|
|||
|
" } else {\n",
|
|||
|
" this._key = event.key;\n",
|
|||
|
" }\n",
|
|||
|
" }\n",
|
|||
|
" if (name === 'key_release') {\n",
|
|||
|
" this._key = null;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" var value = '';\n",
|
|||
|
" if (event.ctrlKey && event.key !== 'Control') {\n",
|
|||
|
" value += 'ctrl+';\n",
|
|||
|
" }\n",
|
|||
|
" else if (event.altKey && event.key !== 'Alt') {\n",
|
|||
|
" value += 'alt+';\n",
|
|||
|
" }\n",
|
|||
|
" else if (event.shiftKey && event.key !== 'Shift') {\n",
|
|||
|
" value += 'shift+';\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" value += 'k' + event.key;\n",
|
|||
|
"\n",
|
|||
|
" this._key_event_extra(event, name);\n",
|
|||
|
"\n",
|
|||
|
" this.send_message(name, { key: value, guiEvent: simpleKeys(event) });\n",
|
|||
|
" return false;\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.toolbar_button_onclick = function (name) {\n",
|
|||
|
" if (name === 'download') {\n",
|
|||
|
" this.handle_save(this, null);\n",
|
|||
|
" } else {\n",
|
|||
|
" this.send_message('toolbar_button', { name: name });\n",
|
|||
|
" }\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.toolbar_button_onmouseover = function (tooltip) {\n",
|
|||
|
" this.message.textContent = tooltip;\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"///////////////// REMAINING CONTENT GENERATED BY embed_js.py /////////////////\n",
|
|||
|
"// prettier-ignore\n",
|
|||
|
"var _JSXTOOLS_RESIZE_OBSERVER=function(A){var t,i=new WeakMap,n=new WeakMap,a=new WeakMap,r=new WeakMap,o=new Set;function s(e){if(!(this instanceof s))throw new TypeError(\"Constructor requires 'new' operator\");i.set(this,e)}function h(){throw new TypeError(\"Function is not a constructor\")}function c(e,t,i,n){e=0 in arguments?Number(arguments[0]):0,t=1 in arguments?Number(arguments[1]):0,i=2 in arguments?Number(arguments[2]):0,n=3 in arguments?Number(arguments[3]):0,this.right=(this.x=this.left=e)+(this.width=i),this.bottom=(this.y=this.top=t)+(this.height=n),Object.freeze(this)}function d(){t=requestAnimationFrame(d);var s=new WeakMap,p=new Set;o.forEach((function(t){r.get(t).forEach((function(i){var r=t instanceof window.SVGElement,o=a.get(t),d=r?0:parseFloat(o.paddingTop),f=r?0:parseFloat(o.paddingRight),l=r?0:parseFloat(o.paddingBottom),u=r?0:parseFloat(o.paddingLeft),g=r?0:parseFloat(o.borderTopWidth),m=r?0:parseFloat(o.borderRightWidth),w=r?0:parseFloat(o.borderBottomWidth),b=u+f,F=d+l,v=(r?0:parseFloat(o.borderLeftWidth))+m,W=g+w,y=r?0:t.offsetHeight-W-t.clientHeight,E=r?0:t.offsetWidth-v-t.clientWidth,R=b+v,z=F+W,M=r?t.width:parseFloat(o.width)-R-E,O=r?t.height:parseFloat(o.height)-z-y;if(n.has(t)){var k=n.get(t);if(k[0]===M&&k[1]===O)return}n.set(t,[M,O]);var S=Object.create(h.prototype);S.target=t,S.contentRect=new c(u,d,M,O),s.has(i)||(s.set(i,[]),p.add(i)),s.get(i).push(S)}))})),p.forEach((function(e){i.get(e).call(e,s.get(e),e)}))}return s.prototype.observe=function(i){if(i instanceof window.Element){r.has(i)||(r.set(i,new Set),o.add(i),a.set(i,window.getComputedStyle(i)));var n=r.get(i);n.has(this)||n.add(this),cancelAnimationFrame(t),t=requestAnimationFrame(d)}},s.prototype.unobserve=function(i){if(i instanceof window.Element&&r.has(i)){var n=r.get(i);n.has(this)&&(n.delete(this),n.size||(r.delete(i),o.delete(i))),n.size||r.delete(i),o.size||cancelAnimationFrame(t)}},A.DOMRectReadOnly=c,A.ResizeObserver=s,A.ResizeObserverEntry=h,A}; // eslint-disable-line\n",
|
|||
|
"mpl.toolbar_items = [[\"Home\", \"Reset original view\", \"fa fa-home icon-home\", \"home\"], [\"Back\", \"Back to previous view\", \"fa fa-arrow-left icon-arrow-left\", \"back\"], [\"Forward\", \"Forward to next view\", \"fa fa-arrow-right icon-arrow-right\", \"forward\"], [\"\", \"\", \"\", \"\"], [\"Pan\", \"Left button pans, Right button zooms\\nx/y fixes axis, CTRL fixes aspect\", \"fa fa-arrows icon-move\", \"pan\"], [\"Zoom\", \"Zoom to rectangle\\nx/y fixes axis\", \"fa fa-square-o icon-check-empty\", \"zoom\"], [\"\", \"\", \"\", \"\"], [\"Download\", \"Download plot\", \"fa fa-floppy-o icon-save\", \"download\"]];\n",
|
|||
|
"\n",
|
|||
|
"mpl.extensions = [\"eps\", \"jpeg\", \"pgf\", \"pdf\", \"png\", \"ps\", \"raw\", \"svg\", \"tif\"];\n",
|
|||
|
"\n",
|
|||
|
"mpl.default_extension = \"png\";/* global mpl */\n",
|
|||
|
"\n",
|
|||
|
"var comm_websocket_adapter = function (comm) {\n",
|
|||
|
" // Create a \"websocket\"-like object which calls the given IPython comm\n",
|
|||
|
" // object with the appropriate methods. Currently this is a non binary\n",
|
|||
|
" // socket, so there is still some room for performance tuning.\n",
|
|||
|
" var ws = {};\n",
|
|||
|
"\n",
|
|||
|
" ws.binaryType = comm.kernel.ws.binaryType;\n",
|
|||
|
" ws.readyState = comm.kernel.ws.readyState;\n",
|
|||
|
" function updateReadyState(_event) {\n",
|
|||
|
" if (comm.kernel.ws) {\n",
|
|||
|
" ws.readyState = comm.kernel.ws.readyState;\n",
|
|||
|
" } else {\n",
|
|||
|
" ws.readyState = 3; // Closed state.\n",
|
|||
|
" }\n",
|
|||
|
" }\n",
|
|||
|
" comm.kernel.ws.addEventListener('open', updateReadyState);\n",
|
|||
|
" comm.kernel.ws.addEventListener('close', updateReadyState);\n",
|
|||
|
" comm.kernel.ws.addEventListener('error', updateReadyState);\n",
|
|||
|
"\n",
|
|||
|
" ws.close = function () {\n",
|
|||
|
" comm.close();\n",
|
|||
|
" };\n",
|
|||
|
" ws.send = function (m) {\n",
|
|||
|
" //console.log('sending', m);\n",
|
|||
|
" comm.send(m);\n",
|
|||
|
" };\n",
|
|||
|
" // Register the callback with on_msg.\n",
|
|||
|
" comm.on_msg(function (msg) {\n",
|
|||
|
" //console.log('receiving', msg['content']['data'], msg);\n",
|
|||
|
" var data = msg['content']['data'];\n",
|
|||
|
" if (data['blob'] !== undefined) {\n",
|
|||
|
" data = {\n",
|
|||
|
" data: new Blob(msg['buffers'], { type: data['blob'] }),\n",
|
|||
|
" };\n",
|
|||
|
" }\n",
|
|||
|
" // Pass the mpl event to the overridden (by mpl) onmessage function.\n",
|
|||
|
" ws.onmessage(data);\n",
|
|||
|
" });\n",
|
|||
|
" return ws;\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.mpl_figure_comm = function (comm, msg) {\n",
|
|||
|
" // This is the function which gets called when the mpl process\n",
|
|||
|
" // starts-up an IPython Comm through the \"matplotlib\" channel.\n",
|
|||
|
"\n",
|
|||
|
" var id = msg.content.data.id;\n",
|
|||
|
" // Get hold of the div created by the display call when the Comm\n",
|
|||
|
" // socket was opened in Python.\n",
|
|||
|
" var element = document.getElementById(id);\n",
|
|||
|
" var ws_proxy = comm_websocket_adapter(comm);\n",
|
|||
|
"\n",
|
|||
|
" function ondownload(figure, _format) {\n",
|
|||
|
" window.open(figure.canvas.toDataURL());\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" var fig = new mpl.figure(id, ws_proxy, ondownload, element);\n",
|
|||
|
"\n",
|
|||
|
" // Call onopen now - mpl needs it, as it is assuming we've passed it a real\n",
|
|||
|
" // web socket which is closed, not our websocket->open comm proxy.\n",
|
|||
|
" ws_proxy.onopen();\n",
|
|||
|
"\n",
|
|||
|
" fig.parent_element = element;\n",
|
|||
|
" fig.cell_info = mpl.find_output_cell(\"<div id='\" + id + \"'></div>\");\n",
|
|||
|
" if (!fig.cell_info) {\n",
|
|||
|
" console.error('Failed to find cell for figure', id, fig);\n",
|
|||
|
" return;\n",
|
|||
|
" }\n",
|
|||
|
" fig.cell_info[0].output_area.element.on(\n",
|
|||
|
" 'cleared',\n",
|
|||
|
" { fig: fig },\n",
|
|||
|
" fig._remove_fig_handler\n",
|
|||
|
" );\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_close = function (fig, msg) {\n",
|
|||
|
" var width = fig.canvas.width / fig.ratio;\n",
|
|||
|
" fig.cell_info[0].output_area.element.off(\n",
|
|||
|
" 'cleared',\n",
|
|||
|
" fig._remove_fig_handler\n",
|
|||
|
" );\n",
|
|||
|
" fig.resizeObserverInstance.unobserve(fig.canvas_div);\n",
|
|||
|
"\n",
|
|||
|
" // Update the output cell to use the data from the current canvas.\n",
|
|||
|
" fig.push_to_output();\n",
|
|||
|
" var dataURL = fig.canvas.toDataURL();\n",
|
|||
|
" // Re-enable the keyboard manager in IPython - without this line, in FF,\n",
|
|||
|
" // the notebook keyboard shortcuts fail.\n",
|
|||
|
" IPython.keyboard_manager.enable();\n",
|
|||
|
" fig.parent_element.innerHTML =\n",
|
|||
|
" '<img src=\"' + dataURL + '\" width=\"' + width + '\">';\n",
|
|||
|
" fig.close_ws(fig, msg);\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.close_ws = function (fig, msg) {\n",
|
|||
|
" fig.send_message('closing', msg);\n",
|
|||
|
" // fig.ws.close()\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.push_to_output = function (_remove_interactive) {\n",
|
|||
|
" // Turn the data on the canvas into data in the output cell.\n",
|
|||
|
" var width = this.canvas.width / this.ratio;\n",
|
|||
|
" var dataURL = this.canvas.toDataURL();\n",
|
|||
|
" this.cell_info[1]['text/html'] =\n",
|
|||
|
" '<img src=\"' + dataURL + '\" width=\"' + width + '\">';\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.updated_canvas_event = function () {\n",
|
|||
|
" // Tell IPython that the notebook contents must change.\n",
|
|||
|
" IPython.notebook.set_dirty(true);\n",
|
|||
|
" this.send_message('ack', {});\n",
|
|||
|
" var fig = this;\n",
|
|||
|
" // Wait a second, then push the new image to the DOM so\n",
|
|||
|
" // that it is saved nicely (might be nice to debounce this).\n",
|
|||
|
" setTimeout(function () {\n",
|
|||
|
" fig.push_to_output();\n",
|
|||
|
" }, 1000);\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._init_toolbar = function () {\n",
|
|||
|
" var fig = this;\n",
|
|||
|
"\n",
|
|||
|
" var toolbar = document.createElement('div');\n",
|
|||
|
" toolbar.classList = 'btn-toolbar';\n",
|
|||
|
" this.root.appendChild(toolbar);\n",
|
|||
|
"\n",
|
|||
|
" function on_click_closure(name) {\n",
|
|||
|
" return function (_event) {\n",
|
|||
|
" return fig.toolbar_button_onclick(name);\n",
|
|||
|
" };\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" function on_mouseover_closure(tooltip) {\n",
|
|||
|
" return function (event) {\n",
|
|||
|
" if (!event.currentTarget.disabled) {\n",
|
|||
|
" return fig.toolbar_button_onmouseover(tooltip);\n",
|
|||
|
" }\n",
|
|||
|
" };\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" fig.buttons = {};\n",
|
|||
|
" var buttonGroup = document.createElement('div');\n",
|
|||
|
" buttonGroup.classList = 'btn-group';\n",
|
|||
|
" var button;\n",
|
|||
|
" for (var toolbar_ind in mpl.toolbar_items) {\n",
|
|||
|
" var name = mpl.toolbar_items[toolbar_ind][0];\n",
|
|||
|
" var tooltip = mpl.toolbar_items[toolbar_ind][1];\n",
|
|||
|
" var image = mpl.toolbar_items[toolbar_ind][2];\n",
|
|||
|
" var method_name = mpl.toolbar_items[toolbar_ind][3];\n",
|
|||
|
"\n",
|
|||
|
" if (!name) {\n",
|
|||
|
" /* Instead of a spacer, we start a new button group. */\n",
|
|||
|
" if (buttonGroup.hasChildNodes()) {\n",
|
|||
|
" toolbar.appendChild(buttonGroup);\n",
|
|||
|
" }\n",
|
|||
|
" buttonGroup = document.createElement('div');\n",
|
|||
|
" buttonGroup.classList = 'btn-group';\n",
|
|||
|
" continue;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" button = fig.buttons[name] = document.createElement('button');\n",
|
|||
|
" button.classList = 'btn btn-default';\n",
|
|||
|
" button.href = '#';\n",
|
|||
|
" button.title = name;\n",
|
|||
|
" button.innerHTML = '<i class=\"fa ' + image + ' fa-lg\"></i>';\n",
|
|||
|
" button.addEventListener('click', on_click_closure(method_name));\n",
|
|||
|
" button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n",
|
|||
|
" buttonGroup.appendChild(button);\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" if (buttonGroup.hasChildNodes()) {\n",
|
|||
|
" toolbar.appendChild(buttonGroup);\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" // Add the status bar.\n",
|
|||
|
" var status_bar = document.createElement('span');\n",
|
|||
|
" status_bar.classList = 'mpl-message pull-right';\n",
|
|||
|
" toolbar.appendChild(status_bar);\n",
|
|||
|
" this.message = status_bar;\n",
|
|||
|
"\n",
|
|||
|
" // Add the close button to the window.\n",
|
|||
|
" var buttongrp = document.createElement('div');\n",
|
|||
|
" buttongrp.classList = 'btn-group inline pull-right';\n",
|
|||
|
" button = document.createElement('button');\n",
|
|||
|
" button.classList = 'btn btn-mini btn-primary';\n",
|
|||
|
" button.href = '#';\n",
|
|||
|
" button.title = 'Stop Interaction';\n",
|
|||
|
" button.innerHTML = '<i class=\"fa fa-power-off icon-remove icon-large\"></i>';\n",
|
|||
|
" button.addEventListener('click', function (_evt) {\n",
|
|||
|
" fig.handle_close(fig, {});\n",
|
|||
|
" });\n",
|
|||
|
" button.addEventListener(\n",
|
|||
|
" 'mouseover',\n",
|
|||
|
" on_mouseover_closure('Stop Interaction')\n",
|
|||
|
" );\n",
|
|||
|
" buttongrp.appendChild(button);\n",
|
|||
|
" var titlebar = this.root.querySelector('.ui-dialog-titlebar');\n",
|
|||
|
" titlebar.insertBefore(buttongrp, titlebar.firstChild);\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._remove_fig_handler = function (event) {\n",
|
|||
|
" var fig = event.data.fig;\n",
|
|||
|
" if (event.target !== this) {\n",
|
|||
|
" // Ignore bubbled events from children.\n",
|
|||
|
" return;\n",
|
|||
|
" }\n",
|
|||
|
" fig.close_ws(fig, {});\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._root_extra_style = function (el) {\n",
|
|||
|
" el.style.boxSizing = 'content-box'; // override notebook setting of border-box.\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._canvas_extra_style = function (el) {\n",
|
|||
|
" // this is important to make the div 'focusable\n",
|
|||
|
" el.setAttribute('tabindex', 0);\n",
|
|||
|
" // reach out to IPython and tell the keyboard manager to turn it's self\n",
|
|||
|
" // off when our div gets focus\n",
|
|||
|
"\n",
|
|||
|
" // location in version 3\n",
|
|||
|
" if (IPython.notebook.keyboard_manager) {\n",
|
|||
|
" IPython.notebook.keyboard_manager.register_events(el);\n",
|
|||
|
" } else {\n",
|
|||
|
" // location in version 2\n",
|
|||
|
" IPython.keyboard_manager.register_events(el);\n",
|
|||
|
" }\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._key_event_extra = function (event, _name) {\n",
|
|||
|
" // Check for shift+enter\n",
|
|||
|
" if (event.shiftKey && event.which === 13) {\n",
|
|||
|
" this.canvas_div.blur();\n",
|
|||
|
" // select the cell after this one\n",
|
|||
|
" var index = IPython.notebook.find_cell_index(this.cell_info[0]);\n",
|
|||
|
" IPython.notebook.select(index + 1);\n",
|
|||
|
" }\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_save = function (fig, _msg) {\n",
|
|||
|
" fig.ondownload(fig, null);\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.find_output_cell = function (html_output) {\n",
|
|||
|
" // Return the cell and output element which can be found *uniquely* in the notebook.\n",
|
|||
|
" // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n",
|
|||
|
" // IPython event is triggered only after the cells have been serialised, which for\n",
|
|||
|
" // our purposes (turning an active figure into a static one), is too late.\n",
|
|||
|
" var cells = IPython.notebook.get_cells();\n",
|
|||
|
" var ncells = cells.length;\n",
|
|||
|
" for (var i = 0; i < ncells; i++) {\n",
|
|||
|
" var cell = cells[i];\n",
|
|||
|
" if (cell.cell_type === 'code') {\n",
|
|||
|
" for (var j = 0; j < cell.output_area.outputs.length; j++) {\n",
|
|||
|
" var data = cell.output_area.outputs[j];\n",
|
|||
|
" if (data.data) {\n",
|
|||
|
" // IPython >= 3 moved mimebundle to data attribute of output\n",
|
|||
|
" data = data.data;\n",
|
|||
|
" }\n",
|
|||
|
" if (data['text/html'] === html_output) {\n",
|
|||
|
" return [cell, data, j];\n",
|
|||
|
" }\n",
|
|||
|
" }\n",
|
|||
|
" }\n",
|
|||
|
" }\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"// Register the function which deals with the matplotlib target/channel.\n",
|
|||
|
"// The kernel may be null if the page has been refreshed.\n",
|
|||
|
"if (IPython.notebook.kernel !== null) {\n",
|
|||
|
" IPython.notebook.kernel.comm_manager.register_target(\n",
|
|||
|
" 'matplotlib',\n",
|
|||
|
" mpl.mpl_figure_comm\n",
|
|||
|
" );\n",
|
|||
|
"}\n"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
"<IPython.core.display.Javascript object>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
},
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/html": [
|
|||
|
"<img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABQAAAAPACAYAAABq3NR5AAAgAElEQVR4XuzdB5QW1d0/8Itgxw5WNBpRsSsKWBBskRKNxl4SSywxiiUaW2KvRKOx9xoTu8ZoBAtYEIOAigVEURELqIi9K8jLnfcwsrALu/uUnZn9zPn/zxv2mbn3dz+/cc6Z75nnmRZTp23BRoAAAQIECBAgQIAAAQIECBAgQIBAIQVaCAAL2VeLIkCAAAECBAgQIECAAAECBAgQIJAICACdCAQIECBAgAABAgQIECBAgAABAgQKLCAALHBzLY0AAQIECBAgQIAAAQIECBAgQICAANA5QIAAAQIECBAgQIAAAQIECBAgQKDAAgLAAjfX0ggQIECAAAECBAgQIECAAAECBAgIAJ0DBAgQIECAAAECBAgQIECAAAECBAosIAAscHMtjQABAgQIECBAgAABAgQIECBAgIAA0DlAgAABAgQIECBAgAABAgQIECBAoMACAsACN9fSCBAgQIAAAQIECBAgQIAAAQIECAgAnQMECBAgQIAAAQIECBAgQIAAAQIECiwgACxwcy2NAAECBAgQIECAAAECBAgQIECAgADQOUCAAAECBAgQIECAAAECBAgQIECgwAICwAI319IIECBAgAABAgQIECBAgAABAgQICACdAwQIECBAgAABAgQIECBAgAABAgQKLCAALHBzLY0AAQIECBAgQIAAAQIECBAgQICAANA5QIAAAQIECBAgQIAAAQIECBAgQKDAAgLAAjfX0ggQIECAAAECBAgQIECAAAECBAgIAJ0DBAgQIECAAAECBAgQIECAAAECBAosIAAscHMtjQABAgQIECBAgAABAgQIECBAgIAA0DlAgAABAgQIECBAgAABAgQIECBAoMACAsACN9fSCBAgQIAAAQIECBAgQIAAAQIECAgAnQMECBAgQIAAAQIECBAgQIAAAQIECiwgACxwcy2NAAECBAgQIECAAAECBAgQIECAgADQOUCAAAECBAgQIECAAAECBAgQIECgwAICwAI319IIECBAgAABAgQIECBAgAABAgQICACdAwQIECBAgAABAgQIECBAgAABAgQKLCAALHBzLY0AAQIECBAgQIAAAQIECBAgQICAANA5QIAAAQIECBAgQIAAAQIECBAgQKDAAgLAAjfX0ggQIECAAAECBAgQIECAAAECBAgIAJ0DBAgQIECAAAECBAgQIECAAAECBAosIAAscHMtjQABAgQIECBAgAABAgQIECBAgIAA0DlAgAABAgQIECBAgAABAgQIECBAoMACAsACN9fSCBAgQIAAAQIECBAgQIAAAQIECAgAnQMECBAgQIAAAQIECBAgQIAAAQIECiwgACxwcy2NAAECBAgQIECAAAECBAgQIECAgADQOUCAAAECBAgQIECAAAECBAgQIECgwAICwAI319IIECBAgAABAgQIECBAgAABAgQICACdAwQIECBAgAABAgQIECBAgAABAgQKLCAALHBzLY0AAQIECBAgQIAAAQIECBAgQICAANA5QIAAAQIECBAgQIAAAQIECBAgQKDAAgLAAjfX0ggQIECAAAECBAgQIECAAAECBAgIAJ0DBAgQIECAAAECBAgQIECAAAECBAosIAAscHMtjQABAgQIECBAgAABAgQIECBAgIAA0DlAgAABAgQIECBAgAABAgQIECBAoMACAsACN9fSCBAgQIAAAQIECBAgQIAAAQIECAgAnQMECBAgQIAAAQIECBAgQIAAAQIECiwgACxwcy2NAAECBAgQIECAAAECBAgQIECAgADQOUCAAAECBAgQIECAAAECBAgQIECgwAICwAI319IIECBAgAABAgQIECBAgAABAgQICACdAwQIECBAgAABAgQIECBAgAABAgQKLCAALHBzLY0AAQIECBAgQIAAAQIECBAgQICAANA5QIAAAQIECBAgQIAAAQIECBAgQKDAAgLAAjfX0ggQIECAAAECBAgQIECAAAECBAgIAJ0DBAgQIECAAAECBAgQIECAAAECBAosIAAscHMtjQABAgQIECBAgAABAgQIECBAgIAA0DlAgAABAgQIECBAgAABAgQIECBAoMACAsACN9fSCBAgQIAAAQIECBAgQIAAAQIECAgAnQMECBAgQIAAAQIECBAgQIAAAQIECiwgACxwcy2NAAECBAgQIECAAAECBAgQIECAgADQOUCAAAECBAgQIECAAAECBAgQIECgwAICwAI319IIECBAgAABAgQIECBAgAABAgQICACdAwQIECBAgAABAgQIECBAgAABAgQKLCAALHBzLY0AAQIECBAgQIAAAQIECBAgQICAANA5QIAAAQIECBAgQIAAAQIECBAgQKDAAgLAAjfX0ggQIECAAAECBAgQIECAAAECBAgIAJ0DBAgQIECAAAECBAgQIECAAAECBAosIAAscHMtjQABAgQIECBAgAABAgQIECBAgIAA0DlAgAABAgQIECBAgAABAgQIECBAoMACAsACN9fSCBAgQIAAAQIECBAgQIAAAQIECAgAnQMECBAgQIAAAQIECBAgQIAAAQIECiwgACxwcy2NAAECBAgQIECAAAECBAgQIECAgADQOUCAAAECBAgQIECAAAECBAgQIECgwAICwAI319IIECBAgAABAgQIECBAgAABAgQICACdAwQIECBAgAABAgQIECBAgAABAgQKLCAALHBzLY0AAQIECBAgQIAAAQIECBAgQICAANA5QIAAAQIECBAgQIAAAQIECBAgQKDAAgLAAjfX0ggQIECAAAECBAgQIECAAAECBAgIAJ0DBAgQIECAAAECBAgQIECAAAECBAosIAAscHMtjQABAgQIECBAgAABAgQIECBAgIAA0DlAgAABAgQIECBAgAABAgQIECBAoMACAsACN9fSCBAgQIAAAQIECBAgQIAAAQIECAgAnQMECBAgQIAAAQIECBAgQIAAAQIECiwgACxwcy2NAAECBAgQIECAAAECBAgQIECAgADQOUCAAAECBAgQIECAAAECBAgQIECgwAICwAI319IIECBAgAABAgQIECBAgAABAgQICACdAwQIECBAgAABAgQIECBAgAABAgQKLCAALHBzLY0AAQIECBAgQIAAAQIECBAgQICAANA5QIAAAQIECBAgQIAAAQIECBAgQKDAAgLAAjfX0ggQIECAAAECBAgQIECAAAECBAgIAJ0DBAgQIECAAAECBAgQIECAAAECBAosIAAscHMtjQABAgQIECBAgAABAgQIECBAgIAA0DlAgAABAgQIECBAgAABAgQIECBAoMACAsACN9fSCBAgQIAAAQIECBAgQIAAAQIECAgAnQMECBAgQIAAAQIECBAgQIAAAQIECiwgACxwcy2NAAECBAgQIECAAAECBAgQIECAgADQOUCAAAECBAgQIECAAAECBAgQIECgwAICwAI319IIECBAgAABAgQIECBAgAABAgQICACdAwQIECBAgAABAgQIECBAgAABAgQKLCAALHBzLY0AAQIECBAgQIAAAQIECBAgQICAANA5QIAAAQIECBAgQIAAAQIECBAgQKDAAgLAAjfX0ggQIECAAAECBAgQIECAAAECBAgIAJ0DBAgQIECAAAECBAgQIECAAAECBAosIAAscHMtjQABAgQIECBAgAABAgQIECBAgIAA0DlAgAABAgQIECBAgAABAgQIECBAoMACAsACN9fSCBAgQIAAAQIECBAgQIAAAQIECAgAnQMECBAgQIAAAQIECBAgQIAAAQIECiwgACxwcy2NAAECBAgQIECAAAECBAgQIECAgADQOUCAAAECBAgQIECAAAECBAgQIECgwAICwAI319IIECBAgAABAgQIECBAgAABAgQICACdAwQIECBAgAABAgQIECBAgAABAgQKLCAALHBzLY0AAQIECBAgQIAAAQIECBAgQICAANA5QIAAAQIECBAgQIAAAQIECBAgQKDAAgLAAjc3y0v79ttvw0svvZSU2LZt29CqVassl6s2AgQIECBAgAABAgQIEC
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
"<IPython.core.display.HTML object>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"%matplotlib notebook\n",
|
|||
|
"y = posts.sort_values(by='likes')['likes'].cumsum()\n",
|
|||
|
"plt.plot(y.reset_index(drop=True))\n",
|
|||
|
"plt.show()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 8,
|
|||
|
"id": "1b9264f4",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"0.34267927903861023"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 8,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"np.sum(posts['likes'] == 0) / posts.shape[0]"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 9,
|
|||
|
"id": "6744b53f",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"0.6709449969440499"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 9,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"np.sum(posts['likes'] <= 1) / posts.shape[0]"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "187f935d",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"Likes per account"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 10,
|
|||
|
"id": "e9b4f141",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/html": [
|
|||
|
"<div>\n",
|
|||
|
"<style scoped>\n",
|
|||
|
" .dataframe tbody tr th:only-of-type {\n",
|
|||
|
" vertical-align: middle;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" .dataframe tbody tr th {\n",
|
|||
|
" vertical-align: top;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" .dataframe thead th {\n",
|
|||
|
" text-align: right;\n",
|
|||
|
" }\n",
|
|||
|
"</style>\n",
|
|||
|
"<table border=\"1\" class=\"dataframe\">\n",
|
|||
|
" <thead>\n",
|
|||
|
" <tr style=\"text-align: right;\">\n",
|
|||
|
" <th></th>\n",
|
|||
|
" <th>account</th>\n",
|
|||
|
" </tr>\n",
|
|||
|
" </thead>\n",
|
|||
|
" <tbody>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>0</th>\n",
|
|||
|
" <td>did:plc:lsmyaz23a3i3r75qki423npq</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>1</th>\n",
|
|||
|
" <td>did:plc:wd5brnxbsbcexgmvnkenkfm3</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>2</th>\n",
|
|||
|
" <td>did:plc:kdqmfumjc75chgkf7npqw5hz</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>3</th>\n",
|
|||
|
" <td>did:plc:pcdqvg6ox7mp67s4wowpqmiu</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>4</th>\n",
|
|||
|
" <td>did:plc:dmmive6fhnvwl5clkhv4tpbc</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>...</th>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>91071</th>\n",
|
|||
|
" <td>did:plc:tru4524pbky2wgxuf37oat6d</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>91072</th>\n",
|
|||
|
" <td>did:plc:7w4gxtfhm5twmuddq2bdgdkn</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>91073</th>\n",
|
|||
|
" <td>did:plc:kwitm3p4rrv5tfy4hx2ayrzb</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>91074</th>\n",
|
|||
|
" <td>did:plc:tjqi5lvhbzfs22x2fivei2kk</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>91075</th>\n",
|
|||
|
" <td>did:plc:3dsgnxr4tjubb437zrwlmyox</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" </tbody>\n",
|
|||
|
"</table>\n",
|
|||
|
"<p>91076 rows × 1 columns</p>\n",
|
|||
|
"</div>"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
" account\n",
|
|||
|
"0 did:plc:lsmyaz23a3i3r75qki423npq\n",
|
|||
|
"1 did:plc:wd5brnxbsbcexgmvnkenkfm3\n",
|
|||
|
"2 did:plc:kdqmfumjc75chgkf7npqw5hz\n",
|
|||
|
"3 did:plc:pcdqvg6ox7mp67s4wowpqmiu\n",
|
|||
|
"4 did:plc:dmmive6fhnvwl5clkhv4tpbc\n",
|
|||
|
"... ...\n",
|
|||
|
"91071 did:plc:tru4524pbky2wgxuf37oat6d\n",
|
|||
|
"91072 did:plc:7w4gxtfhm5twmuddq2bdgdkn\n",
|
|||
|
"91073 did:plc:kwitm3p4rrv5tfy4hx2ayrzb\n",
|
|||
|
"91074 did:plc:tjqi5lvhbzfs22x2fivei2kk\n",
|
|||
|
"91075 did:plc:3dsgnxr4tjubb437zrwlmyox\n",
|
|||
|
"\n",
|
|||
|
"[91076 rows x 1 columns]"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 10,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"accounts = pd.concat([likes['subjectDid'], likes['authorDid'], posts['authorDid']])\n",
|
|||
|
"\n",
|
|||
|
"accounts = pd.DataFrame({'account': accounts.unique()})\n",
|
|||
|
"\n",
|
|||
|
"accounts"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 11,
|
|||
|
"id": "05c7fe61",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/html": [
|
|||
|
"<div>\n",
|
|||
|
"<style scoped>\n",
|
|||
|
" .dataframe tbody tr th:only-of-type {\n",
|
|||
|
" vertical-align: middle;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" .dataframe tbody tr th {\n",
|
|||
|
" vertical-align: top;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" .dataframe thead th {\n",
|
|||
|
" text-align: right;\n",
|
|||
|
" }\n",
|
|||
|
"</style>\n",
|
|||
|
"<table border=\"1\" class=\"dataframe\">\n",
|
|||
|
" <thead>\n",
|
|||
|
" <tr style=\"text-align: right;\">\n",
|
|||
|
" <th></th>\n",
|
|||
|
" <th>account</th>\n",
|
|||
|
" <th>likes</th>\n",
|
|||
|
" </tr>\n",
|
|||
|
" </thead>\n",
|
|||
|
" <tbody>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>0</th>\n",
|
|||
|
" <td>did:plc:222ocxmd3qfo5pn7juncj5ds</td>\n",
|
|||
|
" <td>5</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>1</th>\n",
|
|||
|
" <td>did:plc:222p42fegwhwfyrc3gqam76j</td>\n",
|
|||
|
" <td>10</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>2</th>\n",
|
|||
|
" <td>did:plc:222rnvnta2lbl364bog2plxw</td>\n",
|
|||
|
" <td>5</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>3</th>\n",
|
|||
|
" <td>did:plc:223bx4usklxh4ub66jh6kdwa</td>\n",
|
|||
|
" <td>2</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>4</th>\n",
|
|||
|
" <td>did:plc:223lngzlhynd26g772d4fwsc</td>\n",
|
|||
|
" <td>1</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>...</th>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>54217</th>\n",
|
|||
|
" <td>did:plc:zzxhygmujxo3k64ailvouiti</td>\n",
|
|||
|
" <td>5</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>54218</th>\n",
|
|||
|
" <td>did:plc:zzxwledpqf7ob7svaf675k4c</td>\n",
|
|||
|
" <td>3</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>54219</th>\n",
|
|||
|
" <td>did:plc:zzza7zo2lho4etts27epjgpc</td>\n",
|
|||
|
" <td>3</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>54220</th>\n",
|
|||
|
" <td>did:plc:zzzfnodmpmaqmyugvi77j7bi</td>\n",
|
|||
|
" <td>5</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>54221</th>\n",
|
|||
|
" <td>did:plc:zzzjyeyecqee2ejfgxxobm7e</td>\n",
|
|||
|
" <td>4</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" </tbody>\n",
|
|||
|
"</table>\n",
|
|||
|
"<p>54222 rows × 2 columns</p>\n",
|
|||
|
"</div>"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
" account likes\n",
|
|||
|
"0 did:plc:222ocxmd3qfo5pn7juncj5ds 5\n",
|
|||
|
"1 did:plc:222p42fegwhwfyrc3gqam76j 10\n",
|
|||
|
"2 did:plc:222rnvnta2lbl364bog2plxw 5\n",
|
|||
|
"3 did:plc:223bx4usklxh4ub66jh6kdwa 2\n",
|
|||
|
"4 did:plc:223lngzlhynd26g772d4fwsc 1\n",
|
|||
|
"... ... ...\n",
|
|||
|
"54217 did:plc:zzxhygmujxo3k64ailvouiti 5\n",
|
|||
|
"54218 did:plc:zzxwledpqf7ob7svaf675k4c 3\n",
|
|||
|
"54219 did:plc:zzza7zo2lho4etts27epjgpc 3\n",
|
|||
|
"54220 did:plc:zzzfnodmpmaqmyugvi77j7bi 5\n",
|
|||
|
"54221 did:plc:zzzjyeyecqee2ejfgxxobm7e 4\n",
|
|||
|
"\n",
|
|||
|
"[54222 rows x 2 columns]"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 11,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"account_likes = likes.groupby('subjectDid'\n",
|
|||
|
" ).agg(likes=('uri', 'count')\n",
|
|||
|
" ).reset_index(\n",
|
|||
|
" ).rename(columns={'subjectDid':'account'})\n",
|
|||
|
"account_likes"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 12,
|
|||
|
"id": "956aa546",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"accounts = accounts.merge(account_likes, left_on='account', right_on='account', how='left')\n",
|
|||
|
"accounts.loc[accounts['likes'].isna(), 'likes'] = 0"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 13,
|
|||
|
"id": "152aa08c",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"application/javascript": [
|
|||
|
"/* Put everything inside the global mpl namespace */\n",
|
|||
|
"/* global mpl */\n",
|
|||
|
"window.mpl = {};\n",
|
|||
|
"\n",
|
|||
|
"mpl.get_websocket_type = function () {\n",
|
|||
|
" if (typeof WebSocket !== 'undefined') {\n",
|
|||
|
" return WebSocket;\n",
|
|||
|
" } else if (typeof MozWebSocket !== 'undefined') {\n",
|
|||
|
" return MozWebSocket;\n",
|
|||
|
" } else {\n",
|
|||
|
" alert(\n",
|
|||
|
" 'Your browser does not have WebSocket support. ' +\n",
|
|||
|
" 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n",
|
|||
|
" 'Firefox 4 and 5 are also supported but you ' +\n",
|
|||
|
" 'have to enable WebSockets in about:config.'\n",
|
|||
|
" );\n",
|
|||
|
" }\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure = function (figure_id, websocket, ondownload, parent_element) {\n",
|
|||
|
" this.id = figure_id;\n",
|
|||
|
"\n",
|
|||
|
" this.ws = websocket;\n",
|
|||
|
"\n",
|
|||
|
" this.supports_binary = this.ws.binaryType !== undefined;\n",
|
|||
|
"\n",
|
|||
|
" if (!this.supports_binary) {\n",
|
|||
|
" var warnings = document.getElementById('mpl-warnings');\n",
|
|||
|
" if (warnings) {\n",
|
|||
|
" warnings.style.display = 'block';\n",
|
|||
|
" warnings.textContent =\n",
|
|||
|
" 'This browser does not support binary websocket messages. ' +\n",
|
|||
|
" 'Performance may be slow.';\n",
|
|||
|
" }\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" this.imageObj = new Image();\n",
|
|||
|
"\n",
|
|||
|
" this.context = undefined;\n",
|
|||
|
" this.message = undefined;\n",
|
|||
|
" this.canvas = undefined;\n",
|
|||
|
" this.rubberband_canvas = undefined;\n",
|
|||
|
" this.rubberband_context = undefined;\n",
|
|||
|
" this.format_dropdown = undefined;\n",
|
|||
|
"\n",
|
|||
|
" this.image_mode = 'full';\n",
|
|||
|
"\n",
|
|||
|
" this.root = document.createElement('div');\n",
|
|||
|
" this.root.setAttribute('style', 'display: inline-block');\n",
|
|||
|
" this._root_extra_style(this.root);\n",
|
|||
|
"\n",
|
|||
|
" parent_element.appendChild(this.root);\n",
|
|||
|
"\n",
|
|||
|
" this._init_header(this);\n",
|
|||
|
" this._init_canvas(this);\n",
|
|||
|
" this._init_toolbar(this);\n",
|
|||
|
"\n",
|
|||
|
" var fig = this;\n",
|
|||
|
"\n",
|
|||
|
" this.waiting = false;\n",
|
|||
|
"\n",
|
|||
|
" this.ws.onopen = function () {\n",
|
|||
|
" fig.send_message('supports_binary', { value: fig.supports_binary });\n",
|
|||
|
" fig.send_message('send_image_mode', {});\n",
|
|||
|
" if (fig.ratio !== 1) {\n",
|
|||
|
" fig.send_message('set_device_pixel_ratio', {\n",
|
|||
|
" device_pixel_ratio: fig.ratio,\n",
|
|||
|
" });\n",
|
|||
|
" }\n",
|
|||
|
" fig.send_message('refresh', {});\n",
|
|||
|
" };\n",
|
|||
|
"\n",
|
|||
|
" this.imageObj.onload = function () {\n",
|
|||
|
" if (fig.image_mode === 'full') {\n",
|
|||
|
" // Full images could contain transparency (where diff images\n",
|
|||
|
" // almost always do), so we need to clear the canvas so that\n",
|
|||
|
" // there is no ghosting.\n",
|
|||
|
" fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n",
|
|||
|
" }\n",
|
|||
|
" fig.context.drawImage(fig.imageObj, 0, 0);\n",
|
|||
|
" };\n",
|
|||
|
"\n",
|
|||
|
" this.imageObj.onunload = function () {\n",
|
|||
|
" fig.ws.close();\n",
|
|||
|
" };\n",
|
|||
|
"\n",
|
|||
|
" this.ws.onmessage = this._make_on_message_function(this);\n",
|
|||
|
"\n",
|
|||
|
" this.ondownload = ondownload;\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._init_header = function () {\n",
|
|||
|
" var titlebar = document.createElement('div');\n",
|
|||
|
" titlebar.classList =\n",
|
|||
|
" 'ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix';\n",
|
|||
|
" var titletext = document.createElement('div');\n",
|
|||
|
" titletext.classList = 'ui-dialog-title';\n",
|
|||
|
" titletext.setAttribute(\n",
|
|||
|
" 'style',\n",
|
|||
|
" 'width: 100%; text-align: center; padding: 3px;'\n",
|
|||
|
" );\n",
|
|||
|
" titlebar.appendChild(titletext);\n",
|
|||
|
" this.root.appendChild(titlebar);\n",
|
|||
|
" this.header = titletext;\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._canvas_extra_style = function (_canvas_div) {};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._root_extra_style = function (_canvas_div) {};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._init_canvas = function () {\n",
|
|||
|
" var fig = this;\n",
|
|||
|
"\n",
|
|||
|
" var canvas_div = (this.canvas_div = document.createElement('div'));\n",
|
|||
|
" canvas_div.setAttribute(\n",
|
|||
|
" 'style',\n",
|
|||
|
" 'border: 1px solid #ddd;' +\n",
|
|||
|
" 'box-sizing: content-box;' +\n",
|
|||
|
" 'clear: both;' +\n",
|
|||
|
" 'min-height: 1px;' +\n",
|
|||
|
" 'min-width: 1px;' +\n",
|
|||
|
" 'outline: 0;' +\n",
|
|||
|
" 'overflow: hidden;' +\n",
|
|||
|
" 'position: relative;' +\n",
|
|||
|
" 'resize: both;'\n",
|
|||
|
" );\n",
|
|||
|
"\n",
|
|||
|
" function on_keyboard_event_closure(name) {\n",
|
|||
|
" return function (event) {\n",
|
|||
|
" return fig.key_event(event, name);\n",
|
|||
|
" };\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" canvas_div.addEventListener(\n",
|
|||
|
" 'keydown',\n",
|
|||
|
" on_keyboard_event_closure('key_press')\n",
|
|||
|
" );\n",
|
|||
|
" canvas_div.addEventListener(\n",
|
|||
|
" 'keyup',\n",
|
|||
|
" on_keyboard_event_closure('key_release')\n",
|
|||
|
" );\n",
|
|||
|
"\n",
|
|||
|
" this._canvas_extra_style(canvas_div);\n",
|
|||
|
" this.root.appendChild(canvas_div);\n",
|
|||
|
"\n",
|
|||
|
" var canvas = (this.canvas = document.createElement('canvas'));\n",
|
|||
|
" canvas.classList.add('mpl-canvas');\n",
|
|||
|
" canvas.setAttribute('style', 'box-sizing: content-box;');\n",
|
|||
|
"\n",
|
|||
|
" this.context = canvas.getContext('2d');\n",
|
|||
|
"\n",
|
|||
|
" var backingStore =\n",
|
|||
|
" this.context.backingStorePixelRatio ||\n",
|
|||
|
" this.context.webkitBackingStorePixelRatio ||\n",
|
|||
|
" this.context.mozBackingStorePixelRatio ||\n",
|
|||
|
" this.context.msBackingStorePixelRatio ||\n",
|
|||
|
" this.context.oBackingStorePixelRatio ||\n",
|
|||
|
" this.context.backingStorePixelRatio ||\n",
|
|||
|
" 1;\n",
|
|||
|
"\n",
|
|||
|
" this.ratio = (window.devicePixelRatio || 1) / backingStore;\n",
|
|||
|
"\n",
|
|||
|
" var rubberband_canvas = (this.rubberband_canvas = document.createElement(\n",
|
|||
|
" 'canvas'\n",
|
|||
|
" ));\n",
|
|||
|
" rubberband_canvas.setAttribute(\n",
|
|||
|
" 'style',\n",
|
|||
|
" 'box-sizing: content-box; position: absolute; left: 0; top: 0; z-index: 1;'\n",
|
|||
|
" );\n",
|
|||
|
"\n",
|
|||
|
" // Apply a ponyfill if ResizeObserver is not implemented by browser.\n",
|
|||
|
" if (this.ResizeObserver === undefined) {\n",
|
|||
|
" if (window.ResizeObserver !== undefined) {\n",
|
|||
|
" this.ResizeObserver = window.ResizeObserver;\n",
|
|||
|
" } else {\n",
|
|||
|
" var obs = _JSXTOOLS_RESIZE_OBSERVER({});\n",
|
|||
|
" this.ResizeObserver = obs.ResizeObserver;\n",
|
|||
|
" }\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" this.resizeObserverInstance = new this.ResizeObserver(function (entries) {\n",
|
|||
|
" var nentries = entries.length;\n",
|
|||
|
" for (var i = 0; i < nentries; i++) {\n",
|
|||
|
" var entry = entries[i];\n",
|
|||
|
" var width, height;\n",
|
|||
|
" if (entry.contentBoxSize) {\n",
|
|||
|
" if (entry.contentBoxSize instanceof Array) {\n",
|
|||
|
" // Chrome 84 implements new version of spec.\n",
|
|||
|
" width = entry.contentBoxSize[0].inlineSize;\n",
|
|||
|
" height = entry.contentBoxSize[0].blockSize;\n",
|
|||
|
" } else {\n",
|
|||
|
" // Firefox implements old version of spec.\n",
|
|||
|
" width = entry.contentBoxSize.inlineSize;\n",
|
|||
|
" height = entry.contentBoxSize.blockSize;\n",
|
|||
|
" }\n",
|
|||
|
" } else {\n",
|
|||
|
" // Chrome <84 implements even older version of spec.\n",
|
|||
|
" width = entry.contentRect.width;\n",
|
|||
|
" height = entry.contentRect.height;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" // Keep the size of the canvas and rubber band canvas in sync with\n",
|
|||
|
" // the canvas container.\n",
|
|||
|
" if (entry.devicePixelContentBoxSize) {\n",
|
|||
|
" // Chrome 84 implements new version of spec.\n",
|
|||
|
" canvas.setAttribute(\n",
|
|||
|
" 'width',\n",
|
|||
|
" entry.devicePixelContentBoxSize[0].inlineSize\n",
|
|||
|
" );\n",
|
|||
|
" canvas.setAttribute(\n",
|
|||
|
" 'height',\n",
|
|||
|
" entry.devicePixelContentBoxSize[0].blockSize\n",
|
|||
|
" );\n",
|
|||
|
" } else {\n",
|
|||
|
" canvas.setAttribute('width', width * fig.ratio);\n",
|
|||
|
" canvas.setAttribute('height', height * fig.ratio);\n",
|
|||
|
" }\n",
|
|||
|
" canvas.setAttribute(\n",
|
|||
|
" 'style',\n",
|
|||
|
" 'width: ' + width + 'px; height: ' + height + 'px;'\n",
|
|||
|
" );\n",
|
|||
|
"\n",
|
|||
|
" rubberband_canvas.setAttribute('width', width);\n",
|
|||
|
" rubberband_canvas.setAttribute('height', height);\n",
|
|||
|
"\n",
|
|||
|
" // And update the size in Python. We ignore the initial 0/0 size\n",
|
|||
|
" // that occurs as the element is placed into the DOM, which should\n",
|
|||
|
" // otherwise not happen due to the minimum size styling.\n",
|
|||
|
" if (fig.ws.readyState == 1 && width != 0 && height != 0) {\n",
|
|||
|
" fig.request_resize(width, height);\n",
|
|||
|
" }\n",
|
|||
|
" }\n",
|
|||
|
" });\n",
|
|||
|
" this.resizeObserverInstance.observe(canvas_div);\n",
|
|||
|
"\n",
|
|||
|
" function on_mouse_event_closure(name) {\n",
|
|||
|
" return function (event) {\n",
|
|||
|
" return fig.mouse_event(event, name);\n",
|
|||
|
" };\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" rubberband_canvas.addEventListener(\n",
|
|||
|
" 'mousedown',\n",
|
|||
|
" on_mouse_event_closure('button_press')\n",
|
|||
|
" );\n",
|
|||
|
" rubberband_canvas.addEventListener(\n",
|
|||
|
" 'mouseup',\n",
|
|||
|
" on_mouse_event_closure('button_release')\n",
|
|||
|
" );\n",
|
|||
|
" rubberband_canvas.addEventListener(\n",
|
|||
|
" 'dblclick',\n",
|
|||
|
" on_mouse_event_closure('dblclick')\n",
|
|||
|
" );\n",
|
|||
|
" // Throttle sequential mouse events to 1 every 20ms.\n",
|
|||
|
" rubberband_canvas.addEventListener(\n",
|
|||
|
" 'mousemove',\n",
|
|||
|
" on_mouse_event_closure('motion_notify')\n",
|
|||
|
" );\n",
|
|||
|
"\n",
|
|||
|
" rubberband_canvas.addEventListener(\n",
|
|||
|
" 'mouseenter',\n",
|
|||
|
" on_mouse_event_closure('figure_enter')\n",
|
|||
|
" );\n",
|
|||
|
" rubberband_canvas.addEventListener(\n",
|
|||
|
" 'mouseleave',\n",
|
|||
|
" on_mouse_event_closure('figure_leave')\n",
|
|||
|
" );\n",
|
|||
|
"\n",
|
|||
|
" canvas_div.addEventListener('wheel', function (event) {\n",
|
|||
|
" if (event.deltaY < 0) {\n",
|
|||
|
" event.step = 1;\n",
|
|||
|
" } else {\n",
|
|||
|
" event.step = -1;\n",
|
|||
|
" }\n",
|
|||
|
" on_mouse_event_closure('scroll')(event);\n",
|
|||
|
" });\n",
|
|||
|
"\n",
|
|||
|
" canvas_div.appendChild(canvas);\n",
|
|||
|
" canvas_div.appendChild(rubberband_canvas);\n",
|
|||
|
"\n",
|
|||
|
" this.rubberband_context = rubberband_canvas.getContext('2d');\n",
|
|||
|
" this.rubberband_context.strokeStyle = '#000000';\n",
|
|||
|
"\n",
|
|||
|
" this._resize_canvas = function (width, height, forward) {\n",
|
|||
|
" if (forward) {\n",
|
|||
|
" canvas_div.style.width = width + 'px';\n",
|
|||
|
" canvas_div.style.height = height + 'px';\n",
|
|||
|
" }\n",
|
|||
|
" };\n",
|
|||
|
"\n",
|
|||
|
" // Disable right mouse context menu.\n",
|
|||
|
" this.rubberband_canvas.addEventListener('contextmenu', function (_e) {\n",
|
|||
|
" event.preventDefault();\n",
|
|||
|
" return false;\n",
|
|||
|
" });\n",
|
|||
|
"\n",
|
|||
|
" function set_focus() {\n",
|
|||
|
" canvas.focus();\n",
|
|||
|
" canvas_div.focus();\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" window.setTimeout(set_focus, 100);\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._init_toolbar = function () {\n",
|
|||
|
" var fig = this;\n",
|
|||
|
"\n",
|
|||
|
" var toolbar = document.createElement('div');\n",
|
|||
|
" toolbar.classList = 'mpl-toolbar';\n",
|
|||
|
" this.root.appendChild(toolbar);\n",
|
|||
|
"\n",
|
|||
|
" function on_click_closure(name) {\n",
|
|||
|
" return function (_event) {\n",
|
|||
|
" return fig.toolbar_button_onclick(name);\n",
|
|||
|
" };\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" function on_mouseover_closure(tooltip) {\n",
|
|||
|
" return function (event) {\n",
|
|||
|
" if (!event.currentTarget.disabled) {\n",
|
|||
|
" return fig.toolbar_button_onmouseover(tooltip);\n",
|
|||
|
" }\n",
|
|||
|
" };\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" fig.buttons = {};\n",
|
|||
|
" var buttonGroup = document.createElement('div');\n",
|
|||
|
" buttonGroup.classList = 'mpl-button-group';\n",
|
|||
|
" for (var toolbar_ind in mpl.toolbar_items) {\n",
|
|||
|
" var name = mpl.toolbar_items[toolbar_ind][0];\n",
|
|||
|
" var tooltip = mpl.toolbar_items[toolbar_ind][1];\n",
|
|||
|
" var image = mpl.toolbar_items[toolbar_ind][2];\n",
|
|||
|
" var method_name = mpl.toolbar_items[toolbar_ind][3];\n",
|
|||
|
"\n",
|
|||
|
" if (!name) {\n",
|
|||
|
" /* Instead of a spacer, we start a new button group. */\n",
|
|||
|
" if (buttonGroup.hasChildNodes()) {\n",
|
|||
|
" toolbar.appendChild(buttonGroup);\n",
|
|||
|
" }\n",
|
|||
|
" buttonGroup = document.createElement('div');\n",
|
|||
|
" buttonGroup.classList = 'mpl-button-group';\n",
|
|||
|
" continue;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" var button = (fig.buttons[name] = document.createElement('button'));\n",
|
|||
|
" button.classList = 'mpl-widget';\n",
|
|||
|
" button.setAttribute('role', 'button');\n",
|
|||
|
" button.setAttribute('aria-disabled', 'false');\n",
|
|||
|
" button.addEventListener('click', on_click_closure(method_name));\n",
|
|||
|
" button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n",
|
|||
|
"\n",
|
|||
|
" var icon_img = document.createElement('img');\n",
|
|||
|
" icon_img.src = '_images/' + image + '.png';\n",
|
|||
|
" icon_img.srcset = '_images/' + image + '_large.png 2x';\n",
|
|||
|
" icon_img.alt = tooltip;\n",
|
|||
|
" button.appendChild(icon_img);\n",
|
|||
|
"\n",
|
|||
|
" buttonGroup.appendChild(button);\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" if (buttonGroup.hasChildNodes()) {\n",
|
|||
|
" toolbar.appendChild(buttonGroup);\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" var fmt_picker = document.createElement('select');\n",
|
|||
|
" fmt_picker.classList = 'mpl-widget';\n",
|
|||
|
" toolbar.appendChild(fmt_picker);\n",
|
|||
|
" this.format_dropdown = fmt_picker;\n",
|
|||
|
"\n",
|
|||
|
" for (var ind in mpl.extensions) {\n",
|
|||
|
" var fmt = mpl.extensions[ind];\n",
|
|||
|
" var option = document.createElement('option');\n",
|
|||
|
" option.selected = fmt === mpl.default_extension;\n",
|
|||
|
" option.innerHTML = fmt;\n",
|
|||
|
" fmt_picker.appendChild(option);\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" var status_bar = document.createElement('span');\n",
|
|||
|
" status_bar.classList = 'mpl-message';\n",
|
|||
|
" toolbar.appendChild(status_bar);\n",
|
|||
|
" this.message = status_bar;\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.request_resize = function (x_pixels, y_pixels) {\n",
|
|||
|
" // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,\n",
|
|||
|
" // which will in turn request a refresh of the image.\n",
|
|||
|
" this.send_message('resize', { width: x_pixels, height: y_pixels });\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.send_message = function (type, properties) {\n",
|
|||
|
" properties['type'] = type;\n",
|
|||
|
" properties['figure_id'] = this.id;\n",
|
|||
|
" this.ws.send(JSON.stringify(properties));\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.send_draw_message = function () {\n",
|
|||
|
" if (!this.waiting) {\n",
|
|||
|
" this.waiting = true;\n",
|
|||
|
" this.ws.send(JSON.stringify({ type: 'draw', figure_id: this.id }));\n",
|
|||
|
" }\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_save = function (fig, _msg) {\n",
|
|||
|
" var format_dropdown = fig.format_dropdown;\n",
|
|||
|
" var format = format_dropdown.options[format_dropdown.selectedIndex].value;\n",
|
|||
|
" fig.ondownload(fig, format);\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_resize = function (fig, msg) {\n",
|
|||
|
" var size = msg['size'];\n",
|
|||
|
" if (size[0] !== fig.canvas.width || size[1] !== fig.canvas.height) {\n",
|
|||
|
" fig._resize_canvas(size[0], size[1], msg['forward']);\n",
|
|||
|
" fig.send_message('refresh', {});\n",
|
|||
|
" }\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_rubberband = function (fig, msg) {\n",
|
|||
|
" var x0 = msg['x0'] / fig.ratio;\n",
|
|||
|
" var y0 = (fig.canvas.height - msg['y0']) / fig.ratio;\n",
|
|||
|
" var x1 = msg['x1'] / fig.ratio;\n",
|
|||
|
" var y1 = (fig.canvas.height - msg['y1']) / fig.ratio;\n",
|
|||
|
" x0 = Math.floor(x0) + 0.5;\n",
|
|||
|
" y0 = Math.floor(y0) + 0.5;\n",
|
|||
|
" x1 = Math.floor(x1) + 0.5;\n",
|
|||
|
" y1 = Math.floor(y1) + 0.5;\n",
|
|||
|
" var min_x = Math.min(x0, x1);\n",
|
|||
|
" var min_y = Math.min(y0, y1);\n",
|
|||
|
" var width = Math.abs(x1 - x0);\n",
|
|||
|
" var height = Math.abs(y1 - y0);\n",
|
|||
|
"\n",
|
|||
|
" fig.rubberband_context.clearRect(\n",
|
|||
|
" 0,\n",
|
|||
|
" 0,\n",
|
|||
|
" fig.canvas.width / fig.ratio,\n",
|
|||
|
" fig.canvas.height / fig.ratio\n",
|
|||
|
" );\n",
|
|||
|
"\n",
|
|||
|
" fig.rubberband_context.strokeRect(min_x, min_y, width, height);\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_figure_label = function (fig, msg) {\n",
|
|||
|
" // Updates the figure title.\n",
|
|||
|
" fig.header.textContent = msg['label'];\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_cursor = function (fig, msg) {\n",
|
|||
|
" fig.rubberband_canvas.style.cursor = msg['cursor'];\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_message = function (fig, msg) {\n",
|
|||
|
" fig.message.textContent = msg['message'];\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_draw = function (fig, _msg) {\n",
|
|||
|
" // Request the server to send over a new figure.\n",
|
|||
|
" fig.send_draw_message();\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_image_mode = function (fig, msg) {\n",
|
|||
|
" fig.image_mode = msg['mode'];\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_history_buttons = function (fig, msg) {\n",
|
|||
|
" for (var key in msg) {\n",
|
|||
|
" if (!(key in fig.buttons)) {\n",
|
|||
|
" continue;\n",
|
|||
|
" }\n",
|
|||
|
" fig.buttons[key].disabled = !msg[key];\n",
|
|||
|
" fig.buttons[key].setAttribute('aria-disabled', !msg[key]);\n",
|
|||
|
" }\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_navigate_mode = function (fig, msg) {\n",
|
|||
|
" if (msg['mode'] === 'PAN') {\n",
|
|||
|
" fig.buttons['Pan'].classList.add('active');\n",
|
|||
|
" fig.buttons['Zoom'].classList.remove('active');\n",
|
|||
|
" } else if (msg['mode'] === 'ZOOM') {\n",
|
|||
|
" fig.buttons['Pan'].classList.remove('active');\n",
|
|||
|
" fig.buttons['Zoom'].classList.add('active');\n",
|
|||
|
" } else {\n",
|
|||
|
" fig.buttons['Pan'].classList.remove('active');\n",
|
|||
|
" fig.buttons['Zoom'].classList.remove('active');\n",
|
|||
|
" }\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.updated_canvas_event = function () {\n",
|
|||
|
" // Called whenever the canvas gets updated.\n",
|
|||
|
" this.send_message('ack', {});\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"// A function to construct a web socket function for onmessage handling.\n",
|
|||
|
"// Called in the figure constructor.\n",
|
|||
|
"mpl.figure.prototype._make_on_message_function = function (fig) {\n",
|
|||
|
" return function socket_on_message(evt) {\n",
|
|||
|
" if (evt.data instanceof Blob) {\n",
|
|||
|
" var img = evt.data;\n",
|
|||
|
" if (img.type !== 'image/png') {\n",
|
|||
|
" /* FIXME: We get \"Resource interpreted as Image but\n",
|
|||
|
" * transferred with MIME type text/plain:\" errors on\n",
|
|||
|
" * Chrome. But how to set the MIME type? It doesn't seem\n",
|
|||
|
" * to be part of the websocket stream */\n",
|
|||
|
" img.type = 'image/png';\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" /* Free the memory for the previous frames */\n",
|
|||
|
" if (fig.imageObj.src) {\n",
|
|||
|
" (window.URL || window.webkitURL).revokeObjectURL(\n",
|
|||
|
" fig.imageObj.src\n",
|
|||
|
" );\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(\n",
|
|||
|
" img\n",
|
|||
|
" );\n",
|
|||
|
" fig.updated_canvas_event();\n",
|
|||
|
" fig.waiting = false;\n",
|
|||
|
" return;\n",
|
|||
|
" } else if (\n",
|
|||
|
" typeof evt.data === 'string' &&\n",
|
|||
|
" evt.data.slice(0, 21) === 'data:image/png;base64'\n",
|
|||
|
" ) {\n",
|
|||
|
" fig.imageObj.src = evt.data;\n",
|
|||
|
" fig.updated_canvas_event();\n",
|
|||
|
" fig.waiting = false;\n",
|
|||
|
" return;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" var msg = JSON.parse(evt.data);\n",
|
|||
|
" var msg_type = msg['type'];\n",
|
|||
|
"\n",
|
|||
|
" // Call the \"handle_{type}\" callback, which takes\n",
|
|||
|
" // the figure and JSON message as its only arguments.\n",
|
|||
|
" try {\n",
|
|||
|
" var callback = fig['handle_' + msg_type];\n",
|
|||
|
" } catch (e) {\n",
|
|||
|
" console.log(\n",
|
|||
|
" \"No handler for the '\" + msg_type + \"' message type: \",\n",
|
|||
|
" msg\n",
|
|||
|
" );\n",
|
|||
|
" return;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" if (callback) {\n",
|
|||
|
" try {\n",
|
|||
|
" // console.log(\"Handling '\" + msg_type + \"' message: \", msg);\n",
|
|||
|
" callback(fig, msg);\n",
|
|||
|
" } catch (e) {\n",
|
|||
|
" console.log(\n",
|
|||
|
" \"Exception inside the 'handler_\" + msg_type + \"' callback:\",\n",
|
|||
|
" e,\n",
|
|||
|
" e.stack,\n",
|
|||
|
" msg\n",
|
|||
|
" );\n",
|
|||
|
" }\n",
|
|||
|
" }\n",
|
|||
|
" };\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"// from https://stackoverflow.com/questions/1114465/getting-mouse-location-in-canvas\n",
|
|||
|
"mpl.findpos = function (e) {\n",
|
|||
|
" //this section is from http://www.quirksmode.org/js/events_properties.html\n",
|
|||
|
" var targ;\n",
|
|||
|
" if (!e) {\n",
|
|||
|
" e = window.event;\n",
|
|||
|
" }\n",
|
|||
|
" if (e.target) {\n",
|
|||
|
" targ = e.target;\n",
|
|||
|
" } else if (e.srcElement) {\n",
|
|||
|
" targ = e.srcElement;\n",
|
|||
|
" }\n",
|
|||
|
" if (targ.nodeType === 3) {\n",
|
|||
|
" // defeat Safari bug\n",
|
|||
|
" targ = targ.parentNode;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" // pageX,Y are the mouse positions relative to the document\n",
|
|||
|
" var boundingRect = targ.getBoundingClientRect();\n",
|
|||
|
" var x = e.pageX - (boundingRect.left + document.body.scrollLeft);\n",
|
|||
|
" var y = e.pageY - (boundingRect.top + document.body.scrollTop);\n",
|
|||
|
"\n",
|
|||
|
" return { x: x, y: y };\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"/*\n",
|
|||
|
" * return a copy of an object with only non-object keys\n",
|
|||
|
" * we need this to avoid circular references\n",
|
|||
|
" * https://stackoverflow.com/a/24161582/3208463\n",
|
|||
|
" */\n",
|
|||
|
"function simpleKeys(original) {\n",
|
|||
|
" return Object.keys(original).reduce(function (obj, key) {\n",
|
|||
|
" if (typeof original[key] !== 'object') {\n",
|
|||
|
" obj[key] = original[key];\n",
|
|||
|
" }\n",
|
|||
|
" return obj;\n",
|
|||
|
" }, {});\n",
|
|||
|
"}\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.mouse_event = function (event, name) {\n",
|
|||
|
" var canvas_pos = mpl.findpos(event);\n",
|
|||
|
"\n",
|
|||
|
" if (name === 'button_press') {\n",
|
|||
|
" this.canvas.focus();\n",
|
|||
|
" this.canvas_div.focus();\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" var x = canvas_pos.x * this.ratio;\n",
|
|||
|
" var y = canvas_pos.y * this.ratio;\n",
|
|||
|
"\n",
|
|||
|
" this.send_message(name, {\n",
|
|||
|
" x: x,\n",
|
|||
|
" y: y,\n",
|
|||
|
" button: event.button,\n",
|
|||
|
" step: event.step,\n",
|
|||
|
" guiEvent: simpleKeys(event),\n",
|
|||
|
" });\n",
|
|||
|
"\n",
|
|||
|
" /* This prevents the web browser from automatically changing to\n",
|
|||
|
" * the text insertion cursor when the button is pressed. We want\n",
|
|||
|
" * to control all of the cursor setting manually through the\n",
|
|||
|
" * 'cursor' event from matplotlib */\n",
|
|||
|
" event.preventDefault();\n",
|
|||
|
" return false;\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._key_event_extra = function (_event, _name) {\n",
|
|||
|
" // Handle any extra behaviour associated with a key event\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.key_event = function (event, name) {\n",
|
|||
|
" // Prevent repeat events\n",
|
|||
|
" if (name === 'key_press') {\n",
|
|||
|
" if (event.key === this._key) {\n",
|
|||
|
" return;\n",
|
|||
|
" } else {\n",
|
|||
|
" this._key = event.key;\n",
|
|||
|
" }\n",
|
|||
|
" }\n",
|
|||
|
" if (name === 'key_release') {\n",
|
|||
|
" this._key = null;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" var value = '';\n",
|
|||
|
" if (event.ctrlKey && event.key !== 'Control') {\n",
|
|||
|
" value += 'ctrl+';\n",
|
|||
|
" }\n",
|
|||
|
" else if (event.altKey && event.key !== 'Alt') {\n",
|
|||
|
" value += 'alt+';\n",
|
|||
|
" }\n",
|
|||
|
" else if (event.shiftKey && event.key !== 'Shift') {\n",
|
|||
|
" value += 'shift+';\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" value += 'k' + event.key;\n",
|
|||
|
"\n",
|
|||
|
" this._key_event_extra(event, name);\n",
|
|||
|
"\n",
|
|||
|
" this.send_message(name, { key: value, guiEvent: simpleKeys(event) });\n",
|
|||
|
" return false;\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.toolbar_button_onclick = function (name) {\n",
|
|||
|
" if (name === 'download') {\n",
|
|||
|
" this.handle_save(this, null);\n",
|
|||
|
" } else {\n",
|
|||
|
" this.send_message('toolbar_button', { name: name });\n",
|
|||
|
" }\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.toolbar_button_onmouseover = function (tooltip) {\n",
|
|||
|
" this.message.textContent = tooltip;\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"///////////////// REMAINING CONTENT GENERATED BY embed_js.py /////////////////\n",
|
|||
|
"// prettier-ignore\n",
|
|||
|
"var _JSXTOOLS_RESIZE_OBSERVER=function(A){var t,i=new WeakMap,n=new WeakMap,a=new WeakMap,r=new WeakMap,o=new Set;function s(e){if(!(this instanceof s))throw new TypeError(\"Constructor requires 'new' operator\");i.set(this,e)}function h(){throw new TypeError(\"Function is not a constructor\")}function c(e,t,i,n){e=0 in arguments?Number(arguments[0]):0,t=1 in arguments?Number(arguments[1]):0,i=2 in arguments?Number(arguments[2]):0,n=3 in arguments?Number(arguments[3]):0,this.right=(this.x=this.left=e)+(this.width=i),this.bottom=(this.y=this.top=t)+(this.height=n),Object.freeze(this)}function d(){t=requestAnimationFrame(d);var s=new WeakMap,p=new Set;o.forEach((function(t){r.get(t).forEach((function(i){var r=t instanceof window.SVGElement,o=a.get(t),d=r?0:parseFloat(o.paddingTop),f=r?0:parseFloat(o.paddingRight),l=r?0:parseFloat(o.paddingBottom),u=r?0:parseFloat(o.paddingLeft),g=r?0:parseFloat(o.borderTopWidth),m=r?0:parseFloat(o.borderRightWidth),w=r?0:parseFloat(o.borderBottomWidth),b=u+f,F=d+l,v=(r?0:parseFloat(o.borderLeftWidth))+m,W=g+w,y=r?0:t.offsetHeight-W-t.clientHeight,E=r?0:t.offsetWidth-v-t.clientWidth,R=b+v,z=F+W,M=r?t.width:parseFloat(o.width)-R-E,O=r?t.height:parseFloat(o.height)-z-y;if(n.has(t)){var k=n.get(t);if(k[0]===M&&k[1]===O)return}n.set(t,[M,O]);var S=Object.create(h.prototype);S.target=t,S.contentRect=new c(u,d,M,O),s.has(i)||(s.set(i,[]),p.add(i)),s.get(i).push(S)}))})),p.forEach((function(e){i.get(e).call(e,s.get(e),e)}))}return s.prototype.observe=function(i){if(i instanceof window.Element){r.has(i)||(r.set(i,new Set),o.add(i),a.set(i,window.getComputedStyle(i)));var n=r.get(i);n.has(this)||n.add(this),cancelAnimationFrame(t),t=requestAnimationFrame(d)}},s.prototype.unobserve=function(i){if(i instanceof window.Element&&r.has(i)){var n=r.get(i);n.has(this)&&(n.delete(this),n.size||(r.delete(i),o.delete(i))),n.size||r.delete(i),o.size||cancelAnimationFrame(t)}},A.DOMRectReadOnly=c,A.ResizeObserver=s,A.ResizeObserverEntry=h,A}; // eslint-disable-line\n",
|
|||
|
"mpl.toolbar_items = [[\"Home\", \"Reset original view\", \"fa fa-home icon-home\", \"home\"], [\"Back\", \"Back to previous view\", \"fa fa-arrow-left icon-arrow-left\", \"back\"], [\"Forward\", \"Forward to next view\", \"fa fa-arrow-right icon-arrow-right\", \"forward\"], [\"\", \"\", \"\", \"\"], [\"Pan\", \"Left button pans, Right button zooms\\nx/y fixes axis, CTRL fixes aspect\", \"fa fa-arrows icon-move\", \"pan\"], [\"Zoom\", \"Zoom to rectangle\\nx/y fixes axis\", \"fa fa-square-o icon-check-empty\", \"zoom\"], [\"\", \"\", \"\", \"\"], [\"Download\", \"Download plot\", \"fa fa-floppy-o icon-save\", \"download\"]];\n",
|
|||
|
"\n",
|
|||
|
"mpl.extensions = [\"eps\", \"jpeg\", \"pgf\", \"pdf\", \"png\", \"ps\", \"raw\", \"svg\", \"tif\"];\n",
|
|||
|
"\n",
|
|||
|
"mpl.default_extension = \"png\";/* global mpl */\n",
|
|||
|
"\n",
|
|||
|
"var comm_websocket_adapter = function (comm) {\n",
|
|||
|
" // Create a \"websocket\"-like object which calls the given IPython comm\n",
|
|||
|
" // object with the appropriate methods. Currently this is a non binary\n",
|
|||
|
" // socket, so there is still some room for performance tuning.\n",
|
|||
|
" var ws = {};\n",
|
|||
|
"\n",
|
|||
|
" ws.binaryType = comm.kernel.ws.binaryType;\n",
|
|||
|
" ws.readyState = comm.kernel.ws.readyState;\n",
|
|||
|
" function updateReadyState(_event) {\n",
|
|||
|
" if (comm.kernel.ws) {\n",
|
|||
|
" ws.readyState = comm.kernel.ws.readyState;\n",
|
|||
|
" } else {\n",
|
|||
|
" ws.readyState = 3; // Closed state.\n",
|
|||
|
" }\n",
|
|||
|
" }\n",
|
|||
|
" comm.kernel.ws.addEventListener('open', updateReadyState);\n",
|
|||
|
" comm.kernel.ws.addEventListener('close', updateReadyState);\n",
|
|||
|
" comm.kernel.ws.addEventListener('error', updateReadyState);\n",
|
|||
|
"\n",
|
|||
|
" ws.close = function () {\n",
|
|||
|
" comm.close();\n",
|
|||
|
" };\n",
|
|||
|
" ws.send = function (m) {\n",
|
|||
|
" //console.log('sending', m);\n",
|
|||
|
" comm.send(m);\n",
|
|||
|
" };\n",
|
|||
|
" // Register the callback with on_msg.\n",
|
|||
|
" comm.on_msg(function (msg) {\n",
|
|||
|
" //console.log('receiving', msg['content']['data'], msg);\n",
|
|||
|
" var data = msg['content']['data'];\n",
|
|||
|
" if (data['blob'] !== undefined) {\n",
|
|||
|
" data = {\n",
|
|||
|
" data: new Blob(msg['buffers'], { type: data['blob'] }),\n",
|
|||
|
" };\n",
|
|||
|
" }\n",
|
|||
|
" // Pass the mpl event to the overridden (by mpl) onmessage function.\n",
|
|||
|
" ws.onmessage(data);\n",
|
|||
|
" });\n",
|
|||
|
" return ws;\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.mpl_figure_comm = function (comm, msg) {\n",
|
|||
|
" // This is the function which gets called when the mpl process\n",
|
|||
|
" // starts-up an IPython Comm through the \"matplotlib\" channel.\n",
|
|||
|
"\n",
|
|||
|
" var id = msg.content.data.id;\n",
|
|||
|
" // Get hold of the div created by the display call when the Comm\n",
|
|||
|
" // socket was opened in Python.\n",
|
|||
|
" var element = document.getElementById(id);\n",
|
|||
|
" var ws_proxy = comm_websocket_adapter(comm);\n",
|
|||
|
"\n",
|
|||
|
" function ondownload(figure, _format) {\n",
|
|||
|
" window.open(figure.canvas.toDataURL());\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" var fig = new mpl.figure(id, ws_proxy, ondownload, element);\n",
|
|||
|
"\n",
|
|||
|
" // Call onopen now - mpl needs it, as it is assuming we've passed it a real\n",
|
|||
|
" // web socket which is closed, not our websocket->open comm proxy.\n",
|
|||
|
" ws_proxy.onopen();\n",
|
|||
|
"\n",
|
|||
|
" fig.parent_element = element;\n",
|
|||
|
" fig.cell_info = mpl.find_output_cell(\"<div id='\" + id + \"'></div>\");\n",
|
|||
|
" if (!fig.cell_info) {\n",
|
|||
|
" console.error('Failed to find cell for figure', id, fig);\n",
|
|||
|
" return;\n",
|
|||
|
" }\n",
|
|||
|
" fig.cell_info[0].output_area.element.on(\n",
|
|||
|
" 'cleared',\n",
|
|||
|
" { fig: fig },\n",
|
|||
|
" fig._remove_fig_handler\n",
|
|||
|
" );\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_close = function (fig, msg) {\n",
|
|||
|
" var width = fig.canvas.width / fig.ratio;\n",
|
|||
|
" fig.cell_info[0].output_area.element.off(\n",
|
|||
|
" 'cleared',\n",
|
|||
|
" fig._remove_fig_handler\n",
|
|||
|
" );\n",
|
|||
|
" fig.resizeObserverInstance.unobserve(fig.canvas_div);\n",
|
|||
|
"\n",
|
|||
|
" // Update the output cell to use the data from the current canvas.\n",
|
|||
|
" fig.push_to_output();\n",
|
|||
|
" var dataURL = fig.canvas.toDataURL();\n",
|
|||
|
" // Re-enable the keyboard manager in IPython - without this line, in FF,\n",
|
|||
|
" // the notebook keyboard shortcuts fail.\n",
|
|||
|
" IPython.keyboard_manager.enable();\n",
|
|||
|
" fig.parent_element.innerHTML =\n",
|
|||
|
" '<img src=\"' + dataURL + '\" width=\"' + width + '\">';\n",
|
|||
|
" fig.close_ws(fig, msg);\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.close_ws = function (fig, msg) {\n",
|
|||
|
" fig.send_message('closing', msg);\n",
|
|||
|
" // fig.ws.close()\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.push_to_output = function (_remove_interactive) {\n",
|
|||
|
" // Turn the data on the canvas into data in the output cell.\n",
|
|||
|
" var width = this.canvas.width / this.ratio;\n",
|
|||
|
" var dataURL = this.canvas.toDataURL();\n",
|
|||
|
" this.cell_info[1]['text/html'] =\n",
|
|||
|
" '<img src=\"' + dataURL + '\" width=\"' + width + '\">';\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.updated_canvas_event = function () {\n",
|
|||
|
" // Tell IPython that the notebook contents must change.\n",
|
|||
|
" IPython.notebook.set_dirty(true);\n",
|
|||
|
" this.send_message('ack', {});\n",
|
|||
|
" var fig = this;\n",
|
|||
|
" // Wait a second, then push the new image to the DOM so\n",
|
|||
|
" // that it is saved nicely (might be nice to debounce this).\n",
|
|||
|
" setTimeout(function () {\n",
|
|||
|
" fig.push_to_output();\n",
|
|||
|
" }, 1000);\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._init_toolbar = function () {\n",
|
|||
|
" var fig = this;\n",
|
|||
|
"\n",
|
|||
|
" var toolbar = document.createElement('div');\n",
|
|||
|
" toolbar.classList = 'btn-toolbar';\n",
|
|||
|
" this.root.appendChild(toolbar);\n",
|
|||
|
"\n",
|
|||
|
" function on_click_closure(name) {\n",
|
|||
|
" return function (_event) {\n",
|
|||
|
" return fig.toolbar_button_onclick(name);\n",
|
|||
|
" };\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" function on_mouseover_closure(tooltip) {\n",
|
|||
|
" return function (event) {\n",
|
|||
|
" if (!event.currentTarget.disabled) {\n",
|
|||
|
" return fig.toolbar_button_onmouseover(tooltip);\n",
|
|||
|
" }\n",
|
|||
|
" };\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" fig.buttons = {};\n",
|
|||
|
" var buttonGroup = document.createElement('div');\n",
|
|||
|
" buttonGroup.classList = 'btn-group';\n",
|
|||
|
" var button;\n",
|
|||
|
" for (var toolbar_ind in mpl.toolbar_items) {\n",
|
|||
|
" var name = mpl.toolbar_items[toolbar_ind][0];\n",
|
|||
|
" var tooltip = mpl.toolbar_items[toolbar_ind][1];\n",
|
|||
|
" var image = mpl.toolbar_items[toolbar_ind][2];\n",
|
|||
|
" var method_name = mpl.toolbar_items[toolbar_ind][3];\n",
|
|||
|
"\n",
|
|||
|
" if (!name) {\n",
|
|||
|
" /* Instead of a spacer, we start a new button group. */\n",
|
|||
|
" if (buttonGroup.hasChildNodes()) {\n",
|
|||
|
" toolbar.appendChild(buttonGroup);\n",
|
|||
|
" }\n",
|
|||
|
" buttonGroup = document.createElement('div');\n",
|
|||
|
" buttonGroup.classList = 'btn-group';\n",
|
|||
|
" continue;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" button = fig.buttons[name] = document.createElement('button');\n",
|
|||
|
" button.classList = 'btn btn-default';\n",
|
|||
|
" button.href = '#';\n",
|
|||
|
" button.title = name;\n",
|
|||
|
" button.innerHTML = '<i class=\"fa ' + image + ' fa-lg\"></i>';\n",
|
|||
|
" button.addEventListener('click', on_click_closure(method_name));\n",
|
|||
|
" button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n",
|
|||
|
" buttonGroup.appendChild(button);\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" if (buttonGroup.hasChildNodes()) {\n",
|
|||
|
" toolbar.appendChild(buttonGroup);\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" // Add the status bar.\n",
|
|||
|
" var status_bar = document.createElement('span');\n",
|
|||
|
" status_bar.classList = 'mpl-message pull-right';\n",
|
|||
|
" toolbar.appendChild(status_bar);\n",
|
|||
|
" this.message = status_bar;\n",
|
|||
|
"\n",
|
|||
|
" // Add the close button to the window.\n",
|
|||
|
" var buttongrp = document.createElement('div');\n",
|
|||
|
" buttongrp.classList = 'btn-group inline pull-right';\n",
|
|||
|
" button = document.createElement('button');\n",
|
|||
|
" button.classList = 'btn btn-mini btn-primary';\n",
|
|||
|
" button.href = '#';\n",
|
|||
|
" button.title = 'Stop Interaction';\n",
|
|||
|
" button.innerHTML = '<i class=\"fa fa-power-off icon-remove icon-large\"></i>';\n",
|
|||
|
" button.addEventListener('click', function (_evt) {\n",
|
|||
|
" fig.handle_close(fig, {});\n",
|
|||
|
" });\n",
|
|||
|
" button.addEventListener(\n",
|
|||
|
" 'mouseover',\n",
|
|||
|
" on_mouseover_closure('Stop Interaction')\n",
|
|||
|
" );\n",
|
|||
|
" buttongrp.appendChild(button);\n",
|
|||
|
" var titlebar = this.root.querySelector('.ui-dialog-titlebar');\n",
|
|||
|
" titlebar.insertBefore(buttongrp, titlebar.firstChild);\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._remove_fig_handler = function (event) {\n",
|
|||
|
" var fig = event.data.fig;\n",
|
|||
|
" if (event.target !== this) {\n",
|
|||
|
" // Ignore bubbled events from children.\n",
|
|||
|
" return;\n",
|
|||
|
" }\n",
|
|||
|
" fig.close_ws(fig, {});\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._root_extra_style = function (el) {\n",
|
|||
|
" el.style.boxSizing = 'content-box'; // override notebook setting of border-box.\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._canvas_extra_style = function (el) {\n",
|
|||
|
" // this is important to make the div 'focusable\n",
|
|||
|
" el.setAttribute('tabindex', 0);\n",
|
|||
|
" // reach out to IPython and tell the keyboard manager to turn it's self\n",
|
|||
|
" // off when our div gets focus\n",
|
|||
|
"\n",
|
|||
|
" // location in version 3\n",
|
|||
|
" if (IPython.notebook.keyboard_manager) {\n",
|
|||
|
" IPython.notebook.keyboard_manager.register_events(el);\n",
|
|||
|
" } else {\n",
|
|||
|
" // location in version 2\n",
|
|||
|
" IPython.keyboard_manager.register_events(el);\n",
|
|||
|
" }\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._key_event_extra = function (event, _name) {\n",
|
|||
|
" // Check for shift+enter\n",
|
|||
|
" if (event.shiftKey && event.which === 13) {\n",
|
|||
|
" this.canvas_div.blur();\n",
|
|||
|
" // select the cell after this one\n",
|
|||
|
" var index = IPython.notebook.find_cell_index(this.cell_info[0]);\n",
|
|||
|
" IPython.notebook.select(index + 1);\n",
|
|||
|
" }\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_save = function (fig, _msg) {\n",
|
|||
|
" fig.ondownload(fig, null);\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.find_output_cell = function (html_output) {\n",
|
|||
|
" // Return the cell and output element which can be found *uniquely* in the notebook.\n",
|
|||
|
" // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n",
|
|||
|
" // IPython event is triggered only after the cells have been serialised, which for\n",
|
|||
|
" // our purposes (turning an active figure into a static one), is too late.\n",
|
|||
|
" var cells = IPython.notebook.get_cells();\n",
|
|||
|
" var ncells = cells.length;\n",
|
|||
|
" for (var i = 0; i < ncells; i++) {\n",
|
|||
|
" var cell = cells[i];\n",
|
|||
|
" if (cell.cell_type === 'code') {\n",
|
|||
|
" for (var j = 0; j < cell.output_area.outputs.length; j++) {\n",
|
|||
|
" var data = cell.output_area.outputs[j];\n",
|
|||
|
" if (data.data) {\n",
|
|||
|
" // IPython >= 3 moved mimebundle to data attribute of output\n",
|
|||
|
" data = data.data;\n",
|
|||
|
" }\n",
|
|||
|
" if (data['text/html'] === html_output) {\n",
|
|||
|
" return [cell, data, j];\n",
|
|||
|
" }\n",
|
|||
|
" }\n",
|
|||
|
" }\n",
|
|||
|
" }\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"// Register the function which deals with the matplotlib target/channel.\n",
|
|||
|
"// The kernel may be null if the page has been refreshed.\n",
|
|||
|
"if (IPython.notebook.kernel !== null) {\n",
|
|||
|
" IPython.notebook.kernel.comm_manager.register_target(\n",
|
|||
|
" 'matplotlib',\n",
|
|||
|
" mpl.mpl_figure_comm\n",
|
|||
|
" );\n",
|
|||
|
"}\n"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
"<IPython.core.display.Javascript object>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
},
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/html": [
|
|||
|
"<img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABQAAAAPACAYAAABq3NR5AAAgAElEQVR4XuzdB5gV1f038KNg7wUrMVbELkqxY+xYoold/7HEEmOPJpZYYuwx0diN2EvsGhMjogELaqiKDVQUxIbYjT0K+nIm7w4s7MKye+/dObOfed/n+ce9M3PO7/M7zvPM17l3Zvl+0hZsBAgQIECAAAECBAgQIECAAAECBAiUUmAWAWAp+6ooAgQIECBAgAABAgQIECBAgAABApmAANBCIECAAAECBAgQIECAAAECBAgQIFBiAQFgiZurNAIECBAgQIAAAQIECBAgQIAAAQICQGuAAAECBAgQIECAAAECBAgQIECAQIkFBIAlbq7SCBAgQIAAAQIECBAgQIAAAQIECAgArQECBAgQIECAAAECBAgQIECAAAECJRYQAJa4uUojQIAAAQIECBAgQIAAAQIECBAgIAC0BggQIECAAAECBAgQIECAAAECBAiUWEAAWOLmKo0AAQIECBAgQIAAAQIECBAgQICAANAaIECAAAECBAgQIECAAAECBAgQIFBiAQFgiZurNAIECBAgQIAAAQIECBAgQIAAAQICQGuAAAECBAgQIECAAAECBAgQIECAQIkFBIAlbq7SCBAgQIAAAQIECBAgQIAAAQIECAgArQECBAgQIECAAAECBAgQIECAAAECJRYQAJa4uUojQIAAAQIECBAgQIAAAQIECBAgIAC0BggQIECAAAECBAgQIECAAAECBAiUWEAAWOLmKo0AAQIECBAgQIAAAQIECBAgQICAANAaIECAAAECBAgQIECAAAECBAgQIFBiAQFgiZurNAIECBAgQIAAAQIECBAgQIAAAQICQGuAAAECBAgQIECAAAECBAgQIECAQIkFBIAlbq7SCBAgQIAAAQIECBAgQIAAAQIECAgArQECBAgQIECAAAECBAgQIECAAAECJRYQAJa4uUojQIAAAQIECBAgQIAAAQIECBAgIAC0BggQIECAAAECBAgQIECAAAECBAiUWEAAWOLmKo0AAQIECBAgQIAAAQIECBAgQICAANAaIECAAAECBAgQIECAAAECBAgQIFBiAQFgiZurNAIECBAgQIAAAQIECBAgQIAAAQICQGuAAAECBAgQIECAAAECBAgQIECAQIkFBIAlbq7SCBAgQIAAAQIECBAgQIAAAQIECAgArQECBAgQIECAAAECBAgQIECAAAECJRYQAJa4uUojQIAAAQIECBAgQIAAAQIECBAgIAC0BggQIECAAAECBAgQIECAAAECBAiUWEAAWOLmKo0AAQIECBAgQIAAAQIECBAgQICAANAaIECAAAECBAgQIECAAAECBAgQIFBiAQFgiZurNAIECBAgQIAAAQIECBAgQIAAAQICQGuAAAECBAgQIECAAAECBAgQIECAQIkFBIAlbq7SCBAgQIAAAQIECBAgQIAAAQIECAgArQECBAgQIECAAAECBAgQIECAAAECJRYQAJa4uUojQIAAAQIECBAgQIAAAQIECBAgIAC0BggQIECAAAECBAgQIECAAAECBAiUWEAAWOLmKo0AAQIECBAgQIAAAQIECBAgQICAANAaIECAAAECBAgQIECAAAECBAgQIFBiAQFgiZurNAIECBAgQIAAAQIECBAgQIAAAQICQGuAAAECBAgQIECAAAECBAgQIECAQIkFBIAlbq7SCBAgQIAAAQIECBAgQIAAAQIECAgArQECBAgQIECAAAECBAgQIECAAAECJRYQAJa4uUojQIAAAQIECBAgQIAAAQIECBAgIAC0BggQIECAAAECBAgQIECAAAECBAiUWEAAWOLmKo0AAQIECBAgQIAAAQIECBAgQICAANAaIECAAAECBAgQIECAAAECBAgQIFBiAQFgiZurNAIECBAgQIAAAQIECBAgQIAAAQICQGuAAAECBAgQIECAAAECBAgQIECAQIkFBIAlbq7SCBAgQIAAAQIECBAgQIAAAQIECAgArQECBAgQIECAAAECBAgQIECAAAECJRYQAJa4uUojQIAAAQIECBAgQIAAAQIECBAgIAC0BggQIECAAAECBAgQIECAAAECBAiUWEAAWOLmKo0AAQIECBAgQIAAAQIECBAgQICAANAaIECAAAECBAgQIECAAAECBAgQIFBiAQFgiZurNAIECBAgQIAAAQIECBAgQIAAAQICQGuAAAECBAgQIECAAAECBAgQIECAQIkFBIAlbq7SCBAgQIAAAQIECBAgQIAAAQIECAgArQECBAgQIECAAAECBAgQIECAAAECJRYQAJa4uUojQIAAAQIECBAgQIAAAQIECBAgIAC0BggQIECAAAECBAgQIECAAAECBAiUWEAAWOLmKo0AAQIECBAgQIAAAQIECBAgQICAANAaIECAAAECBAgQIECAAAECBAgQIFBiAQFgiZurNAIECBAgQIAAAQIECBAgQIAAAQICQGuAAAECBAgQIECAAAECBAgQIECAQIkFBIAlbq7SCBAgQIAAAQIECBAgQIAAAQIECAgArQECBAgQIECAAAECBAgQIECAAAECJRYQAJa4uUojQIAAAQIECBAgQIAAAQIECBAgIAC0BggQIECAAAECBAgQIECAAAECBAiUWEAAWOLmKo0AAQIECBAgQIAAAQIECBAgQICAANAaIECAAAECBAgQIECAAAECBAgQIFBiAQFgiZurNAIECBAgQIAAAQIECBAgQIAAAQICQGuAAAECBAgQIECAAAECBAgQIECAQIkFBIAlbq7SCBAgQIAAAQIECBAgQIAAAQIECAgArQECBAgQIECAAAECBAgQIECAAAECJRYQAJa4uUojQIAAAQIECBAgQIAAAQIECBAgIAC0BggQIECAAAECBAgQIECAAAECBAiUWEAAWOLmKo0AAQIECBAgQIAAAQIECBAgQICAANAaIECAAAECBAgQIECAAAECBAgQIFBiAQFgiZurNAIECBAgQIAAAQIECBAgQIAAAQICQGuAAAECBAgQIECAAAECBAgQIECAQIkFBIAlbq7SCBAgQIAAAQIECBAgQIAAAQIECAgArQECBAgQIECAAAECBAgQIECAAAECJRYQAJa4uUojQIAAAQIECBAgQIAAAQIECBAgIAC0BggQIECAAAECBAgQIECAAAECBAiUWEAAWOLmKo0AAQIECBAgQIAAAQIECBAgQICAANAaIECAAAECBAgQIECAAAECBAgQIFBiAQFgiZurNAIECBAgQIAAAQIECBAgQIAAAQICQGuAAAECBAgQIECAAAECBAgQIECAQIkFBIAlbq7SCBAgQIAAAQIECBAgQIAAAQIECAgArQECBAgQIECAAAECBAgQIECAAAECJRYQAJa4uUojQIAAAQIECBAgQIAAAQIECBAgIAC0BggQIECAAAECBAgQIECAAAECBAiUWEAAWOLmKo0AAQIECBAgQIAAAQIECBAgQICAANAaIECAAAECBAgQIECAAAECBAgQIFBiAQFgiZurNAIECBAgQIAAAQIECBAgQIAAAQICQGuAAAECBAgQIECAAAECBAgQIECAQIkFBIAlbq7SCBAgQIAAAQIECBAgQIAAAQIECAgArQECBAgQIECAAAECBAgQIECAAAECJRYQAJa4uUojQIAAAQIECBAgQIAAAQIECBAgIAC0BggQIECAAAECBAgQIECAAAECBAiUWEAAWOLmKo0AAQIECBAgQIAAAQIECBAgQICAANAaIECAAAECBAgQIECAAAECBAgQIFBiAQFgiZurNAIECBAgQIAAAQIECBAgQIAAAQICQGuAAAECBAgQIECAAAECBAgQIECAQIkFBIAlbq7SCBAgQIAAAQIECBAgQIAAAQIECAgArQECBAgQIECAAAECBAgQIECAAAECJRYQAJa4uUojQIAAAQIECBAgQIAAAQIECBAgIAC0BggQIECAAAECBAgQIECAAAECBAiUWEAAWOLmFrm0r7/+Ojz//PPZFDt06BDat29f5OmaGwECBAgQIECAAAECBAgQSFJgwoQJ4f3338/mvs
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
"<IPython.core.display.HTML object>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"%matplotlib notebook\n",
|
|||
|
"y_accounts = accounts.sort_values(by='likes')['likes'].cumsum().reset_index(drop=True)\n",
|
|||
|
"plt.plot(y_accounts)\n",
|
|||
|
"plt.show()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 14,
|
|||
|
"id": "33ec3b44",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"0.00 0.0\n",
|
|||
|
"0.25 0.0\n",
|
|||
|
"0.50 1.0\n",
|
|||
|
"0.75 4.0\n",
|
|||
|
"0.90 15.0\n",
|
|||
|
"0.95 32.0\n",
|
|||
|
"0.99 137.0\n",
|
|||
|
"Name: likes, dtype: float64"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 14,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"quants = [0, 0.25, 0.5, 0.75, 0.9, .95, .99]\n",
|
|||
|
"quantiles = accounts['likes'].quantile(quants)\n",
|
|||
|
"quantiles"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 15,
|
|||
|
"id": "fe29f683",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"[0, 0, 36854, 65304, 81702, 86403, 90162]"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 15,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"sorted_accounts = accounts.sort_values(by='likes')\n",
|
|||
|
"quant_idx = [np.where(sorted_accounts['likes'] >= q)[0][0] for q in quantiles]\n",
|
|||
|
"quant_idx"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 16,
|
|||
|
"id": "36b72cea",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"(array([36854, 36855, 36856, ..., 91073, 91074, 91075]),)"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 16,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"np.where(sorted_accounts['likes'] > 0)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 17,
|
|||
|
"id": "c10b03d4",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"application/javascript": [
|
|||
|
"/* Put everything inside the global mpl namespace */\n",
|
|||
|
"/* global mpl */\n",
|
|||
|
"window.mpl = {};\n",
|
|||
|
"\n",
|
|||
|
"mpl.get_websocket_type = function () {\n",
|
|||
|
" if (typeof WebSocket !== 'undefined') {\n",
|
|||
|
" return WebSocket;\n",
|
|||
|
" } else if (typeof MozWebSocket !== 'undefined') {\n",
|
|||
|
" return MozWebSocket;\n",
|
|||
|
" } else {\n",
|
|||
|
" alert(\n",
|
|||
|
" 'Your browser does not have WebSocket support. ' +\n",
|
|||
|
" 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n",
|
|||
|
" 'Firefox 4 and 5 are also supported but you ' +\n",
|
|||
|
" 'have to enable WebSockets in about:config.'\n",
|
|||
|
" );\n",
|
|||
|
" }\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure = function (figure_id, websocket, ondownload, parent_element) {\n",
|
|||
|
" this.id = figure_id;\n",
|
|||
|
"\n",
|
|||
|
" this.ws = websocket;\n",
|
|||
|
"\n",
|
|||
|
" this.supports_binary = this.ws.binaryType !== undefined;\n",
|
|||
|
"\n",
|
|||
|
" if (!this.supports_binary) {\n",
|
|||
|
" var warnings = document.getElementById('mpl-warnings');\n",
|
|||
|
" if (warnings) {\n",
|
|||
|
" warnings.style.display = 'block';\n",
|
|||
|
" warnings.textContent =\n",
|
|||
|
" 'This browser does not support binary websocket messages. ' +\n",
|
|||
|
" 'Performance may be slow.';\n",
|
|||
|
" }\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" this.imageObj = new Image();\n",
|
|||
|
"\n",
|
|||
|
" this.context = undefined;\n",
|
|||
|
" this.message = undefined;\n",
|
|||
|
" this.canvas = undefined;\n",
|
|||
|
" this.rubberband_canvas = undefined;\n",
|
|||
|
" this.rubberband_context = undefined;\n",
|
|||
|
" this.format_dropdown = undefined;\n",
|
|||
|
"\n",
|
|||
|
" this.image_mode = 'full';\n",
|
|||
|
"\n",
|
|||
|
" this.root = document.createElement('div');\n",
|
|||
|
" this.root.setAttribute('style', 'display: inline-block');\n",
|
|||
|
" this._root_extra_style(this.root);\n",
|
|||
|
"\n",
|
|||
|
" parent_element.appendChild(this.root);\n",
|
|||
|
"\n",
|
|||
|
" this._init_header(this);\n",
|
|||
|
" this._init_canvas(this);\n",
|
|||
|
" this._init_toolbar(this);\n",
|
|||
|
"\n",
|
|||
|
" var fig = this;\n",
|
|||
|
"\n",
|
|||
|
" this.waiting = false;\n",
|
|||
|
"\n",
|
|||
|
" this.ws.onopen = function () {\n",
|
|||
|
" fig.send_message('supports_binary', { value: fig.supports_binary });\n",
|
|||
|
" fig.send_message('send_image_mode', {});\n",
|
|||
|
" if (fig.ratio !== 1) {\n",
|
|||
|
" fig.send_message('set_device_pixel_ratio', {\n",
|
|||
|
" device_pixel_ratio: fig.ratio,\n",
|
|||
|
" });\n",
|
|||
|
" }\n",
|
|||
|
" fig.send_message('refresh', {});\n",
|
|||
|
" };\n",
|
|||
|
"\n",
|
|||
|
" this.imageObj.onload = function () {\n",
|
|||
|
" if (fig.image_mode === 'full') {\n",
|
|||
|
" // Full images could contain transparency (where diff images\n",
|
|||
|
" // almost always do), so we need to clear the canvas so that\n",
|
|||
|
" // there is no ghosting.\n",
|
|||
|
" fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n",
|
|||
|
" }\n",
|
|||
|
" fig.context.drawImage(fig.imageObj, 0, 0);\n",
|
|||
|
" };\n",
|
|||
|
"\n",
|
|||
|
" this.imageObj.onunload = function () {\n",
|
|||
|
" fig.ws.close();\n",
|
|||
|
" };\n",
|
|||
|
"\n",
|
|||
|
" this.ws.onmessage = this._make_on_message_function(this);\n",
|
|||
|
"\n",
|
|||
|
" this.ondownload = ondownload;\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._init_header = function () {\n",
|
|||
|
" var titlebar = document.createElement('div');\n",
|
|||
|
" titlebar.classList =\n",
|
|||
|
" 'ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix';\n",
|
|||
|
" var titletext = document.createElement('div');\n",
|
|||
|
" titletext.classList = 'ui-dialog-title';\n",
|
|||
|
" titletext.setAttribute(\n",
|
|||
|
" 'style',\n",
|
|||
|
" 'width: 100%; text-align: center; padding: 3px;'\n",
|
|||
|
" );\n",
|
|||
|
" titlebar.appendChild(titletext);\n",
|
|||
|
" this.root.appendChild(titlebar);\n",
|
|||
|
" this.header = titletext;\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._canvas_extra_style = function (_canvas_div) {};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._root_extra_style = function (_canvas_div) {};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._init_canvas = function () {\n",
|
|||
|
" var fig = this;\n",
|
|||
|
"\n",
|
|||
|
" var canvas_div = (this.canvas_div = document.createElement('div'));\n",
|
|||
|
" canvas_div.setAttribute(\n",
|
|||
|
" 'style',\n",
|
|||
|
" 'border: 1px solid #ddd;' +\n",
|
|||
|
" 'box-sizing: content-box;' +\n",
|
|||
|
" 'clear: both;' +\n",
|
|||
|
" 'min-height: 1px;' +\n",
|
|||
|
" 'min-width: 1px;' +\n",
|
|||
|
" 'outline: 0;' +\n",
|
|||
|
" 'overflow: hidden;' +\n",
|
|||
|
" 'position: relative;' +\n",
|
|||
|
" 'resize: both;'\n",
|
|||
|
" );\n",
|
|||
|
"\n",
|
|||
|
" function on_keyboard_event_closure(name) {\n",
|
|||
|
" return function (event) {\n",
|
|||
|
" return fig.key_event(event, name);\n",
|
|||
|
" };\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" canvas_div.addEventListener(\n",
|
|||
|
" 'keydown',\n",
|
|||
|
" on_keyboard_event_closure('key_press')\n",
|
|||
|
" );\n",
|
|||
|
" canvas_div.addEventListener(\n",
|
|||
|
" 'keyup',\n",
|
|||
|
" on_keyboard_event_closure('key_release')\n",
|
|||
|
" );\n",
|
|||
|
"\n",
|
|||
|
" this._canvas_extra_style(canvas_div);\n",
|
|||
|
" this.root.appendChild(canvas_div);\n",
|
|||
|
"\n",
|
|||
|
" var canvas = (this.canvas = document.createElement('canvas'));\n",
|
|||
|
" canvas.classList.add('mpl-canvas');\n",
|
|||
|
" canvas.setAttribute('style', 'box-sizing: content-box;');\n",
|
|||
|
"\n",
|
|||
|
" this.context = canvas.getContext('2d');\n",
|
|||
|
"\n",
|
|||
|
" var backingStore =\n",
|
|||
|
" this.context.backingStorePixelRatio ||\n",
|
|||
|
" this.context.webkitBackingStorePixelRatio ||\n",
|
|||
|
" this.context.mozBackingStorePixelRatio ||\n",
|
|||
|
" this.context.msBackingStorePixelRatio ||\n",
|
|||
|
" this.context.oBackingStorePixelRatio ||\n",
|
|||
|
" this.context.backingStorePixelRatio ||\n",
|
|||
|
" 1;\n",
|
|||
|
"\n",
|
|||
|
" this.ratio = (window.devicePixelRatio || 1) / backingStore;\n",
|
|||
|
"\n",
|
|||
|
" var rubberband_canvas = (this.rubberband_canvas = document.createElement(\n",
|
|||
|
" 'canvas'\n",
|
|||
|
" ));\n",
|
|||
|
" rubberband_canvas.setAttribute(\n",
|
|||
|
" 'style',\n",
|
|||
|
" 'box-sizing: content-box; position: absolute; left: 0; top: 0; z-index: 1;'\n",
|
|||
|
" );\n",
|
|||
|
"\n",
|
|||
|
" // Apply a ponyfill if ResizeObserver is not implemented by browser.\n",
|
|||
|
" if (this.ResizeObserver === undefined) {\n",
|
|||
|
" if (window.ResizeObserver !== undefined) {\n",
|
|||
|
" this.ResizeObserver = window.ResizeObserver;\n",
|
|||
|
" } else {\n",
|
|||
|
" var obs = _JSXTOOLS_RESIZE_OBSERVER({});\n",
|
|||
|
" this.ResizeObserver = obs.ResizeObserver;\n",
|
|||
|
" }\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" this.resizeObserverInstance = new this.ResizeObserver(function (entries) {\n",
|
|||
|
" var nentries = entries.length;\n",
|
|||
|
" for (var i = 0; i < nentries; i++) {\n",
|
|||
|
" var entry = entries[i];\n",
|
|||
|
" var width, height;\n",
|
|||
|
" if (entry.contentBoxSize) {\n",
|
|||
|
" if (entry.contentBoxSize instanceof Array) {\n",
|
|||
|
" // Chrome 84 implements new version of spec.\n",
|
|||
|
" width = entry.contentBoxSize[0].inlineSize;\n",
|
|||
|
" height = entry.contentBoxSize[0].blockSize;\n",
|
|||
|
" } else {\n",
|
|||
|
" // Firefox implements old version of spec.\n",
|
|||
|
" width = entry.contentBoxSize.inlineSize;\n",
|
|||
|
" height = entry.contentBoxSize.blockSize;\n",
|
|||
|
" }\n",
|
|||
|
" } else {\n",
|
|||
|
" // Chrome <84 implements even older version of spec.\n",
|
|||
|
" width = entry.contentRect.width;\n",
|
|||
|
" height = entry.contentRect.height;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" // Keep the size of the canvas and rubber band canvas in sync with\n",
|
|||
|
" // the canvas container.\n",
|
|||
|
" if (entry.devicePixelContentBoxSize) {\n",
|
|||
|
" // Chrome 84 implements new version of spec.\n",
|
|||
|
" canvas.setAttribute(\n",
|
|||
|
" 'width',\n",
|
|||
|
" entry.devicePixelContentBoxSize[0].inlineSize\n",
|
|||
|
" );\n",
|
|||
|
" canvas.setAttribute(\n",
|
|||
|
" 'height',\n",
|
|||
|
" entry.devicePixelContentBoxSize[0].blockSize\n",
|
|||
|
" );\n",
|
|||
|
" } else {\n",
|
|||
|
" canvas.setAttribute('width', width * fig.ratio);\n",
|
|||
|
" canvas.setAttribute('height', height * fig.ratio);\n",
|
|||
|
" }\n",
|
|||
|
" canvas.setAttribute(\n",
|
|||
|
" 'style',\n",
|
|||
|
" 'width: ' + width + 'px; height: ' + height + 'px;'\n",
|
|||
|
" );\n",
|
|||
|
"\n",
|
|||
|
" rubberband_canvas.setAttribute('width', width);\n",
|
|||
|
" rubberband_canvas.setAttribute('height', height);\n",
|
|||
|
"\n",
|
|||
|
" // And update the size in Python. We ignore the initial 0/0 size\n",
|
|||
|
" // that occurs as the element is placed into the DOM, which should\n",
|
|||
|
" // otherwise not happen due to the minimum size styling.\n",
|
|||
|
" if (fig.ws.readyState == 1 && width != 0 && height != 0) {\n",
|
|||
|
" fig.request_resize(width, height);\n",
|
|||
|
" }\n",
|
|||
|
" }\n",
|
|||
|
" });\n",
|
|||
|
" this.resizeObserverInstance.observe(canvas_div);\n",
|
|||
|
"\n",
|
|||
|
" function on_mouse_event_closure(name) {\n",
|
|||
|
" return function (event) {\n",
|
|||
|
" return fig.mouse_event(event, name);\n",
|
|||
|
" };\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" rubberband_canvas.addEventListener(\n",
|
|||
|
" 'mousedown',\n",
|
|||
|
" on_mouse_event_closure('button_press')\n",
|
|||
|
" );\n",
|
|||
|
" rubberband_canvas.addEventListener(\n",
|
|||
|
" 'mouseup',\n",
|
|||
|
" on_mouse_event_closure('button_release')\n",
|
|||
|
" );\n",
|
|||
|
" rubberband_canvas.addEventListener(\n",
|
|||
|
" 'dblclick',\n",
|
|||
|
" on_mouse_event_closure('dblclick')\n",
|
|||
|
" );\n",
|
|||
|
" // Throttle sequential mouse events to 1 every 20ms.\n",
|
|||
|
" rubberband_canvas.addEventListener(\n",
|
|||
|
" 'mousemove',\n",
|
|||
|
" on_mouse_event_closure('motion_notify')\n",
|
|||
|
" );\n",
|
|||
|
"\n",
|
|||
|
" rubberband_canvas.addEventListener(\n",
|
|||
|
" 'mouseenter',\n",
|
|||
|
" on_mouse_event_closure('figure_enter')\n",
|
|||
|
" );\n",
|
|||
|
" rubberband_canvas.addEventListener(\n",
|
|||
|
" 'mouseleave',\n",
|
|||
|
" on_mouse_event_closure('figure_leave')\n",
|
|||
|
" );\n",
|
|||
|
"\n",
|
|||
|
" canvas_div.addEventListener('wheel', function (event) {\n",
|
|||
|
" if (event.deltaY < 0) {\n",
|
|||
|
" event.step = 1;\n",
|
|||
|
" } else {\n",
|
|||
|
" event.step = -1;\n",
|
|||
|
" }\n",
|
|||
|
" on_mouse_event_closure('scroll')(event);\n",
|
|||
|
" });\n",
|
|||
|
"\n",
|
|||
|
" canvas_div.appendChild(canvas);\n",
|
|||
|
" canvas_div.appendChild(rubberband_canvas);\n",
|
|||
|
"\n",
|
|||
|
" this.rubberband_context = rubberband_canvas.getContext('2d');\n",
|
|||
|
" this.rubberband_context.strokeStyle = '#000000';\n",
|
|||
|
"\n",
|
|||
|
" this._resize_canvas = function (width, height, forward) {\n",
|
|||
|
" if (forward) {\n",
|
|||
|
" canvas_div.style.width = width + 'px';\n",
|
|||
|
" canvas_div.style.height = height + 'px';\n",
|
|||
|
" }\n",
|
|||
|
" };\n",
|
|||
|
"\n",
|
|||
|
" // Disable right mouse context menu.\n",
|
|||
|
" this.rubberband_canvas.addEventListener('contextmenu', function (_e) {\n",
|
|||
|
" event.preventDefault();\n",
|
|||
|
" return false;\n",
|
|||
|
" });\n",
|
|||
|
"\n",
|
|||
|
" function set_focus() {\n",
|
|||
|
" canvas.focus();\n",
|
|||
|
" canvas_div.focus();\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" window.setTimeout(set_focus, 100);\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._init_toolbar = function () {\n",
|
|||
|
" var fig = this;\n",
|
|||
|
"\n",
|
|||
|
" var toolbar = document.createElement('div');\n",
|
|||
|
" toolbar.classList = 'mpl-toolbar';\n",
|
|||
|
" this.root.appendChild(toolbar);\n",
|
|||
|
"\n",
|
|||
|
" function on_click_closure(name) {\n",
|
|||
|
" return function (_event) {\n",
|
|||
|
" return fig.toolbar_button_onclick(name);\n",
|
|||
|
" };\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" function on_mouseover_closure(tooltip) {\n",
|
|||
|
" return function (event) {\n",
|
|||
|
" if (!event.currentTarget.disabled) {\n",
|
|||
|
" return fig.toolbar_button_onmouseover(tooltip);\n",
|
|||
|
" }\n",
|
|||
|
" };\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" fig.buttons = {};\n",
|
|||
|
" var buttonGroup = document.createElement('div');\n",
|
|||
|
" buttonGroup.classList = 'mpl-button-group';\n",
|
|||
|
" for (var toolbar_ind in mpl.toolbar_items) {\n",
|
|||
|
" var name = mpl.toolbar_items[toolbar_ind][0];\n",
|
|||
|
" var tooltip = mpl.toolbar_items[toolbar_ind][1];\n",
|
|||
|
" var image = mpl.toolbar_items[toolbar_ind][2];\n",
|
|||
|
" var method_name = mpl.toolbar_items[toolbar_ind][3];\n",
|
|||
|
"\n",
|
|||
|
" if (!name) {\n",
|
|||
|
" /* Instead of a spacer, we start a new button group. */\n",
|
|||
|
" if (buttonGroup.hasChildNodes()) {\n",
|
|||
|
" toolbar.appendChild(buttonGroup);\n",
|
|||
|
" }\n",
|
|||
|
" buttonGroup = document.createElement('div');\n",
|
|||
|
" buttonGroup.classList = 'mpl-button-group';\n",
|
|||
|
" continue;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" var button = (fig.buttons[name] = document.createElement('button'));\n",
|
|||
|
" button.classList = 'mpl-widget';\n",
|
|||
|
" button.setAttribute('role', 'button');\n",
|
|||
|
" button.setAttribute('aria-disabled', 'false');\n",
|
|||
|
" button.addEventListener('click', on_click_closure(method_name));\n",
|
|||
|
" button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n",
|
|||
|
"\n",
|
|||
|
" var icon_img = document.createElement('img');\n",
|
|||
|
" icon_img.src = '_images/' + image + '.png';\n",
|
|||
|
" icon_img.srcset = '_images/' + image + '_large.png 2x';\n",
|
|||
|
" icon_img.alt = tooltip;\n",
|
|||
|
" button.appendChild(icon_img);\n",
|
|||
|
"\n",
|
|||
|
" buttonGroup.appendChild(button);\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" if (buttonGroup.hasChildNodes()) {\n",
|
|||
|
" toolbar.appendChild(buttonGroup);\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" var fmt_picker = document.createElement('select');\n",
|
|||
|
" fmt_picker.classList = 'mpl-widget';\n",
|
|||
|
" toolbar.appendChild(fmt_picker);\n",
|
|||
|
" this.format_dropdown = fmt_picker;\n",
|
|||
|
"\n",
|
|||
|
" for (var ind in mpl.extensions) {\n",
|
|||
|
" var fmt = mpl.extensions[ind];\n",
|
|||
|
" var option = document.createElement('option');\n",
|
|||
|
" option.selected = fmt === mpl.default_extension;\n",
|
|||
|
" option.innerHTML = fmt;\n",
|
|||
|
" fmt_picker.appendChild(option);\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" var status_bar = document.createElement('span');\n",
|
|||
|
" status_bar.classList = 'mpl-message';\n",
|
|||
|
" toolbar.appendChild(status_bar);\n",
|
|||
|
" this.message = status_bar;\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.request_resize = function (x_pixels, y_pixels) {\n",
|
|||
|
" // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,\n",
|
|||
|
" // which will in turn request a refresh of the image.\n",
|
|||
|
" this.send_message('resize', { width: x_pixels, height: y_pixels });\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.send_message = function (type, properties) {\n",
|
|||
|
" properties['type'] = type;\n",
|
|||
|
" properties['figure_id'] = this.id;\n",
|
|||
|
" this.ws.send(JSON.stringify(properties));\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.send_draw_message = function () {\n",
|
|||
|
" if (!this.waiting) {\n",
|
|||
|
" this.waiting = true;\n",
|
|||
|
" this.ws.send(JSON.stringify({ type: 'draw', figure_id: this.id }));\n",
|
|||
|
" }\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_save = function (fig, _msg) {\n",
|
|||
|
" var format_dropdown = fig.format_dropdown;\n",
|
|||
|
" var format = format_dropdown.options[format_dropdown.selectedIndex].value;\n",
|
|||
|
" fig.ondownload(fig, format);\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_resize = function (fig, msg) {\n",
|
|||
|
" var size = msg['size'];\n",
|
|||
|
" if (size[0] !== fig.canvas.width || size[1] !== fig.canvas.height) {\n",
|
|||
|
" fig._resize_canvas(size[0], size[1], msg['forward']);\n",
|
|||
|
" fig.send_message('refresh', {});\n",
|
|||
|
" }\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_rubberband = function (fig, msg) {\n",
|
|||
|
" var x0 = msg['x0'] / fig.ratio;\n",
|
|||
|
" var y0 = (fig.canvas.height - msg['y0']) / fig.ratio;\n",
|
|||
|
" var x1 = msg['x1'] / fig.ratio;\n",
|
|||
|
" var y1 = (fig.canvas.height - msg['y1']) / fig.ratio;\n",
|
|||
|
" x0 = Math.floor(x0) + 0.5;\n",
|
|||
|
" y0 = Math.floor(y0) + 0.5;\n",
|
|||
|
" x1 = Math.floor(x1) + 0.5;\n",
|
|||
|
" y1 = Math.floor(y1) + 0.5;\n",
|
|||
|
" var min_x = Math.min(x0, x1);\n",
|
|||
|
" var min_y = Math.min(y0, y1);\n",
|
|||
|
" var width = Math.abs(x1 - x0);\n",
|
|||
|
" var height = Math.abs(y1 - y0);\n",
|
|||
|
"\n",
|
|||
|
" fig.rubberband_context.clearRect(\n",
|
|||
|
" 0,\n",
|
|||
|
" 0,\n",
|
|||
|
" fig.canvas.width / fig.ratio,\n",
|
|||
|
" fig.canvas.height / fig.ratio\n",
|
|||
|
" );\n",
|
|||
|
"\n",
|
|||
|
" fig.rubberband_context.strokeRect(min_x, min_y, width, height);\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_figure_label = function (fig, msg) {\n",
|
|||
|
" // Updates the figure title.\n",
|
|||
|
" fig.header.textContent = msg['label'];\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_cursor = function (fig, msg) {\n",
|
|||
|
" fig.rubberband_canvas.style.cursor = msg['cursor'];\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_message = function (fig, msg) {\n",
|
|||
|
" fig.message.textContent = msg['message'];\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_draw = function (fig, _msg) {\n",
|
|||
|
" // Request the server to send over a new figure.\n",
|
|||
|
" fig.send_draw_message();\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_image_mode = function (fig, msg) {\n",
|
|||
|
" fig.image_mode = msg['mode'];\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_history_buttons = function (fig, msg) {\n",
|
|||
|
" for (var key in msg) {\n",
|
|||
|
" if (!(key in fig.buttons)) {\n",
|
|||
|
" continue;\n",
|
|||
|
" }\n",
|
|||
|
" fig.buttons[key].disabled = !msg[key];\n",
|
|||
|
" fig.buttons[key].setAttribute('aria-disabled', !msg[key]);\n",
|
|||
|
" }\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_navigate_mode = function (fig, msg) {\n",
|
|||
|
" if (msg['mode'] === 'PAN') {\n",
|
|||
|
" fig.buttons['Pan'].classList.add('active');\n",
|
|||
|
" fig.buttons['Zoom'].classList.remove('active');\n",
|
|||
|
" } else if (msg['mode'] === 'ZOOM') {\n",
|
|||
|
" fig.buttons['Pan'].classList.remove('active');\n",
|
|||
|
" fig.buttons['Zoom'].classList.add('active');\n",
|
|||
|
" } else {\n",
|
|||
|
" fig.buttons['Pan'].classList.remove('active');\n",
|
|||
|
" fig.buttons['Zoom'].classList.remove('active');\n",
|
|||
|
" }\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.updated_canvas_event = function () {\n",
|
|||
|
" // Called whenever the canvas gets updated.\n",
|
|||
|
" this.send_message('ack', {});\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"// A function to construct a web socket function for onmessage handling.\n",
|
|||
|
"// Called in the figure constructor.\n",
|
|||
|
"mpl.figure.prototype._make_on_message_function = function (fig) {\n",
|
|||
|
" return function socket_on_message(evt) {\n",
|
|||
|
" if (evt.data instanceof Blob) {\n",
|
|||
|
" var img = evt.data;\n",
|
|||
|
" if (img.type !== 'image/png') {\n",
|
|||
|
" /* FIXME: We get \"Resource interpreted as Image but\n",
|
|||
|
" * transferred with MIME type text/plain:\" errors on\n",
|
|||
|
" * Chrome. But how to set the MIME type? It doesn't seem\n",
|
|||
|
" * to be part of the websocket stream */\n",
|
|||
|
" img.type = 'image/png';\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" /* Free the memory for the previous frames */\n",
|
|||
|
" if (fig.imageObj.src) {\n",
|
|||
|
" (window.URL || window.webkitURL).revokeObjectURL(\n",
|
|||
|
" fig.imageObj.src\n",
|
|||
|
" );\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(\n",
|
|||
|
" img\n",
|
|||
|
" );\n",
|
|||
|
" fig.updated_canvas_event();\n",
|
|||
|
" fig.waiting = false;\n",
|
|||
|
" return;\n",
|
|||
|
" } else if (\n",
|
|||
|
" typeof evt.data === 'string' &&\n",
|
|||
|
" evt.data.slice(0, 21) === 'data:image/png;base64'\n",
|
|||
|
" ) {\n",
|
|||
|
" fig.imageObj.src = evt.data;\n",
|
|||
|
" fig.updated_canvas_event();\n",
|
|||
|
" fig.waiting = false;\n",
|
|||
|
" return;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" var msg = JSON.parse(evt.data);\n",
|
|||
|
" var msg_type = msg['type'];\n",
|
|||
|
"\n",
|
|||
|
" // Call the \"handle_{type}\" callback, which takes\n",
|
|||
|
" // the figure and JSON message as its only arguments.\n",
|
|||
|
" try {\n",
|
|||
|
" var callback = fig['handle_' + msg_type];\n",
|
|||
|
" } catch (e) {\n",
|
|||
|
" console.log(\n",
|
|||
|
" \"No handler for the '\" + msg_type + \"' message type: \",\n",
|
|||
|
" msg\n",
|
|||
|
" );\n",
|
|||
|
" return;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" if (callback) {\n",
|
|||
|
" try {\n",
|
|||
|
" // console.log(\"Handling '\" + msg_type + \"' message: \", msg);\n",
|
|||
|
" callback(fig, msg);\n",
|
|||
|
" } catch (e) {\n",
|
|||
|
" console.log(\n",
|
|||
|
" \"Exception inside the 'handler_\" + msg_type + \"' callback:\",\n",
|
|||
|
" e,\n",
|
|||
|
" e.stack,\n",
|
|||
|
" msg\n",
|
|||
|
" );\n",
|
|||
|
" }\n",
|
|||
|
" }\n",
|
|||
|
" };\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"// from https://stackoverflow.com/questions/1114465/getting-mouse-location-in-canvas\n",
|
|||
|
"mpl.findpos = function (e) {\n",
|
|||
|
" //this section is from http://www.quirksmode.org/js/events_properties.html\n",
|
|||
|
" var targ;\n",
|
|||
|
" if (!e) {\n",
|
|||
|
" e = window.event;\n",
|
|||
|
" }\n",
|
|||
|
" if (e.target) {\n",
|
|||
|
" targ = e.target;\n",
|
|||
|
" } else if (e.srcElement) {\n",
|
|||
|
" targ = e.srcElement;\n",
|
|||
|
" }\n",
|
|||
|
" if (targ.nodeType === 3) {\n",
|
|||
|
" // defeat Safari bug\n",
|
|||
|
" targ = targ.parentNode;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" // pageX,Y are the mouse positions relative to the document\n",
|
|||
|
" var boundingRect = targ.getBoundingClientRect();\n",
|
|||
|
" var x = e.pageX - (boundingRect.left + document.body.scrollLeft);\n",
|
|||
|
" var y = e.pageY - (boundingRect.top + document.body.scrollTop);\n",
|
|||
|
"\n",
|
|||
|
" return { x: x, y: y };\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"/*\n",
|
|||
|
" * return a copy of an object with only non-object keys\n",
|
|||
|
" * we need this to avoid circular references\n",
|
|||
|
" * https://stackoverflow.com/a/24161582/3208463\n",
|
|||
|
" */\n",
|
|||
|
"function simpleKeys(original) {\n",
|
|||
|
" return Object.keys(original).reduce(function (obj, key) {\n",
|
|||
|
" if (typeof original[key] !== 'object') {\n",
|
|||
|
" obj[key] = original[key];\n",
|
|||
|
" }\n",
|
|||
|
" return obj;\n",
|
|||
|
" }, {});\n",
|
|||
|
"}\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.mouse_event = function (event, name) {\n",
|
|||
|
" var canvas_pos = mpl.findpos(event);\n",
|
|||
|
"\n",
|
|||
|
" if (name === 'button_press') {\n",
|
|||
|
" this.canvas.focus();\n",
|
|||
|
" this.canvas_div.focus();\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" var x = canvas_pos.x * this.ratio;\n",
|
|||
|
" var y = canvas_pos.y * this.ratio;\n",
|
|||
|
"\n",
|
|||
|
" this.send_message(name, {\n",
|
|||
|
" x: x,\n",
|
|||
|
" y: y,\n",
|
|||
|
" button: event.button,\n",
|
|||
|
" step: event.step,\n",
|
|||
|
" guiEvent: simpleKeys(event),\n",
|
|||
|
" });\n",
|
|||
|
"\n",
|
|||
|
" /* This prevents the web browser from automatically changing to\n",
|
|||
|
" * the text insertion cursor when the button is pressed. We want\n",
|
|||
|
" * to control all of the cursor setting manually through the\n",
|
|||
|
" * 'cursor' event from matplotlib */\n",
|
|||
|
" event.preventDefault();\n",
|
|||
|
" return false;\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._key_event_extra = function (_event, _name) {\n",
|
|||
|
" // Handle any extra behaviour associated with a key event\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.key_event = function (event, name) {\n",
|
|||
|
" // Prevent repeat events\n",
|
|||
|
" if (name === 'key_press') {\n",
|
|||
|
" if (event.key === this._key) {\n",
|
|||
|
" return;\n",
|
|||
|
" } else {\n",
|
|||
|
" this._key = event.key;\n",
|
|||
|
" }\n",
|
|||
|
" }\n",
|
|||
|
" if (name === 'key_release') {\n",
|
|||
|
" this._key = null;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" var value = '';\n",
|
|||
|
" if (event.ctrlKey && event.key !== 'Control') {\n",
|
|||
|
" value += 'ctrl+';\n",
|
|||
|
" }\n",
|
|||
|
" else if (event.altKey && event.key !== 'Alt') {\n",
|
|||
|
" value += 'alt+';\n",
|
|||
|
" }\n",
|
|||
|
" else if (event.shiftKey && event.key !== 'Shift') {\n",
|
|||
|
" value += 'shift+';\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" value += 'k' + event.key;\n",
|
|||
|
"\n",
|
|||
|
" this._key_event_extra(event, name);\n",
|
|||
|
"\n",
|
|||
|
" this.send_message(name, { key: value, guiEvent: simpleKeys(event) });\n",
|
|||
|
" return false;\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.toolbar_button_onclick = function (name) {\n",
|
|||
|
" if (name === 'download') {\n",
|
|||
|
" this.handle_save(this, null);\n",
|
|||
|
" } else {\n",
|
|||
|
" this.send_message('toolbar_button', { name: name });\n",
|
|||
|
" }\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.toolbar_button_onmouseover = function (tooltip) {\n",
|
|||
|
" this.message.textContent = tooltip;\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"///////////////// REMAINING CONTENT GENERATED BY embed_js.py /////////////////\n",
|
|||
|
"// prettier-ignore\n",
|
|||
|
"var _JSXTOOLS_RESIZE_OBSERVER=function(A){var t,i=new WeakMap,n=new WeakMap,a=new WeakMap,r=new WeakMap,o=new Set;function s(e){if(!(this instanceof s))throw new TypeError(\"Constructor requires 'new' operator\");i.set(this,e)}function h(){throw new TypeError(\"Function is not a constructor\")}function c(e,t,i,n){e=0 in arguments?Number(arguments[0]):0,t=1 in arguments?Number(arguments[1]):0,i=2 in arguments?Number(arguments[2]):0,n=3 in arguments?Number(arguments[3]):0,this.right=(this.x=this.left=e)+(this.width=i),this.bottom=(this.y=this.top=t)+(this.height=n),Object.freeze(this)}function d(){t=requestAnimationFrame(d);var s=new WeakMap,p=new Set;o.forEach((function(t){r.get(t).forEach((function(i){var r=t instanceof window.SVGElement,o=a.get(t),d=r?0:parseFloat(o.paddingTop),f=r?0:parseFloat(o.paddingRight),l=r?0:parseFloat(o.paddingBottom),u=r?0:parseFloat(o.paddingLeft),g=r?0:parseFloat(o.borderTopWidth),m=r?0:parseFloat(o.borderRightWidth),w=r?0:parseFloat(o.borderBottomWidth),b=u+f,F=d+l,v=(r?0:parseFloat(o.borderLeftWidth))+m,W=g+w,y=r?0:t.offsetHeight-W-t.clientHeight,E=r?0:t.offsetWidth-v-t.clientWidth,R=b+v,z=F+W,M=r?t.width:parseFloat(o.width)-R-E,O=r?t.height:parseFloat(o.height)-z-y;if(n.has(t)){var k=n.get(t);if(k[0]===M&&k[1]===O)return}n.set(t,[M,O]);var S=Object.create(h.prototype);S.target=t,S.contentRect=new c(u,d,M,O),s.has(i)||(s.set(i,[]),p.add(i)),s.get(i).push(S)}))})),p.forEach((function(e){i.get(e).call(e,s.get(e),e)}))}return s.prototype.observe=function(i){if(i instanceof window.Element){r.has(i)||(r.set(i,new Set),o.add(i),a.set(i,window.getComputedStyle(i)));var n=r.get(i);n.has(this)||n.add(this),cancelAnimationFrame(t),t=requestAnimationFrame(d)}},s.prototype.unobserve=function(i){if(i instanceof window.Element&&r.has(i)){var n=r.get(i);n.has(this)&&(n.delete(this),n.size||(r.delete(i),o.delete(i))),n.size||r.delete(i),o.size||cancelAnimationFrame(t)}},A.DOMRectReadOnly=c,A.ResizeObserver=s,A.ResizeObserverEntry=h,A}; // eslint-disable-line\n",
|
|||
|
"mpl.toolbar_items = [[\"Home\", \"Reset original view\", \"fa fa-home icon-home\", \"home\"], [\"Back\", \"Back to previous view\", \"fa fa-arrow-left icon-arrow-left\", \"back\"], [\"Forward\", \"Forward to next view\", \"fa fa-arrow-right icon-arrow-right\", \"forward\"], [\"\", \"\", \"\", \"\"], [\"Pan\", \"Left button pans, Right button zooms\\nx/y fixes axis, CTRL fixes aspect\", \"fa fa-arrows icon-move\", \"pan\"], [\"Zoom\", \"Zoom to rectangle\\nx/y fixes axis\", \"fa fa-square-o icon-check-empty\", \"zoom\"], [\"\", \"\", \"\", \"\"], [\"Download\", \"Download plot\", \"fa fa-floppy-o icon-save\", \"download\"]];\n",
|
|||
|
"\n",
|
|||
|
"mpl.extensions = [\"eps\", \"jpeg\", \"pgf\", \"pdf\", \"png\", \"ps\", \"raw\", \"svg\", \"tif\"];\n",
|
|||
|
"\n",
|
|||
|
"mpl.default_extension = \"png\";/* global mpl */\n",
|
|||
|
"\n",
|
|||
|
"var comm_websocket_adapter = function (comm) {\n",
|
|||
|
" // Create a \"websocket\"-like object which calls the given IPython comm\n",
|
|||
|
" // object with the appropriate methods. Currently this is a non binary\n",
|
|||
|
" // socket, so there is still some room for performance tuning.\n",
|
|||
|
" var ws = {};\n",
|
|||
|
"\n",
|
|||
|
" ws.binaryType = comm.kernel.ws.binaryType;\n",
|
|||
|
" ws.readyState = comm.kernel.ws.readyState;\n",
|
|||
|
" function updateReadyState(_event) {\n",
|
|||
|
" if (comm.kernel.ws) {\n",
|
|||
|
" ws.readyState = comm.kernel.ws.readyState;\n",
|
|||
|
" } else {\n",
|
|||
|
" ws.readyState = 3; // Closed state.\n",
|
|||
|
" }\n",
|
|||
|
" }\n",
|
|||
|
" comm.kernel.ws.addEventListener('open', updateReadyState);\n",
|
|||
|
" comm.kernel.ws.addEventListener('close', updateReadyState);\n",
|
|||
|
" comm.kernel.ws.addEventListener('error', updateReadyState);\n",
|
|||
|
"\n",
|
|||
|
" ws.close = function () {\n",
|
|||
|
" comm.close();\n",
|
|||
|
" };\n",
|
|||
|
" ws.send = function (m) {\n",
|
|||
|
" //console.log('sending', m);\n",
|
|||
|
" comm.send(m);\n",
|
|||
|
" };\n",
|
|||
|
" // Register the callback with on_msg.\n",
|
|||
|
" comm.on_msg(function (msg) {\n",
|
|||
|
" //console.log('receiving', msg['content']['data'], msg);\n",
|
|||
|
" var data = msg['content']['data'];\n",
|
|||
|
" if (data['blob'] !== undefined) {\n",
|
|||
|
" data = {\n",
|
|||
|
" data: new Blob(msg['buffers'], { type: data['blob'] }),\n",
|
|||
|
" };\n",
|
|||
|
" }\n",
|
|||
|
" // Pass the mpl event to the overridden (by mpl) onmessage function.\n",
|
|||
|
" ws.onmessage(data);\n",
|
|||
|
" });\n",
|
|||
|
" return ws;\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.mpl_figure_comm = function (comm, msg) {\n",
|
|||
|
" // This is the function which gets called when the mpl process\n",
|
|||
|
" // starts-up an IPython Comm through the \"matplotlib\" channel.\n",
|
|||
|
"\n",
|
|||
|
" var id = msg.content.data.id;\n",
|
|||
|
" // Get hold of the div created by the display call when the Comm\n",
|
|||
|
" // socket was opened in Python.\n",
|
|||
|
" var element = document.getElementById(id);\n",
|
|||
|
" var ws_proxy = comm_websocket_adapter(comm);\n",
|
|||
|
"\n",
|
|||
|
" function ondownload(figure, _format) {\n",
|
|||
|
" window.open(figure.canvas.toDataURL());\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" var fig = new mpl.figure(id, ws_proxy, ondownload, element);\n",
|
|||
|
"\n",
|
|||
|
" // Call onopen now - mpl needs it, as it is assuming we've passed it a real\n",
|
|||
|
" // web socket which is closed, not our websocket->open comm proxy.\n",
|
|||
|
" ws_proxy.onopen();\n",
|
|||
|
"\n",
|
|||
|
" fig.parent_element = element;\n",
|
|||
|
" fig.cell_info = mpl.find_output_cell(\"<div id='\" + id + \"'></div>\");\n",
|
|||
|
" if (!fig.cell_info) {\n",
|
|||
|
" console.error('Failed to find cell for figure', id, fig);\n",
|
|||
|
" return;\n",
|
|||
|
" }\n",
|
|||
|
" fig.cell_info[0].output_area.element.on(\n",
|
|||
|
" 'cleared',\n",
|
|||
|
" { fig: fig },\n",
|
|||
|
" fig._remove_fig_handler\n",
|
|||
|
" );\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_close = function (fig, msg) {\n",
|
|||
|
" var width = fig.canvas.width / fig.ratio;\n",
|
|||
|
" fig.cell_info[0].output_area.element.off(\n",
|
|||
|
" 'cleared',\n",
|
|||
|
" fig._remove_fig_handler\n",
|
|||
|
" );\n",
|
|||
|
" fig.resizeObserverInstance.unobserve(fig.canvas_div);\n",
|
|||
|
"\n",
|
|||
|
" // Update the output cell to use the data from the current canvas.\n",
|
|||
|
" fig.push_to_output();\n",
|
|||
|
" var dataURL = fig.canvas.toDataURL();\n",
|
|||
|
" // Re-enable the keyboard manager in IPython - without this line, in FF,\n",
|
|||
|
" // the notebook keyboard shortcuts fail.\n",
|
|||
|
" IPython.keyboard_manager.enable();\n",
|
|||
|
" fig.parent_element.innerHTML =\n",
|
|||
|
" '<img src=\"' + dataURL + '\" width=\"' + width + '\">';\n",
|
|||
|
" fig.close_ws(fig, msg);\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.close_ws = function (fig, msg) {\n",
|
|||
|
" fig.send_message('closing', msg);\n",
|
|||
|
" // fig.ws.close()\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.push_to_output = function (_remove_interactive) {\n",
|
|||
|
" // Turn the data on the canvas into data in the output cell.\n",
|
|||
|
" var width = this.canvas.width / this.ratio;\n",
|
|||
|
" var dataURL = this.canvas.toDataURL();\n",
|
|||
|
" this.cell_info[1]['text/html'] =\n",
|
|||
|
" '<img src=\"' + dataURL + '\" width=\"' + width + '\">';\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.updated_canvas_event = function () {\n",
|
|||
|
" // Tell IPython that the notebook contents must change.\n",
|
|||
|
" IPython.notebook.set_dirty(true);\n",
|
|||
|
" this.send_message('ack', {});\n",
|
|||
|
" var fig = this;\n",
|
|||
|
" // Wait a second, then push the new image to the DOM so\n",
|
|||
|
" // that it is saved nicely (might be nice to debounce this).\n",
|
|||
|
" setTimeout(function () {\n",
|
|||
|
" fig.push_to_output();\n",
|
|||
|
" }, 1000);\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._init_toolbar = function () {\n",
|
|||
|
" var fig = this;\n",
|
|||
|
"\n",
|
|||
|
" var toolbar = document.createElement('div');\n",
|
|||
|
" toolbar.classList = 'btn-toolbar';\n",
|
|||
|
" this.root.appendChild(toolbar);\n",
|
|||
|
"\n",
|
|||
|
" function on_click_closure(name) {\n",
|
|||
|
" return function (_event) {\n",
|
|||
|
" return fig.toolbar_button_onclick(name);\n",
|
|||
|
" };\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" function on_mouseover_closure(tooltip) {\n",
|
|||
|
" return function (event) {\n",
|
|||
|
" if (!event.currentTarget.disabled) {\n",
|
|||
|
" return fig.toolbar_button_onmouseover(tooltip);\n",
|
|||
|
" }\n",
|
|||
|
" };\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" fig.buttons = {};\n",
|
|||
|
" var buttonGroup = document.createElement('div');\n",
|
|||
|
" buttonGroup.classList = 'btn-group';\n",
|
|||
|
" var button;\n",
|
|||
|
" for (var toolbar_ind in mpl.toolbar_items) {\n",
|
|||
|
" var name = mpl.toolbar_items[toolbar_ind][0];\n",
|
|||
|
" var tooltip = mpl.toolbar_items[toolbar_ind][1];\n",
|
|||
|
" var image = mpl.toolbar_items[toolbar_ind][2];\n",
|
|||
|
" var method_name = mpl.toolbar_items[toolbar_ind][3];\n",
|
|||
|
"\n",
|
|||
|
" if (!name) {\n",
|
|||
|
" /* Instead of a spacer, we start a new button group. */\n",
|
|||
|
" if (buttonGroup.hasChildNodes()) {\n",
|
|||
|
" toolbar.appendChild(buttonGroup);\n",
|
|||
|
" }\n",
|
|||
|
" buttonGroup = document.createElement('div');\n",
|
|||
|
" buttonGroup.classList = 'btn-group';\n",
|
|||
|
" continue;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" button = fig.buttons[name] = document.createElement('button');\n",
|
|||
|
" button.classList = 'btn btn-default';\n",
|
|||
|
" button.href = '#';\n",
|
|||
|
" button.title = name;\n",
|
|||
|
" button.innerHTML = '<i class=\"fa ' + image + ' fa-lg\"></i>';\n",
|
|||
|
" button.addEventListener('click', on_click_closure(method_name));\n",
|
|||
|
" button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n",
|
|||
|
" buttonGroup.appendChild(button);\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" if (buttonGroup.hasChildNodes()) {\n",
|
|||
|
" toolbar.appendChild(buttonGroup);\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" // Add the status bar.\n",
|
|||
|
" var status_bar = document.createElement('span');\n",
|
|||
|
" status_bar.classList = 'mpl-message pull-right';\n",
|
|||
|
" toolbar.appendChild(status_bar);\n",
|
|||
|
" this.message = status_bar;\n",
|
|||
|
"\n",
|
|||
|
" // Add the close button to the window.\n",
|
|||
|
" var buttongrp = document.createElement('div');\n",
|
|||
|
" buttongrp.classList = 'btn-group inline pull-right';\n",
|
|||
|
" button = document.createElement('button');\n",
|
|||
|
" button.classList = 'btn btn-mini btn-primary';\n",
|
|||
|
" button.href = '#';\n",
|
|||
|
" button.title = 'Stop Interaction';\n",
|
|||
|
" button.innerHTML = '<i class=\"fa fa-power-off icon-remove icon-large\"></i>';\n",
|
|||
|
" button.addEventListener('click', function (_evt) {\n",
|
|||
|
" fig.handle_close(fig, {});\n",
|
|||
|
" });\n",
|
|||
|
" button.addEventListener(\n",
|
|||
|
" 'mouseover',\n",
|
|||
|
" on_mouseover_closure('Stop Interaction')\n",
|
|||
|
" );\n",
|
|||
|
" buttongrp.appendChild(button);\n",
|
|||
|
" var titlebar = this.root.querySelector('.ui-dialog-titlebar');\n",
|
|||
|
" titlebar.insertBefore(buttongrp, titlebar.firstChild);\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._remove_fig_handler = function (event) {\n",
|
|||
|
" var fig = event.data.fig;\n",
|
|||
|
" if (event.target !== this) {\n",
|
|||
|
" // Ignore bubbled events from children.\n",
|
|||
|
" return;\n",
|
|||
|
" }\n",
|
|||
|
" fig.close_ws(fig, {});\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._root_extra_style = function (el) {\n",
|
|||
|
" el.style.boxSizing = 'content-box'; // override notebook setting of border-box.\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._canvas_extra_style = function (el) {\n",
|
|||
|
" // this is important to make the div 'focusable\n",
|
|||
|
" el.setAttribute('tabindex', 0);\n",
|
|||
|
" // reach out to IPython and tell the keyboard manager to turn it's self\n",
|
|||
|
" // off when our div gets focus\n",
|
|||
|
"\n",
|
|||
|
" // location in version 3\n",
|
|||
|
" if (IPython.notebook.keyboard_manager) {\n",
|
|||
|
" IPython.notebook.keyboard_manager.register_events(el);\n",
|
|||
|
" } else {\n",
|
|||
|
" // location in version 2\n",
|
|||
|
" IPython.keyboard_manager.register_events(el);\n",
|
|||
|
" }\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._key_event_extra = function (event, _name) {\n",
|
|||
|
" // Check for shift+enter\n",
|
|||
|
" if (event.shiftKey && event.which === 13) {\n",
|
|||
|
" this.canvas_div.blur();\n",
|
|||
|
" // select the cell after this one\n",
|
|||
|
" var index = IPython.notebook.find_cell_index(this.cell_info[0]);\n",
|
|||
|
" IPython.notebook.select(index + 1);\n",
|
|||
|
" }\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_save = function (fig, _msg) {\n",
|
|||
|
" fig.ondownload(fig, null);\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.find_output_cell = function (html_output) {\n",
|
|||
|
" // Return the cell and output element which can be found *uniquely* in the notebook.\n",
|
|||
|
" // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n",
|
|||
|
" // IPython event is triggered only after the cells have been serialised, which for\n",
|
|||
|
" // our purposes (turning an active figure into a static one), is too late.\n",
|
|||
|
" var cells = IPython.notebook.get_cells();\n",
|
|||
|
" var ncells = cells.length;\n",
|
|||
|
" for (var i = 0; i < ncells; i++) {\n",
|
|||
|
" var cell = cells[i];\n",
|
|||
|
" if (cell.cell_type === 'code') {\n",
|
|||
|
" for (var j = 0; j < cell.output_area.outputs.length; j++) {\n",
|
|||
|
" var data = cell.output_area.outputs[j];\n",
|
|||
|
" if (data.data) {\n",
|
|||
|
" // IPython >= 3 moved mimebundle to data attribute of output\n",
|
|||
|
" data = data.data;\n",
|
|||
|
" }\n",
|
|||
|
" if (data['text/html'] === html_output) {\n",
|
|||
|
" return [cell, data, j];\n",
|
|||
|
" }\n",
|
|||
|
" }\n",
|
|||
|
" }\n",
|
|||
|
" }\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"// Register the function which deals with the matplotlib target/channel.\n",
|
|||
|
"// The kernel may be null if the page has been refreshed.\n",
|
|||
|
"if (IPython.notebook.kernel !== null) {\n",
|
|||
|
" IPython.notebook.kernel.comm_manager.register_target(\n",
|
|||
|
" 'matplotlib',\n",
|
|||
|
" mpl.mpl_figure_comm\n",
|
|||
|
" );\n",
|
|||
|
"}\n"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
"<IPython.core.display.Javascript object>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
},
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/html": [
|
|||
|
"<img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABQAAAAPACAYAAABq3NR5AAAgAElEQVR4XuydB9hUxdmGxxJ7F1RAURALYkGkaOxg7xqV2HuJPRqNvceusffeYmwxsWFXFFFBNFgwFhQNWIgl9liSn3v4ZxmWc86e3W/325mzz3tduSLfnvLOPe+ZM/Ocd2am+98kMzIREAEREAEREAEREAEREAEREAEREAEREAEREIFCEphOAmAh61WFEgEREAEREAEREAEREAEREAEREAEREAEREAFLQAKgAkEEREAEREAEREAEREAEREAEREAEREAEREAECkxAAmCBK1dFEwEREAEREAEREAEREAEREAEREAEREAEREAEJgIoBERABERABERABERABERABERABERABERABESgwAQmABa5cFU0EREAEREAEREAEREAEREAEREAEREAEREAEJAAqBkRABERABERABERABERABERABERABERABESgwAQkABa4clU0ERABERABERABERABERABERABERABERABEZAAqBgQAREQAREQAREQAREQAREQAREQAREQAREQgQITkABY4MpV0URABERABERABERABERABERABERABERABERAAqBiQAREQAREQAREQAREQAREQAREQAREQAREQAQKTEACYIErV0UTAREQAREQAREQAREQAREQAREQAREQAREQAQmAigEREAEREAEREAEREAEREAEREAEREAEREAERKDABCYAFrlwVTQREQAREQAREQAREQAREQAREQAREQAREQAQkACoGREAEREAEREAEREAEREAEREAEREAEREAERKDABCQAFrhyVTQREAEREAEREAEREAEREAEREAEREAEREAERkACoGBABERABERABERABERABERABERABERABERCBAhOQAFjgylXRREAEREAEREAEREAEREAEREAEREAEREAEREACoGJABERABERABERABERABERABERABERABERABApMQAJggStXRRMBERABERABERABERABERABERABERABERABCYCKAREQAREQAREQAREQAREQAREQAREQAREQAREoMAEJgAWuXBVNBERABERABERABERABERABERABERABERABCQAKgZEQAREQAREQAREQAREQAREQAREQAREQAREoMAEJAAWuHJVNBEQAREQAREQAREQAREQAREQAREQAREQARGQAKgYEAEREAEREAEREAEREAEREAEREAEREAEREIECE5AAWODKVdFEQAREQAREQAREQAREQAREQAREQAREQAREQAKgYkAEREAEREAEREAEREAEREAEREAEREAEREAECkxAAmCBK1dFEwEREAEREAEREAEREAEREAEREAEREAEREAEJgIoBERABERABERABERABERABERABERABERABESgwAQmABa5cFU0EREAEREAEREAEREAEREAEREAEREAEREAEJAAqBkRABERABERABERABERABERABERABERABESgwAQkABa4clU0ERABERABERABERABERABERABERABERABEZAAqBgQAREQAREQAREQAREQAREQAREQAREQAREQgQITkABY4MpV0URABERABERABERABERABERABERABERABERAAqBiQAREQAREQAREQAREQAREQAREQAREQAREQAQKTEACYIErV0UTAREQAREQAREQAREQAREQAREQAREQAREQAQmAigEREAEREAEREAEREAEREAEREAEREAEREAERKDABCYAFrlwVTQREQAREQAREQAREQAREQAREQAREQAREQAQkACoGREAEREAEREAEREAEREAEREAEREAEREAERKDABCQAFrhyVTQREAEREAEREAEREAEREAEREAEREAEREAERkACoGBABERABERABERABERABERABERABERABERCBAhOQAFjgylXRREAEREAEREAEREAEREAEREAEREAEREAEREACoGJABERABERABERABERABERABERABERABERABApMQAJggStXRRMBERABERABERABERABERABERABERABERABCYCKAREQAREQAREQAREQAREQAREQAREQAREQAREoMAEJgAWuXBVNBERABERABERABERABERABERABERABERABCQAKgZEQAREQAREQAREQAREQAREQAREQAREQAREoMAEJAAWuHJVNBEQAREQAREQAREQAREQAREQAREQAREQARGQAKgYEAEREAEREAEREAEREAEREAEREAEREAEREIECE5AAWODKVdFEQAREQAREQAREQAREQAREQAREQAREQAREQAKgYkAEREAEREAEREAEREAEREAEREAEREAEREAECkxAAmCBK1dFEwEREAEREAEREAEREAEREAEREAEREAEREAEJgIoBERABERABERABERABERABERABERABERABESgwAQmABa5cFU0EREAEREAEREAEREAEREAEREAEREAEREAEJAAqBkRABERABERABERABERABERABERABERABESgwAQkABa4clU0ERABERABERABERABERABERABERABERABEZAAqBgQAREQAREQAREQAREQAREQAREQAREQAREQgQITkABY4MpV0URABERABERABERABERABERABERABERABERAAqBiQAREQAREQAREQAREQAREQAREQAREQAREQAQKTEACYIErV0UTAREQAREQAREQAREQAREQAREQAREQAREQAQmAigEREAEREAEREAEREAEREAEREAEREAEREAERKDABCYAFrlwVTQREQAREQAREQAREQAREQAREQAREQAREQAQkACoGREAEREAEREAEREAEREAEREAEREAEREAERKDABCQAFrhyVTQREAEREAEREAEREAEREAEREAEREAEREAERkACoGBABERABERABERABERABERABERABERABERCBAhOQAFjgylXRREAEREAEREAEREAEREAEREAEREAEREAEREACoGJABERABERABERABERABERABERABERABERABApMQAJggStXRRMBERABERABERABERABERABERABERABERABCYCKAREQAREQAREQAREQAREQAREQAREQAREQAREoMAEJgAWuXBVNBERABERABERABERABERABERABERABERABCQAKgZEQAREQAREQAREQAREQAREQAREQAREQAREoMAEJAAWuHJVNBEQAREQAREQAREQAREQAREQAREQAREQARGQAKgYEAEREAEREAEREAEREAEREAEREAEREAEREIECE5AAWODKVdFEQARak8Baa61lnnrqKVv4J554wvDvEO29994z3bp1s64tuuiihn/LRKCZBL799ltz+eWXm3vuuce8/vrr5osvvjA///yzdemEE04wJ554YlXuXX/99Wa33Xaz5+yyyy6Gf5db3udguummK536v//9ryo/dHBrEWjFWMnzrFUTBbG8R6spk44VAREQAREQAQmAigEREIGGEvjyyy/Ngw8+aB555BEzcuRIM3HiRPOvf/3LzDTTTGbeeec1Sy65pOnXr5/ZbLPNzCqrrNJQX1rl4rEMXPIKH61Sbypncwl89tlnZo011jCvvfZaoiMSAJtbP7p7fgISAJPF9vwEjf1wFsOHtGrKpGNFQAREQAREQAKgYkAERKAhBMikOf/8880555xjPv/881z3QAwkw+bXv/618QcwuU7WQSUCzRi41CLm1XKOqlkEGkVgr732MldffbW9/IwzzmgGDRpkM1N/8Ytf2L9ttNFG9n/VWJ6spLzPQSuKOtWw1rFTCLRirOR51qqJkWa8R6vxT8eKgCOQ9x0iYiIgAiIAAQmAigMREIG6E3j//ffNpptuakaPHj3Vtbt27WqWX35507FjRzut7qOPPjJ///vfzccffzzVcWeeeaY54ogj6u5Xq1ywGQOXWjqgtZzTKnWocrYvgZ9++snMM8885ptvvrE3JvOHbMC2Wh5RIu9z0IqiTlv5t+r5rRgreZ61auKhGe/RavzTsSIgAV
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
"<IPython.core.display.HTML object>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"%matplotlib notebook\n",
|
|||
|
"\n",
|
|||
|
"cumsum_accounts = sorted_accounts['likes'].cumsum().reset_index(drop=True)\n",
|
|||
|
"\n",
|
|||
|
"plt.plot(cumsum_accounts)\n",
|
|||
|
"\n",
|
|||
|
"for q_label, q_idx in zip(quants, quant_idx):\n",
|
|||
|
" plt.axvline(x=q_idx, color='black', linestyle='--', linewidth=.1)\n",
|
|||
|
" plt.annotate(text=str(q_label), xy=(q_idx, max(cumsum_accounts)), xycoords='data')\n",
|
|||
|
"\n",
|
|||
|
"plt.title('Cumulative sum of likes received by accounts') \n",
|
|||
|
"\n",
|
|||
|
"plt.show()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 18,
|
|||
|
"id": "edbf19cc",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"0.4046510606526417"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 18,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"len(accounts[accounts['likes']==0]['likes']) / len(accounts)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "cbf4bf37",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"Proportion of interactions received by the 99th and 95th percentile of most interacted with accounts"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 19,
|
|||
|
"id": "da3a792a",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"0.3979456206591834"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 19,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"percentile = 0.99\n",
|
|||
|
"accounts.loc[accounts['likes'] >= quantiles[percentile], 'likes'].sum() / accounts['likes'].sum()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 116,
|
|||
|
"id": "f018a478",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"0.759416544458887"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 116,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"percentile = 0.95\n",
|
|||
|
"accounts.loc[accounts['likes'] >= quantiles[percentile], 'likes'].sum() / accounts['likes'].sum()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "66961868",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"Excluding interactions with the top (percentile) accounts"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": null,
|
|||
|
"id": "2d6a7119",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": []
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 117,
|
|||
|
"id": "db949eae",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"top_accounts = accounts.loc[accounts['likes'] >= quantiles[percentile]]\n"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 118,
|
|||
|
"id": "660122a8",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"top_posts = posts.loc[posts['authorDid'].isin(top_accounts['account'])]\n",
|
|||
|
"non_top_posts = posts.loc[~posts['authorDid'].isin(top_accounts['account'])]\n",
|
|||
|
"top_threads = posts.loc[np.logical_or(\n",
|
|||
|
" posts['replyRoot'].isin(top_posts['uri']),\n",
|
|||
|
" posts['replyParent'].isin(top_posts['uri'])\n",
|
|||
|
")]"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 119,
|
|||
|
"id": "9bf35229",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/html": [
|
|||
|
"<div>\n",
|
|||
|
"<style scoped>\n",
|
|||
|
" .dataframe tbody tr th:only-of-type {\n",
|
|||
|
" vertical-align: middle;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" .dataframe tbody tr th {\n",
|
|||
|
" vertical-align: top;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" .dataframe thead th {\n",
|
|||
|
" text-align: right;\n",
|
|||
|
" }\n",
|
|||
|
"</style>\n",
|
|||
|
"<table border=\"1\" class=\"dataframe\">\n",
|
|||
|
" <thead>\n",
|
|||
|
" <tr style=\"text-align: right;\">\n",
|
|||
|
" <th></th>\n",
|
|||
|
" <th>uri</th>\n",
|
|||
|
" <th>cid</th>\n",
|
|||
|
" <th>authorDid</th>\n",
|
|||
|
" <th>indexedAt</th>\n",
|
|||
|
" <th>createdAt</th>\n",
|
|||
|
" <th>subjectUri</th>\n",
|
|||
|
" <th>subjectCid</th>\n",
|
|||
|
" <th>subjectDid</th>\n",
|
|||
|
" </tr>\n",
|
|||
|
" </thead>\n",
|
|||
|
" <tbody>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>2</th>\n",
|
|||
|
" <td>at://did:plc:tt2krpcels6fzdwt5e2iold6/app.bsky...</td>\n",
|
|||
|
" <td>bafyreib3ozumx3qi3mb7wqmhedj2fftrosycnksyt25xc...</td>\n",
|
|||
|
" <td>did:plc:tt2krpcels6fzdwt5e2iold6</td>\n",
|
|||
|
" <td>2023-06-28T06:50:32.931Z</td>\n",
|
|||
|
" <td>2023-06-28T06:50:32.736Z</td>\n",
|
|||
|
" <td>at://did:plc:m2hze6zxa744iberzknpkc3i/app.bsky...</td>\n",
|
|||
|
" <td>bafyreibbhg6hz64gakzkptazxpwstfbbbid6a4fw6w5m5...</td>\n",
|
|||
|
" <td>did:plc:m2hze6zxa744iberzknpkc3i</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>3</th>\n",
|
|||
|
" <td>at://did:plc:wdcuds3huxctzwn35sbvskmb/app.bsky...</td>\n",
|
|||
|
" <td>bafyreicosgwinajfnon2splv5u2o6zyiax5trhf6vdxlh...</td>\n",
|
|||
|
" <td>did:plc:wdcuds3huxctzwn35sbvskmb</td>\n",
|
|||
|
" <td>2023-06-28T06:50:33.759Z</td>\n",
|
|||
|
" <td>2023-06-28T06:50:33.539Z</td>\n",
|
|||
|
" <td>at://did:plc:ykzmsemoxmlzmrci2p77eqkm/app.bsky...</td>\n",
|
|||
|
" <td>bafyreidheno2szedmn2ckwtm6zuoadsaxq2rpmgef2bvt...</td>\n",
|
|||
|
" <td>did:plc:ykzmsemoxmlzmrci2p77eqkm</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>7</th>\n",
|
|||
|
" <td>at://did:plc:ufdixs5k6dx6yhfr5a4dr5ax/app.bsky...</td>\n",
|
|||
|
" <td>bafyreih3pmj7hehirajk6xpqejkzs7iyrpt4ausft3wqs...</td>\n",
|
|||
|
" <td>did:plc:ufdixs5k6dx6yhfr5a4dr5ax</td>\n",
|
|||
|
" <td>2023-06-28T06:50:34.059Z</td>\n",
|
|||
|
" <td>2023-06-28T06:50:31.813Z</td>\n",
|
|||
|
" <td>at://did:plc:yx6bxsdt445ybmjwu362riaw/app.bsky...</td>\n",
|
|||
|
" <td>bafyreigupyvy2fdwglafoix3a3cgqgj43pmghearauqbx...</td>\n",
|
|||
|
" <td>did:plc:yx6bxsdt445ybmjwu362riaw</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>14</th>\n",
|
|||
|
" <td>at://did:plc:wdcuds3huxctzwn35sbvskmb/app.bsky...</td>\n",
|
|||
|
" <td>bafyreiardnphqnh554j6ivjdgr4aaojcoxrrnqopbg6od...</td>\n",
|
|||
|
" <td>did:plc:wdcuds3huxctzwn35sbvskmb</td>\n",
|
|||
|
" <td>2023-06-28T06:50:37.626Z</td>\n",
|
|||
|
" <td>2023-06-28T06:50:37.483Z</td>\n",
|
|||
|
" <td>at://did:plc:yt5iskeftjmml3xiuhw5svxl/app.bsky...</td>\n",
|
|||
|
" <td>bafyreicdboh6uublfn6zbalxg7sqx57m77d4ubtvuobv3...</td>\n",
|
|||
|
" <td>did:plc:yt5iskeftjmml3xiuhw5svxl</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>16</th>\n",
|
|||
|
" <td>at://did:plc:4mip3xdpj2iasxiqchzgn4sc/app.bsky...</td>\n",
|
|||
|
" <td>bafyreiduxwt6r6k7sr5oxti4ftrrogwnasjjofaptf3th...</td>\n",
|
|||
|
" <td>did:plc:4mip3xdpj2iasxiqchzgn4sc</td>\n",
|
|||
|
" <td>2023-06-28T06:50:38.198Z</td>\n",
|
|||
|
" <td>2023-06-28T06:50:37.964Z</td>\n",
|
|||
|
" <td>at://did:plc:hb3rpuqloy36skpistigbc3q/app.bsky...</td>\n",
|
|||
|
" <td>bafyreidblyfdtqqnvf7uxh2flv3btil42qywbbws7ucrn...</td>\n",
|
|||
|
" <td>did:plc:hb3rpuqloy36skpistigbc3q</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>...</th>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>1043980</th>\n",
|
|||
|
" <td>at://did:plc:r23oqmp22lkgvynjji7g3jyn/app.bsky...</td>\n",
|
|||
|
" <td>bafyreibwqvsnvahf3ntoc6hw7fo752k43xeci6o2uatbx...</td>\n",
|
|||
|
" <td>did:plc:r23oqmp22lkgvynjji7g3jyn</td>\n",
|
|||
|
" <td>2023-06-30T03:27:29.874Z</td>\n",
|
|||
|
" <td>2023-06-30T03:27:30.228Z</td>\n",
|
|||
|
" <td>at://did:plc:6kdg7avq4vqjgvciwdp5eb6w/app.bsky...</td>\n",
|
|||
|
" <td>bafyreiavih4pssn376ltytm2nbvrs3gt5wf7maly5e6x4...</td>\n",
|
|||
|
" <td>did:plc:6kdg7avq4vqjgvciwdp5eb6w</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>1043983</th>\n",
|
|||
|
" <td>at://did:plc:m3dpze6kfymikzhyorn3yjve/app.bsky...</td>\n",
|
|||
|
" <td>bafyreibfosoiywciqecjxtuymtcmq3ovzwgi4ot2wtweq...</td>\n",
|
|||
|
" <td>did:plc:m3dpze6kfymikzhyorn3yjve</td>\n",
|
|||
|
" <td>2023-06-30T03:27:29.973Z</td>\n",
|
|||
|
" <td>2023-06-30T03:27:29.696Z</td>\n",
|
|||
|
" <td>at://did:plc:wfvahw2jy6eonvvh5wwx2njs/app.bsky...</td>\n",
|
|||
|
" <td>bafyreidyyxu6ywjezyxhjd5omnkir54lasquxmu5my66b...</td>\n",
|
|||
|
" <td>did:plc:wfvahw2jy6eonvvh5wwx2njs</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>1043984</th>\n",
|
|||
|
" <td>at://did:plc:uogqw3tmescpszxmep6e64x2/app.bsky...</td>\n",
|
|||
|
" <td>bafyreib6wq6uv4n6hpzgq7hosxsoynp47tpwyesncegya...</td>\n",
|
|||
|
" <td>did:plc:uogqw3tmescpszxmep6e64x2</td>\n",
|
|||
|
" <td>2023-06-30T03:27:30.072Z</td>\n",
|
|||
|
" <td>2023-06-30T03:27:30.021Z</td>\n",
|
|||
|
" <td>at://did:plc:4u42vwglz35baspkeivbgw3n/app.bsky...</td>\n",
|
|||
|
" <td>bafyreifz6ww7ibjk2estslbjwtbci5ota4ccb5sn3zxqr...</td>\n",
|
|||
|
" <td>did:plc:4u42vwglz35baspkeivbgw3n</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>1043985</th>\n",
|
|||
|
" <td>at://did:plc:i3xuhvb7fndx2r2fhfkyi6r2/app.bsky...</td>\n",
|
|||
|
" <td>bafyreicgukln6qco5dy5vypm6piqh6tr2nvoppm7dal7q...</td>\n",
|
|||
|
" <td>did:plc:i3xuhvb7fndx2r2fhfkyi6r2</td>\n",
|
|||
|
" <td>2023-06-30T03:27:30.182Z</td>\n",
|
|||
|
" <td>2023-06-30T03:27:29.923Z</td>\n",
|
|||
|
" <td>at://did:plc:shmltckvsbkhjbcb4mwdeplx/app.bsky...</td>\n",
|
|||
|
" <td>bafyreihq2tqgnarhdmf27axjhafwk46nub6yn2nzzmevp...</td>\n",
|
|||
|
" <td>did:plc:shmltckvsbkhjbcb4mwdeplx</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>1043986</th>\n",
|
|||
|
" <td>at://did:plc:mxroexojpobpj4e7346mb6hm/app.bsky...</td>\n",
|
|||
|
" <td>bafyreif4suaf5eve4gyj5efn4z6ca6zmgygkp2pur7bqw...</td>\n",
|
|||
|
" <td>did:plc:mxroexojpobpj4e7346mb6hm</td>\n",
|
|||
|
" <td>2023-06-30T03:27:30.244Z</td>\n",
|
|||
|
" <td>2023-06-30T03:27:29.530Z</td>\n",
|
|||
|
" <td>at://did:plc:xridcxx3se5arspf5dtk2ahm/app.bsky...</td>\n",
|
|||
|
" <td>bafyreihcawjk4enlfnka53sgznddhh4h6b2fjzm4vca2q...</td>\n",
|
|||
|
" <td>did:plc:xridcxx3se5arspf5dtk2ahm</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" </tbody>\n",
|
|||
|
"</table>\n",
|
|||
|
"<p>212349 rows × 8 columns</p>\n",
|
|||
|
"</div>"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
" uri \\\n",
|
|||
|
"2 at://did:plc:tt2krpcels6fzdwt5e2iold6/app.bsky... \n",
|
|||
|
"3 at://did:plc:wdcuds3huxctzwn35sbvskmb/app.bsky... \n",
|
|||
|
"7 at://did:plc:ufdixs5k6dx6yhfr5a4dr5ax/app.bsky... \n",
|
|||
|
"14 at://did:plc:wdcuds3huxctzwn35sbvskmb/app.bsky... \n",
|
|||
|
"16 at://did:plc:4mip3xdpj2iasxiqchzgn4sc/app.bsky... \n",
|
|||
|
"... ... \n",
|
|||
|
"1043980 at://did:plc:r23oqmp22lkgvynjji7g3jyn/app.bsky... \n",
|
|||
|
"1043983 at://did:plc:m3dpze6kfymikzhyorn3yjve/app.bsky... \n",
|
|||
|
"1043984 at://did:plc:uogqw3tmescpszxmep6e64x2/app.bsky... \n",
|
|||
|
"1043985 at://did:plc:i3xuhvb7fndx2r2fhfkyi6r2/app.bsky... \n",
|
|||
|
"1043986 at://did:plc:mxroexojpobpj4e7346mb6hm/app.bsky... \n",
|
|||
|
"\n",
|
|||
|
" cid \\\n",
|
|||
|
"2 bafyreib3ozumx3qi3mb7wqmhedj2fftrosycnksyt25xc... \n",
|
|||
|
"3 bafyreicosgwinajfnon2splv5u2o6zyiax5trhf6vdxlh... \n",
|
|||
|
"7 bafyreih3pmj7hehirajk6xpqejkzs7iyrpt4ausft3wqs... \n",
|
|||
|
"14 bafyreiardnphqnh554j6ivjdgr4aaojcoxrrnqopbg6od... \n",
|
|||
|
"16 bafyreiduxwt6r6k7sr5oxti4ftrrogwnasjjofaptf3th... \n",
|
|||
|
"... ... \n",
|
|||
|
"1043980 bafyreibwqvsnvahf3ntoc6hw7fo752k43xeci6o2uatbx... \n",
|
|||
|
"1043983 bafyreibfosoiywciqecjxtuymtcmq3ovzwgi4ot2wtweq... \n",
|
|||
|
"1043984 bafyreib6wq6uv4n6hpzgq7hosxsoynp47tpwyesncegya... \n",
|
|||
|
"1043985 bafyreicgukln6qco5dy5vypm6piqh6tr2nvoppm7dal7q... \n",
|
|||
|
"1043986 bafyreif4suaf5eve4gyj5efn4z6ca6zmgygkp2pur7bqw... \n",
|
|||
|
"\n",
|
|||
|
" authorDid indexedAt \\\n",
|
|||
|
"2 did:plc:tt2krpcels6fzdwt5e2iold6 2023-06-28T06:50:32.931Z \n",
|
|||
|
"3 did:plc:wdcuds3huxctzwn35sbvskmb 2023-06-28T06:50:33.759Z \n",
|
|||
|
"7 did:plc:ufdixs5k6dx6yhfr5a4dr5ax 2023-06-28T06:50:34.059Z \n",
|
|||
|
"14 did:plc:wdcuds3huxctzwn35sbvskmb 2023-06-28T06:50:37.626Z \n",
|
|||
|
"16 did:plc:4mip3xdpj2iasxiqchzgn4sc 2023-06-28T06:50:38.198Z \n",
|
|||
|
"... ... ... \n",
|
|||
|
"1043980 did:plc:r23oqmp22lkgvynjji7g3jyn 2023-06-30T03:27:29.874Z \n",
|
|||
|
"1043983 did:plc:m3dpze6kfymikzhyorn3yjve 2023-06-30T03:27:29.973Z \n",
|
|||
|
"1043984 did:plc:uogqw3tmescpszxmep6e64x2 2023-06-30T03:27:30.072Z \n",
|
|||
|
"1043985 did:plc:i3xuhvb7fndx2r2fhfkyi6r2 2023-06-30T03:27:30.182Z \n",
|
|||
|
"1043986 did:plc:mxroexojpobpj4e7346mb6hm 2023-06-30T03:27:30.244Z \n",
|
|||
|
"\n",
|
|||
|
" createdAt \\\n",
|
|||
|
"2 2023-06-28T06:50:32.736Z \n",
|
|||
|
"3 2023-06-28T06:50:33.539Z \n",
|
|||
|
"7 2023-06-28T06:50:31.813Z \n",
|
|||
|
"14 2023-06-28T06:50:37.483Z \n",
|
|||
|
"16 2023-06-28T06:50:37.964Z \n",
|
|||
|
"... ... \n",
|
|||
|
"1043980 2023-06-30T03:27:30.228Z \n",
|
|||
|
"1043983 2023-06-30T03:27:29.696Z \n",
|
|||
|
"1043984 2023-06-30T03:27:30.021Z \n",
|
|||
|
"1043985 2023-06-30T03:27:29.923Z \n",
|
|||
|
"1043986 2023-06-30T03:27:29.530Z \n",
|
|||
|
"\n",
|
|||
|
" subjectUri \\\n",
|
|||
|
"2 at://did:plc:m2hze6zxa744iberzknpkc3i/app.bsky... \n",
|
|||
|
"3 at://did:plc:ykzmsemoxmlzmrci2p77eqkm/app.bsky... \n",
|
|||
|
"7 at://did:plc:yx6bxsdt445ybmjwu362riaw/app.bsky... \n",
|
|||
|
"14 at://did:plc:yt5iskeftjmml3xiuhw5svxl/app.bsky... \n",
|
|||
|
"16 at://did:plc:hb3rpuqloy36skpistigbc3q/app.bsky... \n",
|
|||
|
"... ... \n",
|
|||
|
"1043980 at://did:plc:6kdg7avq4vqjgvciwdp5eb6w/app.bsky... \n",
|
|||
|
"1043983 at://did:plc:wfvahw2jy6eonvvh5wwx2njs/app.bsky... \n",
|
|||
|
"1043984 at://did:plc:4u42vwglz35baspkeivbgw3n/app.bsky... \n",
|
|||
|
"1043985 at://did:plc:shmltckvsbkhjbcb4mwdeplx/app.bsky... \n",
|
|||
|
"1043986 at://did:plc:xridcxx3se5arspf5dtk2ahm/app.bsky... \n",
|
|||
|
"\n",
|
|||
|
" subjectCid \\\n",
|
|||
|
"2 bafyreibbhg6hz64gakzkptazxpwstfbbbid6a4fw6w5m5... \n",
|
|||
|
"3 bafyreidheno2szedmn2ckwtm6zuoadsaxq2rpmgef2bvt... \n",
|
|||
|
"7 bafyreigupyvy2fdwglafoix3a3cgqgj43pmghearauqbx... \n",
|
|||
|
"14 bafyreicdboh6uublfn6zbalxg7sqx57m77d4ubtvuobv3... \n",
|
|||
|
"16 bafyreidblyfdtqqnvf7uxh2flv3btil42qywbbws7ucrn... \n",
|
|||
|
"... ... \n",
|
|||
|
"1043980 bafyreiavih4pssn376ltytm2nbvrs3gt5wf7maly5e6x4... \n",
|
|||
|
"1043983 bafyreidyyxu6ywjezyxhjd5omnkir54lasquxmu5my66b... \n",
|
|||
|
"1043984 bafyreifz6ww7ibjk2estslbjwtbci5ota4ccb5sn3zxqr... \n",
|
|||
|
"1043985 bafyreihq2tqgnarhdmf27axjhafwk46nub6yn2nzzmevp... \n",
|
|||
|
"1043986 bafyreihcawjk4enlfnka53sgznddhh4h6b2fjzm4vca2q... \n",
|
|||
|
"\n",
|
|||
|
" subjectDid \n",
|
|||
|
"2 did:plc:m2hze6zxa744iberzknpkc3i \n",
|
|||
|
"3 did:plc:ykzmsemoxmlzmrci2p77eqkm \n",
|
|||
|
"7 did:plc:yx6bxsdt445ybmjwu362riaw \n",
|
|||
|
"14 did:plc:yt5iskeftjmml3xiuhw5svxl \n",
|
|||
|
"16 did:plc:hb3rpuqloy36skpistigbc3q \n",
|
|||
|
"... ... \n",
|
|||
|
"1043980 did:plc:6kdg7avq4vqjgvciwdp5eb6w \n",
|
|||
|
"1043983 did:plc:wfvahw2jy6eonvvh5wwx2njs \n",
|
|||
|
"1043984 did:plc:4u42vwglz35baspkeivbgw3n \n",
|
|||
|
"1043985 did:plc:shmltckvsbkhjbcb4mwdeplx \n",
|
|||
|
"1043986 did:plc:xridcxx3se5arspf5dtk2ahm \n",
|
|||
|
"\n",
|
|||
|
"[212349 rows x 8 columns]"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 119,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"non_top_reply_likes = likes.loc[\n",
|
|||
|
" np.logical_and(\n",
|
|||
|
" ~likes['subjectUri'].isin(top_threads['uri']),\n",
|
|||
|
" ~likes['subjectDid'].isin(top_accounts['account'])\n",
|
|||
|
" )]\n",
|
|||
|
"non_top_account_likes = likes.loc[\n",
|
|||
|
" ~likes['subjectDid'].isin(top_accounts['account'])\n",
|
|||
|
"]\n",
|
|||
|
"\n",
|
|||
|
"non_top_reply_likes"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "5d7ca01a",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"Proportion of posts from top posters"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 120,
|
|||
|
"id": "5069cd71",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"0.5337081682060915"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 120,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"top_posts.shape[0] / posts.shape[0]"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "44fa1058",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"Proportion of non-top account likes that are not in threads with top accounts"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 121,
|
|||
|
"id": "79b26b9b",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"0.8454528081030076"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 121,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"non_top_reply_likes.shape[0] / non_top_account_likes.shape[0]"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "455e39bd",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"Proportion of likes to non-top accounts"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 122,
|
|||
|
"id": "602921d8",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"0.24058345554111307"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 122,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"non_top_account_likes.shape[0] / likes.shape[0]"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "19ae2594",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"Proportion of likes to non-top accounts that are not in threads with top accounts"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 123,
|
|||
|
"id": "a3572f44",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"0.2034019580703591"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 123,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"non_top_reply_likes.shape[0] / likes.shape[0]"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "f88361b0",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"Number of top accounts"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 124,
|
|||
|
"id": "7b0094ba",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"2306"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 124,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"top_accounts.shape[0]"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "aae6aa9d",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"Quantiles of likes received by non-top posts"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 125,
|
|||
|
"id": "3a0c7e8b",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"0.00 0.0\n",
|
|||
|
"0.25 0.0\n",
|
|||
|
"0.50 1.0\n",
|
|||
|
"0.75 2.0\n",
|
|||
|
"0.90 3.0\n",
|
|||
|
"0.95 6.0\n",
|
|||
|
"0.99 13.0\n",
|
|||
|
"Name: likes, dtype: float64"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 125,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"non_top_posts['likes'].quantile(quants)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 126,
|
|||
|
"id": "f6471c77",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"0.7470756751975067"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 126,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"sum(non_top_posts['likes'] <= 1) / non_top_posts.shape[0]"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 127,
|
|||
|
"id": "1c9f73b5",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"70.0"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 127,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"non_top_posts['likes'].max()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 128,
|
|||
|
"id": "1e9d4b13",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"3189.0"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 128,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"top_posts['likes'].max()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "9cc66fb2",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"How many accounts who posted received any likes?"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 129,
|
|||
|
"id": "17f85222",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"posting_account_likes = posts.groupby('authorDid'\n",
|
|||
|
" ).agg(\n",
|
|||
|
" likes=('likes', 'sum'),\n",
|
|||
|
" posts=('uri', 'count')\n",
|
|||
|
" ).reset_index()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 130,
|
|||
|
"id": "58fb21bc",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"0.23161960993687383"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 130,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"sum(posting_account_likes['likes'] == 0) / posting_account_likes.shape[0]"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 131,
|
|||
|
"id": "ba4a400e",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"posting_account_likes['likes_per_post'] = \\\n",
|
|||
|
" posting_account_likes['likes'] / posting_account_likes['posts']"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 132,
|
|||
|
"id": "d67e1705",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"0.00 0.000000\n",
|
|||
|
"0.25 0.250000\n",
|
|||
|
"0.50 1.000000\n",
|
|||
|
"0.75 2.285714\n",
|
|||
|
"0.90 4.750000\n",
|
|||
|
"0.95 7.000000\n",
|
|||
|
"0.99 16.640000\n",
|
|||
|
"Name: likes_per_post, dtype: float64"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 132,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"lpp_quantiles = posting_account_likes['likes_per_post'].quantile(quants)\n",
|
|||
|
"lpp_quantiles"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 133,
|
|||
|
"id": "c1daecca",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"0.00 0.000000\n",
|
|||
|
"0.25 0.019419\n",
|
|||
|
"0.50 1.000000\n",
|
|||
|
"0.75 2.000000\n",
|
|||
|
"0.90 4.000000\n",
|
|||
|
"0.95 6.000000\n",
|
|||
|
"0.99 12.000000\n",
|
|||
|
"Name: likes_per_post, dtype: float64"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 133,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"nontop_lpp_quantiles = posting_account_likes[\n",
|
|||
|
" ~posting_account_likes['authorDid'].isin(top_accounts['account'])\n",
|
|||
|
"]['likes_per_post'].quantile(quants)\n",
|
|||
|
"nontop_lpp_quantiles"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 134,
|
|||
|
"id": "8f14183c",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"application/javascript": [
|
|||
|
"/* Put everything inside the global mpl namespace */\n",
|
|||
|
"/* global mpl */\n",
|
|||
|
"window.mpl = {};\n",
|
|||
|
"\n",
|
|||
|
"mpl.get_websocket_type = function () {\n",
|
|||
|
" if (typeof WebSocket !== 'undefined') {\n",
|
|||
|
" return WebSocket;\n",
|
|||
|
" } else if (typeof MozWebSocket !== 'undefined') {\n",
|
|||
|
" return MozWebSocket;\n",
|
|||
|
" } else {\n",
|
|||
|
" alert(\n",
|
|||
|
" 'Your browser does not have WebSocket support. ' +\n",
|
|||
|
" 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n",
|
|||
|
" 'Firefox 4 and 5 are also supported but you ' +\n",
|
|||
|
" 'have to enable WebSockets in about:config.'\n",
|
|||
|
" );\n",
|
|||
|
" }\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure = function (figure_id, websocket, ondownload, parent_element) {\n",
|
|||
|
" this.id = figure_id;\n",
|
|||
|
"\n",
|
|||
|
" this.ws = websocket;\n",
|
|||
|
"\n",
|
|||
|
" this.supports_binary = this.ws.binaryType !== undefined;\n",
|
|||
|
"\n",
|
|||
|
" if (!this.supports_binary) {\n",
|
|||
|
" var warnings = document.getElementById('mpl-warnings');\n",
|
|||
|
" if (warnings) {\n",
|
|||
|
" warnings.style.display = 'block';\n",
|
|||
|
" warnings.textContent =\n",
|
|||
|
" 'This browser does not support binary websocket messages. ' +\n",
|
|||
|
" 'Performance may be slow.';\n",
|
|||
|
" }\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" this.imageObj = new Image();\n",
|
|||
|
"\n",
|
|||
|
" this.context = undefined;\n",
|
|||
|
" this.message = undefined;\n",
|
|||
|
" this.canvas = undefined;\n",
|
|||
|
" this.rubberband_canvas = undefined;\n",
|
|||
|
" this.rubberband_context = undefined;\n",
|
|||
|
" this.format_dropdown = undefined;\n",
|
|||
|
"\n",
|
|||
|
" this.image_mode = 'full';\n",
|
|||
|
"\n",
|
|||
|
" this.root = document.createElement('div');\n",
|
|||
|
" this.root.setAttribute('style', 'display: inline-block');\n",
|
|||
|
" this._root_extra_style(this.root);\n",
|
|||
|
"\n",
|
|||
|
" parent_element.appendChild(this.root);\n",
|
|||
|
"\n",
|
|||
|
" this._init_header(this);\n",
|
|||
|
" this._init_canvas(this);\n",
|
|||
|
" this._init_toolbar(this);\n",
|
|||
|
"\n",
|
|||
|
" var fig = this;\n",
|
|||
|
"\n",
|
|||
|
" this.waiting = false;\n",
|
|||
|
"\n",
|
|||
|
" this.ws.onopen = function () {\n",
|
|||
|
" fig.send_message('supports_binary', { value: fig.supports_binary });\n",
|
|||
|
" fig.send_message('send_image_mode', {});\n",
|
|||
|
" if (fig.ratio !== 1) {\n",
|
|||
|
" fig.send_message('set_device_pixel_ratio', {\n",
|
|||
|
" device_pixel_ratio: fig.ratio,\n",
|
|||
|
" });\n",
|
|||
|
" }\n",
|
|||
|
" fig.send_message('refresh', {});\n",
|
|||
|
" };\n",
|
|||
|
"\n",
|
|||
|
" this.imageObj.onload = function () {\n",
|
|||
|
" if (fig.image_mode === 'full') {\n",
|
|||
|
" // Full images could contain transparency (where diff images\n",
|
|||
|
" // almost always do), so we need to clear the canvas so that\n",
|
|||
|
" // there is no ghosting.\n",
|
|||
|
" fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n",
|
|||
|
" }\n",
|
|||
|
" fig.context.drawImage(fig.imageObj, 0, 0);\n",
|
|||
|
" };\n",
|
|||
|
"\n",
|
|||
|
" this.imageObj.onunload = function () {\n",
|
|||
|
" fig.ws.close();\n",
|
|||
|
" };\n",
|
|||
|
"\n",
|
|||
|
" this.ws.onmessage = this._make_on_message_function(this);\n",
|
|||
|
"\n",
|
|||
|
" this.ondownload = ondownload;\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._init_header = function () {\n",
|
|||
|
" var titlebar = document.createElement('div');\n",
|
|||
|
" titlebar.classList =\n",
|
|||
|
" 'ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix';\n",
|
|||
|
" var titletext = document.createElement('div');\n",
|
|||
|
" titletext.classList = 'ui-dialog-title';\n",
|
|||
|
" titletext.setAttribute(\n",
|
|||
|
" 'style',\n",
|
|||
|
" 'width: 100%; text-align: center; padding: 3px;'\n",
|
|||
|
" );\n",
|
|||
|
" titlebar.appendChild(titletext);\n",
|
|||
|
" this.root.appendChild(titlebar);\n",
|
|||
|
" this.header = titletext;\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._canvas_extra_style = function (_canvas_div) {};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._root_extra_style = function (_canvas_div) {};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._init_canvas = function () {\n",
|
|||
|
" var fig = this;\n",
|
|||
|
"\n",
|
|||
|
" var canvas_div = (this.canvas_div = document.createElement('div'));\n",
|
|||
|
" canvas_div.setAttribute(\n",
|
|||
|
" 'style',\n",
|
|||
|
" 'border: 1px solid #ddd;' +\n",
|
|||
|
" 'box-sizing: content-box;' +\n",
|
|||
|
" 'clear: both;' +\n",
|
|||
|
" 'min-height: 1px;' +\n",
|
|||
|
" 'min-width: 1px;' +\n",
|
|||
|
" 'outline: 0;' +\n",
|
|||
|
" 'overflow: hidden;' +\n",
|
|||
|
" 'position: relative;' +\n",
|
|||
|
" 'resize: both;'\n",
|
|||
|
" );\n",
|
|||
|
"\n",
|
|||
|
" function on_keyboard_event_closure(name) {\n",
|
|||
|
" return function (event) {\n",
|
|||
|
" return fig.key_event(event, name);\n",
|
|||
|
" };\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" canvas_div.addEventListener(\n",
|
|||
|
" 'keydown',\n",
|
|||
|
" on_keyboard_event_closure('key_press')\n",
|
|||
|
" );\n",
|
|||
|
" canvas_div.addEventListener(\n",
|
|||
|
" 'keyup',\n",
|
|||
|
" on_keyboard_event_closure('key_release')\n",
|
|||
|
" );\n",
|
|||
|
"\n",
|
|||
|
" this._canvas_extra_style(canvas_div);\n",
|
|||
|
" this.root.appendChild(canvas_div);\n",
|
|||
|
"\n",
|
|||
|
" var canvas = (this.canvas = document.createElement('canvas'));\n",
|
|||
|
" canvas.classList.add('mpl-canvas');\n",
|
|||
|
" canvas.setAttribute('style', 'box-sizing: content-box;');\n",
|
|||
|
"\n",
|
|||
|
" this.context = canvas.getContext('2d');\n",
|
|||
|
"\n",
|
|||
|
" var backingStore =\n",
|
|||
|
" this.context.backingStorePixelRatio ||\n",
|
|||
|
" this.context.webkitBackingStorePixelRatio ||\n",
|
|||
|
" this.context.mozBackingStorePixelRatio ||\n",
|
|||
|
" this.context.msBackingStorePixelRatio ||\n",
|
|||
|
" this.context.oBackingStorePixelRatio ||\n",
|
|||
|
" this.context.backingStorePixelRatio ||\n",
|
|||
|
" 1;\n",
|
|||
|
"\n",
|
|||
|
" this.ratio = (window.devicePixelRatio || 1) / backingStore;\n",
|
|||
|
"\n",
|
|||
|
" var rubberband_canvas = (this.rubberband_canvas = document.createElement(\n",
|
|||
|
" 'canvas'\n",
|
|||
|
" ));\n",
|
|||
|
" rubberband_canvas.setAttribute(\n",
|
|||
|
" 'style',\n",
|
|||
|
" 'box-sizing: content-box; position: absolute; left: 0; top: 0; z-index: 1;'\n",
|
|||
|
" );\n",
|
|||
|
"\n",
|
|||
|
" // Apply a ponyfill if ResizeObserver is not implemented by browser.\n",
|
|||
|
" if (this.ResizeObserver === undefined) {\n",
|
|||
|
" if (window.ResizeObserver !== undefined) {\n",
|
|||
|
" this.ResizeObserver = window.ResizeObserver;\n",
|
|||
|
" } else {\n",
|
|||
|
" var obs = _JSXTOOLS_RESIZE_OBSERVER({});\n",
|
|||
|
" this.ResizeObserver = obs.ResizeObserver;\n",
|
|||
|
" }\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" this.resizeObserverInstance = new this.ResizeObserver(function (entries) {\n",
|
|||
|
" var nentries = entries.length;\n",
|
|||
|
" for (var i = 0; i < nentries; i++) {\n",
|
|||
|
" var entry = entries[i];\n",
|
|||
|
" var width, height;\n",
|
|||
|
" if (entry.contentBoxSize) {\n",
|
|||
|
" if (entry.contentBoxSize instanceof Array) {\n",
|
|||
|
" // Chrome 84 implements new version of spec.\n",
|
|||
|
" width = entry.contentBoxSize[0].inlineSize;\n",
|
|||
|
" height = entry.contentBoxSize[0].blockSize;\n",
|
|||
|
" } else {\n",
|
|||
|
" // Firefox implements old version of spec.\n",
|
|||
|
" width = entry.contentBoxSize.inlineSize;\n",
|
|||
|
" height = entry.contentBoxSize.blockSize;\n",
|
|||
|
" }\n",
|
|||
|
" } else {\n",
|
|||
|
" // Chrome <84 implements even older version of spec.\n",
|
|||
|
" width = entry.contentRect.width;\n",
|
|||
|
" height = entry.contentRect.height;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" // Keep the size of the canvas and rubber band canvas in sync with\n",
|
|||
|
" // the canvas container.\n",
|
|||
|
" if (entry.devicePixelContentBoxSize) {\n",
|
|||
|
" // Chrome 84 implements new version of spec.\n",
|
|||
|
" canvas.setAttribute(\n",
|
|||
|
" 'width',\n",
|
|||
|
" entry.devicePixelContentBoxSize[0].inlineSize\n",
|
|||
|
" );\n",
|
|||
|
" canvas.setAttribute(\n",
|
|||
|
" 'height',\n",
|
|||
|
" entry.devicePixelContentBoxSize[0].blockSize\n",
|
|||
|
" );\n",
|
|||
|
" } else {\n",
|
|||
|
" canvas.setAttribute('width', width * fig.ratio);\n",
|
|||
|
" canvas.setAttribute('height', height * fig.ratio);\n",
|
|||
|
" }\n",
|
|||
|
" canvas.setAttribute(\n",
|
|||
|
" 'style',\n",
|
|||
|
" 'width: ' + width + 'px; height: ' + height + 'px;'\n",
|
|||
|
" );\n",
|
|||
|
"\n",
|
|||
|
" rubberband_canvas.setAttribute('width', width);\n",
|
|||
|
" rubberband_canvas.setAttribute('height', height);\n",
|
|||
|
"\n",
|
|||
|
" // And update the size in Python. We ignore the initial 0/0 size\n",
|
|||
|
" // that occurs as the element is placed into the DOM, which should\n",
|
|||
|
" // otherwise not happen due to the minimum size styling.\n",
|
|||
|
" if (fig.ws.readyState == 1 && width != 0 && height != 0) {\n",
|
|||
|
" fig.request_resize(width, height);\n",
|
|||
|
" }\n",
|
|||
|
" }\n",
|
|||
|
" });\n",
|
|||
|
" this.resizeObserverInstance.observe(canvas_div);\n",
|
|||
|
"\n",
|
|||
|
" function on_mouse_event_closure(name) {\n",
|
|||
|
" return function (event) {\n",
|
|||
|
" return fig.mouse_event(event, name);\n",
|
|||
|
" };\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" rubberband_canvas.addEventListener(\n",
|
|||
|
" 'mousedown',\n",
|
|||
|
" on_mouse_event_closure('button_press')\n",
|
|||
|
" );\n",
|
|||
|
" rubberband_canvas.addEventListener(\n",
|
|||
|
" 'mouseup',\n",
|
|||
|
" on_mouse_event_closure('button_release')\n",
|
|||
|
" );\n",
|
|||
|
" rubberband_canvas.addEventListener(\n",
|
|||
|
" 'dblclick',\n",
|
|||
|
" on_mouse_event_closure('dblclick')\n",
|
|||
|
" );\n",
|
|||
|
" // Throttle sequential mouse events to 1 every 20ms.\n",
|
|||
|
" rubberband_canvas.addEventListener(\n",
|
|||
|
" 'mousemove',\n",
|
|||
|
" on_mouse_event_closure('motion_notify')\n",
|
|||
|
" );\n",
|
|||
|
"\n",
|
|||
|
" rubberband_canvas.addEventListener(\n",
|
|||
|
" 'mouseenter',\n",
|
|||
|
" on_mouse_event_closure('figure_enter')\n",
|
|||
|
" );\n",
|
|||
|
" rubberband_canvas.addEventListener(\n",
|
|||
|
" 'mouseleave',\n",
|
|||
|
" on_mouse_event_closure('figure_leave')\n",
|
|||
|
" );\n",
|
|||
|
"\n",
|
|||
|
" canvas_div.addEventListener('wheel', function (event) {\n",
|
|||
|
" if (event.deltaY < 0) {\n",
|
|||
|
" event.step = 1;\n",
|
|||
|
" } else {\n",
|
|||
|
" event.step = -1;\n",
|
|||
|
" }\n",
|
|||
|
" on_mouse_event_closure('scroll')(event);\n",
|
|||
|
" });\n",
|
|||
|
"\n",
|
|||
|
" canvas_div.appendChild(canvas);\n",
|
|||
|
" canvas_div.appendChild(rubberband_canvas);\n",
|
|||
|
"\n",
|
|||
|
" this.rubberband_context = rubberband_canvas.getContext('2d');\n",
|
|||
|
" this.rubberband_context.strokeStyle = '#000000';\n",
|
|||
|
"\n",
|
|||
|
" this._resize_canvas = function (width, height, forward) {\n",
|
|||
|
" if (forward) {\n",
|
|||
|
" canvas_div.style.width = width + 'px';\n",
|
|||
|
" canvas_div.style.height = height + 'px';\n",
|
|||
|
" }\n",
|
|||
|
" };\n",
|
|||
|
"\n",
|
|||
|
" // Disable right mouse context menu.\n",
|
|||
|
" this.rubberband_canvas.addEventListener('contextmenu', function (_e) {\n",
|
|||
|
" event.preventDefault();\n",
|
|||
|
" return false;\n",
|
|||
|
" });\n",
|
|||
|
"\n",
|
|||
|
" function set_focus() {\n",
|
|||
|
" canvas.focus();\n",
|
|||
|
" canvas_div.focus();\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" window.setTimeout(set_focus, 100);\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._init_toolbar = function () {\n",
|
|||
|
" var fig = this;\n",
|
|||
|
"\n",
|
|||
|
" var toolbar = document.createElement('div');\n",
|
|||
|
" toolbar.classList = 'mpl-toolbar';\n",
|
|||
|
" this.root.appendChild(toolbar);\n",
|
|||
|
"\n",
|
|||
|
" function on_click_closure(name) {\n",
|
|||
|
" return function (_event) {\n",
|
|||
|
" return fig.toolbar_button_onclick(name);\n",
|
|||
|
" };\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" function on_mouseover_closure(tooltip) {\n",
|
|||
|
" return function (event) {\n",
|
|||
|
" if (!event.currentTarget.disabled) {\n",
|
|||
|
" return fig.toolbar_button_onmouseover(tooltip);\n",
|
|||
|
" }\n",
|
|||
|
" };\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" fig.buttons = {};\n",
|
|||
|
" var buttonGroup = document.createElement('div');\n",
|
|||
|
" buttonGroup.classList = 'mpl-button-group';\n",
|
|||
|
" for (var toolbar_ind in mpl.toolbar_items) {\n",
|
|||
|
" var name = mpl.toolbar_items[toolbar_ind][0];\n",
|
|||
|
" var tooltip = mpl.toolbar_items[toolbar_ind][1];\n",
|
|||
|
" var image = mpl.toolbar_items[toolbar_ind][2];\n",
|
|||
|
" var method_name = mpl.toolbar_items[toolbar_ind][3];\n",
|
|||
|
"\n",
|
|||
|
" if (!name) {\n",
|
|||
|
" /* Instead of a spacer, we start a new button group. */\n",
|
|||
|
" if (buttonGroup.hasChildNodes()) {\n",
|
|||
|
" toolbar.appendChild(buttonGroup);\n",
|
|||
|
" }\n",
|
|||
|
" buttonGroup = document.createElement('div');\n",
|
|||
|
" buttonGroup.classList = 'mpl-button-group';\n",
|
|||
|
" continue;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" var button = (fig.buttons[name] = document.createElement('button'));\n",
|
|||
|
" button.classList = 'mpl-widget';\n",
|
|||
|
" button.setAttribute('role', 'button');\n",
|
|||
|
" button.setAttribute('aria-disabled', 'false');\n",
|
|||
|
" button.addEventListener('click', on_click_closure(method_name));\n",
|
|||
|
" button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n",
|
|||
|
"\n",
|
|||
|
" var icon_img = document.createElement('img');\n",
|
|||
|
" icon_img.src = '_images/' + image + '.png';\n",
|
|||
|
" icon_img.srcset = '_images/' + image + '_large.png 2x';\n",
|
|||
|
" icon_img.alt = tooltip;\n",
|
|||
|
" button.appendChild(icon_img);\n",
|
|||
|
"\n",
|
|||
|
" buttonGroup.appendChild(button);\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" if (buttonGroup.hasChildNodes()) {\n",
|
|||
|
" toolbar.appendChild(buttonGroup);\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" var fmt_picker = document.createElement('select');\n",
|
|||
|
" fmt_picker.classList = 'mpl-widget';\n",
|
|||
|
" toolbar.appendChild(fmt_picker);\n",
|
|||
|
" this.format_dropdown = fmt_picker;\n",
|
|||
|
"\n",
|
|||
|
" for (var ind in mpl.extensions) {\n",
|
|||
|
" var fmt = mpl.extensions[ind];\n",
|
|||
|
" var option = document.createElement('option');\n",
|
|||
|
" option.selected = fmt === mpl.default_extension;\n",
|
|||
|
" option.innerHTML = fmt;\n",
|
|||
|
" fmt_picker.appendChild(option);\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" var status_bar = document.createElement('span');\n",
|
|||
|
" status_bar.classList = 'mpl-message';\n",
|
|||
|
" toolbar.appendChild(status_bar);\n",
|
|||
|
" this.message = status_bar;\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.request_resize = function (x_pixels, y_pixels) {\n",
|
|||
|
" // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,\n",
|
|||
|
" // which will in turn request a refresh of the image.\n",
|
|||
|
" this.send_message('resize', { width: x_pixels, height: y_pixels });\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.send_message = function (type, properties) {\n",
|
|||
|
" properties['type'] = type;\n",
|
|||
|
" properties['figure_id'] = this.id;\n",
|
|||
|
" this.ws.send(JSON.stringify(properties));\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.send_draw_message = function () {\n",
|
|||
|
" if (!this.waiting) {\n",
|
|||
|
" this.waiting = true;\n",
|
|||
|
" this.ws.send(JSON.stringify({ type: 'draw', figure_id: this.id }));\n",
|
|||
|
" }\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_save = function (fig, _msg) {\n",
|
|||
|
" var format_dropdown = fig.format_dropdown;\n",
|
|||
|
" var format = format_dropdown.options[format_dropdown.selectedIndex].value;\n",
|
|||
|
" fig.ondownload(fig, format);\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_resize = function (fig, msg) {\n",
|
|||
|
" var size = msg['size'];\n",
|
|||
|
" if (size[0] !== fig.canvas.width || size[1] !== fig.canvas.height) {\n",
|
|||
|
" fig._resize_canvas(size[0], size[1], msg['forward']);\n",
|
|||
|
" fig.send_message('refresh', {});\n",
|
|||
|
" }\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_rubberband = function (fig, msg) {\n",
|
|||
|
" var x0 = msg['x0'] / fig.ratio;\n",
|
|||
|
" var y0 = (fig.canvas.height - msg['y0']) / fig.ratio;\n",
|
|||
|
" var x1 = msg['x1'] / fig.ratio;\n",
|
|||
|
" var y1 = (fig.canvas.height - msg['y1']) / fig.ratio;\n",
|
|||
|
" x0 = Math.floor(x0) + 0.5;\n",
|
|||
|
" y0 = Math.floor(y0) + 0.5;\n",
|
|||
|
" x1 = Math.floor(x1) + 0.5;\n",
|
|||
|
" y1 = Math.floor(y1) + 0.5;\n",
|
|||
|
" var min_x = Math.min(x0, x1);\n",
|
|||
|
" var min_y = Math.min(y0, y1);\n",
|
|||
|
" var width = Math.abs(x1 - x0);\n",
|
|||
|
" var height = Math.abs(y1 - y0);\n",
|
|||
|
"\n",
|
|||
|
" fig.rubberband_context.clearRect(\n",
|
|||
|
" 0,\n",
|
|||
|
" 0,\n",
|
|||
|
" fig.canvas.width / fig.ratio,\n",
|
|||
|
" fig.canvas.height / fig.ratio\n",
|
|||
|
" );\n",
|
|||
|
"\n",
|
|||
|
" fig.rubberband_context.strokeRect(min_x, min_y, width, height);\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_figure_label = function (fig, msg) {\n",
|
|||
|
" // Updates the figure title.\n",
|
|||
|
" fig.header.textContent = msg['label'];\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_cursor = function (fig, msg) {\n",
|
|||
|
" fig.rubberband_canvas.style.cursor = msg['cursor'];\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_message = function (fig, msg) {\n",
|
|||
|
" fig.message.textContent = msg['message'];\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_draw = function (fig, _msg) {\n",
|
|||
|
" // Request the server to send over a new figure.\n",
|
|||
|
" fig.send_draw_message();\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_image_mode = function (fig, msg) {\n",
|
|||
|
" fig.image_mode = msg['mode'];\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_history_buttons = function (fig, msg) {\n",
|
|||
|
" for (var key in msg) {\n",
|
|||
|
" if (!(key in fig.buttons)) {\n",
|
|||
|
" continue;\n",
|
|||
|
" }\n",
|
|||
|
" fig.buttons[key].disabled = !msg[key];\n",
|
|||
|
" fig.buttons[key].setAttribute('aria-disabled', !msg[key]);\n",
|
|||
|
" }\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_navigate_mode = function (fig, msg) {\n",
|
|||
|
" if (msg['mode'] === 'PAN') {\n",
|
|||
|
" fig.buttons['Pan'].classList.add('active');\n",
|
|||
|
" fig.buttons['Zoom'].classList.remove('active');\n",
|
|||
|
" } else if (msg['mode'] === 'ZOOM') {\n",
|
|||
|
" fig.buttons['Pan'].classList.remove('active');\n",
|
|||
|
" fig.buttons['Zoom'].classList.add('active');\n",
|
|||
|
" } else {\n",
|
|||
|
" fig.buttons['Pan'].classList.remove('active');\n",
|
|||
|
" fig.buttons['Zoom'].classList.remove('active');\n",
|
|||
|
" }\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.updated_canvas_event = function () {\n",
|
|||
|
" // Called whenever the canvas gets updated.\n",
|
|||
|
" this.send_message('ack', {});\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"// A function to construct a web socket function for onmessage handling.\n",
|
|||
|
"// Called in the figure constructor.\n",
|
|||
|
"mpl.figure.prototype._make_on_message_function = function (fig) {\n",
|
|||
|
" return function socket_on_message(evt) {\n",
|
|||
|
" if (evt.data instanceof Blob) {\n",
|
|||
|
" var img = evt.data;\n",
|
|||
|
" if (img.type !== 'image/png') {\n",
|
|||
|
" /* FIXME: We get \"Resource interpreted as Image but\n",
|
|||
|
" * transferred with MIME type text/plain:\" errors on\n",
|
|||
|
" * Chrome. But how to set the MIME type? It doesn't seem\n",
|
|||
|
" * to be part of the websocket stream */\n",
|
|||
|
" img.type = 'image/png';\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" /* Free the memory for the previous frames */\n",
|
|||
|
" if (fig.imageObj.src) {\n",
|
|||
|
" (window.URL || window.webkitURL).revokeObjectURL(\n",
|
|||
|
" fig.imageObj.src\n",
|
|||
|
" );\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(\n",
|
|||
|
" img\n",
|
|||
|
" );\n",
|
|||
|
" fig.updated_canvas_event();\n",
|
|||
|
" fig.waiting = false;\n",
|
|||
|
" return;\n",
|
|||
|
" } else if (\n",
|
|||
|
" typeof evt.data === 'string' &&\n",
|
|||
|
" evt.data.slice(0, 21) === 'data:image/png;base64'\n",
|
|||
|
" ) {\n",
|
|||
|
" fig.imageObj.src = evt.data;\n",
|
|||
|
" fig.updated_canvas_event();\n",
|
|||
|
" fig.waiting = false;\n",
|
|||
|
" return;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" var msg = JSON.parse(evt.data);\n",
|
|||
|
" var msg_type = msg['type'];\n",
|
|||
|
"\n",
|
|||
|
" // Call the \"handle_{type}\" callback, which takes\n",
|
|||
|
" // the figure and JSON message as its only arguments.\n",
|
|||
|
" try {\n",
|
|||
|
" var callback = fig['handle_' + msg_type];\n",
|
|||
|
" } catch (e) {\n",
|
|||
|
" console.log(\n",
|
|||
|
" \"No handler for the '\" + msg_type + \"' message type: \",\n",
|
|||
|
" msg\n",
|
|||
|
" );\n",
|
|||
|
" return;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" if (callback) {\n",
|
|||
|
" try {\n",
|
|||
|
" // console.log(\"Handling '\" + msg_type + \"' message: \", msg);\n",
|
|||
|
" callback(fig, msg);\n",
|
|||
|
" } catch (e) {\n",
|
|||
|
" console.log(\n",
|
|||
|
" \"Exception inside the 'handler_\" + msg_type + \"' callback:\",\n",
|
|||
|
" e,\n",
|
|||
|
" e.stack,\n",
|
|||
|
" msg\n",
|
|||
|
" );\n",
|
|||
|
" }\n",
|
|||
|
" }\n",
|
|||
|
" };\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"// from https://stackoverflow.com/questions/1114465/getting-mouse-location-in-canvas\n",
|
|||
|
"mpl.findpos = function (e) {\n",
|
|||
|
" //this section is from http://www.quirksmode.org/js/events_properties.html\n",
|
|||
|
" var targ;\n",
|
|||
|
" if (!e) {\n",
|
|||
|
" e = window.event;\n",
|
|||
|
" }\n",
|
|||
|
" if (e.target) {\n",
|
|||
|
" targ = e.target;\n",
|
|||
|
" } else if (e.srcElement) {\n",
|
|||
|
" targ = e.srcElement;\n",
|
|||
|
" }\n",
|
|||
|
" if (targ.nodeType === 3) {\n",
|
|||
|
" // defeat Safari bug\n",
|
|||
|
" targ = targ.parentNode;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" // pageX,Y are the mouse positions relative to the document\n",
|
|||
|
" var boundingRect = targ.getBoundingClientRect();\n",
|
|||
|
" var x = e.pageX - (boundingRect.left + document.body.scrollLeft);\n",
|
|||
|
" var y = e.pageY - (boundingRect.top + document.body.scrollTop);\n",
|
|||
|
"\n",
|
|||
|
" return { x: x, y: y };\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"/*\n",
|
|||
|
" * return a copy of an object with only non-object keys\n",
|
|||
|
" * we need this to avoid circular references\n",
|
|||
|
" * https://stackoverflow.com/a/24161582/3208463\n",
|
|||
|
" */\n",
|
|||
|
"function simpleKeys(original) {\n",
|
|||
|
" return Object.keys(original).reduce(function (obj, key) {\n",
|
|||
|
" if (typeof original[key] !== 'object') {\n",
|
|||
|
" obj[key] = original[key];\n",
|
|||
|
" }\n",
|
|||
|
" return obj;\n",
|
|||
|
" }, {});\n",
|
|||
|
"}\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.mouse_event = function (event, name) {\n",
|
|||
|
" var canvas_pos = mpl.findpos(event);\n",
|
|||
|
"\n",
|
|||
|
" if (name === 'button_press') {\n",
|
|||
|
" this.canvas.focus();\n",
|
|||
|
" this.canvas_div.focus();\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" var x = canvas_pos.x * this.ratio;\n",
|
|||
|
" var y = canvas_pos.y * this.ratio;\n",
|
|||
|
"\n",
|
|||
|
" this.send_message(name, {\n",
|
|||
|
" x: x,\n",
|
|||
|
" y: y,\n",
|
|||
|
" button: event.button,\n",
|
|||
|
" step: event.step,\n",
|
|||
|
" guiEvent: simpleKeys(event),\n",
|
|||
|
" });\n",
|
|||
|
"\n",
|
|||
|
" /* This prevents the web browser from automatically changing to\n",
|
|||
|
" * the text insertion cursor when the button is pressed. We want\n",
|
|||
|
" * to control all of the cursor setting manually through the\n",
|
|||
|
" * 'cursor' event from matplotlib */\n",
|
|||
|
" event.preventDefault();\n",
|
|||
|
" return false;\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._key_event_extra = function (_event, _name) {\n",
|
|||
|
" // Handle any extra behaviour associated with a key event\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.key_event = function (event, name) {\n",
|
|||
|
" // Prevent repeat events\n",
|
|||
|
" if (name === 'key_press') {\n",
|
|||
|
" if (event.key === this._key) {\n",
|
|||
|
" return;\n",
|
|||
|
" } else {\n",
|
|||
|
" this._key = event.key;\n",
|
|||
|
" }\n",
|
|||
|
" }\n",
|
|||
|
" if (name === 'key_release') {\n",
|
|||
|
" this._key = null;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" var value = '';\n",
|
|||
|
" if (event.ctrlKey && event.key !== 'Control') {\n",
|
|||
|
" value += 'ctrl+';\n",
|
|||
|
" }\n",
|
|||
|
" else if (event.altKey && event.key !== 'Alt') {\n",
|
|||
|
" value += 'alt+';\n",
|
|||
|
" }\n",
|
|||
|
" else if (event.shiftKey && event.key !== 'Shift') {\n",
|
|||
|
" value += 'shift+';\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" value += 'k' + event.key;\n",
|
|||
|
"\n",
|
|||
|
" this._key_event_extra(event, name);\n",
|
|||
|
"\n",
|
|||
|
" this.send_message(name, { key: value, guiEvent: simpleKeys(event) });\n",
|
|||
|
" return false;\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.toolbar_button_onclick = function (name) {\n",
|
|||
|
" if (name === 'download') {\n",
|
|||
|
" this.handle_save(this, null);\n",
|
|||
|
" } else {\n",
|
|||
|
" this.send_message('toolbar_button', { name: name });\n",
|
|||
|
" }\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.toolbar_button_onmouseover = function (tooltip) {\n",
|
|||
|
" this.message.textContent = tooltip;\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"///////////////// REMAINING CONTENT GENERATED BY embed_js.py /////////////////\n",
|
|||
|
"// prettier-ignore\n",
|
|||
|
"var _JSXTOOLS_RESIZE_OBSERVER=function(A){var t,i=new WeakMap,n=new WeakMap,a=new WeakMap,r=new WeakMap,o=new Set;function s(e){if(!(this instanceof s))throw new TypeError(\"Constructor requires 'new' operator\");i.set(this,e)}function h(){throw new TypeError(\"Function is not a constructor\")}function c(e,t,i,n){e=0 in arguments?Number(arguments[0]):0,t=1 in arguments?Number(arguments[1]):0,i=2 in arguments?Number(arguments[2]):0,n=3 in arguments?Number(arguments[3]):0,this.right=(this.x=this.left=e)+(this.width=i),this.bottom=(this.y=this.top=t)+(this.height=n),Object.freeze(this)}function d(){t=requestAnimationFrame(d);var s=new WeakMap,p=new Set;o.forEach((function(t){r.get(t).forEach((function(i){var r=t instanceof window.SVGElement,o=a.get(t),d=r?0:parseFloat(o.paddingTop),f=r?0:parseFloat(o.paddingRight),l=r?0:parseFloat(o.paddingBottom),u=r?0:parseFloat(o.paddingLeft),g=r?0:parseFloat(o.borderTopWidth),m=r?0:parseFloat(o.borderRightWidth),w=r?0:parseFloat(o.borderBottomWidth),b=u+f,F=d+l,v=(r?0:parseFloat(o.borderLeftWidth))+m,W=g+w,y=r?0:t.offsetHeight-W-t.clientHeight,E=r?0:t.offsetWidth-v-t.clientWidth,R=b+v,z=F+W,M=r?t.width:parseFloat(o.width)-R-E,O=r?t.height:parseFloat(o.height)-z-y;if(n.has(t)){var k=n.get(t);if(k[0]===M&&k[1]===O)return}n.set(t,[M,O]);var S=Object.create(h.prototype);S.target=t,S.contentRect=new c(u,d,M,O),s.has(i)||(s.set(i,[]),p.add(i)),s.get(i).push(S)}))})),p.forEach((function(e){i.get(e).call(e,s.get(e),e)}))}return s.prototype.observe=function(i){if(i instanceof window.Element){r.has(i)||(r.set(i,new Set),o.add(i),a.set(i,window.getComputedStyle(i)));var n=r.get(i);n.has(this)||n.add(this),cancelAnimationFrame(t),t=requestAnimationFrame(d)}},s.prototype.unobserve=function(i){if(i instanceof window.Element&&r.has(i)){var n=r.get(i);n.has(this)&&(n.delete(this),n.size||(r.delete(i),o.delete(i))),n.size||r.delete(i),o.size||cancelAnimationFrame(t)}},A.DOMRectReadOnly=c,A.ResizeObserver=s,A.ResizeObserverEntry=h,A}; // eslint-disable-line\n",
|
|||
|
"mpl.toolbar_items = [[\"Home\", \"Reset original view\", \"fa fa-home icon-home\", \"home\"], [\"Back\", \"Back to previous view\", \"fa fa-arrow-left icon-arrow-left\", \"back\"], [\"Forward\", \"Forward to next view\", \"fa fa-arrow-right icon-arrow-right\", \"forward\"], [\"\", \"\", \"\", \"\"], [\"Pan\", \"Left button pans, Right button zooms\\nx/y fixes axis, CTRL fixes aspect\", \"fa fa-arrows icon-move\", \"pan\"], [\"Zoom\", \"Zoom to rectangle\\nx/y fixes axis\", \"fa fa-square-o icon-check-empty\", \"zoom\"], [\"\", \"\", \"\", \"\"], [\"Download\", \"Download plot\", \"fa fa-floppy-o icon-save\", \"download\"]];\n",
|
|||
|
"\n",
|
|||
|
"mpl.extensions = [\"eps\", \"jpeg\", \"pgf\", \"pdf\", \"png\", \"ps\", \"raw\", \"svg\", \"tif\"];\n",
|
|||
|
"\n",
|
|||
|
"mpl.default_extension = \"png\";/* global mpl */\n",
|
|||
|
"\n",
|
|||
|
"var comm_websocket_adapter = function (comm) {\n",
|
|||
|
" // Create a \"websocket\"-like object which calls the given IPython comm\n",
|
|||
|
" // object with the appropriate methods. Currently this is a non binary\n",
|
|||
|
" // socket, so there is still some room for performance tuning.\n",
|
|||
|
" var ws = {};\n",
|
|||
|
"\n",
|
|||
|
" ws.binaryType = comm.kernel.ws.binaryType;\n",
|
|||
|
" ws.readyState = comm.kernel.ws.readyState;\n",
|
|||
|
" function updateReadyState(_event) {\n",
|
|||
|
" if (comm.kernel.ws) {\n",
|
|||
|
" ws.readyState = comm.kernel.ws.readyState;\n",
|
|||
|
" } else {\n",
|
|||
|
" ws.readyState = 3; // Closed state.\n",
|
|||
|
" }\n",
|
|||
|
" }\n",
|
|||
|
" comm.kernel.ws.addEventListener('open', updateReadyState);\n",
|
|||
|
" comm.kernel.ws.addEventListener('close', updateReadyState);\n",
|
|||
|
" comm.kernel.ws.addEventListener('error', updateReadyState);\n",
|
|||
|
"\n",
|
|||
|
" ws.close = function () {\n",
|
|||
|
" comm.close();\n",
|
|||
|
" };\n",
|
|||
|
" ws.send = function (m) {\n",
|
|||
|
" //console.log('sending', m);\n",
|
|||
|
" comm.send(m);\n",
|
|||
|
" };\n",
|
|||
|
" // Register the callback with on_msg.\n",
|
|||
|
" comm.on_msg(function (msg) {\n",
|
|||
|
" //console.log('receiving', msg['content']['data'], msg);\n",
|
|||
|
" var data = msg['content']['data'];\n",
|
|||
|
" if (data['blob'] !== undefined) {\n",
|
|||
|
" data = {\n",
|
|||
|
" data: new Blob(msg['buffers'], { type: data['blob'] }),\n",
|
|||
|
" };\n",
|
|||
|
" }\n",
|
|||
|
" // Pass the mpl event to the overridden (by mpl) onmessage function.\n",
|
|||
|
" ws.onmessage(data);\n",
|
|||
|
" });\n",
|
|||
|
" return ws;\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.mpl_figure_comm = function (comm, msg) {\n",
|
|||
|
" // This is the function which gets called when the mpl process\n",
|
|||
|
" // starts-up an IPython Comm through the \"matplotlib\" channel.\n",
|
|||
|
"\n",
|
|||
|
" var id = msg.content.data.id;\n",
|
|||
|
" // Get hold of the div created by the display call when the Comm\n",
|
|||
|
" // socket was opened in Python.\n",
|
|||
|
" var element = document.getElementById(id);\n",
|
|||
|
" var ws_proxy = comm_websocket_adapter(comm);\n",
|
|||
|
"\n",
|
|||
|
" function ondownload(figure, _format) {\n",
|
|||
|
" window.open(figure.canvas.toDataURL());\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" var fig = new mpl.figure(id, ws_proxy, ondownload, element);\n",
|
|||
|
"\n",
|
|||
|
" // Call onopen now - mpl needs it, as it is assuming we've passed it a real\n",
|
|||
|
" // web socket which is closed, not our websocket->open comm proxy.\n",
|
|||
|
" ws_proxy.onopen();\n",
|
|||
|
"\n",
|
|||
|
" fig.parent_element = element;\n",
|
|||
|
" fig.cell_info = mpl.find_output_cell(\"<div id='\" + id + \"'></div>\");\n",
|
|||
|
" if (!fig.cell_info) {\n",
|
|||
|
" console.error('Failed to find cell for figure', id, fig);\n",
|
|||
|
" return;\n",
|
|||
|
" }\n",
|
|||
|
" fig.cell_info[0].output_area.element.on(\n",
|
|||
|
" 'cleared',\n",
|
|||
|
" { fig: fig },\n",
|
|||
|
" fig._remove_fig_handler\n",
|
|||
|
" );\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_close = function (fig, msg) {\n",
|
|||
|
" var width = fig.canvas.width / fig.ratio;\n",
|
|||
|
" fig.cell_info[0].output_area.element.off(\n",
|
|||
|
" 'cleared',\n",
|
|||
|
" fig._remove_fig_handler\n",
|
|||
|
" );\n",
|
|||
|
" fig.resizeObserverInstance.unobserve(fig.canvas_div);\n",
|
|||
|
"\n",
|
|||
|
" // Update the output cell to use the data from the current canvas.\n",
|
|||
|
" fig.push_to_output();\n",
|
|||
|
" var dataURL = fig.canvas.toDataURL();\n",
|
|||
|
" // Re-enable the keyboard manager in IPython - without this line, in FF,\n",
|
|||
|
" // the notebook keyboard shortcuts fail.\n",
|
|||
|
" IPython.keyboard_manager.enable();\n",
|
|||
|
" fig.parent_element.innerHTML =\n",
|
|||
|
" '<img src=\"' + dataURL + '\" width=\"' + width + '\">';\n",
|
|||
|
" fig.close_ws(fig, msg);\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.close_ws = function (fig, msg) {\n",
|
|||
|
" fig.send_message('closing', msg);\n",
|
|||
|
" // fig.ws.close()\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.push_to_output = function (_remove_interactive) {\n",
|
|||
|
" // Turn the data on the canvas into data in the output cell.\n",
|
|||
|
" var width = this.canvas.width / this.ratio;\n",
|
|||
|
" var dataURL = this.canvas.toDataURL();\n",
|
|||
|
" this.cell_info[1]['text/html'] =\n",
|
|||
|
" '<img src=\"' + dataURL + '\" width=\"' + width + '\">';\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.updated_canvas_event = function () {\n",
|
|||
|
" // Tell IPython that the notebook contents must change.\n",
|
|||
|
" IPython.notebook.set_dirty(true);\n",
|
|||
|
" this.send_message('ack', {});\n",
|
|||
|
" var fig = this;\n",
|
|||
|
" // Wait a second, then push the new image to the DOM so\n",
|
|||
|
" // that it is saved nicely (might be nice to debounce this).\n",
|
|||
|
" setTimeout(function () {\n",
|
|||
|
" fig.push_to_output();\n",
|
|||
|
" }, 1000);\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._init_toolbar = function () {\n",
|
|||
|
" var fig = this;\n",
|
|||
|
"\n",
|
|||
|
" var toolbar = document.createElement('div');\n",
|
|||
|
" toolbar.classList = 'btn-toolbar';\n",
|
|||
|
" this.root.appendChild(toolbar);\n",
|
|||
|
"\n",
|
|||
|
" function on_click_closure(name) {\n",
|
|||
|
" return function (_event) {\n",
|
|||
|
" return fig.toolbar_button_onclick(name);\n",
|
|||
|
" };\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" function on_mouseover_closure(tooltip) {\n",
|
|||
|
" return function (event) {\n",
|
|||
|
" if (!event.currentTarget.disabled) {\n",
|
|||
|
" return fig.toolbar_button_onmouseover(tooltip);\n",
|
|||
|
" }\n",
|
|||
|
" };\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" fig.buttons = {};\n",
|
|||
|
" var buttonGroup = document.createElement('div');\n",
|
|||
|
" buttonGroup.classList = 'btn-group';\n",
|
|||
|
" var button;\n",
|
|||
|
" for (var toolbar_ind in mpl.toolbar_items) {\n",
|
|||
|
" var name = mpl.toolbar_items[toolbar_ind][0];\n",
|
|||
|
" var tooltip = mpl.toolbar_items[toolbar_ind][1];\n",
|
|||
|
" var image = mpl.toolbar_items[toolbar_ind][2];\n",
|
|||
|
" var method_name = mpl.toolbar_items[toolbar_ind][3];\n",
|
|||
|
"\n",
|
|||
|
" if (!name) {\n",
|
|||
|
" /* Instead of a spacer, we start a new button group. */\n",
|
|||
|
" if (buttonGroup.hasChildNodes()) {\n",
|
|||
|
" toolbar.appendChild(buttonGroup);\n",
|
|||
|
" }\n",
|
|||
|
" buttonGroup = document.createElement('div');\n",
|
|||
|
" buttonGroup.classList = 'btn-group';\n",
|
|||
|
" continue;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" button = fig.buttons[name] = document.createElement('button');\n",
|
|||
|
" button.classList = 'btn btn-default';\n",
|
|||
|
" button.href = '#';\n",
|
|||
|
" button.title = name;\n",
|
|||
|
" button.innerHTML = '<i class=\"fa ' + image + ' fa-lg\"></i>';\n",
|
|||
|
" button.addEventListener('click', on_click_closure(method_name));\n",
|
|||
|
" button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n",
|
|||
|
" buttonGroup.appendChild(button);\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" if (buttonGroup.hasChildNodes()) {\n",
|
|||
|
" toolbar.appendChild(buttonGroup);\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" // Add the status bar.\n",
|
|||
|
" var status_bar = document.createElement('span');\n",
|
|||
|
" status_bar.classList = 'mpl-message pull-right';\n",
|
|||
|
" toolbar.appendChild(status_bar);\n",
|
|||
|
" this.message = status_bar;\n",
|
|||
|
"\n",
|
|||
|
" // Add the close button to the window.\n",
|
|||
|
" var buttongrp = document.createElement('div');\n",
|
|||
|
" buttongrp.classList = 'btn-group inline pull-right';\n",
|
|||
|
" button = document.createElement('button');\n",
|
|||
|
" button.classList = 'btn btn-mini btn-primary';\n",
|
|||
|
" button.href = '#';\n",
|
|||
|
" button.title = 'Stop Interaction';\n",
|
|||
|
" button.innerHTML = '<i class=\"fa fa-power-off icon-remove icon-large\"></i>';\n",
|
|||
|
" button.addEventListener('click', function (_evt) {\n",
|
|||
|
" fig.handle_close(fig, {});\n",
|
|||
|
" });\n",
|
|||
|
" button.addEventListener(\n",
|
|||
|
" 'mouseover',\n",
|
|||
|
" on_mouseover_closure('Stop Interaction')\n",
|
|||
|
" );\n",
|
|||
|
" buttongrp.appendChild(button);\n",
|
|||
|
" var titlebar = this.root.querySelector('.ui-dialog-titlebar');\n",
|
|||
|
" titlebar.insertBefore(buttongrp, titlebar.firstChild);\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._remove_fig_handler = function (event) {\n",
|
|||
|
" var fig = event.data.fig;\n",
|
|||
|
" if (event.target !== this) {\n",
|
|||
|
" // Ignore bubbled events from children.\n",
|
|||
|
" return;\n",
|
|||
|
" }\n",
|
|||
|
" fig.close_ws(fig, {});\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._root_extra_style = function (el) {\n",
|
|||
|
" el.style.boxSizing = 'content-box'; // override notebook setting of border-box.\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._canvas_extra_style = function (el) {\n",
|
|||
|
" // this is important to make the div 'focusable\n",
|
|||
|
" el.setAttribute('tabindex', 0);\n",
|
|||
|
" // reach out to IPython and tell the keyboard manager to turn it's self\n",
|
|||
|
" // off when our div gets focus\n",
|
|||
|
"\n",
|
|||
|
" // location in version 3\n",
|
|||
|
" if (IPython.notebook.keyboard_manager) {\n",
|
|||
|
" IPython.notebook.keyboard_manager.register_events(el);\n",
|
|||
|
" } else {\n",
|
|||
|
" // location in version 2\n",
|
|||
|
" IPython.keyboard_manager.register_events(el);\n",
|
|||
|
" }\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype._key_event_extra = function (event, _name) {\n",
|
|||
|
" // Check for shift+enter\n",
|
|||
|
" if (event.shiftKey && event.which === 13) {\n",
|
|||
|
" this.canvas_div.blur();\n",
|
|||
|
" // select the cell after this one\n",
|
|||
|
" var index = IPython.notebook.find_cell_index(this.cell_info[0]);\n",
|
|||
|
" IPython.notebook.select(index + 1);\n",
|
|||
|
" }\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.figure.prototype.handle_save = function (fig, _msg) {\n",
|
|||
|
" fig.ondownload(fig, null);\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"mpl.find_output_cell = function (html_output) {\n",
|
|||
|
" // Return the cell and output element which can be found *uniquely* in the notebook.\n",
|
|||
|
" // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n",
|
|||
|
" // IPython event is triggered only after the cells have been serialised, which for\n",
|
|||
|
" // our purposes (turning an active figure into a static one), is too late.\n",
|
|||
|
" var cells = IPython.notebook.get_cells();\n",
|
|||
|
" var ncells = cells.length;\n",
|
|||
|
" for (var i = 0; i < ncells; i++) {\n",
|
|||
|
" var cell = cells[i];\n",
|
|||
|
" if (cell.cell_type === 'code') {\n",
|
|||
|
" for (var j = 0; j < cell.output_area.outputs.length; j++) {\n",
|
|||
|
" var data = cell.output_area.outputs[j];\n",
|
|||
|
" if (data.data) {\n",
|
|||
|
" // IPython >= 3 moved mimebundle to data attribute of output\n",
|
|||
|
" data = data.data;\n",
|
|||
|
" }\n",
|
|||
|
" if (data['text/html'] === html_output) {\n",
|
|||
|
" return [cell, data, j];\n",
|
|||
|
" }\n",
|
|||
|
" }\n",
|
|||
|
" }\n",
|
|||
|
" }\n",
|
|||
|
"};\n",
|
|||
|
"\n",
|
|||
|
"// Register the function which deals with the matplotlib target/channel.\n",
|
|||
|
"// The kernel may be null if the page has been refreshed.\n",
|
|||
|
"if (IPython.notebook.kernel !== null) {\n",
|
|||
|
" IPython.notebook.kernel.comm_manager.register_target(\n",
|
|||
|
" 'matplotlib',\n",
|
|||
|
" mpl.mpl_figure_comm\n",
|
|||
|
" );\n",
|
|||
|
"}\n"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
"<IPython.core.display.Javascript object>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
},
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/html": [
|
|||
|
"<img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABQAAAAPACAYAAABq3NR5AAAgAElEQVR4XuzdCbRdVX0/8E0IBAIoYLAlREoIFghaQAgCpQIGlQRRmZTULqUGMDKLQIoDoFGGAIIKIlOqq5Io4FCVxAlEBoMEiwoySYJADUMiQhBiMYF/9+k/z0yPe995976zzz6fs1ZXybtn7/3bn99Zd6379dx71njpf4/gIECAAAECBAgQIECAAAECBAgQIEAgS4E1BIBZ9tWmCBAgQIAAAQIECBAgQIAAAQIECBQCAkAXAgECBAgQIECAAAECBAgQIECAAIGMBQSAGTfX1ggQIECAAAECBAgQIECAAAECBAgIAF0DBAgQIECAAAECBAgQIECAAAECBDIWEABm3FxbI0CAAAECBAgQIECAAAECBAgQICAAdA0QIECAAAECBAgQIECAAAECBAgQyFhAAJhxc22NAAECBAgQIECAAAECBAgQIECAgADQNUCAAAECBAgQIECAAAECBAgQIEAgYwEBYMbNtTUCBAgQIECAAAECBAgQIECAAAECAkDXAAECBAgQIECAAAECBAgQIECAAIGMBQSAGTfX1ggQIECAAAECBAgQIECAAAECBAgIAF0DBAgQIECAAAECBAgQIECAAAECBDIWEABm3FxbI0CAAAECBAgQIECAAAECBAgQICAAdA0QIECAAAECBAgQIECAAAECBAgQyFhAAJhxc22NAAECBAgQIECAAAECBAgQIECAgADQNUCAAAECBAgQIECAAAECBAgQIEAgYwEBYMbNtTUCBAgQIECAAAECBAgQIECAAAECAkDXAAECBAgQIECAAAECBAgQIECAAIGMBQSAGTfX1ggQIECAAAECBAgQIECAAAECBAgIAF0DBAgQIECAAAECBAgQIECAAAECBDIWEABm3FxbI0CAAAECBAgQIECAAAECBAgQICAAdA0QIECAAAECBAgQIECAAAECBAgQyFhAAJhxc22NAAECBAgQIECAAAECBAgQIECAgADQNUCAAAECBAgQIECAAAECBAgQIEAgYwEBYMbNtTUCBAgQIECAAAECBAgQIECAAAECAkDXAAECBAgQIECAAAECBAgQIECAAIGMBQSAGTfX1ggQIECAAAECBAgQIECAAAECBAgIAF0DBAgQIECAAAECBAgQIECAAAECBDIWEABm3FxbI0CAAAECBAgQIECAAAECBAgQICAAdA0QIECAAAECBAgQIECAAAECBAgQyFhAAJhxc22NAAECBAgQIECAAAECBAgQIECAgADQNUCAAAECBAgQIECAAAECBAgQIEAgYwEBYMbNtTUCBAgQIECAAAECBAgQIECAAAECAkDXAAECBAgQIECAAAECBAgQIECAAIGMBQSAGTfX1ggQIECAAAECBAgQIECAAAECBAgIAF0DBAgQIECAAAECBAgQIECAAAECBDIWEABm3FxbI0CAAAECBAgQIECAAAECBAgQICAAdA0QIECAAAECBAgQIECAAAECBAgQyFhAAJhxc22NAAECBAgQIECAAAECBAgQIECAgADQNUCAAAECBAgQIECAAAECBAgQIEAgYwEBYMbNtTUCBAgQIECAAAECBAgQIECAAAECAkDXAAECBAgQIECAAAECBAgQIECAAIGMBQSAGTfX1ggQIECAAAECBAgQIECAAAECBAgIAF0DBAgQIECAAAECBAgQIECAAAECBDIWEABm3FxbI0CAAAECBAgQIECAAAECBAgQICAAdA0QIECAAAECBAgQIECAAAECBAgQyFhAAJhxc22NAAECBAgQIECAAAECBAgQIECAgADQNUCAAAECBAgQIECAAAECBAgQIEAgYwEBYMbNtTUCBAgQIECAAAECBAgQIECAAAECAkDXAAECBAgQIECAAAECBAgQIECAAIGMBQSAGTfX1ggQIECAAAECBAgQIECAAAECBAgIAF0DBAgQIECAAAECBAgQIECAAAECBDIWEABm3FxbI0CAAAECBAgQIECAAAECBAgQICAAdA0QIECAAAECBAgQIECAAAECBAgQyFhAAJhxc22NAAECBAgQIECAAAECBAgQIECAgADQNUCAAAECBAgQIECAAAECBAgQIEAgYwEBYMbNtTUCBAgQIECAAAECBAgQIECAAAECAkDXAAECBAgQIECAAAECBAgQIECAAIGMBQSAGTfX1ggQIECAAAECBAgQIECAAAECBAgIAF0DBAgQIECAAAECBAgQIECAAAECBDIWEABm3FxbI0CAAAECBAgQIECAAAECBAgQICAAdA0QIECAAAECBAgQIECAAAECBAgQyFhAAJhxc22NAAECBAgQIECAAAECBAgQIECAgADQNUCAAAECBAgQIECAAAECBAgQIEAgYwEBYMbNtTUCBAgQIECAAAECBAgQIECAAAECAkDXAAECBAgQIECAAAECBAgQIECAAIGMBQSAGTfX1ggQIECAAAECBAgQIECAAAECBAgIAF0DBAgQIECAAAECBAgQIECAAAECBDIWEABm3FxbI0CAAAECBAgQIECAAAECBAgQICAAdA0QIECAAAECBAgQIECAAAECBAgQyFhAAJhxc22NAAECBAgQIECAAAECBAgQIECAgADQNUCAAAECBAgQIECAAAECBAgQIEAgYwEBYMbNtTUCBAgQIECAAAECBAgQIECAAAECAkDXAAECBAgQIECAAAECBAgQIECAAIGMBQSAGTfX1ggQIECAAAECBAgQIECAAAECBAgIAF0DBAgQIECAAAECBAgQIECAAAECBDIWEABm3FxbI0CAAAECBAgQIECAAAECBAgQICAAdA0QIECAAAECBAgQIECAAAECBAgQyFhAAJhxc22NAAECBAgQIECAAAECBAgQIECAgADQNUCAAAECBAgQIECAAAECBAgQIEAgYwEBYMbNtTUCBAgQIECAAAECBAgQIECAAAECAkDXAAECBAgQIECAAAECBAgQIECAAIGMBQSAGTfX1ggQIECAAAECBAgQIECAAAECBAgIAF0DBAgQIECAAAECBAgQIECAAAECBDIWEABm3FxbI0CAAAECBAgQIECAAAECBAgQICAAdA0QIECAAAECBAgQIECAAAECBAgQyFhAAJhxc22NAAECBAgQIECAAAECBAgQIECAgADQNUCAAAECBAgQIECAAAECBAgQIEAgYwEBYMbNtTUCBAgQIECAAAECBAgQIECAAAECAkDXAAECBAgQIECAAAECBAgQIECAAIGMBQSAGTfX1ggQIECAAAECBAgQIECAAAECBAgIAF0DBAgQIECAAAECBAgQIECAAAECBDIWEABm3FxbI0CAAAECBAgQIECAAAECBAgQICAAdA0QIECAAAECBAgQIECAAAECBAgQyFhAAJhxc22NAAECBAgQIECAAAECBAgQIECAgADQNUCAAAECBAgQIECAAAECBAgQIEAgYwEBYMbNtTUCBAgQIECAAAECBAgQIECAAAECAkDXAAECBAgQIECAAAECBAgQIECAAIGMBQSAGTfX1ggQIECAAAECBAgQIECAAAECBAgIAF0DBAgQIECAAAECBAgQIECAAAECBDIWEABm3FxbI0CAAAECBAgQIECAAAECBAgQICAAdA0QIECAAAECBAgQIECAAAECBAgQyFhAAJhxc22NAAECBAgQIECAAAECBAgQIECAgADQNUCAAAECBAgQIECAAAECBAgQIEAgYwEBYMbNtTUCBAgQIECAAAECBAgQIECAAAECAkDXAAECBAgQIECAAAECBAgQIECAAIGMBQSAGTfX1ggQIECAAAECBAgQIECAAAECBAgIAF0DBAgQIECAAAECBAgQIECAAAECBDIWEABm3FxbI0CAAAECBAgQIECAAAECBAgQICAAdA0QIECAAAECBAgQIECAAAECBAgQyFhAAJhxc22NAAECBAgQIECAAAECBAgQIECAgADQNUCAAAECBAgQIECAAAECBAgQIEAgYwEBYMbNTXlrf/7zn8Ndd91VlLjJJpuEwYMHp1yu2ggQIECAAAECBA
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
"<IPython.core.display.HTML object>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"%matplotlib notebook\n",
|
|||
|
"lpp_sorted = posting_account_likes.sort_values('likes_per_post').reset_index()\n",
|
|||
|
"plt.plot(lpp_sorted['likes_per_post'])\n",
|
|||
|
"plt.show()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 142,
|
|||
|
"id": "729e665e",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/html": [
|
|||
|
"<div>\n",
|
|||
|
"<style scoped>\n",
|
|||
|
" .dataframe tbody tr th:only-of-type {\n",
|
|||
|
" vertical-align: middle;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" .dataframe tbody tr th {\n",
|
|||
|
" vertical-align: top;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" .dataframe thead th {\n",
|
|||
|
" text-align: right;\n",
|
|||
|
" }\n",
|
|||
|
"</style>\n",
|
|||
|
"<table border=\"1\" class=\"dataframe\">\n",
|
|||
|
" <thead>\n",
|
|||
|
" <tr style=\"text-align: right;\">\n",
|
|||
|
" <th></th>\n",
|
|||
|
" <th>account</th>\n",
|
|||
|
" <th>likes</th>\n",
|
|||
|
" </tr>\n",
|
|||
|
" </thead>\n",
|
|||
|
" <tbody>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>2</th>\n",
|
|||
|
" <td>did:plc:m2hze6zxa744iberzknpkc3i</td>\n",
|
|||
|
" <td>12.0</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>14</th>\n",
|
|||
|
" <td>did:plc:hb3rpuqloy36skpistigbc3q</td>\n",
|
|||
|
" <td>2.0</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>27</th>\n",
|
|||
|
" <td>did:plc:vnifedvv4yrjwvi345i6ojyo</td>\n",
|
|||
|
" <td>3.0</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>39</th>\n",
|
|||
|
" <td>did:plc:fxgi2crlym2f3ogvygpysomv</td>\n",
|
|||
|
" <td>3.0</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>47</th>\n",
|
|||
|
" <td>did:plc:d6sjqoyj3f234j2xzbnup3xv</td>\n",
|
|||
|
" <td>2.0</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>...</th>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>42435</th>\n",
|
|||
|
" <td>did:plc:fv4ocfi7ztdxwma2wgq3mrpl</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>42436</th>\n",
|
|||
|
" <td>did:plc:6xizlc72q3qrkxaqnnfazf6v</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>42437</th>\n",
|
|||
|
" <td>did:plc:treg3m5eyfqly26syzyif4rv</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>42438</th>\n",
|
|||
|
" <td>did:plc:aq4s2bchpelfyxyj6d2lnq7v</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>42440</th>\n",
|
|||
|
" <td>did:plc:7jhmbeill5icysvwsqgaxnss</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" </tbody>\n",
|
|||
|
"</table>\n",
|
|||
|
"<p>13829 rows × 2 columns</p>\n",
|
|||
|
"</div>"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
" account likes\n",
|
|||
|
"2 did:plc:m2hze6zxa744iberzknpkc3i 12.0\n",
|
|||
|
"14 did:plc:hb3rpuqloy36skpistigbc3q 2.0\n",
|
|||
|
"27 did:plc:vnifedvv4yrjwvi345i6ojyo 3.0\n",
|
|||
|
"39 did:plc:fxgi2crlym2f3ogvygpysomv 3.0\n",
|
|||
|
"47 did:plc:d6sjqoyj3f234j2xzbnup3xv 2.0\n",
|
|||
|
"... ... ...\n",
|
|||
|
"42435 did:plc:fv4ocfi7ztdxwma2wgq3mrpl 0.0\n",
|
|||
|
"42436 did:plc:6xizlc72q3qrkxaqnnfazf6v 0.0\n",
|
|||
|
"42437 did:plc:treg3m5eyfqly26syzyif4rv 0.0\n",
|
|||
|
"42438 did:plc:aq4s2bchpelfyxyj6d2lnq7v 0.0\n",
|
|||
|
"42440 did:plc:7jhmbeill5icysvwsqgaxnss 0.0\n",
|
|||
|
"\n",
|
|||
|
"[13829 rows x 2 columns]"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 142,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"non_posting_accounts = accounts[~accounts['account'].isin(posting_accounts)]\n",
|
|||
|
"non_posting_accounts"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 145,
|
|||
|
"id": "a7840d6e",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"0.30280271513028245"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 145,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"non_posting_accounts.shape[0] / accounts.shape[0]"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 146,
|
|||
|
"id": "dab2dfa5",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"45670"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 146,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"accounts.shape[0]"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 151,
|
|||
|
"id": "03ea581a",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"0.31687034492732663"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 151,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"sum(non_posting_accounts['likes'] > 0) / non_posting_accounts.shape[0]"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 147,
|
|||
|
"id": "ab29ccc1",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"0.010815268772503873"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 147,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"non_posting_accounts['likes'].sum() / accounts['likes'].sum()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 90,
|
|||
|
"id": "d495fad6",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/html": [
|
|||
|
"<div>\n",
|
|||
|
"<style scoped>\n",
|
|||
|
" .dataframe tbody tr th:only-of-type {\n",
|
|||
|
" vertical-align: middle;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" .dataframe tbody tr th {\n",
|
|||
|
" vertical-align: top;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" .dataframe thead th {\n",
|
|||
|
" text-align: right;\n",
|
|||
|
" }\n",
|
|||
|
"</style>\n",
|
|||
|
"<table border=\"1\" class=\"dataframe\">\n",
|
|||
|
" <thead>\n",
|
|||
|
" <tr style=\"text-align: right;\">\n",
|
|||
|
" <th></th>\n",
|
|||
|
" <th>account</th>\n",
|
|||
|
" <th>likes</th>\n",
|
|||
|
" </tr>\n",
|
|||
|
" </thead>\n",
|
|||
|
" <tbody>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>0</th>\n",
|
|||
|
" <td>did:plc:nvog7rczakwzh5ckxnjnwqdd</td>\n",
|
|||
|
" <td>2009.0</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>1</th>\n",
|
|||
|
" <td>did:plc:z3eu4ec7csnznxrrdrabudgj</td>\n",
|
|||
|
" <td>331.0</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>4</th>\n",
|
|||
|
" <td>did:plc:afrooick4a2hy2m2eme5ognc</td>\n",
|
|||
|
" <td>103.0</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>6</th>\n",
|
|||
|
" <td>did:plc:zsdhduo2ahpdhfa73uynnbf2</td>\n",
|
|||
|
" <td>605.0</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>7</th>\n",
|
|||
|
" <td>did:plc:d7hb4uouljzujxvm55gnanr7</td>\n",
|
|||
|
" <td>195.0</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>...</th>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>27941</th>\n",
|
|||
|
" <td>did:plc:tjhlqxa4vqxr2yfgeykncuy6</td>\n",
|
|||
|
" <td>94.0</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>28023</th>\n",
|
|||
|
" <td>did:plc:oormkmckkga7koagos7yrcn7</td>\n",
|
|||
|
" <td>105.0</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>28442</th>\n",
|
|||
|
" <td>did:plc:z3mut2kadcqhm73epuj4vzyq</td>\n",
|
|||
|
" <td>187.0</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>29049</th>\n",
|
|||
|
" <td>did:plc:ituhatvv5pyz4rwsj4hfrslh</td>\n",
|
|||
|
" <td>91.0</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>29179</th>\n",
|
|||
|
" <td>did:plc:zltiiulpgfxsye6u7xd7qzjh</td>\n",
|
|||
|
" <td>91.0</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" </tbody>\n",
|
|||
|
"</table>\n",
|
|||
|
"<p>2306 rows × 2 columns</p>\n",
|
|||
|
"</div>"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
" account likes\n",
|
|||
|
"0 did:plc:nvog7rczakwzh5ckxnjnwqdd 2009.0\n",
|
|||
|
"1 did:plc:z3eu4ec7csnznxrrdrabudgj 331.0\n",
|
|||
|
"4 did:plc:afrooick4a2hy2m2eme5ognc 103.0\n",
|
|||
|
"6 did:plc:zsdhduo2ahpdhfa73uynnbf2 605.0\n",
|
|||
|
"7 did:plc:d7hb4uouljzujxvm55gnanr7 195.0\n",
|
|||
|
"... ... ...\n",
|
|||
|
"27941 did:plc:tjhlqxa4vqxr2yfgeykncuy6 94.0\n",
|
|||
|
"28023 did:plc:oormkmckkga7koagos7yrcn7 105.0\n",
|
|||
|
"28442 did:plc:z3mut2kadcqhm73epuj4vzyq 187.0\n",
|
|||
|
"29049 did:plc:ituhatvv5pyz4rwsj4hfrslh 91.0\n",
|
|||
|
"29179 did:plc:zltiiulpgfxsye6u7xd7qzjh 91.0\n",
|
|||
|
"\n",
|
|||
|
"[2306 rows x 2 columns]"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 90,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"top_accounts"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 135,
|
|||
|
"id": "77340e08",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/html": [
|
|||
|
"<div>\n",
|
|||
|
"<style scoped>\n",
|
|||
|
" .dataframe tbody tr th:only-of-type {\n",
|
|||
|
" vertical-align: middle;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" .dataframe tbody tr th {\n",
|
|||
|
" vertical-align: top;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" .dataframe thead th {\n",
|
|||
|
" text-align: right;\n",
|
|||
|
" }\n",
|
|||
|
"</style>\n",
|
|||
|
"<table border=\"1\" class=\"dataframe\">\n",
|
|||
|
" <thead>\n",
|
|||
|
" <tr style=\"text-align: right;\">\n",
|
|||
|
" <th></th>\n",
|
|||
|
" <th>account</th>\n",
|
|||
|
" <th>likes</th>\n",
|
|||
|
" </tr>\n",
|
|||
|
" </thead>\n",
|
|||
|
" <tbody>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>0</th>\n",
|
|||
|
" <td>did:plc:nvog7rczakwzh5ckxnjnwqdd</td>\n",
|
|||
|
" <td>2009.0</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>1</th>\n",
|
|||
|
" <td>did:plc:z3eu4ec7csnznxrrdrabudgj</td>\n",
|
|||
|
" <td>331.0</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>2</th>\n",
|
|||
|
" <td>did:plc:m2hze6zxa744iberzknpkc3i</td>\n",
|
|||
|
" <td>12.0</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>3</th>\n",
|
|||
|
" <td>did:plc:ykzmsemoxmlzmrci2p77eqkm</td>\n",
|
|||
|
" <td>41.0</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>4</th>\n",
|
|||
|
" <td>did:plc:afrooick4a2hy2m2eme5ognc</td>\n",
|
|||
|
" <td>103.0</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>...</th>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>45665</th>\n",
|
|||
|
" <td>did:plc:efkxngznfeo2onvrjhskmmou</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>45666</th>\n",
|
|||
|
" <td>did:plc:pv4x356soulpp7spindi57gz</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>45667</th>\n",
|
|||
|
" <td>did:plc:w5reveglbupc6sz4txst2v7b</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>45668</th>\n",
|
|||
|
" <td>did:plc:7o6uylwbtcpwk5c5pqa67fsl</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>45669</th>\n",
|
|||
|
" <td>did:plc:uppr7hyd3a2zzss54drq2s5j</td>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" </tbody>\n",
|
|||
|
"</table>\n",
|
|||
|
"<p>45670 rows × 2 columns</p>\n",
|
|||
|
"</div>"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
" account likes\n",
|
|||
|
"0 did:plc:nvog7rczakwzh5ckxnjnwqdd 2009.0\n",
|
|||
|
"1 did:plc:z3eu4ec7csnznxrrdrabudgj 331.0\n",
|
|||
|
"2 did:plc:m2hze6zxa744iberzknpkc3i 12.0\n",
|
|||
|
"3 did:plc:ykzmsemoxmlzmrci2p77eqkm 41.0\n",
|
|||
|
"4 did:plc:afrooick4a2hy2m2eme5ognc 103.0\n",
|
|||
|
"... ... ...\n",
|
|||
|
"45665 did:plc:efkxngznfeo2onvrjhskmmou 0.0\n",
|
|||
|
"45666 did:plc:pv4x356soulpp7spindi57gz 0.0\n",
|
|||
|
"45667 did:plc:w5reveglbupc6sz4txst2v7b 0.0\n",
|
|||
|
"45668 did:plc:7o6uylwbtcpwk5c5pqa67fsl 0.0\n",
|
|||
|
"45669 did:plc:uppr7hyd3a2zzss54drq2s5j 0.0\n",
|
|||
|
"\n",
|
|||
|
"[45670 rows x 2 columns]"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 135,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"accounts"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": null,
|
|||
|
"id": "75bbb3eb",
|
|||
|
"metadata": {},
|
|||
|
"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.9.1"
|
|||
|
}
|
|||
|
},
|
|||
|
"nbformat": 4,
|
|||
|
"nbformat_minor": 5
|
|||
|
}
|