Skip to content

Commit

Permalink
gr: fix text problems
Browse files Browse the repository at this point in the history
  • Loading branch information
jheinen committed Nov 3, 2021
1 parent c4b7757 commit 6df1f38
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
17 changes: 11 additions & 6 deletions src/backends/gr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6df1f38

Please sign in to comment.