Skip to content

Commit

Permalink
add some offline tests for Makie
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaqz committed Sep 13, 2023
1 parent 16f86ca commit 6caba7b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 11 deletions.
20 changes: 9 additions & 11 deletions ext/DimensionalDataMakie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ for (f1, f2) in _paired(:plot => :heatmap, :heatmap, :image, :contour, :contourf
args, merged_attributes = _surface2(A, attributes, replacements)
p = Makie.$f2(args...; merged_attributes...)
# Add a Colorbar for heatmaps and contourf
if $(f1 in (:heatmap, :contourf))
if $(f1 in (:plot, :heatmap, :contourf))
Colorbar(p.figure[1, 2];
label=DD.label(A), colorbarkw...
)
Expand Down Expand Up @@ -280,17 +280,17 @@ for f in (:violin, :boxplot, :rainclouds)
@eval begin
@doc $docstring
function Makie.$f(A::AbstractDimArray{<:Any,2}; labeldim=nothing, attributes...)
args, merged_attributes = _boxplot(A, attributes, labeldim)
args, merged_attributes = _boxplotlike(A, attributes, labeldim)
return Makie.$f(args...; merged_attributes...)
end
function Makie.$f!(axis, A::AbstractDimArray{<:Any,2}; labeldim=nothing, attributes...)
args, _ = _boxplot(A, attributes, labeldim)
args, _ = _boxplotlike(A, attributes, labeldim)
return Makie.$f!(axis, args...; attributes...)
end
end
end

function _boxplot(A, attributes, labeldim)
function _boxplotlike(A, attributes, labeldim)
# Array/Dimension manipulation
categoricaldim = _categorical_or_dependent(A, labeldim)
categoricallookup = lookup(categoricaldim)
Expand Down Expand Up @@ -441,17 +441,15 @@ end
# relationship with the possible Makie.jl plot axes.
function _get_replacement_dims(A::AbstractDimArray{<:Any,N}, replacements::Tuple) where N
xyz_dims = (X(), Y(), Z())[1:N]
replacements1 = map(replacements) do d
map(replacements) do d
# Make sure replacements contain X/Y/Z only
d_dest = basedims(val(d))
d_dest in xyz_dims || throw(ArgumentError("`dims` destinations must be in $(map(basetypeof, xyz_dims))"))
rebuild(d, d_dest)
hasdim(A, d) || throw(ArgumentError("object does not have a dimension $(basetypeof(d))"))
end
# Find and sort remaining dims
source_dims_remaining = dims(otherdims(A, replacements1), DD.PLOT_DIMENSION_ORDER)
xyz_remaining = otherdims(xyz_dims, map(val, replacements1))[1:length(source_dims_remaining)]
source_dims_remaining = dims(otherdims(A, replacements), DD.PLOT_DIMENSION_ORDER)
xyz_remaining = otherdims(xyz_dims, map(val, replacements))[1:length(source_dims_remaining)]
other_replacements = map(rebuild, source_dims_remaining, xyz_remaining)
return (replacements1..., other_replacements...)
return (replacements..., other_replacements...)
end

# Get all lookups in ascending/forward order
Expand Down
38 changes: 38 additions & 0 deletions test/plotrecipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,41 @@ nothing
# im2 = RGB24.(rand(10, 10))
# da_im2 = DimArray(im2, (X(10:10:100), Y(10:10:100)), "Image")
# da_im2 |> plot

if !haskey(ENV, "CI")
using GLMakie
# 1d
A1 = rand(X('a':'e'); name=:test)
plot(A1)
scatter(A1)
lines(A1)
scatterlines(A1)
stairs(A1)
stem(A1)
barplot(A1)
waterfall(A1)
# 2d
A2 = rand(X(10:10:100), Y(['a', 'b', 'c']))
A2r = rand(Y(10:10:100), X(['a', 'b', 'c']))
plot(A2)
# Categorical wins: it's on x, even though its Y
boxplot(A2)
boxplot(A2r)
violin(A2)
rainclouds(A2)
# Series also puts Categories in the legend no matter where they are
series(A2)
series(A2r)
# x/y can be specified
A2 = DimArray(rand(10, 10), (:a, :b); name=:stuff)
plot(A2)
contourf(A2; x=:a)
heatmap(A2; y=:b)
@test_throws ArgumentError plot(A2; y=:c)
# 3d
A3 = rand(X(7), Z(10), Y(5))
volume(A3)
A3 = DimArray(rand(10, 10, 5), (:a, :b, :c); name=:stuff)
volume(A3)
volumeslices(A3)
end

0 comments on commit 6caba7b

Please sign in to comment.