add legend stylings (#3470)

* add legend stylings

* fix center and default case
This commit is contained in:
Simon Christ 2021-05-04 20:54:11 +02:00 committed by GitHub
parent 57ba6aa5a9
commit 78f7db138f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -183,8 +183,11 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
nothing
sp_height > 0 * mm ? push!(axis_opt, "height" => string(axis_height)) :
nothing
# legend position
push!(axis_opt["legend style"], pgfx_get_legend_pos(sp[:legend])...)
# legend position / formatting
push!(axis_opt["legend style"],
pgfx_get_legend_pos(sp[:legend])...
)
merge!(axis_opt["legend style"], pgfx_get_legend_style(sp))
for letter in (:x, :y, :z)
if letter != :z || RecipesPipeline.is3d(sp)
pgfx_axis!(axis_opt, sp, letter)
@ -799,6 +802,14 @@ function pgfx_get_legend_pos(v::Tuple{S,Symbol}) where S <: Real
return ("at"=>"$(string(legend_pos_from_angle(v[1],rect...)))", "anchor"=>anchor)
end
function pgfx_get_legend_style(sp)
legfont = legendfont(sp)
PGFPlotsX.Options(
"cells" => PGFPlotsX.Options("anchor" => get((left = "west", right = "east", hcenter = "center"), legfont.halign, "west")),
"font" => pgfx_font(legfont.pointsize, pgfx_thickness_scaling(sp))
)
end
pgfx_get_colorbar_pos(s) =
get((left = " left", bottom = " horizontal", top = " horizontal"), s, "")
pgfx_get_colorbar_pos(b::Bool) = ""