Gaston: add support for annotations

This commit is contained in:
t-bltg 2021-07-31 18:14:40 +02:00 committed by GitHub
parent b45400b1d3
commit 4078424f3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -31,12 +31,22 @@ function _before_layout_calcs(plt::Plot{GastonBackend})
@error "Gaston: $n != $(length(plt.subplots))" @error "Gaston: $n != $(length(plt.subplots))"
end end
plt.o.layout = gaston_init_subplots(plt, sps) mapping, plt.o.layout = gaston_init_subplots(plt, sps)
# Then add the series (curves in gaston) # Then add the series (curves in gaston)
for series plt.series_list for series plt.series_list
gaston_add_series(plt, series) gaston_add_series(plt, series)
end end
for (sp, gsp) mapping
for ann in sp[:annotations]
x, y, val = locate_annotation(sp, ann...); ft = val.font
gsp.axesconf *= (
"\nset label \"$(val.str)\" at $x,$y $(ft.halign) rotate by $(ft.rotation) " *
"font \"$(ft.family),$(ft.pointsize)\" front textcolor $(gaston_color(ft.color))"
)
end
end
nothing nothing
end end
@ -108,16 +118,17 @@ end
function gaston_init_subplots(plt, sps) function gaston_init_subplots(plt, sps)
sz = nr, nc = size(sps) sz = nr, nc = size(sps)
mapping = Dict{Subplot{GastonBackend}, Gaston.SubPlot}()
for c 1:nc, r 1:nr # NOTE: row major for c 1:nc, r 1:nr # NOTE: row major
sp = sps[r, c] sp = sps[r, c]
if sp isa Subplot || sp === nothing if sp isa Subplot || sp === nothing
gaston_init_subplot(plt, sp) mapping[sp] = gaston_init_subplot(plt, sp)
else else
gaston_init_subplots(plt, sp) gaston_init_subplots(plt, sp)
sz = max.(sz, size(sp)) sz = max.(sz, size(sp))
end end
end end
return sz return mapping, sz
end end
function gaston_init_subplot(plt::Plot{GastonBackend}, sp::Union{Nothing,Subplot{GastonBackend}}) function gaston_init_subplot(plt::Plot{GastonBackend}, sp::Union{Nothing,Subplot{GastonBackend}})