gr: fix text problems

This commit is contained in:
Josef Heinen 2021-11-03 14:40:37 +01:00
parent c4b7757e22
commit 6df1f38492
2 changed files with 12 additions and 7 deletions

View File

@ -1,7 +1,7 @@
name = "Plots"
uuid = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
author = ["Tom Breloff (@tbreloff)"]
version = "1.23.4"
version = "1.23.5"
[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

View File

@ -228,7 +228,7 @@ end
gr_inqtext(x, y, s) = gr_inqtext(x, y, string(s))
function gr_inqtext(x, y, s::AbstractString)
if (occursin('\\', s) || occursin("10^{", s)) && match(r".*\$[^\$]+?\$.*", s) == nothing
if (occursin('\\', s) || occursin("10^{", s)) && match(r".*\$[^\$]+?\$.*", String(s)) == nothing
GR.inqtextext(x, y, s)
else
GR.inqtext(x, y, s)
@ -238,7 +238,7 @@ end
gr_text(x, y, s) = gr_text(x, y, string(s))
function gr_text(x, y, s::AbstractString)
if (occursin('\\', s) || occursin("10^{", s)) && match(r".*\$[^\$]+?\$.*", s) == nothing
if (occursin('\\', s) || occursin("10^{", s)) && match(r".*\$[^\$]+?\$.*", String(s)) == nothing
GR.textext(x, y, s)
else
GR.text(x, y, s)
@ -1243,21 +1243,26 @@ function gr_get_legend_geometry(viewport_plotarea, sp)
if sp[:legend_position] != :none
GR.savestate()
GR.selntran(0)
GR.setcharup(0, 1)
GR.setscale(0)
if sp[:legend_title] !== nothing
gr_set_font(legendtitlefont(sp), sp)
legendn += 1
tbx, tby = gr_inqtext(0, 0, string(sp[:legend_title]))
legendw = tbx[3] - tbx[1]
dy = tby[3] - tby[1]
l, r = extrema(tbx)
b, t = extrema(tby)
legendw = r - l
dy = t - b
end
gr_set_font(legendfont(sp), sp)
for series in series_list(sp)
should_add_to_legend(series) || continue
legendn += 1
tbx, tby = gr_inqtext(0, 0, string(series[:label]))
legendw = max(legendw, tbx[3] - tbx[1]) # Holds text width right now
dy = max(dy, tby[3] - tby[1])
l, r = extrema(tbx)
b, t = extrema(tby)
legendw = max(legendw, r - l) # Holds text width right now
dy = max(dy, t - b)
end
GR.setscale(1)