情节事件
要捕捉绘图上的点击事件,请使用 @mounted watchplots() 指令。这将在加载页面时执行 watchplots(),生成用于捕捉点击事件的代码和字典变量*in the front end* 。这些字典的名称及其捕获的信息如下:
要从 Julia 代码中访问这些变量,可以用 @in 定义一个同名的输入变量。然后,就可以用 @onchange 代码块来观察它们的内容了。
module App
using GenieFramework, PlotlyBase, StipplePlotly
@genietools
trace1 = scatter(; x=1:4, y=[0, 2, 3, 5], fill="tozeroy")
trace2 = scatter(; x=1:4, y=[3, 5, 1, 7], fill="tonexty")
@app begin
@out traces = [trace1, trace2]
@out plotlayout = PlotlyBase.Layout(title="Filled line chart")
@in data_click = Dict{String,Any}()
@in data_hover = Dict{String,Any}()
@in data_selected = Dict{String,Any}()
@in data_cursor = Dict{String,Any}()
@in data_relayout = Dict{String,Any}()
@onchange data_click begin
@show data_click
end
@onchange data_hover begin
@show data_hover
end
@onchange data_selected begin
@show data_selected
end
@onchange data_cursor begin
@show data_cursor
end
@onchange data_relayout begin
@show data_relayout
end
end
@mounted watchplots()
ui() = plot(:traces, layout=:plotlayout, class="sync_data")
@page("/", ui)
Server.isrunning() || Server.up()
end