From b6855b6fba75975b08eea6f9a7bbfb1ac3d3bbb7 Mon Sep 17 00:00:00 2001 From: Thomas Breloff Date: Tue, 6 Oct 2015 10:07:18 -0500 Subject: [PATCH] working on args --- src/args.jl | 19 ++++++++++++------- src/backends/gadfly.jl | 3 ++- src/backends/gadfly_shapes.jl | 4 ++-- src/colors.jl | 4 ++++ 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/args.jl b/src/args.jl index ac3c498c..34bd7ae6 100644 --- a/src/args.jl +++ b/src/args.jl @@ -301,8 +301,6 @@ wraptuple(x) = (x,) # given one value (:log, or :flip, or (-1,1), etc), set the appropriate arg function processAxisArg(d::Dict, axisletter::AbstractString, arg) T = typeof(arg) - delete!(d, symbol(axisletter * "axis")) - if T <: Symbol arg = get(_scaleAliases, arg, arg) @@ -338,8 +336,6 @@ end function processLineArg(d::Dict, arg) T = typeof(arg) - delete!(d, :line) - if T <: Symbol arg = get(_typeAliases, arg, arg) @@ -367,13 +363,13 @@ end function processMarkerArg(d::Dict, arg) T = typeof(arg) - delete!(d, :marker) - if T <: Symbol arg = get(_markerAliases, arg, arg) + println(arg) if arg in _allMarkers + println("HERE ", arg) d[:marker] = arg elseif arg != :match && !handleColors!(d, arg, :markercolor) warn("Skipped marker arg $arg. Unknown symbol.") @@ -393,19 +389,28 @@ end function preprocessArgs!(d::Dict) replaceAliases!(d, _keyAliases) + # handle axis args for axisletter in ("x", "y") - for arg in wraptuple(get(d, symbol(axisletter * "axis"), ())) + asym = symbol(axisletter * "axis") + for arg in wraptuple(get(d, asym, ())) processAxisArg(d, axisletter, arg) end + delete!(d, asym) end + # handle line args for arg in wraptuple(get(d, :line, ())) processLineArg(d, arg) end + delete!(d, :line) + # handle marker args... default to ellipse if shape not set for arg in wraptuple(get(d, :marker, ())) processMarkerArg(d, arg) end + if haskey(d, :marker) && typeof(d[:marker]) <: Tuple + d[:marker] = :ellipse + end end # ----------------------------------------------------------------------------- diff --git a/src/backends/gadfly.jl b/src/backends/gadfly.jl index 09c8cf50..87c208f7 100644 --- a/src/backends/gadfly.jl +++ b/src/backends/gadfly.jl @@ -277,7 +277,8 @@ function addGadflySeries!(gplt, d::Dict, initargs::Dict) # Should ensure from this side that colors which are the same are merged together push!(guide.labels, d[:label]) - push!(guide.colors, d[:marker] == :none ? first(d[:color]) : d[:markercolor]) + # push!(guide.colors, d[:marker] == :none ? first(d[:color]) : d[:markercolor]) + push!(guide.colors, getColor(d[d[:marker] == :none ? :color : :markercolor], 1)) end # end end diff --git a/src/backends/gadfly_shapes.jl b/src/backends/gadfly_shapes.jl index 5ebadb4f..b84ead2a 100644 --- a/src/backends/gadfly_shapes.jl +++ b/src/backends/gadfly_shapes.jl @@ -14,7 +14,7 @@ function createGadflyAnnotation(d::Dict) shape = ohlcshape(x, y, d[:markersize]) d[:y] = Float64[z.open for z in y] d[:linetype] = :none - return Gadfly.Guide.annotation(Gadfly.compose(Gadfly.context(), shape, Gadfly.fill(nothing), Gadfly.stroke(d[:color]))) + return Gadfly.Guide.annotation(Gadfly.compose(Gadfly.context(), shape, Gadfly.fill(nothing), Gadfly.stroke(getColor(d[:color],1))) elseif marker == :rect shape = square(x, y, sz) @@ -54,7 +54,7 @@ function createGadflyAnnotation(d::Dict) shape = Gadfly.circle(xs,ys,[sz]) end - Gadfly.Guide.annotation(Gadfly.compose(Gadfly.context(), shape, Gadfly.fill(d[:markercolor]), Gadfly.stroke(colorant"white"))) + Gadfly.Guide.annotation(Gadfly.compose(Gadfly.context(), shape, Gadfly.fill(getColorVector(d[:markercolor])), Gadfly.stroke(colorant"white"))) end diff --git a/src/colors.jl b/src/colors.jl index 021483a7..0b066e4a 100644 --- a/src/colors.jl +++ b/src/colors.jl @@ -82,6 +82,7 @@ abstract ColorScheme getColor(scheme::ColorScheme, idx::Integer) = getColor(scheme, 0.0, idx) getColor(scheme::ColorScheme, z::AbstractFloat) = getColor(scheme, z, 0) +getColorVector(scheme::ColorScheme) = [getColor(scheme, 0.0, 1)] colorscheme(scheme::ColorScheme) = scheme colorscheme(s::Symbol) = haskey(_gradients, s) ? ColorGradient(s) : ColorWrapper(convertColor(s)) @@ -144,6 +145,8 @@ function getColor(gradient::ColorGradient, z::Real, idx::Int) cs[end] end +getColorVector(gradient::ColorGradient) = [gradient.cs[1]] + function interpolate(c1::Colorant, c2::Colorant, w::Real) lab1 = Lab(c1) lab2 = Lab(c2) @@ -179,6 +182,7 @@ end typealias CVec ColorVector getColor(scheme::ColorVector, z::Real, idx::Int) = convertColor(scheme.v[mod1(idx, length(scheme.v))]) +getColorVector(scheme::ColorVector) = scheme.v # --------------------------------------------------------------