Skip to content

Commit

Permalink
Fix the implementation of color mapping for categorical values (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
eliascarv authored Apr 8, 2024
1 parent 0e2269d commit 8b9dbb2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ext/ColorfyCategoricalArraysExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function Colorfy.getcolors(colorfier::Colorfier{<:Values{CategoricalValue}})
values = Colorfy.values(colorfier)
colorscheme = Colorfy.colorscheme(colorfier)
nlevels = length(levels(values))
categcolors = colorscheme[range(0, 1, length=nlevels)]
categcolors = colorscheme[range(0, nlevels > 1 ? 1 : 0, length=nlevels)]
categcolors[levelcode.(values)]
end

Expand Down
6 changes: 6 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ using Test
colors = categcolors[[2, 1, 1, 3, 1, 3, 3, 2, 1, 2]]
@test colorfy(values) == coloralpha.(colors, 1)
@test colorfy(values, alphas=0.5) == coloralpha.(colors, 0.5)

values = categorical([1, 1, 1, 1, 1], levels=[1])
categcolors = colorschemes[:viridis][range(0, 0, length=1)]
colors = categcolors[[1, 1, 1, 1, 1]]
@test colorfy(values) == coloralpha.(colors, 1)
@test colorfy(values, alphas=0.5) == coloralpha.(colors, 0.5)
end

@testset "Distributions" begin
Expand Down

0 comments on commit 8b9dbb2

Please sign in to comment.