Skip to content

Commit

Permalink
Update anno_app.ipynb
Browse files Browse the repository at this point in the history
forcing box to be a bit larger
  • Loading branch information
kmader committed Aug 17, 2018
1 parent ac1fb52 commit 9a96e85
Showing 1 changed file with 17 additions and 260 deletions.
277 changes: 17 additions & 260 deletions anno_app.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,9 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<style>\n",
".modebar{\n",
" display: none !important;\n",
"}\n",
"</style>\n",
"<!-- Global site tag(gtag.js) - Google Analytics - ->\n",
"<script async src = \"https://www.googletagmanager.com/gtag/js?id=UA-123889833-1\" > </script >\n",
"<script >\n",
" window.dataLayer = window.dataLayer | | []\n",
" function gtag(){dataLayer.push(arguments)\n",
" }\n",
" gtag('js', new Date())\n",
"\n",
" gtag('config', 'UA-123889833-1')\n",
"</script >"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"%%HTML\n",
"<style>\n",
Expand All @@ -70,29 +43,9 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"application/javascript": [
"$('#appmode-leave').hide()\n",
"// Hides the edit app button.\n",
"$('#appmode-busy').hide()\n",
"// Hides the kernel busy indicator.\n",
"IPython.OutputArea.prototype._should_scroll = function(lines) {\n",
" return false\n",
" // disable scrolling\n",
"}"
],
"text/plain": [
"<IPython.core.display.Javascript object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"%%javascript\n",
"$('#appmode-leave').hide()\n",
Expand All @@ -107,7 +60,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -151,20 +104,9 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/srv/conda/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88\n",
" return f(*args, **kwds)\n",
"/srv/conda/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88\n",
" return f(*args, **kwds)\n"
]
}
],
"outputs": [],
"source": [
"import os\n",
"import ipywidgets as ipw\n",
Expand All @@ -188,7 +130,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -199,7 +141,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -214,180 +156,9 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"application/javascript": [
"window.genUID = function() {\n",
" return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {\n",
" var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);\n",
" return v.toString(16);\n",
" });\n",
"};\n",
"\n",
"\n",
"define('graphWidget', [\"@jupyter-widgets/base\"], function (widget) {\n",
"\n",
" var GraphView = widget.DOMWidgetView.extend({\n",
" render: function(){\n",
" var that = this;\n",
"\n",
" var graphId = window.genUID();\n",
" var loadingId = 'loading-'+graphId;\n",
"\n",
"\n",
" var _graph_url = that.model.get('_graph_url');\n",
"\n",
" // variable plotlyDomain in the case of enterprise\n",
" var url_parts = _graph_url.split('/');\n",
" var plotlyDomain = url_parts[0] + '//' + url_parts[2];\n",
"\n",
" if(!('plotlyDomains' in window)){\n",
" window.plotlyDomains = {};\n",
" }\n",
" window.plotlyDomains[graphId] = plotlyDomain;\n",
"\n",
" // Place IFrame in output cell div `$el`\n",
" that.$el.css('width', '100%');\n",
" that.$graph = $(['<iframe id=\"'+graphId+'\"',\n",
" 'src=\"'+_graph_url+'.embed\"',\n",
" 'seamless',\n",
" 'style=\"border: none;\"',\n",
" 'width=\"100%\"',\n",
" 'height=\"600\">',\n",
" '</iframe>'].join(' '));\n",
" that.$graph.appendTo(that.$el);\n",
"\n",
" that.$loading = $('<div id=\"'+loadingId+'\">Initializing...</div>')\n",
" .appendTo(that.$el);\n",
"\n",
" // for some reason the 'width' is being changed in IPython 3.0.0\n",
" // for the containing `div` element. There's a flicker here, but\n",
" // I was unable to fix it otherwise.\n",
" setTimeout(function () {\n",
" if (IPYTHON_VERSION === '3') {\n",
" $('#' + graphId)[0].parentElement.style.width = '100%';\n",
" }\n",
" }, 500);\n",
"\n",
" // initialize communication with the iframe\n",
" if(!('pingers' in window)){\n",
" window.pingers = {};\n",
" }\n",
"\n",
" window.pingers[graphId] = setInterval(function() {\n",
" that.graphContentWindow = $('#'+graphId)[0].contentWindow;\n",
" that.graphContentWindow.postMessage({task: 'ping'}, plotlyDomain);\n",
" }, 200);\n",
"\n",
" // Assign a message listener to the 'message' events\n",
" // from iframe's postMessage protocol.\n",
" // Filter the messages by iframe src so that the right message\n",
" // gets passed to the right widget\n",
" if(!('messageListeners' in window)){\n",
" window.messageListeners = {};\n",
" }\n",
"\n",
" window.messageListeners[graphId] = function(e) {\n",
" if(_graph_url.indexOf(e.origin)>-1) {\n",
" var frame = document.getElementById(graphId);\n",
"\n",
" if(frame === null){\n",
" // frame doesn't exist in the dom anymore, clean up it's old event listener\n",
" window.removeEventListener('message', window.messageListeners[graphId]);\n",
" clearInterval(window.pingers[graphId]);\n",
" } else if(frame.contentWindow === e.source) {\n",
" // TODO: Stop event propagation, so each frame doesn't listen and filter\n",
" var frameContentWindow = $('#'+graphId)[0].contentWindow;\n",
" var message = e.data;\n",
"\n",
" if('pong' in message && message.pong) {\n",
" $('#loading-'+graphId).hide();\n",
" clearInterval(window.pingers[graphId]);\n",
" that.send({event: 'pong', graphId: graphId});\n",
" } else if (message.type==='hover' ||\n",
" message.type==='zoom' ||\n",
" message.type==='click' ||\n",
" message.type==='unhover') {\n",
"\n",
" // click and hover events contain all of the data in the traces,\n",
" // which can be a very large object and may take a ton of time\n",
" // to pass to the python backend. Strip out the data, and require\n",
" // the user to call get_figure if they need trace information\n",
" if(message.type !== 'zoom') {\n",
" for(var i in message.points) {\n",
" delete message.points[i].data;\n",
" delete message.points[i].fullData;\n",
" }\n",
" }\n",
" that.send({event: message.type, message: message, graphId: graphId});\n",
" } else if (message.task === 'getAttributes') {\n",
" that.send({event: 'getAttributes', response: message.response});\n",
" }\n",
" }\n",
" }\n",
" };\n",
"\n",
" window.removeEventListener('message', window.messageListeners[graphId]);\n",
" window.addEventListener('message', window.messageListeners[graphId]);\n",
"\n",
" },\n",
"\n",
" update: function() {\n",
" // Listen for messages from the graph widget in python\n",
" var jmessage = this.model.get('_message');\n",
" var message = JSON.parse(jmessage);\n",
"\n",
" // check for duplicate messages\n",
" if(!('messageIds' in window)){\n",
" window.messageIds = {};\n",
" }\n",
"\n",
" if(!(message.uid in window.messageIds)){\n",
" // message hasn't been received yet, do stuff\n",
" window.messageIds[message.uid] = true;\n",
"\n",
" if (message.fadeTo) {\n",
" this.fadeTo(message);\n",
" } else {\n",
" var plot = $('#' + message.graphId)[0].contentWindow;\n",
" plot.postMessage(message, window.plotlyDomains[message.graphId]);\n",
" }\n",
" }\n",
"\n",
" return GraphView.__super__.update.apply(this);\n",
" },\n",
"\n",
" /**\n",
" * Wrapper for jquery's `fadeTo` function.\n",
" *\n",
" * @param message Contains the id we need to find the element.\n",
" */\n",
" fadeTo: function (message) {\n",
" var plot = $('#' + message.graphId);\n",
" plot.fadeTo(message.duration, message.opacity);\n",
" }\n",
" });\n",
"\n",
" // Register the GraphView with the widget manager.\n",
" return {\n",
" GraphView: GraphView\n",
" }\n",
"\n",
"});\n",
"\n",
"//@ sourceURL=graphWidget.js\n"
],
"text/plain": [
"<IPython.core.display.Javascript object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"from plotly.widgets import GraphWidget\n",
"import plotly.graph_objs as go\n",
Expand Down Expand Up @@ -507,9 +278,10 @@
" if with_bc:\n",
" bc_tools = [ipw.HBox([self._brightness, self._contrast])]\n",
" else:\n",
" bc_tools = [ipw.HBox(layout=ipw.Layout(width=\"768px\"))]\n",
" bc_tools = []\n",
" super().__init__(\n",
" ipw.VBox(bc_tools+[self._g]))\n",
" ipw.VBox(bc_tools+[self._g], layout=ipw.Layout(width=\"600px\", height=\"600px\"))\n",
" )\n",
"\n",
" def clear_image(self):\n",
" self._raw_img = None\n",
Expand Down Expand Up @@ -736,7 +508,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -766,26 +538,11 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": null,
"metadata": {
"scrolled": false
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "bde1b07cf3904580bc0edc8ea19f72c3",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(HTML(value='<h1> Welcome random githubber</h1>'), HBox(children=(VBox(children=(IntProgress(val…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"title_box = ipw.HTML(value='<h1> Welcome {}</h1>'.format(USERNAME.replace('_', ' ')))\n",
"if BINARY_TASK:\n",
Expand Down

0 comments on commit 9a96e85

Please sign in to comment.