Skip to content

Commit

Permalink
Merge pull request #12 from jpthiele/fix-colors-piracy
Browse files Browse the repository at this point in the history
Fix colors piracy
  • Loading branch information
j-fu authored Nov 23, 2024
2 parents e4331e1 + a82bd28 commit 4187910
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 45 deletions.
3 changes: 3 additions & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
GridVisualizeTools = "5573ae12-3b76-41d9-b48c-81d0b6e61cc5"

[compat]
Colors = "0.13"
2 changes: 1 addition & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Documenter, GridVisualizeTools, ColorTypes
using Documenter, GridVisualizeTools, ColorTypes, Colors

function mkdocs()
DocMeta.setdocmeta!(GridVisualizeTools, :DocTestSetup, :(using GridVisualizeTools, ColorTypes, Colors); recursive = true)
Expand Down
22 changes: 13 additions & 9 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,26 @@ rgbtuple
rgbtuple(:red)
# output
(1.0,1.0,1.0)
(1.0,0.0,0.0)
```

```@docs
ColorTypes.RGB
rgbcolor
```

```@example
using ColorTypes,GridVisualizeTools # hide
RGB(:red)
```@jldoctest
rgbcolor(:red)
# output
RGB{Float64}(1.0,0.0,0.0)
```
```@example
using ColorTypes,GridVisualizeTools # hide
RGB("green")
```@jldoctest
rgbcolor(1.0, 0.0, 0.0)
# output
RGB{Float64}(1.0,0.0,0.0)
```


## Visibility handling of grid cells

```@docs
Expand Down
2 changes: 1 addition & 1 deletion src/GridVisualizeTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ using DocStringExtensions: SIGNATURES, TYPEDEF, TYPEDSIGNATURES
using StaticArraysCore: SVector

include("colors.jl")
export region_cmap, bregion_cmap, rgbtuple
export region_cmap, bregion_cmap, rgbtuple, rgbcolor

include("extraction.jl")
export extract_visible_cells3D, extract_visible_bfaces3D
Expand Down
82 changes: 48 additions & 34 deletions src/colors.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""
"""depend
$(SIGNATURES)
Create customized distinguishable colormap for interior regions.
Expand All @@ -16,7 +16,9 @@ RGB{Float64}(0.85, 0.6, 0.6)
"""
function region_cmap(n)
ColorSchemes.distinguishable_colors(max(5, n),
[Colors.RGB(0.85, 0.6, 0.6), Colors.RGB(0.6, 0.85, 0.6), Colors.RGB(0.6, 0.6, 0.85)];
[Colors.RGB{Float64}(0.85, 0.6, 0.6),
Colors.RGB{Float64}(0.6, 0.85, 0.6),
Colors.RGB{Float64}(0.6, 0.6, 0.85)];
lchoices = range(70; stop = 80, length = 5),
cchoices = range(25; stop = 65, length = 15),
hchoices = range(20; stop = 360, length = 15))
Expand All @@ -39,73 +41,85 @@ RGB{Float64}(1.0, 0.0, 0.0)
"""
function bregion_cmap(n)
ColorSchemes.distinguishable_colors(max(5, n),
[Colors.RGB(1.0, 0.0, 0.0), Colors.RGB(0.0, 1.0, 0.0), Colors.RGB(0.0, 0.0, 1.0)];
[Colors.RGB{Float64}(1.0, 0.0, 0.0),
Colors.RGB{Float64}(0.0, 1.0, 0.0),
Colors.RGB{Float64}(0.0, 0.0, 1.0)];
lchoices = range(50; stop = 75, length = 10),
cchoices = range(75; stop = 100, length = 10),
hchoices = range(20; stop = 360, length = 30))
end

"""
$(SIGNATURES)
Create color tuple from color description (e.g. string)
Create RGB color from color name string.
```jldoctest
julia> rgbtuple(:red)
(1.0, 0.0, 0.0)
julia> Colors.RGB("red")
RGB{Float64}(1.0,0.0,0.0)
julia> rgbtuple("red")
(1.0, 0.0, 0.0)
```
"""
function Colors.RGB(c::String)
c64 = Colors.color_names[c]
Colors.RGB(c64[1] / 255, c64[2] / 255, c64[3] / 255)
end
rgbtuple(c) = rgbtuple(parse(Colors.RGB{Float64},c))

"""
$(SIGNATURES)
Create RGB color from color name symbol.
Create color tuple from RGB color.
```jldoctest
julia> Colors.RGB(:red)
RGB{Float64}(1.0, 0.0, 0.0)
julia> rgbtuple(RGB(0.0,1,0))
(0.0, 1.0, 0.0)
```
"""
Colors.RGB(c::Symbol) = Colors.RGB(String(c))
rgbtuple(c::Colors.RGB) = (Colors.red(c), Colors.green(c), Colors.blue(c))


"""
$(SIGNATURES)
rgbcolor(col::Any)
Create RGB color from tuple
Return Colors.RGB object from string or symbol.
```jldoctest
julia> Colors.RGB((1.0,0,0))
julia> rgbcolor(:red)
RGB{Float64}(1.0, 0.0, 0.0)
julia> rgbcolor("red")
RGB{Float64}(1.0, 0.0, 0.0)
```
"""
Colors.RGB(c::Tuple) = Colors.RGB(c...)
"""
$(SIGNATURES)
rgbcolor(col::Any) = parse(Colors.RGB{Float64},col)

Create color tuple from color description (e.g. string)

```jldoctest
julia> rgbtuple(:red)
(1.0, 0.0, 0.0)
"""
rgbcolor(col::RGB)
julia> rgbtuple("red")
(1.0, 0.0, 0.0)
Pass through of RGB color object.
```jldoctest
julia> rgbcolor(RGB(1.0,0.0, 0.0))
RGB{Float64}(1.0, 0.0, 0.0)
```
"""
rgbtuple(c) = rgbtuple(Colors.RGB(c))
"""
$(SIGNATURES)
rgbcolor(col::Colors.RGB) = col

Create color tuple from RGB color.
"""
rgbcolor(col::Tuple)
Create RGB color object from tuple
```jldoctest
julia> rgbtuple(RGB(0.0,1,0))
(0.0, 1.0, 0.0)
julia> rgbcolor((1.0,0.0, 0.0))
RGB{Float64}(1.0, 0.0, 0.0)
```
"""
rgbtuple(c::Colors.RGB) = (Colors.red(c), Colors.green(c), Colors.blue(c))
function rgbcolor(col::Tuple)
# Base.depwarn(
# "Setting custom colors as `Tuple`, e.g. `color=(0.,0.,1.)` will be removed in the next major release. "*
# "Please use color=RGB(0.,0.,1.) instead.",
# :update_lines,
# )
return Colors.RGB(col...)
end

0 comments on commit 4187910

Please sign in to comment.