detect aliases in recipes (#3904)

* detect aliases in recipes

* remove doubled tests
This commit is contained in:
Simon Christ 2021-10-28 16:12:59 +02:00 committed by GitHub
parent 1c621feacc
commit e84905c2a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 17 deletions

View File

@ -8,24 +8,14 @@ function RecipesPipeline.warn_on_recipe_aliases!(
recipe_type::Symbol,
@nospecialize(args)
)
for k in keys(plotattributes)
if !is_default_attribute(k)
dk = get(_keyAliases, k, k)
if k !== dk
if recipe_type == :user
signature_string = RecipesPipeline.userrecipe_signature_string(args)
elseif recipe_type == :type
signature_string = RecipesPipeline.typerecipe_signature_string(args)
elseif recipe_type == :plot
signature_string = RecipesPipeline.plotrecipe_signature_string(args)
elseif recipe_type == :series
signature_string = RecipesPipeline.seriesrecipe_signature_string(args)
else
throw(ArgumentError("Invalid recipe type `$recipe_type`"))
end
# @warn "Attribute alias `$k` detected in the $recipe_type recipe defined for the signature $signature_string. To ensure expected behavior it is recommended to use the default attribute `$dk`."
pkeys = keys(plotattributes)
for k in pkeys
dk = get(_keyAliases, k, nothing)
if dk !== nothing
kv = RecipesPipeline.pop_kw!(plotattributes, k)
if dk pkeys
plotattributes[dk] = kv
end
plotattributes[dk] = RecipesPipeline.pop_kw!(plotattributes, k)
end
end
end

View File

@ -1,6 +1,18 @@
using Plots, Test
using OffsetArrays
@testset "User recipes" begin
struct LegendPlot end
@recipe function f(plot::LegendPlot)
legend --> :topleft
(1:3, 1:3)
end
pl = plot(LegendPlot(); legend = :right)
@test pl[1][:legend_position] == :right
pl = plot(LegendPlot())
@test pl[1][:legend_position] == :topleft
end
@testset "lens!" begin
pl = plot(1:5)
lens!(pl, [1, 2], [1, 2], inset = (1, bbox(0.0, 0.0, 0.2, 0.2)), colorbar = false)