Skip to content

Instantly share code, notes, and snippets.

@jkrumbiegel
Created March 12, 2020 12:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkrumbiegel/7be90a08be76f44233bc2a206dc86fbd to your computer and use it in GitHub Desktop.
Save jkrumbiegel/7be90a08be76f44233bc2a206dc86fbd to your computer and use it in GitHub Desktop.
Selection rectangle with MakieLayout.jl
using Makie
using MakieLayout
using GLFW; GLFW.WindowHint(GLFW.FLOATING, 1)
##
scene, layout = layoutscene()
ax = layout[1, 1] = LAxis(scene)
heatmap!(ax, randn(500, 500))
tightlimits!(ax)
start_pos = Ref(Point2f0(0, 0))
current_pos = Ref(Point2f0(0, 0))
rectnode = Node(BBox(0, 10, 0, 10))
rectplot = Ref{Union{Nothing, Poly}}(poly!(ax, rectnode, color = (:blue, 0.05), strokecolor = (:blue, 0.5),
strokewidth = 2,xautolimits = false, yautolimits = false, visible = false))
scenestate = MakieLayout.addmousestate!(ax.scene)
MakieLayout.onmouseleftdragstart(scenestate) do state
start_pos[] = state.pos
end
MakieLayout.onmouseleftdrag(scenestate) do state
current_pos[] = state.pos
c = current_pos[]
s = start_pos[]
rectnode[] = let
minx, miny = min.(s, c)
maxx, maxy = max.(s, c)
BBox(minx, maxx, miny, maxy)
end
rectplot[].visible = true
end
MakieLayout.onmouseleftdragstop(scenestate) do state
rectplot[].visible = false
ax.limits[] = rectnode[]
end
scene
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment