JuliaGraphics / ColorSchemes.jl

colorschemes, colormaps, gradients, and palettes
http://juliagraphics.github.io/ColorSchemes.jl/
Other
187 stars 34 forks source link

Iterating over a ColorScheme creates unexpected results #63

Closed lhupe closed 3 years ago

lhupe commented 3 years ago

Hi,

I needed to iterate over a color scheme object in order to perform an operation for every color, when I noticed this strange behaviour

julia> [c for c ∈ ColorSchemes.Dark2_3]
3-element Array{Any,1}:
 ColorTypes.RGB{Float64}[RGB{Float64}(0.106,0.62,0.467), RGB{Float64}(0.851,0.373,0.008), RGB{Float64}(0.459,0.439,0.702)]
 RGB{Float64}(0.106,0.62,0.467)
 RGB{Float64}(0.851,0.373,0.008)

the first entry is an array containg all three colors of the color scheme, the second and third entry are the first and second color respectively.

lhupe commented 3 years ago

For the record: this

julia> [c for c ∈ ColorSchemes.Dark2_3[1:3]]
3-element Array{RGB{Float64},1} with eltype ColorTypes.RGB{Float64}:
 RGB{Float64}(0.106,0.62,0.467)
 RGB{Float64}(0.851,0.373,0.008)
 RGB{Float64}(0.459,0.439,0.702)

works fine

cormullion commented 3 years ago

Hi! Yes, I don't think there's an iterable interface to a colorscheme. You'd probably do:

[c for c ∈ ColorSchemes.Dark2_3.colors]

to run over the colors...

I don't know whether to add an iterable interface...

lhupe commented 3 years ago

If you decide not to, it would be nice to disable the broken iteration behaviour altogether (i.e. overwriting iterate with something that throws an error), so users don't get tricked by the fact that all the functions appear to work (unless you actually take a look at the output, that is…)

cormullion commented 3 years ago

Hopefully fixed in ece0ffefdc709be68ab103cac9cb2cce6d7c2cd5