From ea7572154c9cb813ea62c572cf305e98f3af68c6 Mon Sep 17 00:00:00 2001 From: Thomas Breloff Date: Fri, 11 Sep 2015 12:39:03 -0400 Subject: [PATCH] working on plot/args reorg --- src/Plots.jl | 8 +++--- src/plot.jl | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/subplot.jl | 2 +- 3 files changed, 83 insertions(+), 5 deletions(-) diff --git a/src/Plots.jl b/src/Plots.jl index dc9aea9a..167353df 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -54,19 +54,19 @@ getplot(plt::Plot, args...) = plt # --------------------------------------------------------- type CurrentPlot - nullableplot::Nullable{Plot} + nullableplot::Nullable{PlottingObject} end -const CURRENT_PLOT = CurrentPlot(Nullable{Plot}()) +const CURRENT_PLOT = CurrentPlot(Nullable{PlottingObject}()) isplotnull() = isnull(CURRENT_PLOT.nullableplot) function currentPlot() if isplotnull() - error("No current plot") + error("No current plot/subplot") end get(CURRENT_PLOT.nullableplot) end -currentPlot!(plot) = (CURRENT_PLOT.nullableplot = Nullable(plot)) +currentPlot!(plot::PlottingObject) = (CURRENT_PLOT.nullableplot = Nullable(plot)) # --------------------------------------------------------- diff --git a/src/plot.jl b/src/plot.jl index dd066939..3950d5c1 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -135,37 +135,115 @@ end # create m series, 1 for each column of y function createKWargsList(plt::PlottingObject, x::AVec, y::AMat; kw...) + n,m = size(y) + @assert length(x) == n + ret = [] + for i in 1:m + d = getPlotKeywordArgs(kw, i, plt.n + i) + d[:x] = x + d[:y] = y[:,i] + push!(ret, d) + end + ret end # create m series, 1 for each column of y function createKWargsList(plt::PlottingObject, x::AMat, y::AMat; kw...) + @assert size(x) == size(y) + n,m = size(y) + ret = [] + for i in 1:m + d = getPlotKeywordArgs(kw, i, plt.n + i) + d[:x] = x[:,i] + d[:y] = y[:,i] + push!(ret, d) + end + ret end # create 1 series, y = f(x) function createKWargsList(plt::PlottingObject, x::AVec, f::Function; kw...) + d = getPlotKeywordArgs(kw, 1, plt.n + 1) + d[:x] = x + d[:y] = map(f, x) + [d] end # create m series, y = f(x), 1 for each column of x function createKWargsList(plt::PlottingObject, x::AMat, f::Function; kw...) + n,m = size(x) + ret = [] + for i in 1:m + d = getPlotKeywordArgs(kw, i, plt.n + i) + d[:x] = x[:,i] + d[:y] = map(f, d[:x]) + push!(ret, d) + end + ret end # create m series, 1 for each item in y (assumes vectors of something other than numbers... functions? vectors?) function createKWargsList(plt::PlottingObject, y::AVec; kw...) + m = length(y) + ret = [] + for i in 1:m + d = getPlotKeywordArgs(kw, i, plt.n + i) + d[:x] = 1:length(y[i]) + d[:y] = y[i] + push!(ret, d) + end + ret end +function getyvec(x::AVec, y::AVec) + @assert length(x) == length(y) + y +end +getyvec(x::AVec, f::Function) = map(f, x) +getyvec(x, y) = error("Couldn't create yvec from types: x ($(typeof(x))), y ($(typeof(y)))") + # same, but given an x to use for all series function createKWargsList{T<:Real}(plt::PlottingObject, x::AVec{T}, y::AVec; kw...) + m = length(y) + ret = [] + for i in 1:m + d = getPlotKeywordArgs(kw, i, plt.n + i) + d[:x] = x + d[:y] = getyvec(x, y[i]) + push!(ret, d) + end + ret end # same, but m series of (x[i],y[i]) function createKWargsList(plt::PlottingObject, x::AVec, y::AVec; kw...) + @assert length(x) == length(y) + m = length(y) + ret = [] + for i in 1:m + d = getPlotKeywordArgs(kw, i, plt.n + i) + d[:x] = x[i] + d[:y] = getyvec(x[i], y[i]) + push!(ret, d) + end + ret end # n empty series function createKWargsList(plt::PlottingObject, n::Integer; kw...) + ret = [] + for i in 1:n + d = getPlotKeywordArgs(kw, i, plt.n + i) + d[:x] = zeros(0) + d[:y] = zeros(0) + push!(ret, d) + end + ret end +# ------------------------- +# most calls should flow through here now... we create a Dict with the keyword args for each series, and plot them function plot!(pkg::PlottingPackage, plt::Plot, args...; kw...) kwList = createKWargsList(plt, args...; kw...) for (i,d) in enumerate(kwList) diff --git a/src/subplot.jl b/src/subplot.jl index d7040849..9913d7be 100644 --- a/src/subplot.jl +++ b/src/subplot.jl @@ -22,6 +22,6 @@ getplot(subplt::SubPlot, i::Int) = subplt.plts[mod1(i, subplt.p)] # ------------------------------------------------------------ -function subplot(args...; ) +function subplot(args...; kw...) end