-
-
Notifications
You must be signed in to change notification settings - Fork 370
Refactor marker and line attributes #4505
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 26 commits
0985edb
d12b770
5dae3a3
69e839a
aadc7a4
07aa435
7925968
f931f7a
dd1f611
65fc04c
2ddf825
0efda09
62fee9b
65fed0a
f47764d
719f4b0
38806ac
5e1bd5e
65116fb
867afa0
90bc39f
bffd24d
6dfba96
f737e0f
0150ad2
75db4f3
c49da28
33bae7f
7705f8a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,28 +9,54 @@ const AKW = AbstractDict{Symbol,Any} | |||||||||||||
| # ## DefaultsDict | ||||||||||||||
| # -------------------------------- | ||||||||||||||
|
|
||||||||||||||
| struct DefaultsDict <: AbstractDict{Symbol,Any} | ||||||||||||||
| struct DefaultsDict{P} <: AbstractDict{Symbol,Any} | ||||||||||||||
| plot_type::Type{P} | ||||||||||||||
| explicit::KW | ||||||||||||||
| defaults::KW | ||||||||||||||
| function DefaultsDict{P}(plot_type::Type{P}, explicit::AbstractDict, defaults::AbstractDict) where {P} | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||||||||||
| e = KW( | ||||||||||||||
| key_alias(plot_type, k) => v === :seriestype ? type_alias(plot_type, v) : v | ||||||||||||||
| for (k, v) in explicit | ||||||||||||||
| ) | ||||||||||||||
| new{P}(plot_type, e, defaults) | ||||||||||||||
| end | ||||||||||||||
| end | ||||||||||||||
|
|
||||||||||||||
| Base.merge(d1::DefaultsDict, d2::DefaultsDict) = | ||||||||||||||
| DefaultsDict(merge(d1.explicit, d2.explicit), merge(d1.defaults, d2.defaults)) | ||||||||||||||
| Base.getindex(dd::DefaultsDict, k) = | ||||||||||||||
| DefaultsDict(pt, e, d) = DefaultsDict{pt}(pt, e, d) | ||||||||||||||
| function Base.merge(d1::DefaultsDict, d2::DefaultsDict) | ||||||||||||||
| @assert d1.plot_type === d2.plot_type | ||||||||||||||
| DefaultsDict( | ||||||||||||||
| d1.plot_type, | ||||||||||||||
| merge(d1.explicit, d2.explicit), | ||||||||||||||
| merge(d1.defaults, d2.defaults), | ||||||||||||||
| ) | ||||||||||||||
| end | ||||||||||||||
| function Base.getindex(dd::DefaultsDict, k) | ||||||||||||||
| k = key_alias(dd.plot_type, k) | ||||||||||||||
| if haskey(dd.explicit, k) | ||||||||||||||
| dd.explicit[k] | ||||||||||||||
| else | ||||||||||||||
| dd.defaults[k] | ||||||||||||||
| end | ||||||||||||||
| Base.haskey(dd::DefaultsDict, k) = haskey(dd.explicit, k) || haskey(dd.defaults, k) | ||||||||||||||
| Base.get(dd::DefaultsDict, k, default) = haskey(dd, k) ? dd[k] : default | ||||||||||||||
| Base.get!(dd::DefaultsDict, k, default) = | ||||||||||||||
| end | ||||||||||||||
| function Base.haskey(dd::DefaultsDict, k) | ||||||||||||||
| k = key_alias(dd.plot_type, k) | ||||||||||||||
| haskey(dd.explicit, k) || haskey(dd.defaults, k) | ||||||||||||||
| end | ||||||||||||||
| function Base.get(dd::DefaultsDict, k, default) | ||||||||||||||
| k = key_alias(dd.plot_type, k) | ||||||||||||||
| haskey(dd, k) ? dd[k] : default | ||||||||||||||
| end | ||||||||||||||
| function Base.get!(dd::DefaultsDict, k, default) | ||||||||||||||
| k = key_alias(dd.plot_type, k) | ||||||||||||||
| if haskey(dd, k) | ||||||||||||||
| dd[k] | ||||||||||||||
| else | ||||||||||||||
| dd.defaults[k] = default | ||||||||||||||
| end | ||||||||||||||
| end | ||||||||||||||
| function Base.delete!(dd::DefaultsDict, k) | ||||||||||||||
| k = key_alias(dd.plot_type, k) | ||||||||||||||
| haskey(dd.explicit, k) && delete!(dd.explicit, k) | ||||||||||||||
| haskey(dd.defaults, k) && delete!(dd.defaults, k) | ||||||||||||||
| dd | ||||||||||||||
|
|
@@ -46,12 +72,24 @@ function Base.iterate(dd::DefaultsDict, (key_list, i)) | |||||||||||||
| (k => dd[k], (key_list, i + 1)) | ||||||||||||||
| end | ||||||||||||||
|
|
||||||||||||||
| Base.copy(dd::DefaultsDict) = DefaultsDict(copy(dd.explicit), dd.defaults) | ||||||||||||||
| Base.copy(dd::DefaultsDict) = DefaultsDict(dd.plot_type, copy(dd.explicit), dd.defaults) | ||||||||||||||
|
|
||||||||||||||
| RecipesBase.is_explicit(dd::DefaultsDict, k) = haskey(dd.explicit, k) | ||||||||||||||
| RecipesBase.is_default(dd::DefaultsDict, k) = !is_explicit(dd, k) && haskey(dd.defaults, k) | ||||||||||||||
| function RecipesBase.is_explicit(dd::DefaultsDict, k) | ||||||||||||||
| k = key_alias(dd.plot_type, k) | ||||||||||||||
| haskey(dd.explicit, k) | ||||||||||||||
| end | ||||||||||||||
| function RecipesBase.is_default(dd::DefaultsDict, k) | ||||||||||||||
| k = key_alias(dd.plot_type, k) | ||||||||||||||
| !is_explicit(dd, k) && haskey(dd.defaults, k) | ||||||||||||||
| end | ||||||||||||||
|
|
||||||||||||||
| Base.setindex!(dd::DefaultsDict, v, k) = dd.explicit[k] = v | ||||||||||||||
| function Base.setindex!(dd::DefaultsDict, v, k) | ||||||||||||||
| k = key_alias(dd.plot_type, k) | ||||||||||||||
| if k === :seriestype | ||||||||||||||
| v = type_alias(dd.plot_type, v) | ||||||||||||||
| end | ||||||||||||||
| dd.explicit[k] = v | ||||||||||||||
| end | ||||||||||||||
|
|
||||||||||||||
| # Reset to default value and return dict | ||||||||||||||
| function reset_kw!(dd::DefaultsDict, k) | ||||||||||||||
|
|
||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,8 +6,10 @@ using Test | |||||||||||||
| import RecipesPipeline: _prepare_series_data | ||||||||||||||
| import RecipesBase | ||||||||||||||
|
|
||||||||||||||
| struct MyPlot end | ||||||||||||||
|
|
||||||||||||||
| @testset "DefaultsDict" begin | ||||||||||||||
| dd = DefaultsDict(Dict(:foo => 1, :bar => missing), Dict(:foo => nothing, :baz => 'x')) | ||||||||||||||
| dd = DefaultsDict(MyPlot, Dict(:foo => 1, :bar => missing), Dict(:foo => nothing, :baz => 'x')) | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||||||||||
|
|
||||||||||||||
| @test all(explicitkeys(dd) .== [:bar, :foo]) | ||||||||||||||
| @test all(defaultkeys(dd) .== [:baz, :foo]) | ||||||||||||||
|
|
@@ -44,7 +46,8 @@ end | |||||||||||||
| @test !is_axis_attribute(plt, :foo) | ||||||||||||||
|
|
||||||||||||||
| @test process_userrecipe!(plt, [:foo], :bar) == [:foo, :bar] | ||||||||||||||
| @test type_alias(plt, :wireframe) ≡ :wireframe | ||||||||||||||
| @test type_alias(typeof(plt), :wireframe) ≡ :wireframe | ||||||||||||||
| @test key_alias(typeof(plt), :label) ≡ :label | ||||||||||||||
|
|
||||||||||||||
| @test plot_setup!(plt, plotattributes, kw_list) isa Nothing | ||||||||||||||
| @test slice_series_attributes!(plt, kw_list, kw) isa Nothing | ||||||||||||||
|
|
||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,22 +9,22 @@ const _arg_desc = KW( | |||||||||||||
| :seriescolor => (ColorType, "The base color for this series. `:auto` (the default) will select a color from the subplot's `color_palette`, based on the order it was added to the subplot. Also describes the colormap for surfaces."), | ||||||||||||||
| :seriesalpha => (Real, "The alpha/opacity override for the series. `nothing` (the default) means it will take the alpha value of the color."), | ||||||||||||||
| :seriestype => (Symbol, "This is the identifier of the type of visualization for this series. Choose from $(_allTypes) or any series recipes which are defined."), | ||||||||||||||
| :linestyle => (Symbol, "Style of the line (for path and bar stroke). Choose from $(_allStyles)"), | ||||||||||||||
| :linewidth => (Real, "Width of the line (in pixels)."), | ||||||||||||||
| :linecolor => (ColorType, "Color of the line (for path and bar stroke). `:match` will take the value from `:seriescolor`, (though histogram/bar types use `:black` as a default)."), | ||||||||||||||
| :linealpha => (Real, "The alpha/opacity override for the line. `nothing` (the default) means it will take the alpha value of linecolor."), | ||||||||||||||
| :line_style => (Symbol, "Style of the line (for path and bar stroke). Choose from $(_allStyles)"), | ||||||||||||||
| :line_width => (Real, "Width of the line (in pixels)."), | ||||||||||||||
| :line_color => (ColorType, "Color of the line (for path and bar stroke). `:match` will take the value from `:seriescolor`, (though histogram/bar types use `:black` as a default)."), | ||||||||||||||
| :line_alpha => (Real, "The alpha/opacity override for the line. `nothing` (the default) means it will take the alpha value of linecolor."), | ||||||||||||||
| :fillrange => (Union{Real,AVec}, "Fills area between fillrange and `y` for line-types, sets the base for `bar`, `sticks` types, and similar for other types."), | ||||||||||||||
| :fillcolor => (ColorType, "Color of the filled area of path or bar types. `:match` will take the value from `:seriescolor`."), | ||||||||||||||
| :fillalpha => (Real, "The alpha/opacity override for the fill area. `nothing` (the default) means it will take the alpha value of fillcolor."), | ||||||||||||||
|
||||||||||||||
| :fillrange => (Union{Real,AVec}, "Fills area between fillrange and `y` for line-types, sets the base for `bar`, `sticks` types, and similar for other types."), | |
| :fillcolor => (ColorType, "Color of the filled area of path or bar types. `:match` will take the value from `:seriescolor`."), | |
| :fillalpha => (Real, "The alpha/opacity override for the fill area. `nothing` (the default) means it will take the alpha value of fillcolor."), | |
| :fillrange => (Union{Real,AVec}, "Fills area between fillrange and `y` for line-types, sets the base for `bar`, `sticks` types, and similar for other types."), | |
| :fillcolor => (ColorType, "Color of the filled area of path or bar types. `:match` will take the value from `:seriescolor`."), | |
| :fillalpha => (Real, "The alpha/opacity override for the fill area. `nothing` (the default) means it will take the alpha value of fillcolor."), |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
| :fillstyle => (Symbol, "Style of the fill area. `nothing` (the default) means solid fill. Choose from :/, :\\, :|, :-, :+, :x."), | |
| :fillstyle => (Symbol, "Style of the fill area. `nothing` (the default) means solid fill. Choose from :/, :\\, :|, :-, :+, :x."), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