diff --git a/src/arg_desc.jl b/src/arg_desc.jl index 9ea4f463..7ea839ac 100644 --- a/src/arg_desc.jl +++ b/src/arg_desc.jl @@ -53,7 +53,8 @@ const _arg_desc = KW( :colorbar_entry => "Bool. Include this series in the color bar? Set to `false` to exclude.", # plot args -:plot_title => "String. Title for the whole plot (not the subplots) (Note: Not currently implemented)", +:plot_title => "String. Title for the whole plot (not the subplots)", +:plot_titlevspan => "Number in [0,1]. Vertical span of the whole plot title (fraction of the plot height)", :background_color => "Color Type. Base color for all backgrounds.", :background_color_outside => "Color Type or `:match` (matches `:background_color`). Color outside the plot area(s)", :foreground_color => "Color Type. Base color for all foregrounds.", diff --git a/src/args.jl b/src/args.jl index 965f3fc2..c376a07d 100644 --- a/src/args.jl +++ b/src/args.jl @@ -338,6 +338,7 @@ const _plot_defaults = KW( :plot_titlefontvalign => :vcenter, :plot_titlefontrotation => 0.0, :plot_titlefontcolor => :match, + :plot_titlevspan => 0.05, # vertical span of the plot title, here 5% :background_color => colorant"white", # default for all backgrounds, :background_color_outside => :match, # background outside grid, :foreground_color => :auto, # default for all foregrounds, and title color, diff --git a/src/pipeline.jl b/src/pipeline.jl index 77493eb3..bf84c051 100644 --- a/src/pipeline.jl +++ b/src/pipeline.jl @@ -286,14 +286,24 @@ function _add_plot_title!(plt) plot_title = plt[:plot_title] if plot_title != "" the_layout = plt.layout - plt.layout = grid(2, 1, heights=(.01, .99)) + vspan = plt[:plot_titlevspan] + if plt.backend isa PGFPlotsXBackend + # FIXME: we hit a 45pt height limit: + # https://github.com/pgf-tikz/pgfplots/blob/3bc2f42258fbfac9fe50b2978459da7e76fc046c/tex/generic/pgfplots/pgfplots.scaling.code.tex#L153 + vspan = max(vspan, .16) + end + plt.layout = grid(2, 1, heights=(vspan, 1 - vspan)) + plt.layout.grid[1, 1] = subplot = Subplot(plt.backend, parent=plt.layout[1, 1]) plt.layout.grid[2, 1] = the_layout - subplot = Subplot(backend(), parent = plt.layout[1, 1]) subplot.plt = plt - subplot[:title] = plot_title + # propagate arguments plt[:plot_titleXXX] --> subplot[:titleXXX] + for sym ∈ filter(x -> startswith(string(x), "plot_title"), keys(_plot_defaults)) + subplot[Symbol(string(sym)[length("plot_") + 1:end])] = plt[sym] + end + plt[:force_minpad] = nothing, 0px, nothing, 0px subplot[:subplot_index] = last(plt.subplots)[:subplot_index] + 1 subplot[:framestyle] = :none - plt.layout.grid[1, 1] = subplot + subplot[:margin] = 0px push!(plt.subplots, subplot) end return nothing diff --git a/src/plot.jl b/src/plot.jl index ee3fb7e9..90799496 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -224,6 +224,16 @@ function prepare_output(plt::Plot) _update_min_padding!(sp) end + # spedific to :plot_title see _add_plot_title! + force_minpad = get(plt, :force_minpad, ()) + if !isempty(force_minpad) + for i ∈ eachindex(plt.layout.grid) + plt.layout.grid[i].minpad = Tuple( + i === nothing ? j : i for (i, j) ∈ zip(force_minpad, plt.layout.grid[i].minpad) + ) + end + end + # now another pass down, to update the bounding boxes update_child_bboxes!(plt.layout)