{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/Users/diaz/anaconda/lib/python2.7/site-packages/pandas/computation/__init__.py:19: UserWarning: The installed version of numexpr 2.4.4 is not supported in pandas and will be not be used\n", "\n", " UserWarning)\n" ] }, { "data": { "text/html": [ "\n", "
" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", "(function(global) {\n", " function now() {\n", " return new Date();\n", " }\n", "\n", " if (typeof (window._bokeh_onload_callbacks) === \"undefined\") {\n", " window._bokeh_onload_callbacks = [];\n", " }\n", "\n", " function run_callbacks() {\n", " window._bokeh_onload_callbacks.forEach(function(callback) { callback() });\n", " delete window._bokeh_onload_callbacks\n", " console.info(\"Bokeh: all callbacks have finished\");\n", " }\n", "\n", " function load_libs(js_urls, callback) {\n", " window._bokeh_onload_callbacks.push(callback);\n", " if (window._bokeh_is_loading > 0) {\n", " console.log(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n", " return null;\n", " }\n", " if (js_urls == null || js_urls.length === 0) {\n", " run_callbacks();\n", " return null;\n", " }\n", " console.log(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n", " window._bokeh_is_loading = js_urls.length;\n", " for (var i = 0; i < js_urls.length; i++) {\n", " var url = js_urls[i];\n", " var s = document.createElement('script');\n", " s.src = url;\n", " s.async = false;\n", " s.onreadystatechange = s.onload = function() {\n", " window._bokeh_is_loading--;\n", " if (window._bokeh_is_loading === 0) {\n", " console.log(\"Bokeh: all BokehJS libraries loaded\");\n", " run_callbacks()\n", " }\n", " };\n", " s.onerror = function() {\n", " console.warn(\"failed to load library \" + url);\n", " };\n", " console.log(\"Bokeh: injecting script tag for BokehJS library: \", url);\n", " document.getElementsByTagName(\"head\")[0].appendChild(s);\n", " }\n", " };\n", "\n", " var js_urls = ['https://cdn.pydata.org/bokeh/release/bokeh-0.11.1.min.js', 'https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.11.1.min.js', 'https://cdn.pydata.org/bokeh/release/bokeh-compiler-0.11.1.min.js'];\n", "\n", " var inline_js = [\n", " function(Bokeh) {\n", " Bokeh.set_log_level(\"info\");\n", " },\n", " \n", " function(Bokeh) {\n", " Bokeh.$(\"#3bcfb936-076e-4065-9a90-3203241d5de6\").text(\"BokehJS successfully loaded\");\n", " },\n", " function(Bokeh) {\n", " console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-0.11.1.min.css\");\n", " Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-0.11.1.min.css\");\n", " console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.11.1.min.css\");\n", " Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.11.1.min.css\");\n", " }\n", " ];\n", "\n", " function run_inline_js() {\n", " for (var i = 0; i < inline_js.length; i++) {\n", " inline_js[i](window.Bokeh);\n", " }\n", " }\n", "\n", " if (window._bokeh_is_loading === 0) {\n", " console.log(\"Bokeh: BokehJS loaded, going straight to plotting\");\n", " run_inline_js();\n", " } else {\n", " load_libs(js_urls, function() {\n", " console.log(\"Bokeh: BokehJS plotting callback run at\", now());\n", " run_inline_js();\n", " });\n", " }\n", "}(this));" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from __future__ import division\n", "\n", "import pandas as pd\n", "import numpy as np\n", "\n", "import bokeh.plotting as bkP\n", "import bokeh.models as bkM\n", "from bokeh.palettes import Spectral6\n", "from bokeh.embed import file_html\n", "from bokeh.resources import CDN\n", "\n", "bkP.output_notebook()\n", "\n" ] }, { "cell_type": "code", "execution_count": 41, "metadata": { "collapsed": true }, "outputs": [], "source": [ "source = bkM.ColumnDataSource(data=dict(x=[], y=[], width=[], height=[],leftEdge=[],rightEdge=[]))\n", "\n", "boxCallback = bkM.CustomJS(args=dict(source=source), code=\"\"\"\n", " \n", " // get data source from Callback args\n", " var data = source.get('data');\n", "\n", " /// get BoxSelectTool dimensions from cb_data parameter of Callback\n", " var geometry = cb_data['geometry'];\n", "\n", " /// calculate Rect attributes\n", " var width = geometry['x1'] - geometry['x0'];\n", " var height = geometry['y1'] - geometry['y0'];\n", " var x = geometry['x0'] + width/2;\n", " var y = geometry['y0'] + height/2;\n", " \n", " var leftEdge = geometry['x0']\n", " var rightEdge = geometry['x1']\n", " \n", " /// update data source with new Rect attributes\n", " data['x'].push(x);\n", " data['y'].push(y);\n", " \n", " data['width'].push(width);\n", " data['height'].push(height);\n", " data['eventType'] = 'none'\n", " data['leftEdge'] = leftEdge\n", " data['rightEdge'] = rightEdge\n", " \n", " // trigger update of data source\n", " source.trigger('change');\n", " \n", " \"\"\")\n", "\n", "tapCallback = bkM.CustomJS(args=dict(source=source), code=\"\"\"\n", " \n", " // get data source from Callback args\n", " var data = source.get('data');\n", " \n", " var width = data['width']\n", " \n", " IPython.notebook.kernel.execute(\"leftEdge = \" + data['leftEdge']);\n", " IPython.notebook.kernel.execute(\"rightEdge = \" + data['rightEdge'] );\n", "\n", " \n", " \"\"\")\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Need an identifier / pointer to the glyph.\n", "Once I have that, how to I remove the glpyh?" ] }, { "cell_type": "code", "execution_count": 42, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "\n", " \n", "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "<Bokeh Notebook handle for In[42]>