working on args

This commit is contained in:
Thomas Breloff 2015-10-06 09:49:33 -05:00
parent f632f2f39e
commit 70db97d576
12 changed files with 95 additions and 82 deletions

View File

@ -184,7 +184,7 @@ Keyword | Default | Type | Aliases
`:annotation` | `nothing` | Series | `:ann`, `:annotate`, `:annotations`, `:anns` `:annotation` | `nothing` | Series | `:ann`, `:annotate`, `:annotations`, `:anns`
`:axis` | `left` | Series | `:axiss` `:axis` | `left` | Series | `:axiss`
`:color` | `auto` | Series | `:c`, `:colors` `:color` | `auto` | Series | `:c`, `:colors`
`:fillto` | `nothing` | Series | `:area`, `:fill`, `:filltos` `:fill` | `nothing` | Series | `:area`, `:fill`, `:fills`
`:group` | `nothing` | Series | `:g`, `:groups` `:group` | `nothing` | Series | `:g`, `:groups`
`:heatmap_c` | `(0.15,0.5)` | Series | `:heatmap_cs` `:heatmap_c` | `(0.15,0.5)` | Series | `:heatmap_cs`
`:label` | `AUTO` | Series | `:lab`, `:labels` `:label` | `AUTO` | Series | `:lab`, `:labels`

View File

@ -15,6 +15,7 @@ export
current, current,
default, default,
colorscheme,
scatter, scatter,
scatter!, scatter!,

View File

