Gaston: add support for background color

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

View File

@ -62,18 +62,19 @@ function _update_plot_object(plt::Plot{GastonBackend})
end end
for (mime, term) ( for (mime, term) (
"application/eps" => "epscairo", # NEED fixing TODO "application/eps" => "epscairo",
"image/eps" => "epslatex", # NEED fixing TODO "image/eps" => "epslatex",
"application/pdf" => "pdfcairo", # NEED fixing TODO "application/pdf" => "pdfcairo",
"application/postscript" => "postscript", # NEED fixing TODO "application/postscript" => "postscript",
"image/png" => "pngcairo",
"image/svg+xml" => "svg", "image/svg+xml" => "svg",
"text/latex" => "tikz", # NEED fixing TODO "text/latex" => "tikz",
"application/x-tex" => "epslatex", # NEED fixing TODO "application/x-tex" => "epslatex",
"text/plain" => "dumb", # NEED fixing TODO "text/plain" => "dumb",
) )
@eval function _show(io::IO, ::MIME{Symbol($mime)}, plt::Plot{GastonBackend}) @eval function _show(io::IO, ::MIME{Symbol($mime)}, plt::Plot{GastonBackend})
tmpfile = "$(Gaston.tempname()).$term" tmpfile = "$(Gaston.tempname()).$term"
Gaston.save(term=$term, output=tmpfile, handle=plt.o.handle) Gaston.save(term=$term, output=tmpfile, handle=plt.o.handle, saveopts=gaston_saveopts(plt))
while !isfile(tmpfile) end # avoid race condition with read in next line while !isfile(tmpfile) end # avoid race condition with read in next line
write(io, read(tmpfile)) write(io, read(tmpfile))
rm(tmpfile, force=true) rm(tmpfile, force=true)
@ -81,26 +82,21 @@ for (mime, term) ∈ (
end end
end end
function _show(io::IO, mime::MIME{Symbol("image/png")}, plt::Plot{GastonBackend})
scaling = plt.attr[:dpi] / Plots.DPI
# Scale all plot elements to match Plots.jl DPI standard
saveopts = "fontscale $scaling lw $scaling dl $scaling ps $scaling"
tmpfile = Gaston.tempname()
Gaston.save(term="pngcairo", output=tmpfile, handle=plt.o.handle, saveopts=saveopts)
while !isfile(tmpfile) end # avoid race condition with read in next line
write(io, read(tmpfile))
rm(tmpfile, force=true)
nothing
end
_display(plt::Plot{GastonBackend}) = display(plt.o) _display(plt::Plot{GastonBackend}) = display(plt.o)
# -------------------------------------------- # --------------------------------------------
# These functions are gaston specific # These functions are gaston specific
# -------------------------------------------- # --------------------------------------------
function gaston_saveopts(plt::Plot{GastonBackend})
xsize, ysize = plt.attr[:size]
saveopts = "size $xsize,$ysize background $(gaston_color(plt.attr[:background_color]))"
# Scale all plot elements to match Plots.jl DPI standard
scaling = plt.attr[:dpi] / Plots.DPI
saveopts *= "fontscale $scaling lw $scaling dl $scaling ps $scaling"
end
function gaston_get_subplots(n, plt_subplots, layout) function gaston_get_subplots(n, plt_subplots, layout)
nr, nc = size(layout) nr, nc = size(layout)
sps = Array{Any}(undef, nr, nc) sps = Array{Any}(undef, nr, nc)
@ -310,7 +306,7 @@ function gaston_parse_axes_args(plt::Plot{GastonBackend}, sp::Subplot{GastonBack
# Handle ticks # Handle ticks
# ticksyle # ticksyle
push!(axesconf, "set $(letter)tics font \"$(axis[:tickfontfamily]), $(axis[:tickfontsize])\"") push!(axesconf, "set $(letter)tics font \"$(axis[:tickfontfamily]), $(axis[:tickfontsize])\"")
push!(axesconf, "set $(letter)tics textcolor rgb \"#$(hex(axis[:tickfontcolor], :rrggbb))\"") push!(axesconf, "set $(letter)tics textcolor $(gaston_color(axis[:tickfontcolor]))")
push!(axesconf, "set $(letter)tics $(axis[:tick_direction])") push!(axesconf, "set $(letter)tics $(axis[:tick_direction])")
mirror = axis[:mirror] ? "mirror" : "nomirror" mirror = axis[:mirror] ? "mirror" : "nomirror"