Skip to content

Commit

Permalink
Scatter dimpoints (#833)
Browse files Browse the repository at this point in the history
* add makie plots for DimPoints

* allow plot as scatter on DimPoints

* Makie.
  • Loading branch information
rafaqz authored Nov 2, 2024
1 parent 55c765c commit 667741d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
11 changes: 10 additions & 1 deletion ext/DimensionalDataMakie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions test/plotrecipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 667741d

Please sign in to comment.