working on subplots and recipes

This commit is contained in:
Thomas Breloff 2015-10-09 16:00:24 -04:00
parent 45747e3635
commit a51a8abf27
7 changed files with 379 additions and 65 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -486,6 +486,53 @@ function buildSubplotObject!(subplt::Subplot{GadflyPackage})
subplt.o = nothing
end
# link the subplots together to share axes... useful for facet plots, cross-scatters, etc
function linkXAxis(subplt::Subplot{GadflyPackage})
for (i,(r,c)) in enumerate(subplt.layout)
gplt = subplt.plts[i].o
if r < nrows(subplt.layout)
#addOrReplace(gplt.guides, Gadfly.Guide.xticks; label=false)
addOrReplace(gplt.guides, Gadfly.Guide.xlabel, "")
end
end
lims = [Inf,-Inf]
for plt in subplt.plts
for l in plt.o.layers
expandLimits!(lims, l.mapping[:x])
end
end
for plt in subplt.plts
xlims!(plt, lims...)
end
end
# link the subplots together to share axes... useful for facet plots, cross-scatters, etc
function linkYAxis(subplt::Subplot{GadflyPackage})
for (i,(r,c)) in enumerate(subplt.layout)
gplt = subplt.plts[i].o
if c > 1
#addOrReplace(gplt.guides, Gadfly.Guide.yticks; label=false)
addOrReplace(gplt.guides, Gadfly.Guide.ylabel, "")
end
end
lims = [Inf,-Inf]
for plt in subplt.plts
for l in plt.o.layers
expandLimits!(lims, l.mapping[:y])
end
end
for plt in subplt.plts
ylims!(plt, lims...)
end
end
# ----------------------------------------------------------------

View File

@ -62,13 +62,6 @@ supportedMarkers(::UnicodePlotsPackage) = [:none, :auto, :ellipse]
supportedScales(::UnicodePlotsPackage) = [:identity]
function expandLimits!(lims, x)
e1, e2 = extrema(x)
lims[1] = min(lims[1], e1)
lims[2] = max(lims[2], e2)
nothing
end
# do all the magic here... build it all at once, since we need to know about all the series at the very beginning
function rebuildUnicodePlot!(plt::Plot)

View File

@ -51,8 +51,6 @@ function getRecipeXY(ep::EllipseRecipe)
end
function getRecipeArgs(ep::EllipseRecipe)
d = Dict()
d[:line] = (3, [:dot :solid], [:red :blue], :path)
d
[(:line, (3, [:dot :solid], [:red :blue], :path))]
end

View File

@ -91,6 +91,9 @@ end
nrows(layout::FlexLayout) = length(layout.rowcounts)
ncols(layout::FlexLayout, row::Int) = row < 1 ? 0 : (row > nrows(layout) ? 0 : layout.rowcounts[row])
# get the plot index given row and column
Base.getindex(layout::FlexLayout, r::Int, c::Int) = sum(layout.rowcounts[1:r-1]) + c
Base.length(layout::GridLayout) = layout.nr * layout.nc
Base.start(layout::GridLayout) = 1
Base.done(layout::GridLayout, state) = state > length(layout)
@ -104,6 +107,9 @@ nrows(layout::GridLayout) = layout.nr
ncols(layout::GridLayout) = layout.nc
ncols(layout::GridLayout, row::Int) = layout.nc
# get the plot index given row and column
Base.getindex(layout::GridLayout, r::Int, c::Int) = (r-1) * layout.nc + c
# ------------------------------------------------------------

View File

@ -116,6 +116,27 @@ maketuple{T,S}(x::@compat(Tuple{T,S})) = x
unzip{T,S}(v::AVec{@compat(Tuple{T,S})}) = [vi[1] for vi in v], [vi[2] for vi in v]
# given 2-element lims and a vector of data x, widen lims to account for the extrema of x
function expandLimits!(lims, x)
e1, e2 = extrema(x)
lims[1] = min(lims[1], e1)
lims[2] = max(lims[2], e2)
nothing
end
# if the type exists in a list, replace the first occurence. otherwise add it to the end
function addOrReplace(v::AbstractVector, t::DataType, args...; kw...)
for (i,vi) in enumerate(v)
if isa(vi, t)
v[i] = t(args...; kw...)
return
end
end
push!(v, t(args...; kw...))
return
end
function replaceAliases!(d::Dict, aliases::Dict)
for (k,v) in d