Created
November 3, 2020 07:57
-
-
Save jkrumbiegel/8e75419fd3b60569d0eae50398f9997e to your computer and use it in GitHub Desktop.
activate / deactivate scatter interaction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using AbstractPlotting | |
| using AbstractPlotting.MakieLayout | |
| using GLMakie | |
| set_window_config!(float = true) | |
| ## | |
| scene, layout = layoutscene(resolution = (1000, 800)) | |
| ax = layout[1, 1] = LAxis(scene) | |
| phase = Node(0.0) | |
| amplitude = Node(0.0) | |
| frequency = Node(0.5) | |
| xs = LinRange(0, 5, 2000) | |
| ys = @lift($amplitude * sin.(2pi * $frequency * (xs .- $phase))) | |
| lines!(ax, xs, ys) | |
| points = Node(Point2f0[]) | |
| scatter!(ax, points) | |
| ylims!(ax, -1.1, 1.1) | |
| register_interaction!(ax, :make_points) do event::MouseEvent, ax | |
| if event.type === MouseEventTypes.leftclick | |
| points[] = push!(points[], event.data) | |
| end | |
| end | |
| deactivate_interaction!(ax, :make_points) | |
| slidergrid = labelslidergrid!(scene, | |
| ["Amplitude", "Phase", "Frequency"], | |
| [LinRange(0, 1, 100), LinRange(0, 2pi, 100), LinRange(0.5, 10, 1000)], | |
| valuekw = (width = 50,), | |
| formats = Ref(x -> string(round(x, digits = 2)))) | |
| toggle = LToggle(scene) | |
| on(toggle.active) do active | |
| (active ? activate_interaction! : deactivate_interaction!)(ax, :make_points) | |
| end | |
| toggle_x = LToggle(scene, active = true) | |
| toggle_y = LToggle(scene, active = true) | |
| AbstractPlotting.Observables.connect!(toggle_x.active, ax.xrectzoom) | |
| AbstractPlotting.Observables.connect!(toggle_y.active, ax.yrectzoom) | |
| AbstractPlotting.Observables.connect!(slidergrid.sliders[1].value, amplitude) | |
| AbstractPlotting.Observables.connect!(slidergrid.sliders[2].value, phase) | |
| AbstractPlotting.Observables.connect!(slidergrid.sliders[3].value, frequency) | |
| layout[1, 2] = vbox!( | |
| LMenu(scene, options = ["This", "Does", "Nothing"], tellheight = true), | |
| slidergrid.layout, | |
| hbox!(LText(scene, "Scatter Interaction"), toggle, tellwidth = false), | |
| hbox!(LText(scene, "Rectzoom X"), toggle_x, tellwidth = false), | |
| hbox!(LText(scene, "Rectzoom Y"), toggle_y, tellwidth = false), | |
| tellheight = false, width = 400) | |
| scene |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment