Skip to content

Instantly share code, notes, and snippets.

@jkrumbiegel
Created January 21, 2025 14:58
Show Gist options
  • Save jkrumbiegel/95eeba11e6ae58d76347a2efd9504622 to your computer and use it in GitHub Desktop.
Save jkrumbiegel/95eeba11e6ae58d76347a2efd9504622 to your computer and use it in GitHub Desktop.
Makie text boundingboxes
using GLMakie
f = Figure()
ax = Axis(f[1, 1])
scatter!(ax, -1..2, randn(20_000), marker = 'O')
t = text!(ax,
[(0, 0), (1, 0), (0.5, 1)],
text = ["Hello", "Bonjour", "Guten Tag"],
)
translate!(t, 0, 0, 10)
glyphcolls = t.plots[1][1]
bboxes = lift(glyphcolls, ax.scene.camera.projectionview, ax.scene.viewport) do glyphcolls, _, _
transformed = Makie.apply_transform(t.transformation.transform_func[], t[1][])
pos = Makie.project.(Ref(ax.scene.camera), t.space[], t.markerspace[], transformed)
map(glyphcolls, pos) do glyphcoll, pos
Rect2f(Makie.unchecked_boundingbox(glyphcoll, pos, Makie.to_rotation(t.rotation[])))
end
end
poly!(ax, bboxes, space = :pixel, color = (:white, 0.5))
f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment