Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ UnicodeFun = "1cfade01-22cf-5700-b092-accc4b62d6e1"
Unzip = "41fe7b60-77ed-43a1-b4f0-825fd5a5650d"

[compat]
Conda = "1"
Contour = "0.5 - 0.6"
FFMPEG = "0.2 - 0.4"
FixedPointNumbers = "0.6 - 0.8"
GR = "0.69.5"
Gaston = "1"
JLFzf = "0.1"
JSON = "0.21, 1"
LaTeXStrings = "1"
Expand All @@ -56,6 +58,7 @@ PlotUtils = "1"
PlotlyBase = "0.7 - 0.8"
PlotlyJS = "0.18"
PlotlyKaleido = "1"
PyCall = "1"
PyPlot = "2"
RecipesBase = "^1.2"
RecipesPipeline = "0.6.5"
Expand All @@ -72,7 +75,9 @@ Unzip = "0.1 - 0.2"
julia = "1.6"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
Conda = "8f4d0f93-b110-5947-807f-2305c1781a2d"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
FilePathsBase = "48062228-2e41-5def-b9a4-89aafe57970f"
Expand All @@ -89,6 +94,7 @@ PGFPlotsX = "8314cec4-20b6-5062-9cdb-752b83310925"
PlotlyBase = "a03496cd-edff-5a9b-9e67-9cda94a718b5"
PlotlyJS = "f0f68f2c-4968-5e81-91da-67840de0976a"
PlotlyKaleido = "f2990250-8cf9-495f-b13a-cce12b45703c"
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
PyPlot = "d330b81b-6aea-500a-939a-2ce795aea3ee"
RDatasets = "ce6b1742-4840-55fa-b093-852dadbb1d8b"
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
Expand All @@ -101,4 +107,4 @@ Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
VisualRegressionTests = "34922c18-7c2a-561c-bac1-01e79b2c4c92"

[targets]
test = ["Colors", "Distributions", "FileIO", "FilePathsBase", "Gaston", "GeometryBasics", "Gtk", "ImageMagick", "Images", "InspectDR", "LibGit2", "OffsetArrays", "PGFPlotsX", "PlotlyJS", "PlotlyBase", "PyPlot", "PlotlyKaleido", "HDF5", "RDatasets", "StableRNGs", "StaticArrays", "StatsPlots", "Test", "TestImages", "UnicodePlots", "Unitful", "VisualRegressionTests"]
test = ["Aqua", "Colors", "Conda", "Distributions", "FileIO", "FilePathsBase", "Gaston", "GeometryBasics", "Gtk", "ImageMagick", "Images", "InspectDR", "LibGit2", "OffsetArrays", "PGFPlotsX", "PlotlyJS", "PlotlyBase", "PyCall", "PyPlot", "PlotlyKaleido", "HDF5", "RDatasets", "StableRNGs", "StaticArrays", "StatsPlots", "Test", "TestImages", "UnicodePlots", "Unitful", "VisualRegressionTests"]
118 changes: 49 additions & 69 deletions RecipesBase/src/RecipesBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,11 @@ end
@inline wrap_tuple(v) = (v,)

# check for flags as part of the `-->` expression
function _is_arrow_tuple(expr::Expr)
_is_arrow_tuple(expr::Expr) =
expr.head ≡ :tuple &&
!isempty(expr.args) &&
isa(expr.args[1], Expr) &&
expr.args[1].head == :(-->)
end
!isempty(expr.args) &&
isa(expr.args[1], Expr) &&
expr.args[1].head == :(-->)

_equals_symbol(x::Symbol, sym::Symbol) = x == sym
_equals_symbol(x::QuoteNode, sym::Symbol) = x.value == sym
Expand Down Expand Up @@ -111,8 +110,7 @@ function create_kw_body(func_signature::Expr)
# bunch of get!(kw, key, value) lines
func_signature.head ≡ :where && return create_kw_body(func_signature.args[1])
args = func_signature.args[2:end]
kw_body = Expr(:block)
cleanup_body = Expr(:block)
kw_body, cleanup_body = map(_ -> Expr(:block), 1:2)
arg1 = args[1]
if isa(arg1, Expr) && arg1.head ≡ :parameters
for kwpair in arg1.args
Expand Down Expand Up @@ -149,7 +147,6 @@ end
function process_recipe_body!(expr::Expr)
for (i, e) in enumerate(expr.args)
if isa(e, Expr)

