cleaned up magic args; fixed alphas

This commit is contained in:
Thomas Breloff 2016-03-07 21:38:31 -05:00
parent 5699446d69
commit ed336bc0ff
5 changed files with 60 additions and 25 deletions

View File

@ -360,12 +360,6 @@ end
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
wraptuple(x::@compat(Tuple)) = x
wraptuple(x) = (x,)
trueOrAllTrue(f::Function, x::AbstractArray) = all(f, x)
trueOrAllTrue(f::Function, x) = f(x)
function handleColors!(d::Dict, arg, csym::Symbol) function handleColors!(d::Dict, arg, csym::Symbol)
try try
if arg == :auto if arg == :auto
@ -417,11 +411,13 @@ end
function processLineArg(d::Dict, arg) function processLineArg(d::Dict, arg)
# linetype # linetype
if trueOrAllTrue(a -> get(_typeAliases, a, a) in _allTypes, arg) # if trueOrAllTrue(a -> get(_typeAliases, a, a) in _allTypes, arg)
if allLineTypes(arg)
d[:linetype] = arg d[:linetype] = arg
# linestyle # linestyle
elseif trueOrAllTrue(a -> get(_styleAliases, a, a) in _allStyles, arg) # elseif trueOrAllTrue(a -> get(_styleAliases, a, a) in _allStyles, arg)
elseif allStyles(arg)
d[:linestyle] = arg d[:linestyle] = arg
elseif typeof(arg) <: Stroke elseif typeof(arg) <: Stroke
@ -436,11 +432,13 @@ function processLineArg(d::Dict, arg)
arg.alpha == nothing || (d[:fillalpha] = arg.alpha) arg.alpha == nothing || (d[:fillalpha] = arg.alpha)
# linealpha # linealpha
elseif trueOrAllTrue(a -> typeof(a) <: Real && a > 0 && a < 1, arg) # elseif trueOrAllTrue(a -> typeof(a) <: Real && a > 0 && a < 1, arg)
elseif allAlphas(arg)
d[:linealpha] = arg d[:linealpha] = arg
# linewidth # linewidth
elseif trueOrAllTrue(a -> typeof(a) <: Real, arg) # elseif trueOrAllTrue(a -> typeof(a) <: Real, arg)
elseif allReals(arg)
d[:linewidth] = arg d[:linewidth] = arg
# color # color
@ -454,13 +452,16 @@ end
function processMarkerArg(d::Dict, arg) function processMarkerArg(d::Dict, arg)
# markershape # markershape
if trueOrAllTrue(a -> get(_markerAliases, a, a) in _allMarkers, arg) # if trueOrAllTrue(a -> get(_markerAliases, a, a) in _allMarkers, arg)
d[:markershape] = arg # d[:markershape] = arg
elseif trueOrAllTrue(a -> isa(a, Shape), arg)
# elseif trueOrAllTrue(a -> isa(a, Shape), arg)
if allShapes(arg)
d[:markershape] = arg d[:markershape] = arg
# stroke style # stroke style
elseif trueOrAllTrue(a -> get(_styleAliases, a, a) in _allStyles, arg) # elseif trueOrAllTrue(a -> get(_styleAliases, a, a) in _allStyles, arg)
elseif allStyles(arg)
d[:markerstrokestyle] = arg d[:markerstrokestyle] = arg
elseif typeof(arg) <: Stroke elseif typeof(arg) <: Stroke
@ -475,11 +476,13 @@ function processMarkerArg(d::Dict, arg)
arg.alpha == nothing || (d[:markeralpha] = arg.alpha) arg.alpha == nothing || (d[:markeralpha] = arg.alpha)
# linealpha # linealpha
elseif trueOrAllTrue(a -> typeof(a) <: Real && a > 0 && a < 1, arg) # elseif trueOrAllTrue(a -> typeof(a) <: Real && a > 0 && a < 1, arg)
elseif allAlphas(arg)
d[:markeralpha] = arg d[:markeralpha] = arg
# markersize # markersize
elseif trueOrAllTrue(a -> typeof(a) <: Real, arg) # elseif trueOrAllTrue(a -> typeof(a) <: Real, arg)
elseif allReals(arg)
d[:markersize] = arg d[:markersize] = arg
# markercolor # markercolor
@ -498,11 +501,13 @@ function processFillArg(d::Dict, arg)
arg.alpha == nothing || (d[:fillalpha] = arg.alpha) arg.alpha == nothing || (d[:fillalpha] = arg.alpha)
# fillrange function # fillrange function
elseif trueOrAllTrue(a -> isa(a, Function), arg) # elseif trueOrAllTrue(a -> isa(a, Function), arg)
elseif allFunctions(arg)
d[:fillrange] = arg d[:fillrange] = arg
# fillalpha # fillalpha
elseif trueOrAllTrue(a -> typeof(a) <: Real && a > 0 && a < 1, arg) # elseif trueOrAllTrue(a -> typeof(a) <: Real && a > 0 && a < 1, arg)
elseif allAlphas(arg)
d[:fillalpha] = arg d[:fillalpha] = arg
elseif !handleColors!(d, arg, :fillcolor) elseif !handleColors!(d, arg, :fillcolor)

