JuliaGizmos / Interact.jl

Interactive widgets to play with your Julia code
Other
522 stars 77 forks source link

OnClick? #345

Open caseykneale opened 4 years ago

caseykneale commented 4 years ago

Any hope for an OnClick, OnDrag, etc type listeners?

I know we can do it with buttons, but what about with Julia objects, like plots? Or plotted shapes? Even if it required custom interfaces and geometry stores it would be worth it. A tiny bit of interactivity to julia objects could go a really really long way. Integration with Plots.jl would be very profound. I already use Interact for animating plots(https://discourse.julialang.org/t/current-state-of-live-plots-in-atom-juno/30379).

twavv commented 4 years ago

I'm not entirely sure what you're trying to accomplish here. If you have a potential API that might help to clarify.

Otherwise, you can always wrap things in WebIO elements and attach event listeners there.

myplot = make_plot(0)
myplot_wrapper = dom"div"(myplot;
    event=Dict("click" => js"function() { ... }"),
)

or if you wanted to call back into Julia,

myplot = Observable(make_plot(0))
update_plot(x) = myplot[] = make_plot(x)
myplot_wrapper = dom"div"(myplot;
    # Interpolating the update_plot function will make it callable from JS
    # It runs async though (returns a promise if you need to wait for it to complete)
    event=Dict("click" => js"function() { $update_plot(123); }"),
)
caseykneale commented 4 years ago

is there a way to get the mouse x and y positions in widget space? in units of pixels would be fine.

Basically what I want is to add interactivity to plots. The only way I've found this so far is by hacking away at GR and GTK.

I will try your example later and see if I can make it do cool things :). If so I think we should extend the docs!

amonpuschel commented 4 years ago

I am interested in getting the mouse x/y in diagram coordinates like to_world() in makie.jl.