Fix ribbon slicing (#4068)

* move ribbon handling after slicing

* format file
This commit is contained in:
Simon Christ 2022-01-25 21:20:18 +01:00 committed by GitHub
parent 2eaf9f3b15
commit 915df5d3ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 16 deletions

View File

@ -83,19 +83,6 @@ function _preprocess_userrecipe(kw::AKW)
map(kw[:line_z], kw[:x], kw[:y], kw[:z])
end
rib = get(kw, :ribbon, default(:ribbon))
fr = get(kw, :fillrange, default(:fillrange))
# map ribbon if it's a Function
if rib isa Function
kw[:ribbon] = map(rib, kw[:x])
end
# convert a ribbon into a fillrange
if rib !== nothing
make_fillrange_from_ribbon(kw)
# map fillrange if it's a Function
elseif fr !== nothing && fr isa Function
kw[:fillrange] = map(fr, kw[:x])
end
return
end
@ -164,6 +151,21 @@ function RecipesPipeline.process_sliced_series_attributes!(plt::Plots.Plot, kw_l
end
end
for kw in kw_list
rib = get(kw, :ribbon, default(:ribbon))
fr = get(kw, :fillrange, default(:fillrange))
# map ribbon if it's a Function
if rib isa Function
kw[:ribbon] = map(rib, kw[:x])
end
# convert a ribbon into a fillrange
if rib !== nothing
make_fillrange_from_ribbon(kw)
# map fillrange if it's a Function
elseif fr !== nothing && fr isa Function
kw[:fillrange] = map(fr, kw[:x])
end
end
return nothing
end

View File

@ -21,9 +21,16 @@ end
@testset "Slicing" begin
@test plot(1:5, fillrange = 0)[1][1][:fillrange] == 0
data4 = rand(4, 4)
mat = reshape(1:8, 2, 4)
for i in axes(data4, 1)
@test plot(data4, fillrange = 0)[1][i][:fillrange] == 0
@test plot(data4, fillrange = [1, 2])[1][i][:fillrange] == [1.0, 2.0]
@test plot(data4, fillrange = [1 2])[1][i][:fillrange] == (iseven(i) ? 2 : 1)
for attribute in (:fillrange, :ribbon)
@test plot(data4; NamedTuple{tuple(attribute)}(0)...)[1][i][attribute] == 0
@test plot(data4; NamedTuple{tuple(attribute)}(Ref([1, 2]))...)[1][i][attribute] ==
[1.0, 2.0]
@test plot(data4; NamedTuple{tuple(attribute)}(Ref([1 2]))...)[1][i][attribute] ==
(iseven(i) ? 2 : 1)
@test plot(data4; NamedTuple{tuple(attribute)}(Ref(mat))...)[1][i][attribute] ==
[2(i - 1) + 1, 2i]
end
end
end