{ "cells": [ { "cell_type": "code", "execution_count": 73, "metadata": { "collapsed": false, "extensions": { "jupyter_dashboards": { "version": 1, "views": { "grid_default": { "hidden": true }, "report_default": { "hidden": false } } } }, "urth": { "dashboard": { "hidden": true, "layout": {} } } }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "#from __future__ import print_function\n", "import ipywidgets as widgets\n", "from IPython.display import display, clear_output\n", "import numpy as np\n", "from rsfmodel import rsf, staterelations, plot\n", "\n", "%matplotlib notebook" ] }, { "cell_type": "code", "execution_count": 74, "metadata": { "collapsed": false, "extensions": { "jupyter_dashboards": { "version": 1, "views": { "grid_default": { "hidden": true }, "report_default": { "hidden": false } } } }, "urth": { "dashboard": { "hidden": true, "layout": {} } } }, "outputs": [], "source": [ "def RunModel():\n", " # Set model initial conditions\n", " model.mu0 = 0.6 # Friction initial (at the reference velocity)\n", " model.a = a_floatBox.value # Empirical coefficient for the direct effect\n", " model.k = k_floatBox.value # Normalized System stiffness (friction/micron)\n", "\n", " if sv1_dropdown.value == \"Aging Relation\":\n", " state1 = staterelations.DieterichState()\n", " state1.b = b1_floatBox.value # Empirical coefficient for the evolution effect\n", " state1.Dc = Dc1_floatBox.value # Critical slip distance\n", " \n", " elif sv1_dropdown.value == \"Slowness Relation\":\n", " state1 = staterelations.RuinaState()\n", " state1.b = b1_floatBox.value # Empirical coefficient for the evolution effect\n", " state1.Dc = Dc1_floatBox.value # Critical slip distance\n", " \n", " else:\n", " # We shouldn't be here!\n", " pass\n", " \n", " if sv2_dropdown.value == \"Aging Relation\":\n", " state2 = staterelations.DieterichState()\n", " state2.b = b1_floatBox.value # Empirical coefficient for the evolution effect\n", " state2.Dc = Dc1_floatBox.value # Critical slip distance\n", " \n", " elif sv2_dropdown.value == \"Slowness Relation\":\n", " state2 = staterelations.RuinaState()\n", " state2.b = b1_floatBox.value # Empirical coefficient for the evolution effect\n", " state2.Dc = Dc1_floatBox.value # Critical slip distance\n", " \n", " else:\n", " # None\n", " pass\n", " \n", " model.state_relations = [state1] # Which state relation we want to use\n", " \n", " if sv2_dropdown.value != \"None\":\n", " model.state_relations.append(state2)\n", "\n", " time, velocity = parse_sequence(step_sequence_string.value)\n", "\n", " model.time = time\n", " # Set the model load point velocity, must be same shape as model.model_time\n", " model.loadpoint_velocity = velocity\n", "\n", " model.v = velocity[0] # Initial slider velocity, generally is vlp(t=0)\n", " model.vref = velocity[0] # Reference velocity, generally vlp(t=0)\n", " \n", " # Run the model!\n", " model.solve()" ] }, { "cell_type": "code", "execution_count": 75, "metadata": { "collapsed": true, "extensions": { "jupyter_dashboards": { "version": 1, "views": { "grid_default": { "hidden": true }, "report_default": { "hidden": false } } } }, "urth": { "dashboard": { "hidden": true, "layout": {} } } }, "outputs": [], "source": [ "def update_dispalcement_plot(model):\n", " #clear_output(wait=True)\n", " line_lp_mu.set_xdata(model.results.loadpoint_displacement)\n", " line_lp_mu.set_ydata(model.results.friction)\n", " \n", " line_lp_vs.set_xdata(model.results.loadpoint_displacement)\n", " line_lp_vs.set_ydata(model.results.slider_velocity)\n", " \n", " ax1.set_xlim(0, np.max(model.results.loadpoint_displacement))\n", " \n", " ax1.relim()\n", " ax1.autoscale_view(False, False, True)\n", " \n", " ax1b.relim()\n", " ax1b.autoscale_view(False, False, True)\n", " fig_vars.canvas.draw()" ] }, { "cell_type": "code", "execution_count": 76, "metadata": { "collapsed": true, "extensions": { "jupyter_dashboards": { "version": 1, "views": { "grid_default": { "hidden": true }, "report_default": { "hidden": false } } } }, "urth": { "dashboard": { "hidden": true, "layout": {} } } }, "outputs": [], "source": [ "def update_time_plot(model):\n", " #clear_output(wait=True)\n", "\n", " line_time_mu.set_xdata(model.results.time)\n", " line_time_mu.set_ydata(model.results.friction)\n", " \n", " line_time_vs.set_xdata(model.results.time)\n", " line_time_vs.set_ydata(model.results.slider_velocity)\n", " \n", " ax2.set_xlim(0, np.max(model.results.time))\n", " \n", " ax2.relim()\n", " ax2.autoscale_view(False, False, True)\n", " \n", " ax2b.relim()\n", " ax2b.autoscale_view(False, False, True)\n", " fig_vars.canvas.draw()\n" ] }, { "cell_type": "code", "execution_count": 77, "metadata": { "collapsed": false, "extensions": { "jupyter_dashboards": { "version": 1, "views": { "grid_default": { "hidden": true }, "report_default": { "hidden": false } } } }, "urth": { "dashboard": { "hidden": true, "layout": {} } } }, "outputs": [], "source": [ "def update_phase_plot(model):\n", " ax3.cla()\n", " phase_line, = ax3.plot([], [], color=tableau20[4], linewidth=2)\n", "\n", " ax3.set_xlabel(r'ln$\\frac{V}{V_{ref}}$', fontsize=16, labelpad=20)\n", " ax3.set_ylabel(r'$\\mu$', fontsize=16)\n", " \n", " v_ratio = np.log(model.results.slider_velocity/model.vref)\n", " phase_line.set_xdata(v_ratio)\n", " phase_line.set_ydata(model.results.friction)\n", " \n", " #xlims = ax2.get_xlims()#[np.min(v_ratio), np.max(v_ratio)]\n", " #ylims = ax3.get_xlims()#[np.min(model.results.friction), np.max(model.results.friction)]\n", " ax3.relim()\n", " ax3.autoscale_view(False, True, True)\n", " ylims = ax3.get_ylim()\n", " xlims = ax3.get_xlim()\n", " # Plot lines of constant a that are in the view\n", " y_line = model.a * np.array(xlims)\n", " for mu in np.arange(0, ylims[1]*2, 0.005):\n", " y_line_plot = y_line + mu\n", " if max(y_line_plot) > ylims[0]:\n", " ax3.plot([xlims[0], xlims[1]], y_line_plot, color='k', linestyle='--')\n", "\n", " # Plot a line of rate dependence \"Steady State Line\"\n", " state_b_sum = 0\n", " for state in model.state_relations:\n", " state_b_sum += state.b\n", " mu_rate_dependence = model.mu0 + (model.a - state_b_sum)*np.array(xlims)\n", " ax3.plot(xlims, mu_rate_dependence, color='k', linestyle='--')\n", "\n", " ax3.set_xlim(xlims)\n", " ax3.set_ylim(ylims)\n", " #ax3.relim()\n", " #ax3.autoscale_view(False, True, True)\n", " fig_phase.canvas.draw()" ] }, { "cell_type": "code", "execution_count": 78, "metadata": { "collapsed": true, "extensions": { "jupyter_dashboards": { "version": 1, "views": { "grid_default": { "hidden": true }, "report_default": { "hidden": false } } } }, "urth": { "dashboard": { "hidden": true, "layout": {} } } }, "outputs": [], "source": [ "def stiffness_text_update(model):\n", " kc = (model.state_relations[0].b - model.a)/model.state_relations[0].Dc\n", " kc_label.value = \"k$_c$ [$\\mu$m$^{-1}$]: %f\" %kc\n", " kappa_label.value = \"k/k$_c$: %f\" %(model.k/kc)" ] }, { "cell_type": "code", "execution_count": 79, "metadata": { "collapsed": false, "extensions": { "jupyter_dashboards": { "version": 1, "views": { "grid_default": { "hidden": true }, "report_default": { "hidden": false } } } }, "urth": { "dashboard": { "hidden": true, "layout": {} } } }, "outputs": [], "source": [ "def parse_sequence(seqString):\n", " steps = seqString.split(',')\n", " if len(steps)%2 != 0:\n", " # Odd number of steps is an error!\n", " step_sequence_string.border_color = 'red'\n", " else:\n", " step_sequence_string.border_color = 'green'\n", " steps = np.array(steps)\n", " steps = steps.astype(int)\n", " \n", " steps = steps.reshape((len(steps)/2,2))\n", " \n", " dt = 0.01\n", "\n", " if simType_buttons.value == 'Velocity-Displacement':\n", " velocity = np.array([])\n", " time = np.arange(0, np.sum(steps[:,1]/steps[:,0]), dt)\n", " for step_velocity, step_displacement in steps:\n", " step_time = step_displacement/step_velocity\n", " velocity = np.hstack((velocity, np.ones(step_time/dt) * step_velocity))\n", " \n", " if simType_buttons.value == 'Velocity-Time':\n", " velocity = np.array([])\n", " time = np.arange(0, np.sum(steps[:,1]), dt)\n", " for step_velocity, step_time in steps:\n", " velocity = np.hstack((velocity, np.ones(step_time/dt) * step_velocity))\n", " \n", " return time, velocity " ] }, { "cell_type": "code", "execution_count": 80, "metadata": { "collapsed": false, "extensions": { "jupyter_dashboards": { "version": 1, "views": { "grid_default": { "hidden": true }, "report_default": { "hidden": false } } } }, "urth": { "dashboard": { "hidden": true, "layout": {} } } }, "outputs": [], "source": [ "def on_calculate_clicked(button): \n", " RunModel()\n", " update_dispalcement_plot(model)\n", " update_time_plot(model)\n", " update_phase_plot(model)\n", " stiffness_text_update(model)\n", " clear_output(wait=True)\n" ] }, { "cell_type": "code", "execution_count": 81, "metadata": { "collapsed": false, "extensions": { "jupyter_dashboards": { "version": 1, "views": { "grid_default": { "hidden": true }, "report_default": { "hidden": false } } } }, "urth": { "dashboard": { "hidden": true, "layout": {} } } }, "outputs": [], "source": [ "def on_reset(button):\n", " a_floatBox.value = 0.005\n", " b1_floatBox.value = 0.01\n", " Dc1_floatBox.value = 10.\n", " b2_floatBox.value = 0.01\n", " Dc2_floatBox.value = 10.\n", " k_floatBox.value = 1e-3\n", " sv1_dropdown.value = \"Aging Relation\"\n", " sv2_dropdown.value = \"None\"\n", " RunModel()\n", " update_plot()" ] }, { "cell_type": "code", "execution_count": 82, "metadata": { "collapsed": true, "extensions": { "jupyter_dashboards": { "version": 1, "views": { "grid_default": { "hidden": true }, "report_default": { "hidden": false } } } }, "urth": { "dashboard": { "hidden": true, "layout": {} } } }, "outputs": [], "source": [ "# These are the \"Tableau 20\" colors as RGB. \n", "tableau20 = [(31, 119, 180), (174, 199, 232), (255, 127, 14), (255, 187, 120), \n", " (44, 160, 44), (152, 223, 138), (214, 39, 40), (255, 152, 150), \n", " (148, 103, 189), (197, 176, 213), (140, 86, 75), (196, 156, 148), \n", " (227, 119, 194), (247, 182, 210), (127, 127, 127), (199, 199, 199), \n", " (188, 189, 34), (219, 219, 141), (23, 190, 207), (158, 218, 229)] \n", " \n", "# Scale the RGB values to the [0, 1] range, which is the format matplotlib accepts. \n", "for i in range(len(tableau20)): \n", " r, g, b = tableau20[i] \n", " tableau20[i] = (r / 255., g / 255., b / 255.) " ] }, { "cell_type": "code", "execution_count": 83, "metadata": { "collapsed": false, "extensions": { "jupyter_dashboards": { "version": 1, "views": { "grid_default": { "hidden": true }, "report_default": { "hidden": false } } } }, "urth": { "dashboard": { "hidden": true, "layout": {} } } }, "outputs": [], "source": [ "model = rsf.Model()" ] }, { "cell_type": "code", "execution_count": 84, "metadata": { "collapsed": false, "extensions": { "jupyter_dashboards": { "version": 1, "views": { "grid_default": { "hidden": true }, "report_default": { "hidden": false } } } }, "urth": { "dashboard": { "hidden": true, "layout": {} } } }, "outputs": [], "source": [ "a_floatBox = widgets.BoundedFloatText(\n", " value=0.005,\n", " min=0,\n", " max=1,\n", " description='a:',\n", ")\n", "\n", "b1_floatBox = widgets.BoundedFloatText(\n", " value=0.01,\n", " min=0,\n", " max=1,\n", " description='b:',\n", ")\n", "\n", "b2_floatBox = widgets.BoundedFloatText(\n", " value=0.01,\n", " min=0,\n", " max=1,\n", " description='b:',\n", ")\n", "\n", "Dc1_floatBox = widgets.BoundedFloatText(\n", " value=10.0,\n", " min=0,\n", " max=30000.0,\n", " description='Dc:',\n", ")\n", "\n", "Dc2_floatBox = widgets.BoundedFloatText(\n", " value=10.0,\n", " min=0,\n", " max=30000.0,\n", " description='Dc:',\n", ")\n", "\n", "k_floatBox = widgets.BoundedFloatText(\n", " value=1e-3,\n", " min=0.,\n", " max=100,\n", " description='k:',\n", ")\n", "\n", "sv1_dropdown = widgets.Dropdown(\n", " options=['Aging Relation', 'Slowness Relation'],\n", " value='Aging Relation',\n", " decription='State Relation:')\n", "\n", "sv2_dropdown = widgets.Dropdown(\n", " options=['None', 'Aging Relation', 'Slowness Relation'],\n", " value='None',\n", " decription='State Relation:')\n", "\n", "simType_buttons = widgets.ToggleButtons(\n", " description='Simulation Type',\n", " options=['Velocity-Displacement', 'Velocity-Time'])\n", "\n", "calculate_button = widgets.Button(\n", " description=\"Calculate\")\n", "\n", "reset_button = widgets.Button(\n", " description=\"Reset\")\n", "\n", "step_sequence_string = widgets.Text(\n", " description='Sequence:',\n", " value='1,10,10,200',\n", ")" ] }, { "cell_type": "code", "execution_count": 85, "metadata": { "collapsed": false, "extensions": { "jupyter_dashboards": { "version": 1, "views": { "grid_default": { "hidden": true }, "report_default": { "hidden": false } } } }, "urth": { "dashboard": { "hidden": true, "layout": {} } } }, "outputs": [], "source": [ "sv1_label = widgets.Latex(\n", " value=\"First State Variable\",\n", ")\n", "\n", "sv2_label = widgets.Latex(\n", " value=\"Second State Variable\",\n", ")\n", "\n", "kc_label = widgets.Latex(\n", " value=\"k$_c$ [$\\mu$m$^{-1}$]: \"\n", ")\n", "\n", "kappa_label = widgets.Latex(\n", " value=\"k/k$_c$: \"\n", ")" ] }, { "cell_type": "code", "execution_count": 86, "metadata": { "collapsed": false, "extensions": { "jupyter_dashboards": { "version": 1, "views": { "grid_default": { "col": 2, "height": 3, "hidden": false, "row": 4, "width": 2 }, "report_default": { "hidden": false } } } }, "urth": { "dashboard": { "layout": { "col": 0, "height": 4, "row": 0, "width": 4 } } } }, "outputs": [], "source": [ "display(kc_label, kappa_label)" ] }, { "cell_type": "code", "execution_count": 87, "metadata": { "collapsed": false, "extensions": { "jupyter_dashboards": { "version": 1, "views": { "grid_default": { "col": 0, "height": 4, "hidden": false, "row": 4, "width": 2 }, "report_default": { "hidden": false } } } }, "urth": { "dashboard": { "layout": { "col": 4, "height": 4, "row": 0, "width": 4 } } } }, "outputs": [], "source": [ "display(calculate_button, reset_button)" ] }, { "cell_type": "code", "execution_count": 88, "metadata": { "collapsed": false, "extensions": { "jupyter_dashboards": { "version": 1, "views": { "grid_default": { "hidden": true }, "report_default": { "hidden": false } } } }, "urth": { "dashboard": { "hidden": true, "layout": {} } } }, "outputs": [], "source": [ "def state_of_sv2():\n", " if sv2_dropdown.value == \"None\":\n", " b2_floatBox.disabled = True\n", " Dc2_floatBox.disabled = True\n", " else:\n", " b2_floatBox.disabled = False\n", " Dc2_floatBox.disabled = False" ] }, { "cell_type": "code", "execution_count": 89, "metadata": { "collapsed": false, "extensions": { "jupyter_dashboards": { "version": 1, "views": { "grid_default": { "hidden": true }, "report_default": { "hidden": false } } } }, "urth": { "dashboard": { "hidden": true, "layout": {} } } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/Users/jleeman/anaconda/lib/python2.7/site-packages/ipykernel/__main__.py:3: DeprecationWarning: on_trait_change is deprecated: use observe instead\n", " app.launch_new_instance()\n" ] } ], "source": [ "calculate_button.on_click(on_calculate_clicked)\n", "reset_button.on_click(on_reset)\n", "sv2_dropdown.on_trait_change(state_of_sv2)\n", "b2_floatBox.disabled = True\n", "Dc2_floatBox.disabled = True" ] }, { "cell_type": "code", "execution_count": 90, "metadata": { "collapsed": false, "extensions": { "jupyter_dashboards": { "version": 1, "views": { "grid_default": { "col": 0, "height": 4, "hidden": false, "row": 0, "width": 4 }, "report_default": { "hidden": false } } } }, "urth": { "dashboard": { "layout": { "col": 8, "height": 4, "row": 0, "width": 4 } } } }, "outputs": [], "source": [ "display(k_floatBox, a_floatBox)" ] }, { "cell_type": "code", "execution_count": 91, "metadata": { "collapsed": true, "extensions": { "jupyter_dashboards": { "version": 1, "views": { "grid_default": { "col": 4, "height": 4, "hidden": false, "row": 0, "width": 4 }, "report_default": { "hidden": false } } } }, "urth": { "dashboard": { "layout": { "col": 0, "height": 5, "row": 4, "width": 4 } } } }, "outputs": [], "source": [ "display(sv1_label, sv1_dropdown, b1_floatBox, Dc1_floatBox)" ] }, { "cell_type": "code", "execution_count": 92, "metadata": { "collapsed": false, "extensions": { "jupyter_dashboards": { "version": 1, "views": { "grid_default": { "col": 8, "height": 4, "hidden": false, "row": 0, "width": 4 }, "report_default": { "hidden": false } } } }, "urth": { "dashboard": { "layout": { "col": 4, "height": 5, "row": 4, "width": 4 } } } }, "outputs": [], "source": [ "display(sv2_label, sv2_dropdown, b2_floatBox, Dc2_floatBox)" ] }, { "cell_type": "code", "execution_count": 93, "metadata": { "collapsed": false, "extensions": { "jupyter_dashboards": { "version": 1, "views": { "grid_default": { "col": 4, "height": 4, "hidden": false, "row": 4, "width": 8 }, "report_default": { "hidden": false } } } }, "urth": { "dashboard": { "layout": { "col": 8, "height": 4, "row": 4, "width": 4 } } } }, "outputs": [], "source": [ "display(simType_buttons)\n", "display(step_sequence_string)" ] }, { "cell_type": "code", "execution_count": 94, "metadata": { "collapsed": false, "extensions": { "jupyter_dashboards": { "version": 1, "views": { "grid_default": { "col": 1, "height": 17, "hidden": false, "row": 8, "width": 4 }, "report_default": { "hidden": false } } } }, "urth": { "dashboard": { "layout": { "col": 0, "height": 18, "row": 9, "width": 5 } } } }, "outputs": [ { "data": { "application/javascript": [ "/* Put everything inside the global mpl namespace */\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('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", "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 = $('
');\n", " this._root_extra_style(this.root)\n", " this.root.attr('style', 'display: inline-block');\n", "\n", " $(parent_element).append(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", " 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", " this.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 = $(\n", " '');\n", " var titletext = $(\n", " '');\n", " titlebar.append(titletext)\n", " this.root.append(titlebar);\n", " this.header = titletext[0];\n", "}\n", "\n", "\n", "\n", "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n", "\n", "}\n", "\n", "\n", "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n", "\n", "}\n", "\n", "mpl.figure.prototype._init_canvas = function() {\n", " var fig = this;\n", "\n", " var canvas_div = $('');\n", "\n", " canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n", "\n", " function canvas_keyboard_event(event) {\n", " return fig.key_event(event, event['data']);\n", " }\n", "\n", " canvas_div.keydown('key_press', canvas_keyboard_event);\n", " canvas_div.keyup('key_release', canvas_keyboard_event);\n", " this.canvas_div = canvas_div\n", " this._canvas_extra_style(canvas_div)\n", " this.root.append(canvas_div);\n", "\n", " var canvas = $('');\n", " canvas.addClass('mpl-canvas');\n", " canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n", "\n", " this.canvas = canvas[0];\n", " this.context = canvas[0].getContext(\"2d\");\n", "\n", " var rubberband = $('');\n", " rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n", "\n", " var pass_mouse_events = true;\n", "\n", " canvas_div.resizable({\n", " start: function(event, ui) {\n", " pass_mouse_events = false;\n", " },\n", " resize: function(event, ui) {\n", " fig.request_resize(ui.size.width, ui.size.height);\n", " },\n", " stop: function(event, ui) {\n", " pass_mouse_events = true;\n", " fig.request_resize(ui.size.width, ui.size.height);\n", " },\n", " });\n", "\n", " function mouse_event_fn(event) {\n", " if (pass_mouse_events)\n", " return fig.mouse_event(event, event['data']);\n", " }\n", "\n", " rubberband.mousedown('button_press', mouse_event_fn);\n", " rubberband.mouseup('button_release', mouse_event_fn);\n", " // Throttle sequential mouse events to 1 every 20ms.\n", " rubberband.mousemove('motion_notify', mouse_event_fn);\n", "\n", " rubberband.mouseenter('figure_enter', mouse_event_fn);\n", " rubberband.mouseleave('figure_leave', mouse_event_fn);\n", "\n", " canvas_div.on(\"wheel\", function (event) {\n", " event = event.originalEvent;\n", " event['data'] = 'scroll'\n", " if (event.deltaY < 0) {\n", " event.step = 1;\n", " } else {\n", " event.step = -1;\n", " }\n", " mouse_event_fn(event);\n", " });\n", "\n", " canvas_div.append(canvas);\n", " canvas_div.append(rubberband);\n", "\n", " this.rubberband = rubberband;\n", " this.rubberband_canvas = rubberband[0];\n", " this.rubberband_context = rubberband[0].getContext(\"2d\");\n", " this.rubberband_context.strokeStyle = \"#000000\";\n", "\n", " this._resize_canvas = function(width, height) {\n", " // Keep the size of the canvas, canvas container, and rubber band\n", " // canvas in synch.\n", " canvas_div.css('width', width)\n", " canvas_div.css('height', height)\n", "\n", " canvas.attr('width', width);\n", " canvas.attr('height', height);\n", "\n", " rubberband.attr('width', width);\n", " rubberband.attr('height', height);\n", " }\n", "\n", " // Set the figure to an initial 600x600px, this will subsequently be updated\n", " // upon first draw.\n", " this._resize_canvas(600, 600);\n", "\n", " // Disable right mouse context menu.\n", " $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\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 nav_element = $('')\n", " nav_element.attr('style', 'width: 100%');\n", " this.root.append(nav_element);\n", "\n", " // Define a callback function for later on.\n", " function toolbar_event(event) {\n", " return fig.toolbar_button_onclick(event['data']);\n", " }\n", " function toolbar_mouse_event(event) {\n", " return fig.toolbar_button_onmouseover(event['data']);\n", " }\n", "\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", " // put a spacer in here.\n", " continue;\n", " }\n", " var button = $('');\n", " button.addClass('ui-button ui-widget ui-state-default ui-corner-all ' +\n", " 'ui-button-icon-only');\n", " button.attr('role', 'button');\n", " button.attr('aria-disabled', 'false');\n", " button.click(method_name, toolbar_event);\n", " button.mouseover(tooltip, toolbar_mouse_event);\n", "\n", " var icon_img = $('');\n", " icon_img.addClass('ui-button-icon-primary ui-icon');\n", " icon_img.addClass(image);\n", " icon_img.addClass('ui-corner-all');\n", "\n", " var tooltip_span = $('');\n", " tooltip_span.addClass('ui-button-text');\n", " tooltip_span.html(tooltip);\n", "\n", " button.append(icon_img);\n", " button.append(tooltip_span);\n", "\n", " nav_element.append(button);\n", " }\n", "\n", " var fmt_picker_span = $('');\n", "\n", " var fmt_picker = $('');\n", " fmt_picker.addClass('mpl-toolbar-option ui-widget ui-widget-content');\n", " fmt_picker_span.append(fmt_picker);\n", " nav_element.append(fmt_picker_span);\n", " this.format_dropdown = fmt_picker[0];\n", "\n", " for (var ind in mpl.extensions) {\n", " var fmt = mpl.extensions[ind];\n", " var option = $(\n", " '', {selected: fmt === mpl.default_extension}).html(fmt);\n", " fmt_picker.append(option)\n", " }\n", "\n", " // Add hover states to the ui-buttons\n", " $( \".ui-button\" ).hover(\n", " function() { $(this).addClass(\"ui-state-hover\");},\n", " function() { $(this).removeClass(\"ui-state-hover\");}\n", " );\n", "\n", " var status_bar = $('