Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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