MakieOrg / Makie.jl

Interactive data visualizations and plotting in Julia
https://docs.makie.org/stable
MIT License
2.42k stars 313 forks source link

`boundingbox` for `GlyphCollections` #3860

Closed hexaeder closed 2 months ago

hexaeder commented 5 months ago

In GraphMakie on Makie@0.20 we used to use

using GLMakie
fig, ax, p = text([(0,0),(0,1)]; text=["foo", "bar"])

glyphcollections = p.plots[1][1][]

boundingbox(glyphcollections[1], Quaternion((1,0,0,0))) # bouding box of text "foo"
boundingbox(glyphcollections[2], Quaternion((1,0,0,0))) # bouding box of text "bar"

to get the the bounding box of single elements within a textplot to draw node shapes around it in the correct size.

grafik

This solution (...which admittedly abused internals...) does not work anymore in Makie@0.21. Any suggestions on how to replace it?

ERROR: LoadError: LoadError: LoadError: MethodError: no method matching boundingbox(::Makie.GlyphCollection, ::Quaternion{Int64})
Closest candidates are:
  boundingbox(::Any, ::Function) at /home/runner/.julia/packages/Makie/eziUH/src/layouting/boundingbox.jl:17
  boundingbox(::Any, ::Function, ::Symbol) at /home/runner/.julia/packages/Makie/eziUH/src/layouting/boundingbox.jl:17
  boundingbox(::Any) at /home/runner/.julia/packages/Makie/eziUH/src/layouting/boundingbox.jl:17
Stacktrace:
  [1] (::GraphMakie.var"#24#50"{Int64, MakieCore.Automatic})(::Tuple{Int64, Makie.GlyphCollection})
    @ GraphMakie ~/work/GraphMakie.jl/GraphMakie.jl/src/recipes.jl:259
  [2] iterate
    @ ./generator.jl:47 [inlined]
  [3] collect(itr::Base.Generator{Base.Iterators.Enumerate{Vector{Makie.GlyphCollection}}, GraphMakie.var"#24#50"{Int64, MakieCore.Automatic}})
    @ Base ./array.jl:681
  [4] map(f::Function, A::Base.Iterators.Enumerate{Vector{Makie.GlyphCollection}})
    @ Base ./abstractarray.jl:2323
  [5] #23
    @ ~/work/GraphMakie.jl/GraphMakie.jl/src/recipes.jl:256 [inlined]
  [6] #map#13
    @ ~/.julia/packages/Observables/YdEbO/src/Observables.jl:[570](https://github.com/MakieOrg/GraphMakie.jl/actions/runs/9045902924/job/24856138523?pr=183#step:6:573) [inlined]
  [7] map(::GraphMakie.var"#23#49", ::Observable{Vector{Makie.GlyphCollection}}, ::Observable{Any}, ::Observable{Any})
    @ Observables ~/.julia/packages/Observables/YdEbO/src/Observables.jl:570
  [8] plot!(gp::Plot{GraphMakie.graphplot, Tuple{SimpleDiGraph{Int64}}})
    @ GraphMakie ~/work/GraphMakie.jl/GraphMakie.jl/src/recipes.jl:255

xref https://github.com/MakieOrg/GraphMakie.jl/pull/183

ffreyer commented 5 months ago

boundingbox(plot, plot.markerspace[]) will give you a bounding box for the text plot with positions included, and string_boundingbox(glyph_collection, pos, rot) = unchecked_boundingbox(glyph_collection, pos, rot) will give you one without if you set pos = Point3d(0). The former is public, the latter still internal.

hexaeder commented 5 months ago

Thank you! For now unchecked_boundingbox is a working replacement. Of course it would be nice to go to the documented API. boundingbox(plot, plot.markerspace[]) will still give me a bounding box for the entire text plot. What I need specifically is the bounding box for each individual label. Am I missing something?

ffreyer commented 2 months ago

Closing as solved/answered