Gaston: try to respect the layout ratio

This commit is contained in:
t-bltg 2021-07-29 22:16:37 +02:00 committed by GitHub
parent cbc0417cea
commit d3380f4ee8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -36,8 +36,6 @@ function _before_layout_calcs(plt::Plot{GastonBackend})
@error "Gaston: $n != $(length(plt.subplots))" @error "Gaston: $n != $(length(plt.subplots))"
end end
# FIXME: find a way to support nested layouts
# e.g. figures spanning multiple rows/cols
plt.o.layout = gaston_init_subplots(plt, sps) plt.o.layout = gaston_init_subplots(plt, sps)
# Then add the series (curves in gaston) # Then add the series (curves in gaston)
@ -81,6 +79,17 @@ end
function _show(io::IO, mime::MIME{Symbol("image/png")}, plt::Plot{GastonBackend}) function _show(io::IO, mime::MIME{Symbol("image/png")}, plt::Plot{GastonBackend})
scaling = plt.attr[:dpi] / Plots.DPI scaling = plt.attr[:dpi] / Plots.DPI
# try to respect the layout ratio
_, sps = gaston_get_subplots(0, plt.subplots, plt.layout)
nr, nc = size(sps); n = 0
for c 1:nc, r 1:nr # NOTE: row major
sp = plt.o.subplots[n += 1]
w = plt.layout.widths[r]
h = plt.layout.widths[c]
sp.axesconf = "set size $(w.value),$(h.value)\n" * sp.axesconf
end
# Scale all plot elements to match Plots.jl DPI standard # Scale all plot elements to match Plots.jl DPI standard
saveopts = "fontscale $scaling lw $scaling dl $scaling ps $scaling" saveopts = "fontscale $scaling lw $scaling dl $scaling ps $scaling"
@ -235,7 +244,7 @@ function gaston_parse_axes_args(plt::Plot{GastonBackend}, sp::Subplot{GastonBack
for letter in (:x, :y, :z) for letter in (:x, :y, :z)
axis_attr = sp.attr[Symbol(letter, :axis)] axis_attr = sp.attr[Symbol(letter, :axis)]
# label names # label names
push!(axesconf, "set $(letter)label \"$(axis_attr[:guide])\" ") push!(axesconf, "set $(letter)label \"$(axis_attr[:guide])\"")
push!(axesconf, "set $(letter)label font \"$(axis_attr[:guidefontfamily]), $(axis_attr[:guidefontsize])\"") push!(axesconf, "set $(letter)label font \"$(axis_attr[:guidefontfamily]), $(axis_attr[:guidefontsize])\"")
# Handle ticks # Handle ticks