{ "cells": [ { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "abc = 0; // test variable" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [], "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": 4, "metadata": { "collapsed": true }, "outputs": [], "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": 9, "metadata": { "tags": [ "on_click_any_action" ] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "5\n" ] }, { "data": { "text/plain": [ "null" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "println abc" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": true }, "outputs": [], "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": 22, "metadata": { "tags": [ "run_tag" ] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "You clicked on orange Points (element with coordinates [2,2])\n", "Key pressed = null Tag = run_tag Action = ONCLICK\n" ] }, { "data": { "text/plain": [ "null" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "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": 23, "metadata": { "collapsed": true }, "outputs": [], "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", " //Plot update not ready, so this is executed but not displayed\n", " //Also buttons like KeyboardCodes.UP_ARROW is nahdled by jupyter notebook\n", " .onKey(KeyboardCodes.SPACE, {info -> info.graphics.y[info.index]++})\n", "\n", " //Plot update not ready, so this is executed but not displayed \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": 25, "metadata": { "tags": [ "run_tag2" ] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Key action on Bars (element with coordinates [5,7])\n", "Ket pressed = T Tag = run_tag2 Action = ONKEY\n" ] }, { "data": { "text/plain": [ "null" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "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 \"Ket pressed = \" + key + \" Tag = \" + tag + \" Action = \" + action" ] }, { "cell_type": "code", "execution_count": 26, "metadata": { "collapsed": true }, "outputs": [], "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", " //Plot update not ready, so we can only put here some other actions, like this:\n", " //Also buttons like KeyboardCodes.UP_ARROW is nahdled by jupyter notebook\n", " .onKey(KeyboardCodes.SPACE, {\n", " abc++\n", " beaker.runByTag(\"run_tag3\")\n", " })\n" ] }, { "cell_type": "code", "execution_count": 28, "metadata": { "tags": [ "run_tag3" ] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "12\n" ] }, { "data": { "text/plain": [ "null" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "println abc" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "beakerx_kernel_parameters": { "classpath": [], "imports": [ "com.twosigma.beaker.easyform.EasyForm", "com.github.lwhite1.tablesaw.api.ml.regression.*", "static com.twosigma.beaker.mimetype.MIMEContainer.VimeoVideo", "static com.twosigma.beaker.mimetype.FileLinkContainer.FileLinks", "com.twosigma.beaker.chart.Color", "com.github.lwhite1.tablesaw.api.*", "static com.twosigma.beaker.mimetype.MIMEContainer.IFrame", "com.twosigma.beaker.NamespaceClient", "com.twosigma.beaker.chart.treemap.*", "com.twosigma.beaker.jvm.object.OutputCell", "com.twosigma.beaker.chart.treemap.util.*", "com.github.lwhite1.tablesaw.filtering.*", "static com.twosigma.beaker.mimetype.MIMEContainer.HTML", "static com.twosigma.beaker.mimetype.MIMEContainer.Javascript", "static com.twosigma.beaker.mimetype.FileLinkContainer.FileLink", "static com.twosigma.beaker.mimetype.MIMEContainer.ScribdDocument", "static com.twosigma.beaker.mimetype.SVGContainer.SVG", "com.twosigma.beaker.mimetype.MIMEContainer", "net.sf.jtreemap.swing.*", "com.twosigma.beaker.chart.histogram.*", "static com.github.lwhite1.tablesaw.api.QueryHelper.*", "com.twosigma.beaker.chart.heatmap.HeatMap", "com.twosigma.beaker.chart.xychart.*", "static com.twosigma.beaker.mimetype.ImageContainer.Image", "com.github.lwhite1.tablesaw.api.ml.clustering.*", "com.twosigma.beaker.chart.Filter", "static java.lang.Math.*", "static com.twosigma.beaker.mimetype.MIMEContainer.YoutubeVideo", "static com.twosigma.beaker.mimetype.MIMEContainer.Math", "com.twosigma.beaker.fileloader.CsvPlotReader", "static com.twosigma.beaker.mimetype.MIMEContainer.Markdown", "java.util.concurrent.TimeUnit", "com.twosigma.beaker.chart.categoryplot.plotitem.*", "static com.twosigma.beaker.mimetype.MIMEContainer.Video", "com.twosigma.beaker.chart.categoryplot.*", "static com.twosigma.beaker.mimetype.MIMEContainer.Latex", "com.twosigma.beaker.chart.xychart.plotitem.*", "com.twosigma.beaker.table.*", "com.twosigma.beaker.chart.KeyboardCodes", "com.twosigma.beaker.chart.GradientColor", "com.github.lwhite1.tablesaw.columns.*", "com.twosigma.beaker.chart.legend.*", "com.github.lwhite1.tablesaw.reducing.*" ] }, "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 }