{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "abc = 0; // test variable" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "62ad754a-eebc-4f45-92e1-2644dfb0d927", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "def random = new Random()\n", "def p = new Plot(showLegend: true, useToolTip: false);\n", "p << new Line(x: [1, 2, 3], y: [2, 3, 4], width: 10, displayName: \"line 1\")\n", "\n", "//Plot update not ready, so this is executed but not displayed \n", ".onClick({info -> info.graphics.displayName = \"new name\"})\n", "\n", "\n", "p << new Line(x: [1, 2, 3], y: [5, 6, 7,], width: 10, displayName: \"line 2\")\n", "\n", "//Plot update not ready, so this is executed but not displayed \n", ".onClick({info -> info.graphics.y[1] = random.nextInt(10)})" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "2d11f9f0-c2fb-4bac-a018-d88e9d2d6fb2", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "def p = new Plot(showLegend: true, useToolTip: false);\n", "\n", "p << new Line(x: [1, 2, 3], y: [2, 3, 4], width: 10, displayName: \"line 1\")\n", "//Plot update not ready, so we can only put here some other actions, like this:\n", ".onClick({\n", " abc++\n", " beakerx.runByTag(\"on_click_any_action\")\n", "})" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "tags": [ "on_click_any_action" ] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0\n" ] }, { "data": { "text/plain": [ "null" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "println abc" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "be04e41f-eec2-4448-8c87-48c42c9e359c", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "plot = new Plot(useToolTip: false);\n", "//Tag actions is ready\n", "plot << new Points(x: (1..5), y: (1..5), size: 12.0, color: Color.orange, outlineColor: Color.black, displayName: \"orange\").onClick(\"run_tag\")\n", "plot << new Points(x: (1..5), y: (3..8), size: 12.0, color: Color.green, outlineColor: Color.black, displayName: \"green\").onClick(\"run_tag\")" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "tags": [ "run_tag" ] }, "outputs": [ { "ename": "java.lang.NullPointerException", "evalue": " Cannot get property 'graphics' on null object", "output_type": "error", "traceback": [ "\u001b[0;31mjava.lang.NullPointerException: Cannot get property 'graphics' on null object", "\u001b[0;31m\tat script15111839588071021580988.run(script15111839588071021580988.groovy:2)", "\u001b[0;31m\tat com.twosigma.beakerx.groovy.evaluator.GroovyCodeRunner.run(GroovyCodeRunner.java:71)" ] } ], "source": [ "def details = plot.details\n", "def item = details.graphics\n", "def index = details.index\n", "def key = details.key\n", "def tag = details.tag\n", "def action = details.actionType\n", "println (\"You clicked on \" + item.displayName + \" \" + item.class.simpleName + \" (element with coordinates [\" + item.x[index] + \",\" + item.y[index] + \"])\")\n", "println \"Key pressed = \" + key + \" Tag = \" + tag + \" Action = \" + action" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "88d3f271-0da4-42f4-8e66-903bc12e14b7", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "barsPlot = new Plot(useToolTip: false);\n", "barsPlot << new Bars(x: (1..5), y: [5, 2, 4, 3, 7], color: Color.green, outlineColor: Color.black, width: 0.3)\n", " \n", " //Also buttons like KeyboardCodes.UP_ARROW is nahdled by jupyter notebook\n", " .onKey(KeyboardCodes.SPACE, {info -> info.graphics.y[info.index]++})\n", "\n", " //Also buttons like KeyboardCodes.DOWN_ARROW is nahdled by jupyter notebook\n", " .onKey(KeyboardCodes.CAPS_LOCK, {info -> info.graphics.y[info.index]--})\n", " \n", " //Tag events working\n", " .onKey(\"T\", \"run_tag2\")" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "tags": [ "run_tag2" ] }, "outputs": [ { "ename": "java.lang.NullPointerException", "evalue": " Cannot get property 'graphics' on null object", "output_type": "error", "traceback": [ "\u001b[0;31mjava.lang.NullPointerException: Cannot get property 'graphics' on null object", "\u001b[0;31m\tat script1511183958881735139571.run(script1511183958881735139571.groovy:2)", "\u001b[0;31m\tat com.twosigma.beakerx.groovy.evaluator.GroovyCodeRunner.run(GroovyCodeRunner.java:71)" ] } ], "source": [ "def details = barsPlot.details\n", "def item = details.graphics\n", "def index = details.index\n", "def key = details.key\n", "def tag = details.tag\n", "def action = details.actionType\n", "println (\"Key action on \" + item.class.simpleName + \" (element with coordinates [\" + item.x[index] + \",\" + item.y[index] + \"])\")\n", "println \"Key pressed = \" + key + \" Tag = \" + tag + \" Action = \" + action" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "bd385750-1841-4541-9734-e2f8813fce20", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "barsPlot = new Plot(useToolTip: false);\n", "barsPlot << new Bars(x: (1..5), y: [5, 2, 4, 3, 7], color: Color.green, outlineColor: Color.black, width: 0.3)\n", " \n", " //Buttons like KeyboardCodes.UP_ARROW is nahdled by jupyter notebook\n", " .onKey(KeyboardCodes.SPACE, {\n", " abc++\n", " beakerx.runByTag(\"run_tag3\")\n", " })\n" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "tags": [ "run_tag3" ] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0\n" ] }, { "data": { "text/plain": [ "null" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "println abc" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "beakerx_kernel_parameters": {}, "celltoolbar": "Tags", "kernelspec": { "display_name": "Groovy", "language": "groovy", "name": "groovy" }, "language_info": { "codemirror_mode": "groovy", "file_extension": ".groovy", "mimetype": "", "name": "Groovy", "nbconverter_exporter": "", "version": "2.4.3" } }, "nbformat": 4, "nbformat_minor": 2 }