From 76bb6bab961626e91784c2be2600d3f5e64db448 Mon Sep 17 00:00:00 2001 From: Thomas Breloff Date: Fri, 19 Aug 2016 01:55:55 -0400 Subject: [PATCH] gr support for mirror; switch Axis.sp for sps; fixes to inset sp setup and linking --- src/args.jl | 2 +- src/axes.jl | 10 ++++++---- src/backends.jl | 9 +++++++++ src/backends/gr.jl | 18 +++++++++++------- src/backends/pyplot.jl | 12 +++++++----- src/layouts.jl | 11 ++++++++++- src/pipeline.jl | 4 ++-- src/types.jl | 4 +++- 8 files changed, 49 insertions(+), 21 deletions(-) diff --git a/src/args.jl b/src/args.jl index 28ebb7d9..b1e7c552 100644 --- a/src/args.jl +++ b/src/args.jl @@ -946,7 +946,7 @@ function Base.getindex(axis::Axis, k::Symbol) v = axis.d[k] if v == :match if haskey(_match_map2, k) - axis.sp[_match_map2[k]] + axis.sps[1][_match_map2[k]] else axis[_match_map[k]] end diff --git a/src/axes.jl b/src/axes.jl index 3bbdc769..0ce290ee 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -29,7 +29,7 @@ function Axis(sp::Subplot, letter::Symbol, args...; kw...) d[:discrete_values] = [] # update the defaults - update!(Axis(sp, d), args...; kw...) + update!(Axis([sp], d), args...; kw...) end function get_axis(sp::Subplot, letter::Symbol) @@ -341,9 +341,11 @@ end function default_should_widen(axis::Axis) should_widen = false if axis[:scale] == :identity - for series in series_list(axis.sp) - if series.d[:seriestype] in (:scatter,) || series.d[:markershape] != :none - should_widen = true + for sp in axis.sps + for series in series_list(sp) + if series.d[:seriestype] in (:scatter,) || series.d[:markershape] != :none + should_widen = true + end end end end diff --git a/src/backends.jl b/src/backends.jl index 2313ef03..08624262 100644 --- a/src/backends.jl +++ b/src/backends.jl @@ -80,6 +80,15 @@ function _update_min_padding!(sp::Subplot) toppad = sp[:top_margin] + title_padding(sp) rightpad = sp[:right_margin] bottompad = tick_padding(sp[:xaxis]) + sp[:bottom_margin] + guide_padding(sp[:xaxis]) + + # switch them? + if sp[:xaxis][:mirror] + bottompad, toppad = toppad, bottompad + end + if sp[:yaxis][:mirror] + leftpad, rightpad = rightpad, leftpad + end + # @show (leftpad, toppad, rightpad, bottompad) sp.minpad = (leftpad, toppad, rightpad, bottompad) end diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 49e5cae8..bbb94b91 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -587,22 +587,26 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) if !(xticks in (nothing, false)) # x labels flip = sp[:yaxis][:flip] - gr_set_font(sp[:xaxis][:tickfont], valign = :top, color = sp[:xaxis][:foreground_color_axis]) + mirror = sp[:xaxis][:mirror] + gr_set_font(sp[:xaxis][:tickfont], valign = (mirror ? :bottom : :top), color = sp[:xaxis][:foreground_color_axis]) for (cv, dv) in zip(xticks...) - xi, yi = GR.wctondc(cv, flip ? ymax : ymin) - # @show cv dv ymin xi yi - gr_text(xi, yi-0.01, string(dv)) + # use xor ($) to get the right y coords + xi, yi = GR.wctondc(cv, (flip $ mirror) ? ymax : ymin) + # @show cv dv ymin xi yi flip mirror (flip $ mirror) + gr_text(xi, yi + (mirror ? 1 : -1) * 0.01, string(dv)) end end if !(yticks in (nothing, false)) # y labels flip = sp[:xaxis][:flip] - gr_set_font(sp[:yaxis][:tickfont], halign = :right, color = sp[:yaxis][:foreground_color_axis]) + mirror = sp[:yaxis][:mirror] + gr_set_font(sp[:yaxis][:tickfont], halign = (mirror ? :left : :right), color = sp[:yaxis][:foreground_color_axis]) for (cv, dv) in zip(yticks...) - xi, yi = GR.wctondc(flip ? xmax : xmin, cv) + # use xor ($) to get the right y coords + xi, yi = GR.wctondc((flip $ mirror) ? xmax : xmin, cv) # @show cv dv xmin xi yi - gr_text(xi-0.01, yi, string(dv)) + gr_text(xi + (mirror ? 1 : -1) * 0.01, yi, string(dv)) end end diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 9c37ffee..99d166ef 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -876,11 +876,13 @@ end function py_compute_axis_minval(axis::Axis) # compute the smallest absolute value for the log scale's linear threshold minval = 1.0 - sp = axis.sp - for series in series_list(axis.sp) - v = series.d[axis[:letter]] - if !isempty(v) - minval = min(minval, minimum(abs(v))) + sps = axis.sps + for sp in sps + for series in series_list(sp) + v = series.d[axis[:letter]] + if !isempty(v) + minval = min(minval, minimum(abs(v))) + end end end diff --git a/src/layouts.jl b/src/layouts.jl index 6fef8fee..7ada1982 100644 --- a/src/layouts.jl +++ b/src/layouts.jl @@ -648,14 +648,23 @@ end # ------------------------------------------------------------------------- -# make all reference the same axis extrema/values +# make all reference the same axis extrema/values. +# merge subplot lists. function link_axes!(axes::Axis...) a1 = axes[1] for i=2:length(axes) a2 = axes[i] + expand_extrema!(a1, extrema(a2)) for k in (:extrema, :discrete_values, :continuous_values, :discrete_map) a2[k] = a1[k] end + + # make a2's subplot list refer to a1's and add any missing values + sps2 = a2.sps + for sp in sps2 + sp in a1.sps || push!(a1.sps, sp) + end + a2.sps = a1.sps end end diff --git a/src/pipeline.jl b/src/pipeline.jl index 9a4c9228..9e8c504e 100644 --- a/src/pipeline.jl +++ b/src/pipeline.jl @@ -242,10 +242,10 @@ function _plot_setup(plt::Plot, d::KW, kw_list::Vector{KW}) end sp = Subplot(backend(), parent=parent) sp.plt = plt - sp.attr[:relative_bbox] = bb - sp.attr[:subplot_index] = length(plt.subplots) push!(plt.subplots, sp) push!(plt.inset_subplots, sp) + sp.attr[:relative_bbox] = bb + sp.attr[:subplot_index] = length(plt.subplots) end end plt[:inset_subplots] = nothing diff --git a/src/types.jl b/src/types.jl index 5b97e0e8..8fdb45e5 100644 --- a/src/types.jl +++ b/src/types.jl @@ -34,11 +34,13 @@ type Subplot{T<:AbstractBackend} <: AbstractLayout plt # the enclosing Plot object (can't give it a type because of no forward declarations) end +Base.show(io::IO, sp::Subplot) = print(io, "Subplot{$(sp[:subplot_index])}") + # ----------------------------------------------------------- # simple wrapper around a KW so we can hold all attributes pertaining to the axis in one place type Axis - sp::Subplot + sps::Vector{Subplot} d::KW end