Skip to content

Commit

Permalink
findcolorscheme changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cormullion committed Sep 25, 2021
1 parent f7d43fe commit 2052f0a
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 56 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

## [v3.15] - 2021 forthcoming
## [v3.15] - 2021-09-25

### Added

Expand All @@ -10,6 +10,8 @@

## Changed

- findcolorscheme() returns list of matching scheme names as symbols

### Removed

### Deprecated
Expand Down
130 changes: 95 additions & 35 deletions docs/src/basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,46 +103,30 @@ colorschemes[:summer] |> show

## Finding colorschemes

Use the [`findcolorscheme`](@ref) function to search through the pre-defined colorschemes. The string you provide can occur in the colorscheme’s name, in the category, or in the notes. It’s interpreted as a case-insensitive regular expression.
Use the [`findcolorscheme`](@ref) function to search through
the pre-defined colorschemes. The string you provide can
occur in the colorscheme’s name, in the category, or
(optionally) in the notes. It’s interpreted as a
case-insensitive regular expression.

```julia
julia> findcolorscheme("magen")
julia> findcolorscheme("ice")

colorschemes containing "magen"
colorschemes containing "ice"

spring (notes) sampled color schemes, linearl...
cool (notes) sampled color schemes, linearl...
hsv (notes) sampled color schemes, red-yel...
seaborn_icefire_gradient
seaborn_icefire_gradient (notes) sequential, ice fire gradient...
ice
flag_is (notes) The flag of Iceland...
botticelli
botticelli (notes) palette from artist Sandro Bot...

found 3 results for "magenta"
```

```julia
julia> findcolorscheme("cmocean")
colorschemes containing "cmocean"

oxy (category) cmocean
matter (category) cmocean
dense (category) cmocean
balance (category) cmocean
thermal (category) cmocean
tempo (category) cmocean
grays (category) cmocean
speed (category) cmocean
turbid (category) cmocean
solar (category) cmocean
ice (category) cmocean
haline (category) cmocean
algae (category) cmocean
amp (category) cmocean
deep (category) cmocean
delta (category) cmocean
curl (category) cmocean
phase (category) cmocean

found 18 results for "cmocean"
...found 6 results for "ice"
```

The function returns a list of matching colorscheme names as symbols.

```@docs
findcolorscheme
```
Expand Down Expand Up @@ -201,25 +185,101 @@ ColorScheme([get(myscheme, i) for i in 0.0:0.01:1.0])
Another way is to use `loadcolorscheme()` function:

```julia
using Colors
loadcolorscheme(:mygrays, [RGB{Float64}(i, i, i) for i in 0:0.1:1.0],
"useful schemes", "just some dull grey shades")
```

and that will be added (temporarily).
and that will be added (temporarily) to the built-in list.

```julia
julia> findcolorscheme("dull")

colorschemes containing "dull"

mygrays (notes) just some dull grey shades...
mygrays (notes) just some dull grey shades...


found 1 result for "dull"
...found 1 result for "dull"
```

If you want to make more advanced ColorSchemes, use linear-segment dictionaries or indexed lists, and use functions to generate color values, see the `make_colorscheme()` function in the [ColorSchemeTools.jl](https://github.com/JuliaGraphics/ColorSchemeTools.jl) package.

## For CVD (color-vision deficient or "color-blind:) users

This package contains a number of colorschemes that are designed to be helpful for people with some deficiencies in their perception of color:

- deuteranomaly (where green looks more red)

- protanomaly (where red looks more green and less bright)

- tritanomaly (difficult to tell the difference between blue and green, and between yellow and red)

- tritanopia (difficult to tell the difference between blue and green, purple and red, and yellow and pink)

```julia
findcolorscheme("cvd")

colorschemes containing "cvd"

tol_light (category) cvd
tol_muted (category) cvd
tol_bright (category) cvd
okabe_ito (category) cvd
mk_8 (category) cvd
mk_12 (category) cvd
mk_15 (category) cvd
```

### :tol_light
```@example
using ColorSchemes # hide
ColorSchemes.tol_light # hide
```

### :tol_muted
```@example
using ColorSchemes # hide
ColorSchemes.tol_muted # hide
```

### :tol_bright
```@example
using ColorSchemes # hide
ColorSchemes.tol_bright # hide
```

### :okabe_ito
```@example
using ColorSchemes # hide
ColorSchemes.okabe_ito # hide
```

### :mk_8
```@example
using ColorSchemes # hide
ColorSchemes.mk_8 # hide
```

### :mk_12
```@example
using ColorSchemes # hide
ColorSchemes.mk_12 # hide
```

### :mk_15
```@example
using ColorSchemes # hide
ColorSchemes.mk_15 # hide
```

Also, it's possible to generate schemes using `Colors.distinguishable_colors()`:

```@example
using Colors, ColorSchemes
ColorScheme(distinguishable_colors(10, transform=protanopic))
```

## Continuous color sampling

You can access the specific colors of a colorscheme by indexing (eg `leonardo[2]` or `leonardo[5:end]`). Or you can sample a ColorScheme at a point between 0.0 and 1.0 as if it were a continuous range of colors:
Expand Down
74 changes: 54 additions & 20 deletions src/ColorSchemes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ speify a category and some notes.
This is an example (from `ColorsSchemes/data/flags.jl`) of how the supplied colorschemes are
loaded into the ColorSchemes dictionary.
```
```julia
loadcolorscheme(:flag_nu, [
RGB(0.7843137254901961, 0.06274509803921569, 0.1803921568627451),
RGB(0.00392156862745098, 0.12941176470588237, 0.4117647058823529),
Expand All @@ -86,7 +86,7 @@ end
An exported dictionary of pre-defined colorschemes:
```
```julia
colorschemes[:summer] |> show
ColorScheme(
ColorTypes.RGB{Float64}[
Expand All @@ -96,7 +96,7 @@ colorschemes[:summer] |> show
To choose a random ColorScheme:
```
```julia
scheme = rand(keys(colorschemes))
```
Expand Down Expand Up @@ -129,39 +129,73 @@ end
loadallschemes()

"""
findcolorscheme(str)
findcolorscheme(str;
search_notes=true)
Find all colorschemes matching `str`. `str` is interpreted
as a regular expression (case-insensitive).
This returns an array of symbols which are the names of
matching schemes in the `colorschemes` dictionary.
```julia
julia> findcolorscheme("ice")
colorschemes containing "ice"
Find all color schemes matching `str`. `str` is interpreted as a regular expression (case-insensitive).
seaborn_icefire_gradient
seaborn_icefire_gradient (notes) sequential, ice fire gradient...
ice
flag_is (notes) The flag of Iceland...
botticelli
botticelli (notes) palette from artist Sandro Bot...
To read the notes of built-in colorscheme `cscheme`:
...found 6 results for "ice"
```
To read the notes of a built-in colorscheme `cscheme`:
```julia
colorschemes[:cscheme].notes
```
"""
function findcolorscheme(str)
function findcolorscheme(str;
search_notes=true)
println("\ncolorschemes containing \"$str\"\n")
counter = 0
found = Symbol[]
for (k, v) in colorschemes
if occursin(Regex(str, "i"), string(k))
printstyled("$(rpad(k, 20))\n", bold=true)
# found in name
printstyled(" $(rpad(k, 20))\n", bold=true)
counter += 1
push!(found, k)
elseif occursin(Regex(str, "i"), string(v.category))
printstyled("$(rpad(k, 20))", bold=true)
# found in category
printstyled(" $(rpad(k, 20))", bold=true)
println(" (category) $(v.category)")
counter += 1
push!(found, k)
end
if occursin(Regex(str, "i"), string(v.notes))
printstyled("$(rpad(k, 20))", bold=true)
l = min(30, length(v.notes))
println(" (notes) $(v.notes[1:l])...")
counter += 1
if occursin(Regex(str, "i"), string(v.notes)) && search_notes == true
# found in notes
# avoid duplication
if k found
printstyled(" $(rpad(k, 20))", bold=true)
l = min(30, length(v.notes))
println(" (notes) $(v.notes[1:l])...")
counter += 1
push!(found, k)
end
end
end
counter > 0 ?
println("\n\nfound $counter result$(counter > 1 ? "s" : "") for \"$str\"") :
println("\n\nnothing found for \"$str\"")
return nothing
if counter > 0
println("\n\n ...found $counter result$(counter > 1 ? "s" : "") for \"$str\"")
else
println("\n\n ...nothing found for \"$str\"")
end
return found
end

# Interfaces
Expand Down Expand Up @@ -216,7 +250,7 @@ RGB [0.0-1.0] values. It should work with more colortypes.
# Examples
```
```julia
img = get(colorschemes[:leonardo], rand(10,10)) # displays in Juno Plots window, but
save("testoutput.png", img) # you'll need FileIO or similar to do this
Expand Down Expand Up @@ -280,7 +314,7 @@ for which `get(scheme, x)` would most closely match the provided Color `c`.
The first example asks: "where in the `leonardo` colorscheme will I find the nearest
color to red?":
```
```julia
julia> getinverse(colorschemes[:leonardo], RGB(1, 0, 0))
0.6248997995654847
Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ end
counter += 1
end
@test counter == 33

# test findcolorschemes()
@test length(findcolorscheme("rainbow")) > 0
end

# these won't error but they don't yet work correctly either
Expand Down

0 comments on commit 2052f0a

Please sign in to comment.