@ -113,7 +113,7 @@ _seriesDefaults[:fillcolor] = :match
# _seriesDefaults[:ribboncolor] = :match # _seriesDefaults[:ribboncolor] = :match
_seriesDefaults[:nbins] = 100 # number of bins for heatmaps and hists _seriesDefaults[:nbins] = 100 # number of bins for heatmaps and hists
_seriesDefaults[:heatmap_c] = (0.15, 0.5) # TODO: this should be replaced with a ColorGradient _seriesDefaults[:heatmap_c] = (0.15, 0.5) # TODO: this should be replaced with a ColorGradient
# _seriesDefaults[:fillto] = nothing # fills in the area # _seriesDefaults[:fill] = nothing # fills in the area
_seriesDefaults[:reg] = false # regression line? _seriesDefaults[:reg] = false # regression line?
_seriesDefaults[:group] = nothing # groupby vector _seriesDefaults[:group] = nothing # groupby vector
_seriesDefaults[:annotation] = nothing # annotation tuple(s)... (x,y,annotation) _seriesDefaults[:annotation] = nothing # annotation tuple(s)... (x,y,annotation)
@ -206,8 +206,8 @@ const _keyAliases = Dict(
:msize => :markersize, :msize => :markersize,
:nb => :nbins, :nb => :nbins,
:nbin => :nbins, :nbin => :nbins,
:fill => :fillto, :fill => :fill,
:area => :fillto, :area => :fill,
:g => :group, :g => :group,
:rib => :ribbon, :rib => :ribbon,
:ann => :annotation, :ann => :annotation,
@ -305,16 +305,11 @@ function processAxisArg(d::Dict, axisletter::AbstractString, arg)
if T <: Symbol if T <: Symbol
# xscale/yscale arg = get(_scaleAliases, arg, arg)
if haskey(_scaleAliases, arg)
arg = _scaleAliases[arg]
end
if arg in _allScales if arg in _allScales
d[symbol(axisletter * "scale")] = arg d[symbol(axisletter * "scale")] = arg
end elseif arg in (:flip, :invert, :inverted)
# xflip/yflip
if arg in (:flip, :invert, :inverted)
d[symbol(axisletter * "flip")] = true d[symbol(axisletter * "flip")] = true
end end
@ -332,6 +327,15 @@ function processAxisArg(d::Dict, axisletter::AbstractString, arg)
end end
end end
function handleColors!(d::Dict, arg, csym::Symbol)
try
c = colorscheme(arg)
d[csym] = c
return true
end
false
end
function processLineArg(d::Dict, arg) function processLineArg(d::Dict, arg)
T = typeof(arg) T = typeof(arg)
delete!(d, :line) delete!(d, :line)
@ -346,7 +350,7 @@ function processLineArg(d::Dict, arg)
d[:linetype] = arg d[:linetype] = arg
elseif arg in _allStyles elseif arg in _allStyles
d[:linestyle] = arg d[:linestyle] = arg
else elseif !handleColors!(d, arg, :color)
warn("Skipped line arg $arg. Unknown symbol.") warn("Skipped line arg $arg. Unknown symbol.")
end end
@ -354,14 +358,8 @@ function processLineArg(d::Dict, arg)
elseif T <: Real elseif T <: Real
d[:linewidth] = arg d[:linewidth] = arg
else elseif !handleColors!(d, arg, :color)
warn("Skipped line arg $arg. Unhandled type $T.")
try
c = colorscheme(arg)
d[:color] = c
catch
warn("Skipped line arg $arg. Unhandled type $T.")
end
end end
end end
@ -377,7 +375,7 @@ function processMarkerArg(d::Dict, arg)
if arg in _allMarkers if arg in _allMarkers
d[:marker] = arg d[:marker] = arg
elseif arg != :match elseif arg != :match && !handleColors!(d, arg, :markercolor)
warn("Skipped marker arg $arg. Unknown symbol.") warn("Skipped marker arg $arg. Unknown symbol.")
end end
@ -385,15 +383,9 @@ function processMarkerArg(d::Dict, arg)
elseif T <: Real elseif T <: Real
d[:markersize] = arg d[:markersize] = arg
else elseif !handleColors!(d, arg, :markercolor)
warn("Skipped marker arg $arg. Unhandled type $T.")
try
c = colorscheme(arg)
d[:markercolor] = c
catch
warn("Skipped marker arg $arg. Unhandled type $T.")
end
end end
end end

View File

@ -14,7 +14,7 @@ supportedArgs(::GadflyPackage) = [
# :axis, # :axis,
:background_color, :background_color,
:color, :color,
:fillto, :fill,
# :foreground_color, # :foreground_color,
:group, :group,
# :heatmap_c, # :heatmap_c,
@ -153,7 +153,8 @@ function addGadflySeries!(gplt, d::Dict, initargs::Dict)
# set theme: color, line linewidth, and point size # set theme: color, line linewidth, and point size
line_width = d[:linewidth] * (d[:linetype] in (:none, :ohlc, :scatter) ? 0 : 1) * Gadfly.px # 0 linewidth when we don't show a line line_width = d[:linewidth] * (d[:linetype] in (:none, :ohlc, :scatter) ? 0 : 1) * Gadfly.px # 0 linewidth when we don't show a line
line_color = isa(d[:color], AbstractVector) ? colorant"black" : d[:color] # line_color = isa(d[:color], AbstractVector) ? colorant"black" : d[:color]
line_color = getColor(d[:color], 1)
# fg = initargs[:foreground_color] # fg = initargs[:foreground_color]
theme = Gadfly.Theme(; default_color = line_color, theme = Gadfly.Theme(; default_color = line_color,
line_width = line_width, line_width = line_width,
@ -195,50 +196,67 @@ function addGadflySeries!(gplt, d::Dict, initargs::Dict)
append!(gfargs, getLineGeoms(d)) append!(gfargs, getLineGeoms(d))
# colorgroup # colorgroup
if isa(d[:color], AbstractVector) z = d[:z]
# handle line segments of different colors
cscheme = d[:color]
if isa(cscheme, ColorVector)
# create a color scale, and set the color group to the index of the color # create a color scale, and set the color group to the index of the color
push!(gplt.scales, Gadfly.Scale.color_discrete_manual(d[:color]...)) push!(gplt.scales, Gadfly.Scale.color_discrete_manual(cscheme.v...))
# this is super weird, but... oh well... for some reason this creates n separate line segments... # this is super weird, but... oh well... for some reason this creates n separate line segments...
# create a list of vertices that go: [x1,x2,x2,x3,x3, ... ,xi,xi, ... xn,xn] (same for y) # create a list of vertices that go: [x1,x2,x2,x3,x3, ... ,xi,xi, ... xn,xn] (same for y)
# then the vector passed to the "color" keyword should be a vector: [1,1,2,2,3,3,4,4, ..., i,i, ... , n,n] # then the vector passed to the "color" keyword should be a vector: [1,1,2,2,3,3,4,4, ..., i,i, ... , n,n]
csindices = Int[mod1(i,length(d[:color])) for i in 1:length(d[:y])] csindices = Int[mod1(i,length(cscheme.v)) for i in 1:length(d[:y])]
cs = collect(repmat(csindices', 2, 1))[1:end-1] cs = collect(repmat(csindices', 2, 1))[1:end-1]
grp = collect(repmat((1:length(d[:y]))', 2, 1))[1:end-1] grp = collect(repmat((1:length(d[:y]))', 2, 1))[1:end-1]
d[:x], d[:y] = map(createSegments, (d[:x], d[:y])) d[:x], d[:y] = map(createSegments, (d[:x], d[:y]))
colorgroup = [(:color, cs), (:group, grp)] colorgroup = [(:color, cs), (:group, grp)]
elseif d[:z] != nothing # handle continuous color scales for the markers
# colorgroup = [(:color, d[:z]), (:color_key_title, d[:label])] elseif z != nothing && typeof(z) <: AVec
colorgroup = [(:color, d[:z])] colorgroup = [(:color, z)]
minz, maxz = minimum(z), maximum(z)
push!(gplt.scales, Gadfly.Scale.ContinuousColorScale(p -> getColor(d[:markercolor], minz + p * (maxz - minz))))
# nothing special...
else else
colorgroup = [] colorgroup = []
end end
# fillto and ribbon # fills/ribbons
yminmax = [] yminmax = []
fillto, ribbon = d[:fillto], d[:ribbon] if d[:fill] != nothing
fillmin, fillmax = map(makevec, maketuple(d[:fill]))
if fillto != nothing nmin, nmax = length(fillmin), length(fillmax)
if ribbon != nothing push!(yminmax, (:ymin, Float64[min(y, fillmin[mod1(i, nmin)], fillmax[mod1(i, nmax)]) for (i,y) in enumerate(d[:y])]))
warn("Ignoring ribbon arg since fillto is set!") push!(yminmax, (:ymax, Float64[max(y, fillmin[mod1(i, nmin)], fillmax[mod1(i, nmax)]) for (i,y) in enumerate(d[:y])]))
end
fillto = makevec(fillto)
n = length(fillto)
push!(yminmax, (:ymin, Float64[min(y, fillto[mod1(i,n)]) for (i,y) in enumerate(d[:y])]))
push!(yminmax, (:ymax, Float64[max(y, fillto[mod1(i,n)]) for (i,y) in enumerate(d[:y])]))
push!(gfargs, Gadfly.Geom.ribbon) push!(gfargs, Gadfly.Geom.ribbon)
elseif ribbon != nothing
ribbon = makevec(ribbon)
n = length(ribbon)
@show ribbon
push!(yminmax, (:ymin, Float64[y - ribbon[mod1(i,n)] for (i,y) in enumerate(d[:y])]))
push!(yminmax, (:ymax, Float64[y + ribbon[mod1(i,n)] for (i,y) in enumerate(d[:y])]))
push!(gfargs, Gadfly.Geom.ribbon)
end end
# # fillto and ribbon
# yminmax = []
# fillto, ribbon = d[:fill], d[:ribbon]
# if fillto != nothing
# if ribbon != nothing
# warn("Ignoring ribbon arg since fillto is set!")
# end
# fillto = makevec(fillto)
# n = length(fillto)
# push!(yminmax, (:ymin, Float64[min(y, fillto[mod1(i,n)]) for (i,y) in enumerate(d[:y])]))
# push!(yminmax, (:ymax, Float64[max(y, fillto[mod1(i,n)]) for (i,y) in enumerate(d[:y])]))
# push!(gfargs, Gadfly.Geom.ribbon)
# elseif ribbon != nothing
# ribbon = makevec(ribbon)
# n = length(ribbon)
# @show ribbon
# push!(yminmax, (:ymin, Float64[y - ribbon[mod1(i,n)] for (i,y) in enumerate(d[:y])]))
# push!(yminmax, (:ymax, Float64[y + ribbon[mod1(i,n)] for (i,y) in enumerate(d[:y])]))
# push!(gfargs, Gadfly.Geom.ribbon)
# end
# handle markers # handle markers
geoms, guides = getMarkerGeomsAndGuides(d) geoms, guides = getMarkerGeomsAndGuides(d)

View File

@ -8,14 +8,14 @@ pyplot() = backend(:pyplot)
# ------------------------------- # -------------------------------
# supportedArgs(::PyPlotPackage) = setdiff(_allArgs, [:reg, :heatmap_c, :fillto, :pos, :xlims, :ylims, :xticks, :yticks]) # supportedArgs(::PyPlotPackage) = setdiff(_allArgs, [:reg, :heatmap_c, :fill, :pos, :xlims, :ylims, :xticks, :yticks])
supportedArgs(::PyPlotPackage) = [ supportedArgs(::PyPlotPackage) = [
:annotation, :annotation,
# :args, # :args,
:axis, :axis,
:background_color, :background_color,
:color, :color,
# :fillto, # :fill,
:foreground_color, :foreground_color,
:group, :group,
# :heatmap_c, # :heatmap_c,
@ -227,7 +227,7 @@ function plot!(pkg::PyPlotPackage, plt::Plot; kw...)
if lt in (:hist, :sticks, :bar) if lt in (:hist, :sticks, :bar)
# NOTE: this is unsupported because it does the wrong thing... it shifts the whole axis # NOTE: this is unsupported because it does the wrong thing... it shifts the whole axis
# extraargs[:bottom] = d[:fillto] # extraargs[:bottom] = d[:fill]
if lt == :hist if lt == :hist
extraargs[:bins] = d[:nbins] extraargs[:bins] = d[:nbins]

View File

@ -13,7 +13,7 @@ supportedArgs(::QwtPackage) = [
:axis, :axis,
:background_color, :background_color,
:color, :color,
:fillto, :fill,
:foreground_color, :foreground_color,
:group, :group,
:heatmap_c, :heatmap_c,

View File

@ -17,7 +17,7 @@ supportedArgs(::[PkgName]Package) = [
:axis, :axis,
:background_color, :background_color,
:color, :color,
:fillto, :fill,
:foreground_color, :foreground_color,
:group, :group,
# :heatmap_c, # :heatmap_c,

View File

@ -8,14 +8,14 @@ unicodeplots() = backend(:unicodeplots)
# ------------------------------- # -------------------------------
# supportedArgs(::UnicodePlotsPackage) = setdiff(_allArgs, [:reg, :heatmap_c, :fillto, :pos, :xlims, :ylims, :xticks, :yticks]) # supportedArgs(::UnicodePlotsPackage) = setdiff(_allArgs, [:reg, :heatmap_c, :fill, :pos, :xlims, :ylims, :xticks, :yticks])
supportedArgs(::UnicodePlotsPackage) = [ supportedArgs(::UnicodePlotsPackage) = [
# :annotation, # :annotation,
# :args, # :args,
# :axis, # :axis,
# :background_color, # :background_color,
# :color, # :color,
# :fillto, # :fill,
# :foreground_color, # :foreground_color,
:group, :group,
# :heatmap_c, # :heatmap_c,

View File

@ -30,14 +30,14 @@ const winston_marker = Dict(:none=>".",
) )
# supportedArgs(::WinstonPackage) = setdiff(_allArgs, [:heatmap_c, :fillto, :pos, :markercolor, :background_color, :xlims, :ylims, :xticks, :yticks]) # supportedArgs(::WinstonPackage) = setdiff(_allArgs, [:heatmap_c, :fill, :pos, :markercolor, :background_color, :xlims, :ylims, :xticks, :yticks])
supportedArgs(::WinstonPackage) = [ supportedArgs(::WinstonPackage) = [
:annotation, :annotation,
# :args, # :args,
# :axis, # :axis,
# :background_color, # :background_color,
:color, :color,
:fillto, :fill,
# :foreground_color, # :foreground_color,
:group, :group,
# :heatmap_c, # :heatmap_c,
@ -150,7 +150,7 @@ function plot!(::WinstonPackage, plt::Plot; kw...)
x, y = d[:x], d[:y] x, y = d[:x], d[:y]
Winston.add(wplt, Winston.Curve(x, y; e...)) Winston.add(wplt, Winston.Curve(x, y; e...))
fillto = d[:fillto] fillto = d[:fill]
if fillto != nothing if fillto != nothing
if isa(fillto, AbstractVector) if isa(fillto, AbstractVector)
y2 = fillto y2 = fillto

View File

@ -83,6 +83,7 @@ abstract ColorScheme
getColor(scheme::ColorScheme, idx::Integer) = getColor(scheme, 0.0, idx) getColor(scheme::ColorScheme, idx::Integer) = getColor(scheme, 0.0, idx)
getColor(scheme::ColorScheme, z::AbstractFloat) = getColor(scheme, z, 0) getColor(scheme::ColorScheme, z::AbstractFloat) = getColor(scheme, z, 0)
colorscheme(scheme::ColorScheme) = scheme
colorscheme(s::Symbol) = haskey(_gradients, s) ? ColorGradient(s) : ColorWrapper(convertColor(s)) colorscheme(s::Symbol) = haskey(_gradients, s) ? ColorGradient(s) : ColorWrapper(convertColor(s))
colorscheme{T<:Real}(s::Symbol, vals::AVec{T}) = ColorGradient(s, vals) colorscheme{T<:Real}(s::Symbol, vals::AVec{T}) = ColorGradient(s, vals)
colorscheme(cs::AVec, vs::AVec) = ColorGradient(cs, vs) colorscheme(cs::AVec, vs::AVec) = ColorGradient(cs, vs)
@ -288,13 +289,11 @@ function getSeriesRGBColor(c, d::Dict, n::Int)
if c == :auto if c == :auto
c = autopick(d[:color_palette], n) c = autopick(d[:color_palette], n)
else # else
c = convertColor(c) # # c = convertColor(c)
# c = colorscheme(c)
end end
# # should be a RGB now... either it was passed in, generated automatically, or created from a string # c should now be a subtype of ColorScheme
# @assert isa(c, Colorant) colorscheme(c)
# return the RGB
c
end end

View File

@ -46,7 +46,10 @@ function plot(args...; kw...)
pkg = backend() pkg = backend()
d = Dict(kw) d = Dict(kw)
preprocessArgs!(d) preprocessArgs!(d)
for k in sort(collect(keys(d))); println(); @printf("%14s: ", k); println(d[k], "\n"); end
println()
for k in sort(collect(keys(d))); @printf("%14s: ", k); println(d[k]); end
println()
# # ensure we're passing in an RGB # # ensure we're passing in an RGB
# if haskey(d, :background_color) # if haskey(d, :background_color)

View File

@ -26,7 +26,7 @@ function histogramHack(; kw...)
d[:x] = midpoints d[:x] = midpoints
d[:y] = float(counts) d[:y] = float(counts)
d[:linetype] = :bar d[:linetype] = :bar
d[:fillto] = d[:fillto] == nothing ? 0.0 : d[:fillto] d[:fill] = d[:fill] == nothing ? 0.0 : d[:fill]
d d
end end
@ -38,7 +38,7 @@ function barHack(; kw...)
d = Dict(kw) d = Dict(kw)
midpoints = d[:x] midpoints = d[:x]
heights = d[:y] heights = d[:y]
fillto = d[:fillto] == nothing ? 0.0 : d[:fillto] fillto = d[:fill] == nothing ? 0.0 : d[:fill]
# estimate the edges # estimate the edges
dists = diff(midpoints) * 0.5 dists = diff(midpoints) * 0.5
@ -65,7 +65,7 @@ function barHack(; kw...)
d[:x] = x d[:x] = x
d[:y] = y d[:y] = y
d[:linetype] = :path d[:linetype] = :path
d[:fillto] = fillto d[:fill] = fillto
d d
end end
@ -81,7 +81,7 @@ function sticksHack(; kw...)
# these are the line vertices # these are the line vertices
x = Float64[] x = Float64[]
y = Float64[] y = Float64[]
fillto = dLine[:fillto] == nothing ? 0.0 : dLine[:fillto] fillto = dLine[:fill] == nothing ? 0.0 : dLine[:fill]
# calculate the vertices # calculate the vertices
yScatter = dScatter[:y] yScatter = dScatter[:y]
@ -96,7 +96,7 @@ function sticksHack(; kw...)
dLine[:y] = y dLine[:y] = y
dLine[:linetype] = :path dLine[:linetype] = :path
dLine[:marker] = :none dLine[:marker] = :none
dLine[:fillto] = nothing dLine[:fill] = nothing
# change the scatter args # change the scatter args
dScatter[:linetype] = :none dScatter[:linetype] = :none