working on plot/args reorg

This commit is contained in:
Thomas Breloff 2015-09-11 12:39:03 -04:00
parent 60ce3c5b5f
commit ea7572154c
3 changed files with 83 additions and 5 deletions

View File

@ -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))
# ---------------------------------------------------------

View File

@ -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)

View File

@ -22,6 +22,6 @@ getplot(subplt::SubPlot, i::Int) = subplt.plts[mod1(i, subplt.p)]
# ------------------------------------------------------------
function subplot(args...; )
function subplot(args...; kw...)
end