From d2d9f3ebf4d1eee4f20c7a74bdfc4d54f617ee9c Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Mon, 24 Jun 2024 09:17:35 -0400 Subject: [PATCH] Add definitions for expand_dimensions to the Makie extension (#747) * 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! --- ext/DimensionalDataMakie.jl | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/ext/DimensionalDataMakie.jl b/ext/DimensionalDataMakie.jl index 0e3d24a3..5544dd48 100644 --- a/ext/DimensionalDataMakie.jl +++ b/ext/DimensionalDataMakie.jl @@ -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) @@ -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))) @@ -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 @@ -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)