# Makie \`convert\_arguments\`

**URL:** <https://discourse.julialang.org/t/makie-convert-arguments/71270>\
**Category:** General Usage\
**Tags:** makie\
**Created:** [November 10, 2021, 5:16pm UTC](https://discourse.julialang.org/t/makie-convert-arguments/71270 "2021-11-10T17:16:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![circonflexe](https://avatars.discourse-cdn.com/v4/letter/c/c57346/32.png) [@circonflexe](https://discourse.julialang.org/u/circonflexe)\
**Post date:** [November 10, 2021, 5:16pm UTC](https://discourse.julialang.org/t/makie-convert-arguments/71270/1 "2021-11-10T17:16:10Z")

</div>

So I am trying to extend Makie plotting to some types of my own. According to the (very terse) [online documentation](http://juliaplots.org/MakieGallery.jl/dev/recipes.html) it is sufficient to define a new method for `convert_arguments`:

```julia
using GLMakie
using StaticArrays

struct Foo; end

v = SVector{2, Float64}[[0,0],[1,0],[0,1]]
f = [1 2 3]

# let's define both methods just to be sure
Makie.convert_arguments(::Type{<:Makie.Mesh},::Foo) = (v,f,)
Makie.convert_arguments(::Foo) = (v,f,)

mesh(convert_arguments(Mesh, Foo())...) # works fine
mesh(Foo()) # should this not be equivalent to the above?

```

throws the following:

```julia
ERROR: MethodError: no method matching isfinite(::SVector{2, Float64})
Closest candidates are:
  isfinite(::Integer) at float.jl:454
  isfinite(::Complex) at complex.jl:135
  isfinite(::Missing) at missing.jl:101
  ...
Stacktrace:
  [1] (::StaticArrays.var"#315#316"{typeof(isfinite)})(x::SVector{2, Float64})
    @ StaticArrays ~/.julia/packages/StaticArrays/OWJK7/src/mapreduce.jl:262
  [2] macro expansion
    @ ~/.julia/packages/StaticArrays/OWJK7/src/mapreduce.jl:140 [inlined]
  [3] _mapfoldl
    @ ~/.julia/packages/StaticArrays/OWJK7/src/mapreduce.jl:115 [inlined]
  [4] _mapreduce
    @ ~/.julia/packages/StaticArrays/OWJK7/src/mapreduce.jl:113 [inlined]
  [5] #all#314
    @ ~/.julia/packages/StaticArrays/OWJK7/src/mapreduce.jl:262 [inlined]
  [6] all
    @ ~/.julia/packages/StaticArrays/OWJK7/src/mapreduce.jl:262 [inlined]
  [7] _isfinite(x::Point3{Any})
    @ Makie ~/.julia/packages/Makie/Riyar/src/layouting/data_limits.jl:29
  [8] extrema_nan(itr::Base.Generator{Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{2}, Nothing, Type{Point3{T} where T}, Tuple{Vector{SVector{2, Float64}}, Matrix{Int64}, Int64}}, Makie.var"#606#607"{typeof(identity)}})
    @ Makie ~/.julia/packages/Makie/Riyar/src/layouting/data_limits.jl:44
  [9] xyz_boundingbox(transform_func::Function, xyz::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{2}, Nothing, Type{Point3{T} where T}, Tuple{Vector{SVector{2, Float64}}, Matrix{Int64}, Int64}})
    @ Makie ~/.julia/packages/Makie/Riyar/src/layouting/data_limits.jl:65
 [10] xyz_boundingbox
    @ ~/.julia/packages/Makie/Riyar/src/layouting/data_limits.jl:81 [inlined]
 [11] xyz_boundingbox(transform_func::Function, x::Vector{SVector{2, Float64}}, y::Matrix{Int64})
    @ Makie ~/.julia/packages/Makie/Riyar/src/layouting/data_limits.jl:80
 [12] atomic_limits(x::Mesh{Tuple{Vector{SVector{2, Float64}}, Matrix{Int64}}})
    @ Makie ~/.julia/packages/Makie/Riyar/src/layouting/data_limits.jl:25
 [13] data_limits
    @ ~/.julia/packages/Makie/Riyar/src/layouting/data_limits.jl:9 [inlined]
 [14] push!(scene::Scene, plot::Mesh{Tuple{Vector{SVector{2, Float64}}, Matrix{Int64}}})
    @ Makie ~/.julia/packages/Makie/Riyar/src/scenes.jl:354
 [15] plot!(scene::Scene, P::Type{Mesh{Tuple{Foo}}}, attributes::Attributes, input::Tuple{Observable{Foo}}, args::Observable{Tuple{Vector{SVector{2, Float64}}, Matrix{Int64}}})
    @ Makie ~/.julia/packages/Makie/Riyar/src/interfaces.jl:478
 [16] plot!(scene::Scene, P::Type{Mesh{ArgType} where ArgType}, attributes::Attributes, args::Foo; kw_attributes::Base.Iterators.Pairs{Symbol, Bool, Tuple{Symbol}, NamedTuple{(:show_axis,), Tuple{Bool}}})
    @ Makie ~/.julia/packages/Makie/Riyar/src/interfaces.jl:387
 [17] plot(P::Type{Mesh{ArgType} where ArgType}, args::Foo; axis::NamedTuple{(), Tuple{}}, figure::NamedTuple{(), Tuple{}}, kw_attributes::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Makie ~/.julia/packages/Makie/Riyar/src/figureplotting.jl:28
 [18] plot
    @ ~/.julia/packages/Makie/Riyar/src/figureplotting.jl:18 [inlined]
 [19] #mesh#37
    @ ~/.julia/packages/MakieCore/S8PkO/src/recipes.jl:31 [inlined]
 [20] mesh(args::Foo)
    @ MakieCore ~/.julia/packages/MakieCore/S8PkO/src/recipes.jl:31
 [21] top-level scope
    @ REPL[20]:1

```

I read [a recent question on the same topic](https://discourse.julialang.org/t/makie-convert-arguments-example/70823) but my case is even simpler and that question did not help.

---

<div class="post-metadata">

**Author:** ![ffreyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffreyer/32/21569_2.png) [@ffreyer](https://discourse.julialang.org/u/ffreyer)\
**Post date:** [November 10, 2021, 6:39pm UTC](https://discourse.julialang.org/t/makie-convert-arguments/71270/2 "2021-11-10T18:39:30Z")

</div>

> I read [a recent question on the same topic](https://discourse.julialang.org/t/makie-convert-arguments-example/70823) but my case is even simpler and that question did not help.

The solution is the same though, either call `convert_arguments` on the output or convert to a `GeometryBasics.Mesh` which is the final output `Makie.mesh` expects.

---

<div class="post-metadata">

**Author:** ![circonflexe](https://avatars.discourse-cdn.com/v4/letter/c/c57346/32.png) [@circonflexe](https://discourse.julialang.org/u/circonflexe)\
**Post date:** [November 10, 2021, 7:22pm UTC](https://discourse.julialang.org/t/makie-convert-arguments/71270/3 "2021-11-10T19:22:33Z")

</div>

> The solution is the same though, either call `convert_arguments` on the output

This is among the things I tried:

```julia
Makie.convert_arguments(T::Type{<:Makie.Mesh},::Foo) =
  convert_arguments(T, (v,f,))

```

This produces the same error as the previous attempt.

> or convert to a `GeometryBasics.Mesh` which is the final output `Makie.mesh` expects.

Is this (and the similar behaviour for `PointBased`) documented anywhere?

---

<div class="post-metadata">

**Author:** ![ffreyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffreyer/32/21569_2.png) [@ffreyer](https://discourse.julialang.org/u/ffreyer)\
**Post date:** [November 10, 2021, 7:36pm UTC](https://discourse.julialang.org/t/makie-convert-arguments/71270/4 "2021-11-10T19:36:45Z")

</div>

Maybe it needs to be `Makie.convert_arguments` in the function?

> Is this (and the similar behaviour for PointBased) documented anywhere?

Not that I know of. I think the idea is that you chain another `convert_arguments`. With that you should be able to use most signatures. If you want to figure out the final type you could check [conversions.jl](https://github.com/JuliaPlots/Makie.jl/blob/befc016aa974ad06b178e02e3d29f0b751558f54/src/conversions.jl).

---

<div class="post-metadata">

**Author:** ![circonflexe](https://avatars.discourse-cdn.com/v4/letter/c/c57346/32.png) [@circonflexe](https://discourse.julialang.org/u/circonflexe)\
**Post date:** [November 10, 2021, 10:46pm UTC](https://discourse.julialang.org/t/makie-convert-arguments/71270/5 "2021-11-10T22:46:21Z")

</div>

Ooooh, I found it! I put an extra `Tuple` in there; it should have been: `convert_arguments(T, v, f)`