View File

@ -235,7 +235,8 @@ function pyplot_figure(plotargs::Dict)
end end
# update the specs # update the specs
fig[:set_size_inches](w,h,true) # fig[:set_size_inches](w,h, (isijulia() ? [] : [true])...)
fig[:set_size_inches](w, h, forward = true)
fig[:set_facecolor](bgcolor) fig[:set_facecolor](bgcolor)
fig[:set_dpi](DPI) fig[:set_dpi](DPI)
fig[:set_tight_layout](true) fig[:set_tight_layout](true)
@ -396,9 +397,9 @@ function _add_series(pkg::PyPlotPackage, plt::Plot; kw...)
extra_kwargs[:c] = ppc extra_kwargs[:c] = ppc
end end
if d[:markeralpha] != nothing # if d[:markeralpha] != nothing
extra_kwargs[:alpha] = d[:markeralpha] # extra_kwargs[:alpha] = d[:markeralpha]
end # end
extra_kwargs[:edgecolors] = getPyPlotColor(d[:markerstrokecolor], d[:markerstrokealpha]) extra_kwargs[:edgecolors] = getPyPlotColor(d[:markerstrokecolor], d[:markerstrokealpha])
extra_kwargs[:linewidths] = d[:markerstrokewidth] extra_kwargs[:linewidths] = d[:markerstrokewidth]
else else

View File

@ -44,6 +44,7 @@ supportedArgs(::GadflyPackage) = [
:markeralpha, :markeralpha,
:markerstrokewidth, :markerstrokewidth,
:markerstrokecolor, :markerstrokecolor,
:markerstrokealpha,
# :markerstrokestyle, # :markerstrokestyle,
:n, :n,
:nbins, :nbins,
@ -124,6 +125,7 @@ supportedArgs(::PyPlotPackage) = [
:markersize, :markersize,
:markerstrokewidth, :markerstrokewidth,
:markerstrokecolor, :markerstrokecolor,
:markerstrokealpha,
# :markerstrokestyle, # :markerstrokestyle,
:n, :n,
:nbins, :nbins,

View File

@ -158,7 +158,8 @@ function stroke(args...; alpha = nothing)
for arg in args for arg in args
T = typeof(arg) T = typeof(arg)
if arg in _allStyles # if arg in _allStyles
if allStyles(arg)
style = arg style = arg
elseif T <: Colorant elseif T <: Colorant
color = arg color = arg
@ -166,7 +167,11 @@ function stroke(args...; alpha = nothing)
try try
color = parse(Colorant, string(arg)) color = parse(Colorant, string(arg))
end end
elseif typeof(arg) <: Real # elseif trueOrAllTrue(a -> typeof(a) <: Real && a > 0 && a < 1, arg)
elseif allAlphas(arg)
alpha = arg
# elseif typeof(arg) <: Real
elseif allReals(arg)
width = arg width = arg
else else
warn("Unused stroke arg: $arg ($(typeof(arg)))") warn("Unused stroke arg: $arg ($(typeof(arg)))")
@ -199,7 +204,11 @@ function brush(args...; alpha = nothing)
try try
color = parse(Colorant, string(arg)) color = parse(Colorant, string(arg))
end end
elseif typeof(arg) <: Real # elseif trueOrAllTrue(a -> typeof(a) <: Real && a > 0 && a < 1, arg)
elseif allAlphas(arg)
alpha = arg
# elseif typeof(arg) <: Real
elseif allReals(arg)
size = arg size = arg
else else
warn("Unused brush arg: $arg ($(typeof(arg)))") warn("Unused brush arg: $arg ($(typeof(arg)))")

View File

@ -222,6 +222,24 @@ Base.merge(a::AbstractVector, b::AbstractVector) = sort(unique(vcat(a,b)))
# --------------------------------------------------------------- # ---------------------------------------------------------------
wraptuple(x::@compat(Tuple)) = x
wraptuple(x) = (x,)
trueOrAllTrue(f::Function, x::AbstractArray) = all(f, x)
trueOrAllTrue(f::Function, x) = f(x)
allLineTypes(arg) = trueOrAllTrue(a -> get(_typeAliases, a, a) in _allTypes, arg)
allStyles(arg) = trueOrAllTrue(a -> get(_styleAliases, a, a) in _allStyles, arg)
allShapes(arg) = trueOrAllTrue(a -> get(_markerAliases, a, a) in _allMarkers, arg) ||
trueOrAllTrue(a -> isa(a, Shape), arg)
allAlphas(arg) = trueOrAllTrue(a -> (typeof(a) <: Real && a > 0 && a < 1) ||
(typeof(a) <: AbstractFloat && (a == zero(typeof(a)) || a == one(typeof(a)))), arg)
allReals(arg) = trueOrAllTrue(a -> typeof(a) <: Real, arg)
allFunctions(arg) = trueOrAllTrue(a -> isa(a, Function), arg)
# ---------------------------------------------------------------
""" """
Allows temporary setting of backend and defaults for Plots. Settings apply only for the `do` block. Example: Allows temporary setting of backend and defaults for Plots. Settings apply only for the `do` block. Example:
``` ```