Skip to content

Commit

Permalink
test for geom_text and geom_label (currently an alias for text) imple…
Browse files Browse the repository at this point in the history
…mented and geom working
  • Loading branch information
rdboyes committed Mar 23, 2024
1 parent eaabd2e commit 3c7fe49
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/draw.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ function Makie.SpecApi.Axis(plot::GGPlot)
# which optional aesthetics were given?
optional_aes_given = [k for (k, v) in aes_dict if !(k in required_aes)]
visual_optional_aes = Dict{Symbol, Any}()

dont_categorize = ["text", "label"]

for a in optional_aes_given
if haskey(ggplot_to_makie_geom, a)
Expand All @@ -67,7 +69,9 @@ function Makie.SpecApi.Axis(plot::GGPlot)
aes = Symbol(a)
end

if eltype(plot_data[!, aes_dict[a]]) <: Union{AbstractString, AbstractChar}
if a in dont_categorize
column_data = String.(plot_data[!, aes_dict[a]])
elseif eltype(plot_data[!, aes_dict[a]]) <: Union{AbstractString, AbstractChar}
if haskey(plot.axis_options, "cat_inorder")
cat_column = plot_data[!, aes_dict[a]]
cat_array = CategoricalArray(cat_column,
Expand Down Expand Up @@ -113,7 +117,9 @@ function Makie.SpecApi.Axis(plot::GGPlot)

for req_aes in required_aes

if eltype(plot_data[!, aes_dict[req_aes]]) <: Union{AbstractString, AbstractChar}
if req_aes in dont_categorize
column_data = String.(plot_data[!, aes_dict[req_aes]])
elseif eltype(plot_data[!, aes_dict[req_aes]]) <: Union{AbstractString, AbstractChar}
if haskey(plot.axis_options, "cat_inorder")
cat_column = plot_data[!, aes_dict[req_aes]]
cat_array = CategoricalArray(cat_column, levels = unique(cat_column), ordered = true)
Expand All @@ -137,8 +143,6 @@ function Makie.SpecApi.Axis(plot::GGPlot)
push!(plot_list, Makie.PlotSpec(args...; kwargs...))
end

println(plot.axis_options)

# remove options from args_dict that are not meant for Makie

if haskey(plot.axis_options, "cat_inorder")
Expand Down
22 changes: 22 additions & 0 deletions test/test_geoms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -288,4 +288,26 @@
@test plot_images_equal(t, m)

end

@testset "geom_text" begin
t = ggplot(penguins) +
geom_text(aes(x = :bill_length_mm, y = :bill_depth_mm, text = :species))

m = Makie.plot(
Makie.SpecApi.GridLayout(
Makie.SpecApi.Axis(
plots = [
Makie.PlotSpec(
:Text,
penguins.bill_length_mm,
penguins.bill_depth_mm;
text = String.(penguins.species))
]
)
)
)

@test plot_images_equal(t, m)

end
end

0 comments on commit 3c7fe49

Please sign in to comment.