gr support for mirror; switch Axis.sp for sps; fixes to inset sp setup and linking
This commit is contained in:
parent
55a598b796
commit
76bb6bab96
@ -946,7 +946,7 @@ function Base.getindex(axis::Axis, k::Symbol)
|
|||||||
v = axis.d[k]
|
v = axis.d[k]
|
||||||
if v == :match
|
if v == :match
|
||||||
if haskey(_match_map2, k)
|
if haskey(_match_map2, k)
|
||||||
axis.sp[_match_map2[k]]
|
axis.sps[1][_match_map2[k]]
|
||||||
else
|
else
|
||||||
axis[_match_map[k]]
|
axis[_match_map[k]]
|
||||||
end
|
end
|
||||||
|
|||||||
10
src/axes.jl
10
src/axes.jl
@ -29,7 +29,7 @@ function Axis(sp::Subplot, letter::Symbol, args...; kw...)
|
|||||||
d[:discrete_values] = []
|
d[:discrete_values] = []
|
||||||
|
|
||||||
# update the defaults
|
# update the defaults
|
||||||
update!(Axis(sp, d), args...; kw...)
|
update!(Axis([sp], d), args...; kw...)
|
||||||
end
|
end
|
||||||
|
|
||||||
function get_axis(sp::Subplot, letter::Symbol)
|
function get_axis(sp::Subplot, letter::Symbol)
|
||||||
@ -341,9 +341,11 @@ end
|
|||||||
function default_should_widen(axis::Axis)
|
function default_should_widen(axis::Axis)
|
||||||
should_widen = false
|
should_widen = false
|
||||||
if axis[:scale] == :identity
|
if axis[:scale] == :identity
|
||||||
for series in series_list(axis.sp)
|
for sp in axis.sps
|
||||||
if series.d[:seriestype] in (:scatter,) || series.d[:markershape] != :none
|
for series in series_list(sp)
|
||||||
should_widen = true
|
if series.d[:seriestype] in (:scatter,) || series.d[:markershape] != :none
|
||||||
|
should_widen = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -80,6 +80,15 @@ function _update_min_padding!(sp::Subplot)
|
|||||||
toppad = sp[:top_margin] + title_padding(sp)
|
toppad = sp[:top_margin] + title_padding(sp)
|
||||||
rightpad = sp[:right_margin]
|
rightpad = sp[:right_margin]
|
||||||
bottompad = tick_padding(sp[:xaxis]) + sp[:bottom_margin] + guide_padding(sp[:xaxis])
|
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)
|
# @show (leftpad, toppad, rightpad, bottompad)
|
||||||
sp.minpad = (leftpad, toppad, rightpad, bottompad)
|
sp.minpad = (leftpad, toppad, rightpad, bottompad)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -587,22 +587,26 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
if !(xticks in (nothing, false))
|
if !(xticks in (nothing, false))
|
||||||
# x labels
|
# x labels
|
||||||
flip = sp[:yaxis][:flip]
|
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...)
|
for (cv, dv) in zip(xticks...)
|
||||||
xi, yi = GR.wctondc(cv, flip ? ymax : ymin)
|
# use xor ($) to get the right y coords
|
||||||
# @show cv dv ymin xi yi
|
xi, yi = GR.wctondc(cv, (flip $ mirror) ? ymax : ymin)
|
||||||
gr_text(xi, yi-0.01, string(dv))
|
# @show cv dv ymin xi yi flip mirror (flip $ mirror)
|
||||||
|
gr_text(xi, yi + (mirror ? 1 : -1) * 0.01, string(dv))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if !(yticks in (nothing, false))
|
if !(yticks in (nothing, false))
|
||||||
# y labels
|
# y labels
|
||||||
flip = sp[:xaxis][:flip]
|
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...)
|
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
|
# @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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -876,11 +876,13 @@ end
|
|||||||
function py_compute_axis_minval(axis::Axis)
|
function py_compute_axis_minval(axis::Axis)
|
||||||
# compute the smallest absolute value for the log scale's linear threshold
|
# compute the smallest absolute value for the log scale's linear threshold
|
||||||
minval = 1.0
|
minval = 1.0
|
||||||
sp = axis.sp
|
sps = axis.sps
|
||||||
for series in series_list(axis.sp)
|
for sp in sps
|
||||||
v = series.d[axis[:letter]]
|
for series in series_list(sp)
|
||||||
if !isempty(v)
|
v = series.d[axis[:letter]]
|
||||||
minval = min(minval, minimum(abs(v)))
|
if !isempty(v)
|
||||||
|
minval = min(minval, minimum(abs(v)))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -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...)
|
function link_axes!(axes::Axis...)
|
||||||
a1 = axes[1]
|
a1 = axes[1]
|
||||||
for i=2:length(axes)
|
for i=2:length(axes)
|
||||||
a2 = axes[i]
|
a2 = axes[i]
|
||||||
|
expand_extrema!(a1, extrema(a2))
|
||||||
for k in (:extrema, :discrete_values, :continuous_values, :discrete_map)
|
for k in (:extrema, :discrete_values, :continuous_values, :discrete_map)
|
||||||
a2[k] = a1[k]
|
a2[k] = a1[k]
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -242,10 +242,10 @@ function _plot_setup(plt::Plot, d::KW, kw_list::Vector{KW})
|
|||||||
end
|
end
|
||||||
sp = Subplot(backend(), parent=parent)
|
sp = Subplot(backend(), parent=parent)
|
||||||
sp.plt = plt
|
sp.plt = plt
|
||||||
sp.attr[:relative_bbox] = bb
|
|
||||||
sp.attr[:subplot_index] = length(plt.subplots)
|
|
||||||
push!(plt.subplots, sp)
|
push!(plt.subplots, sp)
|
||||||
push!(plt.inset_subplots, sp)
|
push!(plt.inset_subplots, sp)
|
||||||
|
sp.attr[:relative_bbox] = bb
|
||||||
|
sp.attr[:subplot_index] = length(plt.subplots)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
plt[:inset_subplots] = nothing
|
plt[:inset_subplots] = nothing
|
||||||
|
|||||||
@ -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)
|
plt # the enclosing Plot object (can't give it a type because of no forward declarations)
|
||||||
end
|
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
|
# simple wrapper around a KW so we can hold all attributes pertaining to the axis in one place
|
||||||
type Axis
|
type Axis
|
||||||
sp::Subplot
|
sps::Vector{Subplot}
|
||||||
d::KW
|
d::KW
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user