Skip to content

Commit

Permalink
fix type checks
Browse files Browse the repository at this point in the history
  • Loading branch information
rdboyes committed Apr 17, 2024
1 parent a27dd1d commit 622ac22
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Makie Themes:

Colour Scales:

- `scale_color_manual()` - arguments should be given directly in order, accepts anything that can be parsed as a color by Colors.jl (named colors, hex values, etc.)
- `scale_color_manual()` - set `values = c(c1, c2, c3, ...)`, accepts anything that can be parsed as a color by Colors.jl (named colors, hex values, etc.)
- `scale_color_[discrete|continuous|binned]()` - set `palette =` a [ColorSchemes.jl palette](https://juliagraphics.github.io/ColorSchemes.jl/stable/catalogue/) as a string or symbol. Also accepts ColorSchemes.jl color scheme objects.

Additional Elements:
Expand Down
2 changes: 1 addition & 1 deletion src/legend.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function build_legend(plot::GGPlot)
plot_data = isnothing(geom.data) ? plot.data : geom.data

if isnothing(palette_function)
if typeof(plot_data[!, color_colname]) <: Union{AbstractVector{String}, AbstractVector{Char}, CategoricalArray}
if eltype(plot_data[!, color_colname]) <: Union{AbstractString, AbstractChar, CategoricalValue}
plot = plot + scale_colour_manual(values = c(
RGB(0/255, 114/255, 178/255), # blue
RGB(230/255, 159/255, 0/255), # orange
Expand Down
25 changes: 6 additions & 19 deletions src/scales_colour.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function color_scale_to_ggoptions(args_dict::Dict)
function color_transform_fn(target::Symbol, source::Vector{Symbol}, data::DataFrame)
input = data[!, source[1]]

if typeof(input) <: Union{AbstractVector{String}, Vector{AbstractString}, AbstractVector{Char}, CategoricalArray}
if eltype(input) <: Union{AbstractString, AbstractChar, CategoricalValue}

cat_array = CategoricalArray(input)

Expand All @@ -102,7 +102,7 @@ function color_scale_to_ggoptions(args_dict::Dict)
nothing
)
)
elseif typeof(input) <: Union{Vector{Int}, Vector{Float64}, Vector{Float32}}
elseif eltype(input) <: Union{Integer, AbstractFloat}
return Dict{Symbol, PlottableData}(
target => PlottableData(
input,
Expand All @@ -111,23 +111,10 @@ function color_scale_to_ggoptions(args_dict::Dict)
nothing
)
)
else # try to parse whatever it is as an int, error if not successful
try
int_array = parse.(Int, input)
catch
scale = args_dict[:scale]
@error "Column is not compatible with scale: $scale"
end

return Dict{Symbol, PlottableData}(
target => PlottableData(
int_array,
x -> lookup(x),
nothing,
nothing
)
)
end
else
scale = args_dict[:scale]
throw(@error "Column is not compatible with scale: $scale")
end
end
return color_transform_fn
end
Expand Down

0 comments on commit 622ac22

Please sign in to comment.