working on groups and iris notebook

This commit is contained in:
Thomas Breloff 2015-09-23 23:15:15 -04:00
parent fcfcc9a94a
commit 431d60a58a
4 changed files with 78 additions and 232 deletions

File diff suppressed because one or more lines are too long

View File

@ -260,7 +260,8 @@ type GroupBy
end end
function extractGroupArgs(v::AVec) # this is when given a vector-type of values to group by
function extractGroupArgs(v::AVec, d::Dict)
groupLabels = sort(collect(unique(v))) groupLabels = sort(collect(unique(v)))
n = length(groupLabels) n = length(groupLabels)
if n > 20 if n > 20
@ -272,13 +273,23 @@ end
# expecting a mapping of "group label" to "group indices" # expecting a mapping of "group label" to "group indices"
function extractGroupArgs{T, V<:AVec{Int}}(d::Dict{T,V}) function extractGroupArgs{T, V<:AVec{Int}}(idxmap::Dict{T,V}, d::Dict)
groupLabels = sortedkeys(d) groupLabels = sortedkeys(idxmap)
groupIds = VecI[collect(d[k]) for k in groupLabels] groupIds = VecI[collect(idxmap[k]) for k in groupLabels]
GroupBy(groupLabels, groupIds) GroupBy(groupLabels, groupIds)
end end
# expecting the column name of a dataframe that was passed in... anything else should error
function extractGroupArgs(s::Symbol, d::Dict)
if haskey(d, :dataframe) && haskey(d[:dataframe], s)
return extractGroupArgs(d[:dataframe][s])
else
error("Got a symbol, and expected that to be a key in d[:dataframe]. s=$s d=$d")
end
end
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
function warnOnUnsupportedArgs(pkg::PlottingPackage, d::Dict) function warnOnUnsupportedArgs(pkg::PlottingPackage, d::Dict)

View File

@ -134,7 +134,7 @@ function addGadflySeries!(gplt, d::Dict, initargs::Dict)
# line_style = line_style) # line_style = line_style)
push!(gfargs, theme) push!(gfargs, theme)
# first things first... lets so the sticks hack # first things first... lets do the sticks hack
if d[:linetype] == :sticks if d[:linetype] == :sticks
d, dScatter = sticksHack(;d...) d, dScatter = sticksHack(;d...)
@ -177,8 +177,14 @@ function addGadflySeries!(gplt, d::Dict, initargs::Dict)
# add to the legend # add to the legend
if length(gplt.guides) > 0 && isa(gplt.guides[1], Gadfly.Guide.ManualColorKey) if length(gplt.guides) > 0 && isa(gplt.guides[1], Gadfly.Guide.ManualColorKey)
# TODO: there's a BUG in gadfly if you pass in the same color more than once,
# since gadfly will call unique(colors), but doesn't also merge the rows that match
# Should ensure from this side that colors which are the same are merged together
push!(gplt.guides[1].labels, d[:label]) push!(gplt.guides[1].labels, d[:label])
push!(gplt.guides[1].colors, d[:marker] == :none ? d[:color] : d[:markercolor]) push!(gplt.guides[1].colors, d[:marker] == :none ? d[:color] : d[:markercolor])
# println("updated legend: ", gplt.guides)
end end
# for histograms, set x=y # for histograms, set x=y

View File

@ -88,8 +88,8 @@ function plot!(plt::Plot, args...; kw...)
# index partitions/filters to be passed through to the next step. # index partitions/filters to be passed through to the next step.
# Ideally we don't change the insides ot createKWargsList too much to # Ideally we don't change the insides ot createKWargsList too much to
# save from code repetition. We could consider adding a throw # save from code repetition. We could consider adding a throw
groupargs = haskey(d, :group) ? [extractGroupArgs(d[:group])] : [] groupargs = haskey(d, :group) ? [extractGroupArgs(d[:group], d)] : []
@show groupargs # @show groupargs
# just in case the backend needs to set up the plot (make it current or something) # just in case the backend needs to set up the plot (make it current or something)
preparePlotUpdate(plt) preparePlotUpdate(plt)
@ -105,10 +105,11 @@ function plot!(plt::Plot, args...; kw...)
# now we can plot the series # now we can plot the series
for (i,di) in enumerate(kwList) for (i,di) in enumerate(kwList)
plt.n += 1 plt.n += 1
# println("Plotting: ", di)
plot!(plt.plotter, plt; di...) plot!(plt.plotter, plt; di...)
end end
# # add title, axis labels, ticks, etc
updatePlotItems(plt, d) updatePlotItems(plt, d)
currentPlot!(plt) currentPlot!(plt)
@ -205,10 +206,16 @@ function createKWargsList(plt::PlottingObject, x, y; kw...)
end end
# build the series arg dict # build the series arg dict
n = plt.n + i n = plt.n + i + get(d, :numUncounted, 0)
d = getSeriesArgs(plt.plotter, getinitargs(plt, n), d, i, convertSeriesIndex(plt, n), n) d = getSeriesArgs(plt.plotter, getinitargs(plt, n), d, i, convertSeriesIndex(plt, n), n)
d[:x], d[:y] = computeXandY(xs[mod1(i,mx)], ys[mod1(i,my)]) d[:x], d[:y] = computeXandY(xs[mod1(i,mx)], ys[mod1(i,my)])
if haskey(d, :idxfilter)
# @show d[:idxfilter] d[:x] d[:y]
d[:x] = d[:x][d[:idxfilter]]
d[:y] = d[:y][d[:idxfilter]]
end
# for linetype `line`, need to sort by x values # for linetype `line`, need to sort by x values
if d[:linetype] == :line if d[:linetype] == :line
# order by x # order by x
@ -230,7 +237,10 @@ function createKWargsList(plt::PlottingObject, groupby::GroupBy, args...; kw...)
ret = [] ret = []
for (i,glab) in enumerate(groupby.groupLabels) for (i,glab) in enumerate(groupby.groupLabels)
# TODO: don't automatically overwrite labels # TODO: don't automatically overwrite labels
kwlist = createKWargsList(plt, args...; kw..., idxfilter = groupby.groupIds[i], label = glab) kwlist, xmeta, ymeta = createKWargsList(plt, args...; kw...,
idxfilter = groupby.groupIds[i],
label = string(glab),
numUncounted = length(ret)) # we count the idx from plt.n + numUncounted + i
append!(ret, kwlist) append!(ret, kwlist)
end end
ret, nothing, nothing # TODO: handle passing meta through ret, nothing, nothing # TODO: handle passing meta through