Skip to content

Commit

Permalink
Add definitions for expand_dimensions to the Makie extension (#747)
Browse files Browse the repository at this point in the history
* Add definitions for `expand_dimensions` to the Makie extension

* Coerce real values to f64 not f32

* AbstractMatrix -> AbstractDimMatrix

Arrr, gather 'round, ye scurvy dogs, and listen well! The infamous AbstractMatrix band o' pirates, scourge o' the high seas, met their end not by the hand o' the navy, but by those meddlin' kids! Aye, it be true! Just as they were about to loot a treasure-laden galleon, them pesky young'uns swooped in with their clever tricks and caught the lot o' them red-handed. Now, the once-feared AbstractMatrix pirates be languishin' in the brig, their days o' plunderin' and pillagin' naught but a distant memory. Yarrr!
  • Loading branch information
asinghvi17 committed Jun 24, 2024
1 parent 58dedd6 commit d2d9f3e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions ext/DimensionalDataMakie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ for (f1, f2) in _paired(:plot => :heatmap, :heatmap, :image, :contour, :contourf
end
return p
end
function Makie.$f1!(axis, A::AbstractMatrix;
function Makie.$f1!(axis, A::AbstractDimMatrix;
x=nothing, y=nothing, colorbarkw=(;), attributes...
)
replacements = _keywords2dimpairs(x, y)
Expand Down Expand Up @@ -350,7 +350,7 @@ Makie.plottype(A::AbstractDimMatrix) = Makie.Heatmap
Makie.plottype(A::AbstractDimArray{<:Any,3}) = Makie.Volume

# Conversions
function Makie.convert_arguments(t::Type{<:Makie.AbstractPlot}, A::AbstractMatrix)
function Makie.convert_arguments(t::Type{<:Makie.AbstractPlot}, A::AbstractDimMatrix)
A1 = _prepare_for_makie(A)
xs, ys = map(parent, lookup(A1))
return xs, ys, last(Makie.convert_arguments(t, parent(A1)))
Expand Down Expand Up @@ -388,6 +388,13 @@ function Makie.convert_arguments(t::Makie.ConversionTrait, A::AbstractDimArray{<
return Makie.convert_arguments(t, parent(A))
end

# We also implement expand_dimensions for recognized plot traits.
# These can just forward to the relevant converts.
Makie.expand_dimensions(t::Makie.PointBased, A::AbstractDimVector) = Makie.convert_arguments(t, A)
Makie.expand_dimensions(t::Makie.PointBased, A::AbstractDimMatrix) = Makie.convert_arguments(t, A)
Makie.expand_dimensions(t::SurfaceLikeCompat, A::AbstractDimMatrix) = Makie.convert_arguments(t, A)
Makie.expand_dimensions(t::Makie.CellGrid, A::AbstractDimMatrix) = Makie.convert_arguments(t, A)
Makie.expand_dimensions(t::Makie.VolumeLike, A::AbstractDimArray{<:Any,3}) = Makie.convert_arguments(t, A)

# Utility methods

Expand Down Expand Up @@ -503,7 +510,7 @@ function _keywords2dimpairs(x, y)
end
end

_floatornan(A::AbstractArray{<:Union{Missing,<:Real}}) = _floatornan32.(A)
_floatornan(A::AbstractArray{<:Union{Missing,<:Real}}) = _floatornan64.(A)
_floatornan(A::AbstractArray{<:Union{Missing,Float64}}) = _floatornan64.(A)
_floatornan(A) = A
_floatornan32(x) = ismissing(x) ? NaN32 : Float32(x)
Expand Down

0 comments on commit d2d9f3e

Please sign in to comment.