# process trailing flags, like:
# a --> b, :quiet, :force
quiet, require, force = false, false, false
Expand Down Expand Up @@ -272,12 +269,10 @@ number of series to display. User-defined keyword arguments are passed through,
macro recipe(funcexpr::Expr)
func_signature, func_body = funcexpr.args

if !(funcexpr.head in (:(=), :function))
error("Must wrap a valid function call!")
end
funcexpr.head in (:(=), :function) || error("Must wrap a valid function call!")
if !(isa(func_signature, Expr) && func_signature.head in (:call, :where))
error(
"Expected `func_signature = ...` with func_signature as a call or where Expr... got: $func_signature",
"Expected `func_signature = ...` with func_signature as a call or where Expr...got: $func_signature",
)
end
if length(func_signature.args) < 2
Expand All @@ -287,40 +282,32 @@ macro recipe(funcexpr::Expr)
args, kw_body, cleanup_body = create_kw_body(func_signature)
func = get_function_def(func_signature, args)

@debug "$(__source__.file):$(__source__.line)" func args kw_body cleanup_body

# this is where the receipe func_body is processed
# replace all the key => value lines with argument setting logic
# and break up by series.
process_recipe_body!(func_body)

# now build a function definition for apply_recipe, wrapping the return value in a tuple if needed.
# we are creating a vector of RecipeData objects, one per series.
funcdef = Expr(
return Expr(
:function,
func,
esc(
quote
@nospecialize
if RecipesBase._debug_recipes[]
println("apply_recipe args: ", $args)
end
$kw_body
$cleanup_body
series_list = RecipesBase.RecipeData[]
func_return = $func_body
if func_return != nothing
push!(
series_list,
RecipesBase.RecipeData(
plotattributes,
RecipesBase.wrap_tuple(func_return),
),
)
end
series_list
end,
),
quote
@nospecialize
RecipesBase._debug_recipes[] && println("apply_recipe args: ", $args)
$kw_body
$cleanup_body
series_list = RecipesBase.RecipeData[]
func_return = $func_body
func_return === nothing || push!(
series_list,
RecipesBase.RecipeData(plotattributes, RecipesBase.wrap_tuple(func_return)),
)
series_list
end |> esc,
)
funcdef
end

# --------------------------------------------------------------------------
Expand Down Expand Up @@ -512,29 +499,22 @@ isrow(v) = isa(v, Expr) && v.head in (:hcat, :row)
iscol(v) = isa(v, Expr) && v.head ≡ :vcat
rowsize(v) = isrow(v) ? length(v.args) : 1

function create_grid(expr::Expr)
create_grid(expr::Expr) =
if iscol(expr)
create_grid_vcat(expr)
elseif isrow(expr)
:(
sub(x) = :(cell[1, $(first(x))] = $(create_grid(last(x))))
quote
let cell = Matrix(undef, 1, $(length(expr.args)))
$(
[
:(cell[1, $i] = $(create_grid(v))) for
(i, v) in enumerate(expr.args)
]...
)
$(map(sub, enumerate(expr.args))...)
cell
end
)

end
elseif expr.head ≡ :curly
create_grid_curly(expr)
else
# if it's something else, just return that (might be an existing layout?)
esc(expr)
esc(expr) # if it's something else, just return that (might be an existing layout?)
end
end

function create_grid_vcat(expr::Expr)
rowsizes = map(rowsize, expr.args)
Expand All @@ -554,25 +534,21 @@ function create_grid_vcat(expr::Expr)
push!(body.args, :(cell[$r, 1] = $(create_grid(arg))))
end
end
:(
quote
let cell = Matrix(undef, $nr, $nc)
$body
cell
end
)
end
else
# otherwise just build one row at a time
:(
sub(x) = :(cell[$(first(x)), 1] = $(create_grid(last(x))))
quote
let cell = Matrix(undef, $(length(expr.args)), 1)
$(
[
:(cell[$i, 1] = $(create_grid(v))) for
(i, v) in enumerate(expr.args)
]...
)
$(map(sub, enumerate(expr.args))...)
cell
end
)
end
end
end

Expand All @@ -584,18 +560,22 @@ function create_grid_curly(expr::Expr)
s = expr.args[1]
if isa(s, Expr) && s.head ≡ :call && s.args[1] ≡ :grid
create_grid(
:(grid(
$(s.args[2:end]...),
width = $(get(kw, :w, QuoteNode(:auto))),
height = $(get(kw, :h, QuoteNode(:auto))),
)),
quote
grid(
$(s.args[2:end]...),
width = $(get(kw, :w, QuoteNode(:auto))),
height = $(get(kw, :h, QuoteNode(:auto))),
)
end,
)
elseif isa(s, Symbol)
:((
label = $(QuoteNode(s)),
width = $(get(kw, :w, QuoteNode(:auto))),
height = $(get(kw, :h, QuoteNode(:auto))),
))
quote
(
label = $(QuoteNode(s)),
width = $(get(kw, :w, QuoteNode(:auto))),
height = $(get(kw, :h, QuoteNode(:auto))),
)
end
else
error("Unknown use of curly brackets: $expr")
end
Expand Down
2 changes: 1 addition & 1 deletion src/Plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,6 @@ include("backends/web.jl")
include("backends/gr.jl")

include("shorthands.jl")
include("precompilation.jl")
include("precompile.jl")

end
40 changes: 12 additions & 28 deletions src/args.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ const _keyAliases = Dict{Symbol,Symbol}()

function add_aliases(sym::Symbol, aliases::Symbol...)
for alias in aliases
if haskey(_keyAliases, alias) || alias === sym
return nothing
end
(haskey(_keyAliases, alias) || alias === sym) && return nothing
_keyAliases[alias] = sym
end
return nothing
Expand All @@ -23,17 +21,15 @@ end

function add_non_underscore_aliases!(aliases::Dict{Symbol,Symbol})
for (k, v) in aliases
s = string(k)
if '_' in s
if '_' in string(k)
aliases[make_non_underscore(k)] = v
end
end
end

function add_non_underscore_aliases!(aliases::Dict{Symbol,Symbol}, args::Vector{Symbol})
for arg in args
s = string(arg)
if '_' in s
if '_' in string(arg)
aliases[make_non_underscore(arg)] = arg
end
end
Expand Down Expand Up @@ -2043,9 +2039,10 @@ function _update_subplot_args(
anns = RecipesPipeline.pop_kw!(sp.attr, :annotations)

# grab those args which apply to this subplot
for k in keys(_subplot_defaults)
slice_arg!(plotattributes_in, sp.attr, k, subplot_index, remove_pair)
end
foreach(
k -> slice_arg!(plotattributes_in, sp.attr, k, subplot_index, remove_pair),
keys(_subplot_defaults),
)

_update_subplot_colors(sp)

Expand Down Expand Up @@ -2125,15 +2122,14 @@ label_to_string(label::Bool, series_plotindex) =
label ? label_to_string(:auto, series_plotindex) : ""
label_to_string(label::Nothing, series_plotindex) = ""
label_to_string(label::Missing, series_plotindex) = ""
function label_to_string(label::Symbol, series_plotindex)
label_to_string(label::Symbol, series_plotindex) =
if label === :auto
return string("y", series_plotindex)
string("y", series_plotindex)
elseif label === :none
return ""
""
else
throw(ArgumentError("unsupported symbol $(label) passed to `label`"))
end
end
label_to_string(label, series_plotindex) = string(label) # Fallback to string promotion

function _update_series_attributes!(plotattributes::AKW, plt::Plot, sp::Subplot)
Expand Down Expand Up @@ -2245,13 +2241,11 @@ Also creates pluralized and non-underscore aliases for these keywords.
macro add_attributes(level, expr, match_table)
expr = macroexpand(__module__, expr) # to expand @static
expr isa Expr && expr.head === :struct || error("Invalid usage of @add_attributes")
T = expr.args[2]
if T isa Expr && T.head === :<:
if (T = expr.args[2]) isa Expr && T.head === :<:
T = T.args[1]
end

key_dict = KW()

_splitdef!(expr.args[3], key_dict)

insert_block = Expr(:block)
Expand All @@ -2269,20 +2263,11 @@ macro add_attributes(level, expr, match_table)
Expr(:ref, Symbol("_", level, "_defaults"), QuoteNode(exp_key)),
value,
),
)
push!(
insert_block.args,
:(add_aliases($(QuoteNode(exp_key)), $(QuoteNode(pl_key)))),
)
push!(
insert_block.args,
:(add_aliases(
$(QuoteNode(exp_key)),
$(QuoteNode(make_non_underscore(exp_key))),
)),
)
push!(
insert_block.args,
:(add_aliases(
$(QuoteNode(exp_key)),
$(QuoteNode(make_non_underscore(pl_key))),
Expand All @@ -2297,8 +2282,7 @@ end

function _splitdef!(blk, key_dict)
for i in eachindex(blk.args)
ei = blk.args[i]
if ei isa Symbol
if (ei = blk.args[i]) isa Symbol
# var
continue
elseif ei isa Expr
Expand Down
Loading