Plots can be configured to run code or other cells when the user clicks on or types into them.
abc = 0; // test variable
def random = new Random()
def p = new Plot(showLegend: true, useToolTip: false);
p << new Line(x: [1, 2, 3], y: [2, 3, 4], width: 10, displayName: "line 1")
.onClick({info -> info.graphics.displayName = "new name"})
p << new Line(x: [1, 2, 3], y: [5, 6, 7,], width: 10, displayName: "line 2")
.onClick({info -> info.graphics.y[1] = random.nextInt(10)})
def p = new Plot(showLegend: true, useToolTip: false);
p << new Line(x: [1, 2, 3], y: [2, 3, 4], width: 10, displayName: "line 1")
.onClick({
abc++
beakerx.runByTag("on_click_any_action")
})
println abc
plot = new Plot(useToolTip: false);
plot << new Points(x: (1..5), y: (1..5), size: 12.0, color: Color.orange, outlineColor: Color.black, displayName: "orange").onClick("run_tag")
plot << new Points(x: (1..5), y: (3..8), size: 12.0, color: Color.green, outlineColor: Color.black, displayName: "green").onClick("run_tag")
def details = plot.details
def item = details.graphics
def index = details.index
def key = details.key
def tag = details.tag
def action = details.actionType
println ("You clicked on " + item.displayName + " " + item.class.simpleName + " (element with coordinates [" + item.x[index] + "," + item.y[index] + "])")
println "Key pressed = " + key + " Tag = " + tag + " Action = " + action
barsPlot = new Plot(useToolTip: false);
barsPlot << new Bars(x: (1..5), y: [5, 2, 4, 3, 7], color: Color.green, outlineColor: Color.black, width: 0.3)
//Also buttons like KeyboardCodes.UP_ARROW is handled by jupyter notebook
.onKey(KeyboardCodes.SPACE, {info -> info.graphics.y[info.index]++})
//Also buttons like KeyboardCodes.DOWN_ARROW is handled by jupyter notebook
.onKey(KeyboardCodes.CAPS_LOCK, {info -> info.graphics.y[info.index]--})
//Tag events working
.onKey("T", "run_tag2")
def details = barsPlot.details
def item = details.graphics
def index = details.index
def key = details.key
def tag = details.tag
def action = details.actionType
println ("Key action on " + item.class.simpleName + " (element with coordinates [" + item.x[index] + "," + item.y[index] + "])")
println "Key pressed = " + key + " Tag = " + tag + " Action = " + action
barsPlot = new Plot(useToolTip: false);
barsPlot << new Bars(x: (1..5), y: [5, 2, 4, 3, 7], color: Color.green, outlineColor: Color.black, width: 0.3)
//Buttons like KeyboardCodes.UP_ARROW is handled by jupyter notebook
.onKey(KeyboardCodes.SPACE, {
abc++
beakerx.runByTag("run_tag3")
})
println abc