a shift solution

This commit is contained in:
Simon Christ 2020-01-13 16:05:07 +01:00
parent 154ecd9869
commit f4dee045b6

View File

@ -77,7 +77,6 @@ end
function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend}) function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
if !pgfx_plot.is_created if !pgfx_plot.is_created
the_plot = PGFPlotsX.TikzPicture(PGFPlotsX.Options()) the_plot = PGFPlotsX.TikzPicture(PGFPlotsX.Options())
# rows, cols = size(plt.layout.grid)
bgc = plt.attr[:background_color_outside] == :match ? plt.attr[:background_color] : plt.attr[:background_color_outside] bgc = plt.attr[:background_color_outside] == :match ? plt.attr[:background_color] : plt.attr[:background_color_outside]
if bgc isa Colors.Colorant if bgc isa Colors.Colorant
cstr = plot_color(bgc) cstr = plot_color(bgc)
@ -85,7 +84,7 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
push!( push!(
the_plot.options, the_plot.options,
"/tikz/background rectangle/.style" => PGFPlotsX.Options( "/tikz/background rectangle/.style" => PGFPlotsX.Options(
# "draw" => "black", "draw" => "black",
"fill" => cstr, "fill" => cstr,
"draw opacity" => a, "draw opacity" => a,
), ),
@ -93,32 +92,15 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
) )
end end
# the combination of groupplot and polaraxis is broken in pgfplots
# if !any( sp -> ispolar(sp), plt.subplots )
# pl_height, pl_width = plt.attr[:size]
# push!( the_plot, PGFPlotsX.GroupPlot(
# PGFPlotsX.Options(
# "group style" => PGFPlotsX.Options(
# "group size" => string(cols)*" by "*string(rows),
# "horizontal sep" => string(maximum(sp -> sp.minpad[1], plt.subplots)),
# "vertical sep" => string(maximum(sp -> sp.minpad[2], plt.subplots)),
# ),
# "height" => pl_height > 0 ? string(pl_height * px) : "{}",
# "width" => pl_width > 0 ? string(pl_width * px) : "{}",
# )
# )
# )
# end
inset_subplots = plt.inset_subplots
parents = getproperty.(inset_subplots, :parent)
total_height = bottom(bbox(plt.layout))
for sp in plt.subplots for sp in plt.subplots
sp_id = uuid4()
_pgfplotsx_subplot_ids[Symbol("$(sp[:subplot_index])")] = sp_id
bb = bbox(sp) bb = bbox(sp)
sp_width = width(bb) sp_width = width(bb)
sp_height = height(bb) sp_height = height(bb)
dx, dy = bb.x0 dx, dy = bb.x0
# TODO: does this hold at every scale?
if sp[:legend] in (:outertopright, nothing)
dx *= 1.2
end
cstr = plot_color(sp[:background_color_legend]) cstr = plot_color(sp[:background_color_legend])
a = alpha(cstr) a = alpha(cstr)
fg_alpha = alpha(plot_color(sp[:foreground_color_legend])) fg_alpha = alpha(plot_color(sp[:foreground_color_legend]))
@ -157,10 +139,11 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
"opacity" => bgc_inside_a, "opacity" => bgc_inside_a,
), ),
"axis on top" => nothing, "axis on top" => nothing,
"name" => string(sp_id), "framed" => nothing,
"anchor" => "outer north west", # These are for layouting
"anchor" => "north west",
"xshift" => string(dx), "xshift" => string(dx),
"yshift" => string(-dy) "yshift" => string(-dy),
) )
sp_width > 0 * mm ? push!(axis_opt, "width" => string(sp_width)) : sp_width > 0 * mm ? push!(axis_opt, "width" => string(sp_width)) :
nothing nothing
@ -527,8 +510,6 @@ function pgfx_series_coordinates!(
""" """
end end
## ##
const _pgfplotsx_subplot_ids = KW()
const _pgfplotsx_linestyles = KW( const _pgfplotsx_linestyles = KW(
:solid => "solid", :solid => "solid",
:dash => "dashed", :dash => "dashed",
@ -1011,11 +992,11 @@ end
# to fit ticks, tick labels, guides, colorbars, etc. # to fit ticks, tick labels, guides, colorbars, etc.
function _update_min_padding!(sp::Subplot{PGFPlotsXBackend}) function _update_min_padding!(sp::Subplot{PGFPlotsXBackend})
# TODO: make padding more intelligent # TODO: make padding more intelligent
# TODO: how to include margins properly? # TODO: currently padding does not apply
# sp.minpad = (50mm + sp[:left_margin], sp.minpad = (50mm + sp[:left_margin],
# 0mm + sp[:top_margin], 0mm + sp[:top_margin],
# 50mm + sp[:right_margin], 50mm + sp[:right_margin],
# 0mm + sp[:bottom_margin]) 0mm + sp[:bottom_margin])
end end
function _create_backend_figure(plt::Plot{PGFPlotsXBackend}) function _create_backend_figure(plt::Plot{PGFPlotsXBackend})