`Makie.convert_arguments` example

I found this https://makie.juliaplots.org/stable/documentation/recipes/ but I’m not able to able to follow it to be honest.

For example, let’s have a struct

struct A
    val::Float32
end

which I want to plot by

using CairoMakie
y = [A(convert(Float32, i^2) for i in 1:20);]
lines(y)

I tried

get(a::A) = a.x
Makie.convert_arguments(P::PointBased, a::Vector{A}) = (Float32.(get.(a)),)

but I get an error

MethodError: no method matching to_ndim(::Type{GeometryBasics.Vec{3, Float32}}, ::Float32, ::Int64)

Closest candidates are:

to_ndim(::Type{var"#s12"} where var"#s12"<:Union{Tuple{Vararg{ET, N}}, StaticArrays.StaticVector{N, ET}}, !Matched::Union{Tuple{Vararg{T, N2}}, StaticArrays.StaticVector{N2, T}} where T, ::Any) where {N, ET, N2} at /home/christian/.julia/packages/Makie/gQOQF/src/utilities/utilities.jl:203

    1. xyz_boundingbox(::Function, ::Vector{Float32})@data_limits.jl:67
    2. atomic_limits(::MakieCore.Lines{Tuple{Vector{Float32}}})@data_limits.jl:17
    3. data_limits@data_limits.jl:9[inlined]
    4. push!(::Makie.Scene, ::MakieCore.Lines{Tuple{Vector{Float32}}})@scenes.jl:364
    5. plot!(::Makie.Scene, ::Type{MakieCore.Lines{Tuple{Vector{Main.workspace#8.A}}}}, ::MakieCore.Attributes, ::Tuple{Observables.Observable{Vector{Main.workspace#8.A}}}, ::Observables.Observable{Tuple{Vector{Float32}}})@interfaces.jl:430
    6. var"#plot!#159"(::Base.Iterators.Pairs{Symbol, Bool, Tuple{Symbol}, NamedTuple{(:show_axis,), Tuple{Bool}}}, ::typeof(MakieCore.plot!), ::Makie.Scene, ::Type{MakieCore.Lines{ArgType} where ArgType}, ::MakieCore.Attributes, ::Vector{Main.workspace#8.A})@interfaces.jl:339
    7. var"#plot#948"(::NamedTuple{(), Tuple{}}, ::NamedTuple{(), Tuple{}}, ::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, ::typeof(MakieCore.plot), ::Type{MakieCore.Lines{ArgType} where ArgType}, ::Vector{Main.workspace#8.A})@figureplotting.jl:28
    8. plot@figureplotting.jl:18[inlined]
    9. #lines#29@recipes.jl:31[inlined]
   10. lines(::Vector{Main.workspace#8.A})@recipes.jl:31
   11. top-level scope@Local: 1[inlined]

I think PointBased needs to get to Tuple{Vector{Point{D, Float32}}}. So either you convert to that directly or you continue the pipeline with

Makie.convert_arguments(P::PointBased, a::Vector{A}) = convert_arguments(P, get.(a))

thanks!

And how does it work with Makie.convert_single_argument?

Makie.convert_single_argument(a::Vector{A}) = Float32.(get.(a))
lines(y)

yields

MethodError: no method matching to_ndim(::Type{GeometryBasics.Vec{3, Float32}}, ::Float32, ::Int64)

Closest candidates are:

to_ndim(::Type{var"#s12"} where var"#s12"<:Union{Tuple{Vararg{ET, N}}, StaticArrays.StaticVector{N, ET}}, !Matched::Union{Tuple{Vararg{T, N2}}, StaticArrays.StaticVector{N2, T}} where T, ::Any) where {N, ET, N2} at /home/christian/.julia/packages/Makie/gQOQF/src/utilities/utilities.jl:203

    1. xyz_boundingbox(::Function, ::Vector{Float32})@data_limits.jl:67
    2. atomic_limits(::MakieCore.Lines{Tuple{Vector{Float32}}})@data_limits.jl:17
    3. data_limits@data_limits.jl:9[inlined]
    4. push!(::Makie.Scene, ::MakieCore.Lines{Tuple{Vector{Float32}}})@scenes.jl:364
    5. plot!(::Makie.Scene, ::Type{MakieCore.Lines{Tuple{Vector{Main.workspace#8.A}}}}, ::MakieCore.Attributes, ::Tuple{Observables.Observable{Vector{Main.workspace#8.A}}}, ::Observables.Observable{Tuple{Vector{Float32}}})@interfaces.jl:430
    6. var"#plot!#159"(::Base.Iterators.Pairs{Symbol, Bool, Tuple{Symbol}, NamedTuple{(:show_axis,), Tuple{Bool}}}, ::typeof(MakieCore.plot!), ::Makie.Scene, ::Type{MakieCore.Lines{ArgType} where ArgType}, ::MakieCore.Attributes, ::Vector{Main.workspace#8.A})@interfaces.jl:339
    7. var"#plot#948"(::NamedTuple{(), Tuple{}}, ::NamedTuple{(), Tuple{}}, ::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, ::typeof(MakieCore.plot), ::Type{MakieCore.Lines{ArgType} where ArgType}, ::Vector{Main.workspace#8.A})@figureplotting.jl:28
    8. plot@figureplotting.jl:18[inlined]
    9. #lines#29@recipes.jl:31[inlined]
   10. lines@recipes.jl:31[inlined]
   11. top-level scope@Local: 1[inlined]