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 Zhanibek
parent 82a0d55195
commit 0e25a6d3bf
2 changed files with 19 additions and 17 deletions

View File

@ -8,24 +8,14 @@ function RecipesPipeline.warn_on_recipe_aliases!(
recipe_type::Symbol, recipe_type::Symbol,
@nospecialize(args) @nospecialize(args)
) )
for k in keys(plotattributes) pkeys = keys(plotattributes)
if !is_default_attribute(k) for k in pkeys
dk = get(_keyAliases, k, k) dk = get(_keyAliases, k, nothing)
if k !== dk if dk !== nothing
if recipe_type == :user kv = RecipesPipeline.pop_kw!(plotattributes, k)
signature_string = RecipesPipeline.userrecipe_signature_string(args) if dk pkeys
elseif recipe_type == :type plotattributes[dk] = kv
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`."
end end
plotattributes[dk] = RecipesPipeline.pop_kw!(plotattributes, k)
end end
end end
end end

View File

@ -1,6 +1,18 @@
using Plots, Test using Plots, Test
using OffsetArrays 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 @testset "lens!" begin
pl = plot(1:5) pl = plot(1:5)
lens!(pl, [1, 2], [1, 2], inset = (1, bbox(0.0, 0.0, 0.2, 0.2)), colorbar = false) lens!(pl, [1, 2], [1, 2], inset = (1, bbox(0.0, 0.0, 0.2, 0.2)), colorbar = false)