Move fillrange and ribbon logic from RecipesPipeline and add tests for default function (#4030)
* add tests for default function * remove fillrange and ribbon handling from RecipesPipeline * adjust compat
This commit is contained in:
parent
b1c11cca33
commit
a24fb93ab1
@ -48,7 +48,7 @@ NaNMath = "0.3"
|
|||||||
PlotThemes = "2"
|
PlotThemes = "2"
|
||||||
PlotUtils = "1"
|
PlotUtils = "1"
|
||||||
RecipesBase = "1.2"
|
RecipesBase = "1.2"
|
||||||
RecipesPipeline = "0.3.5, 0.4"
|
RecipesPipeline = "0.5"
|
||||||
Reexport = "0.2, 1.0"
|
Reexport = "0.2, 1.0"
|
||||||
Requires = "1"
|
Requires = "1"
|
||||||
Scratch = "1"
|
Scratch = "1"
|
||||||
|
|||||||
@ -50,6 +50,7 @@ const _magic_axis_args = [:axis, :tickfont, :guidefont, :grid, :minorgrid]
|
|||||||
const _magic_subplot_args =
|
const _magic_subplot_args =
|
||||||
[:title_font, :legend_font, :legend_title_font, :plot_title_font, :colorbar_titlefont]
|
[:title_font, :legend_font, :legend_title_font, :plot_title_font, :colorbar_titlefont]
|
||||||
const _magic_series_args = [:line, :marker, :fill]
|
const _magic_series_args = [:line, :marker, :fill]
|
||||||
|
const _all_magic_args = sort(union(_magic_axis_args, _magic_series_args, _magic_subplot_args))
|
||||||
|
|
||||||
const _all_axis_args = sort(union([_axis_args; _magic_axis_args]))
|
const _all_axis_args = sort(union([_axis_args; _magic_axis_args]))
|
||||||
const _all_subplot_args = sort(union([_subplot_args; _magic_subplot_args]))
|
const _all_subplot_args = sort(union([_subplot_args; _magic_subplot_args]))
|
||||||
|
|||||||
@ -69,7 +69,7 @@ function _preprocess_userrecipe(kw::AKW)
|
|||||||
_add_markershape(kw)
|
_add_markershape(kw)
|
||||||
|
|
||||||
# map marker_z if it's a Function
|
# map marker_z if it's a Function
|
||||||
if isa(get(kw, :marker_z, nothing), Function)
|
if isa(get(kw, :marker_z, default(:marker_z)), Function)
|
||||||
# TODO: should this take y and/or z as arguments?
|
# TODO: should this take y and/or z as arguments?
|
||||||
kw[:marker_z] =
|
kw[:marker_z] =
|
||||||
isa(kw[:z], Nothing) ? map(kw[:marker_z], kw[:x], kw[:y]) :
|
isa(kw[:z], Nothing) ? map(kw[:marker_z], kw[:x], kw[:y]) :
|
||||||
@ -77,15 +77,24 @@ function _preprocess_userrecipe(kw::AKW)
|
|||||||
end
|
end
|
||||||
|
|
||||||
# map line_z if it's a Function
|
# map line_z if it's a Function
|
||||||
if isa(get(kw, :line_z, nothing), Function)
|
if isa(get(kw, :line_z, default(:line_z)), Function)
|
||||||
kw[:line_z] =
|
kw[:line_z] =
|
||||||
isa(kw[:z], Nothing) ? map(kw[:line_z], kw[:x], kw[:y]) :
|
isa(kw[:z], Nothing) ? map(kw[:line_z], kw[:x], kw[:y]) :
|
||||||
map(kw[:line_z], kw[:x], kw[:y], kw[:z])
|
map(kw[:line_z], kw[:x], kw[:y], kw[:z])
|
||||||
end
|
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
|
# convert a ribbon into a fillrange
|
||||||
if get(kw, :ribbon, nothing) !== nothing
|
if rib !== nothing
|
||||||
make_fillrange_from_ribbon(kw)
|
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
|
return
|
||||||
end
|
end
|
||||||
@ -154,6 +163,7 @@ function RecipesPipeline.process_sliced_series_attributes!(plt::Plots.Plot, kw_l
|
|||||||
kw_list[ind - 1] = tmp
|
kw_list[ind - 1] = tmp
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return nothing
|
return nothing
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -418,3 +428,4 @@ function _add_the_series(plt, sp, plotattributes)
|
|||||||
_series_added(plt, series)
|
_series_added(plt, series)
|
||||||
_update_subplot_colorbars(sp)
|
_update_subplot_colorbars(sp)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -12,6 +12,14 @@ end
|
|||||||
empty!(PLOTS_DEFAULTS)
|
empty!(PLOTS_DEFAULTS)
|
||||||
Plots.__init__()
|
Plots.__init__()
|
||||||
|
|
||||||
|
@testset "default" begin
|
||||||
|
default(fillrange=0)
|
||||||
|
@test Plots._series_defaults[:fillrange] == 0
|
||||||
|
pl = plot(1:5)
|
||||||
|
@test pl[1][1][:fillrange] == 0
|
||||||
|
default()
|
||||||
|
end
|
||||||
|
|
||||||
@testset "Legend defaults" begin
|
@testset "Legend defaults" begin
|
||||||
p = plot()
|
p = plot()
|
||||||
@test p[1][:legend_font_family] == "sans-serif"
|
@test p[1][:legend_font_family] == "sans-serif"
|
||||||
|
|||||||
@ -17,3 +17,14 @@ end
|
|||||||
@test all(RecipesPipeline.get_axis_limits(p1, :x) .== x)
|
@test all(RecipesPipeline.get_axis_limits(p1, :x) .== x)
|
||||||
@test all(RecipesPipeline.get_axis_limits(p2, :x) .== x)
|
@test all(RecipesPipeline.get_axis_limits(p2, :x) .== x)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@testset "Slicing" begin
|
||||||
|
|
||||||
|
@test plot(1:5, fillrange = 0)[1][1][:fillrange] == 0
|
||||||
|
data4 = rand(4,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)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user