Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get bbox box of objects #154

Open
isentropic opened this issue May 30, 2022 · 2 comments
Open

Get bbox box of objects #154

isentropic opened this issue May 30, 2022 · 2 comments

Comments

@isentropic
Copy link

Is there an easy way to obtain bboxes of text objects and latex rendered text objects? Asking to for Plots jl. If there would be some communication with gr backend it would be great.
Now, creating layouts is a little difficult as it is hard to determining appropriate padding for text

@jheinen
Copy link
Collaborator

jheinen commented May 31, 2022

The bounding box of text objects can be obtained using the GR.inqtext function. There are several examples in the GR examples directory (mixed_text.jl, user_fonts.jl, math_align.jl, math_bbox.jl, circumscribe_text.jl), e.g.:

using GR
using LaTeXStrings

s = "Using inline math \$\\frac{2hc^2}{\\lambda^5} \\frac{1}{e^{\\frac{hc}{\\lambda k_B T}} - 1}\$ in GR text\nmixed with LaTeXStrings " * L"- \frac{{\hbar ^2}}{{2m}}\frac{{\partial ^2 \psi (x,t)}}{{\partial x^2 }} + U(x)\psi (x,t) = i\hbar \frac{{\partial \psi (x,t)}}{{\partial t}}" * "\n– with line breaks\nand UTF-8 characters (ħπ),\nand rendered using GR's text attributes"

selntran(0)

settextfontprec(232, 3)
settextalign(2, 3)
setcharheight(0.02)

for ϕ in LinRange(0, 2π, 360)
    clearws()
    setcharup(sin(ϕ), cos(ϕ))
    text(0.5, 0.5, s)
    tbx, tby = inqtext(0.5, 0.5, s)
    fillarea(tbx, tby)
    updatews()
end

Screenshot 2022-05-31 at 09 06 23

From Plots.jl, you can access this function with Plots.GR.inqtext(). But as the text attributes might be changed within Plots, it would probably be better to provide a dedicated Plots function to provide this functionality.

@t-bltg
Copy link
Contributor

t-bltg commented Oct 12, 2022

It would be really great to be able to toggle bounding boxes in Plots for developing / debugging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants