From f632f2f39ed9010bfe1355e68bcf5ba741973b5f Mon Sep 17 00:00:00 2001 From: Thomas Breloff Date: Tue, 6 Oct 2015 09:04:57 -0500 Subject: [PATCH] working on args --- src/args.jl | 67 +++++++++++++++++++++++++++------------------------ src/colors.jl | 11 +++++---- src/plot.jl | 1 + 3 files changed, 42 insertions(+), 37 deletions(-) diff --git a/src/args.jl b/src/args.jl index f773ec38..9f325764 100644 --- a/src/args.jl +++ b/src/args.jl @@ -300,7 +300,10 @@ wraptuple(x) = (x,) # given one value (:log, or :flip, or (-1,1), etc), set the appropriate arg function processAxisArg(d::Dict, axisletter::AbstractString, arg) - if isa(arg, Symbol) + T = typeof(arg) + delete!(d, symbol(axisletter * "axis")) + + if T <: Symbol # xscale/yscale if haskey(_scaleAliases, arg) @@ -316,40 +319,39 @@ function processAxisArg(d::Dict, axisletter::AbstractString, arg) end # xlims/ylims - elseif (arg <: Tuple || arg <: AVec) && length(arg) == 2 + elseif (T <: Tuple || T <: AVec) && length(arg) == 2 d[symbol(axisletter * "lims")] = arg # xticks/yticks - elseif arg <: AVec + elseif T <: AVec d[symbol(axisletter * "ticks")] = arg else - warn("Skipped $(axisletter)axis arg $arg. Unhandled type $(typeof(arg))") + warn("Skipped $(axisletter)axis arg $arg. Unhandled type $T") end end function processLineArg(d::Dict, arg) - if isa(arg, Symbol) + T = typeof(arg) + delete!(d, :line) + + if T <: Symbol + + arg = get(_typeAliases, arg, arg) + arg = get(_styleAliases, arg, arg) # linetype - if haskey(_typeAliases, arg) - arg = _typeAliases[arg] - end if arg in _allTypes d[:linetype] = arg - end - - # linestyle - if haskey(_styleAliases, arg) - arg = _styleAliases[arg] - end - if arg in _allStyles + elseif arg in _allStyles d[:linestyle] = arg + else + warn("Skipped line arg $arg. Unknown symbol.") end # linewidth - elseif arg <: Real + elseif T <: Real d[:linewidth] = arg else @@ -358,7 +360,7 @@ function processLineArg(d::Dict, arg) c = colorscheme(arg) d[:color] = c catch - warn("Skipped line arg $arg. Unhandled type $(typeof(arg))") + warn("Skipped line arg $arg. Unhandled type $T.") end end @@ -366,30 +368,31 @@ end function processMarkerArg(d::Dict, arg) - if isa(arg, Symbol) + T = typeof(arg) + delete!(d, :marker) + + if T <: Symbol + + arg = get(_markerAliases, arg, arg) - # shape - if haskey(_markerAliases, arg) - arg = _markerAliases[arg] - end if arg in _allMarkers d[:marker] = arg - end - - # linestyle - if haskey(_styleAliases, arg) - arg = _styleAliases[arg] - end - if arg in _allStyles - d[:linestyle] = arg + elseif arg != :match + warn("Skipped marker arg $arg. Unknown symbol.") end # markersize - elseif arg <: Real + elseif T <: Real d[:markersize] = arg else - warn("Skipped line arg $arg. Unhandled type $(typeof(arg))") + + try + c = colorscheme(arg) + d[:markercolor] = c + catch + warn("Skipped marker arg $arg. Unhandled type $T.") + end end end diff --git a/src/colors.jl b/src/colors.jl index 5ebae5fb..f0f0f487 100644 --- a/src/colors.jl +++ b/src/colors.jl @@ -95,8 +95,8 @@ const _gradients = Dict( :blues => [colorant"lightblue", colorant"darkblue"], :reds => [colorant"lightpink", colorant"darkred"], :greens => [colorant"lightgreen", colorant"darkgreen"], - :redsblues => [colorant"darkred", RGB(0.9,0.9,0.9), colorant"darkblue"] - :bluesreds => [colorant"darkblue", RGB(0.9,0.9,0.9), colorant"darkred"] + :redsblues => [colorant"darkred", RGB(0.9,0.9,0.9), colorant"darkblue"], + :bluesreds => [colorant"darkblue", RGB(0.9,0.9,0.9), colorant"darkred"], ) # -------------------------------------------------------------- @@ -169,9 +169,10 @@ getColor(scheme::ColorFunction, z::Real, idx::Int) = scheme.f(z, idx) # -------------------------------------------------------------- -"Wraps a vector of colors... may be Symbol/String or a Colorant" -immutable ColorVector{V<:AbstractVector} <: ColorScheme - v::V +"Wraps a vector of colors... may be vector of Symbol/String/Colorant" +immutable ColorVector <: ColorScheme + v::Vector{Colorant} + ColorVector(v::AVec) = convertColor(v) end typealias CVec ColorVector diff --git a/src/plot.jl b/src/plot.jl index 16c70645..04b81337 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -46,6 +46,7 @@ function plot(args...; kw...) pkg = backend() d = Dict(kw) preprocessArgs!(d) + for k in sort(collect(keys(d))); println(); @printf("%14s: ", k); println(d[k], "\n"); end # # ensure we're passing in an RGB # if haskey(d, :background_color)