Skip to content

Instantly share code, notes, and snippets.

@asinghvi17
Created August 6, 2020 00:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asinghvi17/1e6794aec0fef851c0d7fd904456a26d to your computer and use it in GitHub Desktop.
Save asinghvi17/1e6794aec0fef851c0d7fd904456a26d to your computer and use it in GitHub Desktop.
Makie position popup along multiple axes
using Makie
using Makie.AbstractPlotting.MakieLayout
function position_popup!(
scene, axes;
formatter = (point::Point2f0) -> string(round.(Float64.(point), digits = 3)),
)
visible = Observable(false)
poprect = Observable{FRect2D}(FRect(1, 1, 1, 1))
textpos = Observable{Vec3f0}(Vec3f0(1, 1, 120))
rect = poly!(
scene,
poprect;
color = :white,
strokewidth = 2,
strokecolor = :black,
visible = visible,
)[end]
translate!(rect, Vec3f0(0, 0, 100))
textnode = Node(" ")
text!(
scene,
textnode;
textsize = 20,
position = textpos,
color = :blue,
align = (:center, :center),
raw = true,
visible = visible
)
axis_scenes = getproperty.(axes, :scene)
current_scene = scene
lift(scene.events.mouseposition, scene.events.mousebuttons, current_scene) do mp, mb, current_scene
# search for the axis which the mouse is over
for axis in axes
if Point2f0(mp) in pixelarea(axis.scene)[]
current_scene = axis.scene
break
end
end
# update the observables
poprect[] = FRect((mp .+ 5), 250, 40)
textpos[] = Vec3f0((mp .+ 5 .+ (250/2, 40 / 2))..., 120)
textnode[] = to_world(current_scene, Point2f0(mp) .- Makie.AbstractPlotting.GeometryBasics.origin(pixelarea(current_scene)[])) |> formatter
if ispressed(scene, Mouse.left) && current_scene ∈ axis_scenes
visible[] = true
else
visible[] = false
end
end
end
using Makie
using Makie.AbstractPlotting.MakieLayout
scene, layout = layoutscene()
layout[1:2, 1:3] = axes = LAxis[LAxis(scene; title = string(i*3 + j)) for i in 0:1, j in 1:3]
display(scene)
position_popup!(scene, axes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment