Skip to content

Conversation

BeastyBlacksmith
Copy link
Member

Description

Closes #3942

Ports the changes from #3942, didn't check yet if we need further modifications

Attribution

Things to consider

  • Does it work on log scales?
  • Does it work in layouts?
  • Does it work in recipes?
  • Does it work with multiple series in one call?
  • PR includes or updates tests?
  • PR includes or updates documentation?

@BeastyBlacksmith BeastyBlacksmith added this to the v2.0 milestone Nov 16, 2024
Comment on lines 901 to 903
function gr_text_size(str)
GR.savestate()
GR.selntran(0)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jheinen can you give what the numbers returned by GR.inqtext mean in terms of the size of the displayed area?
Do they have a unit?
Further down I try to add padding for the labels and somehow I need all kinds of correction factors to make it look good, but I am not sure that it scales well when I change the size of the plot.

Copy link
Member

@jheinen jheinen Jan 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The values are normalized device coordinates. Hopefully, the following example describes how it works:

using GR

charHeight = 0.2

selntran(0)
setcharheight(charHeight)
settextalign(GR.TEXT_HALIGN_CENTER, GR.TEXT_VALIGN_HALF)

setlinecolorind(4)
polyline([0, 1], [0.5 - 0.5 * charHeight, 0.5 - 0.5 * charHeight])
polyline([0, 1], [0.5 + 0.5 * charHeight, 0.5 + 0.5 * charHeight])
setlinecolorind(2)
polyline([0, 1], [0.5 - 0.8 * charHeight, 0.5 - 0.8 * charHeight])
polyline([0, 1], [0.5 + 0.7 * charHeight, 0.5 + 0.7 * charHeight])

settextfontprec(232, GR.TEXT_PRECISION_OUTLINE)
text(0.5, 0.5, "Julia!")
tbx, tby = inqtext(0.5, 0.5, "Julia!")
fillrect(tbx[1], tbx[2], tby[1], tby[3])

updatews()
charheight

The lines shown correspond to the vertical alignment attributes top, cap, base, bottom.

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

Successfully merging this pull request may close these issues.

2 participants