From 345bceb5262d8386f22d9f5d02d75a07e7f0f00d Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Sat, 1 Aug 2020 00:34:04 +0200 Subject: [PATCH] conserve extra_kwargs (#2885) * conserve extra_kwargs * Update test_pgfplotsx.jl * remove wraptuples * Update test_pgfplotsx.jl * Update test_pgfplotsx.jl * Update test_pgfplotsx.jl * Update test_pgfplotsx.jl * Revert "remove wraptuples" This reverts commit 6d66d69692ad1ffb72a99ed4777658d14ad749f1. * Auto stash before revert of "remove wraptuples" --- src/backends/pgfplotsx.jl | 24 +++++++++--------------- test/test_pgfplotsx.jl | 10 ++++++++++ 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/backends/pgfplotsx.jl b/src/backends/pgfplotsx.jl index 56d8844f..d9476914 100644 --- a/src/backends/pgfplotsx.jl +++ b/src/backends/pgfplotsx.jl @@ -83,17 +83,17 @@ function Base.push!(pgfx_plot::PGFPlotsXPlot, item) push!(pgfx_plot.the_plot, item) end +function pgfx_split_extra_opts(extra) + return (get(extra, :add, nothing), filter( x-> first(x) != :add, extra)) +end function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend}) if !pgfx_plot.is_created || pgfx_plot.was_shown pgfx_sanitize_plot!(plt) # extract extra kwargs - extra_plot_opt = plt[:extra_plot_kwargs] - extra_plot = nothing - if haskey(extra_plot_opt, :add) - extra_plot = wraptuple(pop!(extra_plot_opt,:add)) - end + extra_plot, extra_plot_opt = pgfx_split_extra_opts(plt[:extra_plot_kwargs]) the_plot = PGFPlotsX.TikzPicture(PGFPlotsX.Options(extra_plot_opt...)) if extra_plot !== nothing + extra_plot = wraptuple(extra_plot) push!(the_plot, extra_plot...) end bgc = plt.attr[:background_color_outside] == :match ? @@ -249,13 +249,10 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend}) else PGFPlotsX.Axis end - extra_sp_opt = sp[:extra_kwargs] - extra_sp = nothing - if haskey(extra_sp_opt, :add) - extra_sp = wraptuple(pop!(extra_sp_opt,:add)) - end + extra_sp, extra_sp_opt = pgfx_split_extra_opts(sp[:extra_kwargs]) axis = axisf(merge(axis_opt, PGFPlotsX.Options(extra_sp_opt...))) if extra_sp !== nothing + extra_sp = wraptuple(extra_sp) push!(axis, extra_sp...) end if sp[:legendtitle] !== nothing @@ -279,11 +276,7 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend}) "color" => single_color(opt[:linecolor]), "name path" => string(series_id), ) - extra_series_opt = series[:extra_kwargs] - extra_series = nothing - if haskey(extra_series_opt, :add) - extra_series = wraptuple(pop!(extra_series_opt,:add)) - end + extra_series, extra_series_opt = pgfx_split_extra_opts(series[:extra_kwargs]) series_opt = merge(series_opt, PGFPlotsX.Options(extra_series_opt...)) if RecipesPipeline.is3d(series) || st in (:heatmap, :contour) series_func = PGFPlotsX.Plot3 @@ -376,6 +369,7 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend}) segment_plot = series_func(merge(series_opt, segment_opt), coordinates) if extra_series !== nothing + extra_series = wraptuple(extra_series) push!(segment_plot, extra_series...) end push!(axis, segment_plot) diff --git a/test/test_pgfplotsx.jl b/test/test_pgfplotsx.jl index 9345018a..2d797b7e 100644 --- a/test/test_pgfplotsx.jl +++ b/test/test_pgfplotsx.jl @@ -341,4 +341,14 @@ end # testset axes = Plots.pgfx_axes(pl.o) @test !haskey(axes[1].options.dict, "axis line shift") @test haskey(axes[2].options.dict, "axis line shift") + pl = plot(x->x, -1:1; add = raw"\node at (0,0.5) {\huge hi};", extra_kwargs = :subplot) + @test pl[1][:extra_kwargs] == Dict(:add => raw"\node at (0,0.5) {\huge hi};") + Plots._update_plot_object(pl) + axes = Plots.pgfx_axes(pl.o) + @test filter(x->x isa String, axes[1].contents)[1] == raw"\node at (0,0.5) {\huge hi};" + plot!(pl) + @test pl[1][:extra_kwargs] == Dict(:add => raw"\node at (0,0.5) {\huge hi};") + Plots._update_plot_object(pl) + axes = Plots.pgfx_axes(pl.o) + @test filter(x->x isa String, axes[1].contents)[1] == raw"\node at (0,0.5) {\huge hi};" end # testset