Skip to content

Commit

Permalink
Merge pull request #53 from daschw/colorschemes
Browse files Browse the repository at this point in the history
Switch to ColorSchemes
  • Loading branch information
daschw authored Apr 24, 2020
2 parents 01208d4 + db35bb7 commit 81ce6ef
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 23 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name = "PlotThemes"
uuid = "ccf2f8ad-2431-5c83-bf29-c5338b663b6a"
version = "1.0.3"
version = "2.0.0"

[deps]
PlotUtils = "995b91a9-d308-5afd-9ec6-746e21dbc043"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[compat]
PlotUtils = "0.5, 0.6"
PlotUtils = "1"
Requires = "0.5, 1.0"
julia = "0.7, 1"

Expand Down
19 changes: 9 additions & 10 deletions src/PlotThemes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ module PlotThemes

using PlotUtils, Requires

export
add_theme, palette
export add_theme, theme_palette

_255_to_1(c::Symbol, colors) = RGBA(map(x-> x/255,colors[c])...)
RGB255(r,g,b) = RGB(r/255, g/255, b/255)
expand_palette(bg, palette; kwargs...) = [convert(RGBA,c) for c in distinguishable_colors(20, vcat(bg, palette); kwargs...)][2:end]

function expand_palette(bg, cs; kwargs...)
colors = palette(cs).colors.colors
c = convert.(RGBA, distinguishable_colors(20, vcat(bg, colors); kwargs...))[2:end]
return palette(c)
end

const KW = Dict{Symbol, Any}

Expand All @@ -23,22 +27,17 @@ PlotTheme(; kw...) = PlotTheme(KW(kw))
PlotTheme(base::PlotTheme; kw...) = PlotTheme(KW(base.defaults..., KW(kw)...))

"Get the palette of a PlotTheme"
function palette(s::Symbol)
function theme_palette(s::Symbol)
if haskey(_themes, s) && haskey(_themes[s].defaults, :palette)
return _themes[s].defaults[:palette]
else
return get_color_palette(:auto, plot_color(:white), 17)
return palette(:default)
end
end

const _themes = Dict{Symbol, PlotTheme}(:default => PlotTheme())

gradient_name(s::Symbol) = s == :default ? :inferno : Symbol(s, "_grad")

function add_theme(s::Symbol, thm::PlotTheme)
if haskey(thm.defaults, :colorgradient)
PlotUtils.register_gradient_colors(gradient_name(s), thm.defaults[:colorgradient], :misc)
end
_themes[s] = thm
end

Expand Down
2 changes: 1 addition & 1 deletion src/dark.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ _themes[:dark] = PlotTheme(
legendtitlefontcolor = colorant"#FFFFFF",
titlefontcolor = colorant"#FFFFFF",
palette = expand_palette(dark_bg, dark_palette; lchoices = [57], cchoices = [100]),
colorgradient = cgrad(:fire).colors
colorgradient = :fire
)
4 changes: 2 additions & 2 deletions src/gruvbox.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ _themes[:gruvbox_dark] = PlotTheme(
fgguide = _gruvbox_colors[:dark1],
fglegend = _gruvbox_colors[:light3],
palette = expand_palette(_gruvbox_colors[:dark3], [_gruvbox_colors[c] for c in _gruvbox_dark_palette]),
colorgradient = cgrad(:YlOrRd_r).colors
colorgradient = cgrad(:YlOrRd, rev = true)
)

_themes[:gruvbox_light] = PlotTheme(
Expand All @@ -64,5 +64,5 @@ _themes[:gruvbox_light] = PlotTheme(
fgguide = _gruvbox_colors[:dark1],
fglegend = _gruvbox_colors[:dark1],
palette = expand_palette(_gruvbox_colors[:light3], [_gruvbox_colors[c] for c in _gruvbox_light_palette]),
colorgradient = cgrad(:YlOrRd_r).colors
colorgradient = cgrad(:YlOrRd, rev = true)
)
2 changes: 1 addition & 1 deletion src/juno.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ _themes[:juno] = PlotTheme(
fgguide = colorant"#9EB1BE",
fglegend = colorant"#9EB1BE",
palette = expand_palette(juno_bg, juno_palette; lchoices = [57], cchoices = [100]),
colorgradient = cgrad(:fire).colors
colorgradient = :fire
)
2 changes: 1 addition & 1 deletion src/lime.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ _themes[:lime] = PlotTheme(
fgguide = lime_palette[2],
fglegend = lime_palette[2],
palette = expand_palette(black, lime_palette[1:4]),
colorgradient = cgrad(:viridis).colors
colorgradient = :viridis
)
2 changes: 1 addition & 1 deletion src/orange.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ _themes[:orange] = PlotTheme(
fgguide = orange_palette[2],
fglegend = orange_palette[2],
palette = expand_palette(black, orange_palette[1:4]),
colorgradient = cgrad(:viridis).colors
colorgradient = :viridis
)
2 changes: 1 addition & 1 deletion src/sand.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ _themes[:sand] = PlotTheme(
fgguide = colorant"#725B61",
fglegend = colorant"#725B61",
palette = expand_palette(sand_bg, sand_palette),
colorgradient = cgrad(:dense).colors
colorgradient = :dense
)
4 changes: 2 additions & 2 deletions src/solarized.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ _themes[:solarized] = PlotTheme(
fgguide = _solarized_colors[:base01],
fglegend = _solarized_colors[:base01],
palette = expand_palette(_solarized_colors[:base03], [_solarized_colors[c] for c in _solarized_palette]),
colorgradient = cgrad(:YlOrRd_r).colors
colorgradient = :YlOrRd
)

_themes[:solarized_light] = PlotTheme(
Expand All @@ -39,5 +39,5 @@ _themes[:solarized_light] = PlotTheme(
fgguide = _solarized_colors[:base1],
fglegend = _solarized_colors[:base1],
palette = expand_palette(_solarized_colors[:base3], [_solarized_colors[c] for c in _solarized_palette]),
colorgradient = cgrad(:YlOrRd_r).colors
colorgradient = cgrad(:YlOrRd, rev = true)
)
2 changes: 1 addition & 1 deletion src/wong.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ _themes[:wong] = PlotTheme(

_themes[:wong2] = PlotTheme(
palette = expand_palette(colorant"white", [RGB(0,0,0); wong_palette]; lchoices = [57], cchoices = [100]),
colorgradient = cgrad(:viridis).colors,
colorgradient = :viridis,
)
1 change: 0 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ using PlotThemes
using Test, PlotUtils

@test in(:sand, keys(PlotThemes._themes))
@test in(:sand_grad, PlotUtils.cgradients(:misc))

2 comments on commit 81ce6ef

@daschw
Copy link
Member Author

@daschw daschw commented on 81ce6ef Apr 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/13603

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v2.0.0 -m "<description of version>" 81ce6ef995aef2efe94ae2ef8e3a20d5f823d6cd
git push origin v2.0.0

Please sign in to comment.