Skip to content

Commit

Permalink
Respect axis = (; type = ...) when type is a LScene (#855)
Browse files Browse the repository at this point in the history
* Respect `axis = (; type = ...)` when type is a LScene

Previously not respected.

* Update DimensionalDataMakie.jl

* Fix tests
  • Loading branch information
asinghvi17 authored Nov 12, 2024
1 parent fa1f52d commit f4d73f3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
22 changes: 15 additions & 7 deletions ext/DimensionalDataMakie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,26 @@ for (f1, f2) in _paired(:plot => :heatmap, :heatmap, :image, :contour, :contourf

axis_kw, figure_kw = _handle_axis_figure_attrs(merged_attributes, axis, figure)

axis_type = if haskey(axis, :type)
to_value(axis.type)
axis_type = if haskey(axis_kw, :type)
to_value(axis_kw[:type])
else
Makie.args_preferred_axis(Makie.Plot{$f2}, args...)
end

p = if axis_type isa Type && axis_type <: Union{LScene, Makie.PolarAxis}
# surface is an LScene so we cant pass attributes
p = Makie.$f2(args...; figure = figure_kw, attributes...)
p = if axis_type isa Type && axis_type <: Union{Makie.LScene, Makie.PolarAxis}
# LScene can only take a limited set of attributes
# so we extract those that can be passed.
# TODO: do the same for polaraxis,
# or filter out shared attributes from axis_kw somehow.
lscene_attrs = Dict{Symbol, Any}()
lscene_attrs[:type] = axis_type
haskey(axis_kw, :scenekw) && (lscene_attrs[:scenekw] = axis_kw[:scenekw])
haskey(axis_kw, :show_axis) && (lscene_attrs[:show_axis] = axis_kw[:show_axis])
# surface is an LScene so we cant pass some axis attributes
p = Makie.$f2(args...; figure = figure_kw, axis = lscene_attrs, merged_attributes...)
# And instead set axisnames manually
if p.axis isa LScene && !isnothing(p.axis.scene[OldAxis])
p.axis.scene[OldAxis][:names, :axisnames] = map(DD.label, DD.dims(A2))
if p.axis isa Makie.LScene && !isnothing(p.axis.scene[Makie.OldAxis])
p.axis.scene[Makie.OldAxis][:names, :axisnames] = map(DD.label, DD.dims(A2))
end
p
else # axis_type isa Nothing, axis_type isa Makie.Axis or GeoAxis or similar
Expand Down
6 changes: 6 additions & 0 deletions test/plotrecipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,12 @@ end
# fig, ax, _ = M.volumeslices(A3abc; x=:c)
# fig, ax, _ = M.volumeslices(A3abc; z=:a)
# M.volumeslices!(ax, A3abc;z=:a)

@testset "LScene support" begin
f, a, p = M.heatmap(A2ab; axis = (; type = M.LScene, show_axis = false))
@test a isa M.LScene
@test isnothing(a.scene[M.OldAxis])
end
end

@testset "AlgebraOfGraphics" begin
Expand Down

0 comments on commit f4d73f3

Please sign in to comment.