From 667741d776c3dc8377703918ccfc46be8b15626e Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Sat, 2 Nov 2024 11:18:22 +0100 Subject: [PATCH] Scatter dimpoints (#833) * add makie plots for DimPoints * allow plot as scatter on DimPoints * Makie. --- ext/DimensionalDataMakie.jl | 11 ++++++++++- test/plotrecipes.jl | 7 +++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ext/DimensionalDataMakie.jl b/ext/DimensionalDataMakie.jl index 1c404c2ca..5824d99a0 100644 --- a/ext/DimensionalDataMakie.jl +++ b/ext/DimensionalDataMakie.jl @@ -379,6 +379,7 @@ end Makie.plottype(::AbstractDimVector) = Makie.Scatter Makie.plottype(::AbstractDimMatrix) = Makie.Heatmap Makie.plottype(::AbstractDimArray{<:Any,3}) = Makie.Volume +Makie.plottype(::DimPoints) = Makie.Scatter # TODO this needs to be added to Makie # Makie.to_endpoints(x::Tuple{Makie.Unitful.AbstractQuantity,Makie.Unitful.AbstractQuantity}) = (ustrip(x[1]), ustrip(x[2])) @@ -438,7 +439,7 @@ function Makie.convert_arguments( return xs, ys, last(Makie.convert_arguments(t, parent(A1))) end -function Makie.convert_arguments(t::Type{<: Makie.Spy}, A::AbstractDimMatrix{<: Real}) +function Makie.convert_arguments(t::Type{<:Makie.Spy}, A::AbstractDimMatrix{<:Real}) A1 = _prepare_for_makie(A) xs, ys = map(_lookup_to_interval, lookup(A1)) return xs, ys, last(Makie.convert_arguments(t, parent(A1))) @@ -473,6 +474,14 @@ function Makie.convert_arguments(t::Makie.ConversionTrait, A::AbstractDimArray{< return Makie.convert_arguments(t, parent(A)) end +function Makie.convert_arguments(t::Makie.PointBased, A::DimPoints) + return Makie.convert_arguments(t, vec(A)) +end +# This doesn't work, but it will at least give the normal Makie error +function Makie.convert_arguments(t::Makie.PointBased, A::DimPoints{<:Any,1}) + return Makie.convert_arguments(t, collect(A)) +end + @static if :expand_dimensions in names(Makie; all=true) # We also implement expand_dimensions for recognized plot traits. # These can just forward to the relevant converts. diff --git a/test/plotrecipes.jl b/test/plotrecipes.jl index 1e9bc5068..2ff63e9b6 100644 --- a/test/plotrecipes.jl +++ b/test/plotrecipes.jl @@ -405,4 +405,11 @@ end # Test that the number of axes is equal to the size of A3 in the y dimension. @test sum(x -> x isa AlgebraOfGraphics.Makie.Axis, AlgebraOfGraphics.Makie.contents(fg.figure.layout)) == size(A3, Y) end + + @testset "DimPoints" begin + DimPoints(rand(X(10), Y(1.0:0.1:2.0))) |> Makie.scatter + DimPoints(rand(X(10), Y(1.0:0.1:2.0))) |> Makie.plot + DimPoints(rand(X(10), Y(1.0:0.1:2.0), Z(10:10:40))) |> Makie.scatter + DimPoints(rand(X(10), Y(1.0:0.1:2.0), Z(10:10:40))) |> Makie.plot + end end