Mercurial > repos > public > sbplib_julia
diff ext/SbplibMakieExt.jl @ 1629:2fab141e4a9a feature/grids/plotting
Add attempt at proper makie recipes for plotting a grid.
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Mon, 24 Jun 2024 08:40:57 +0200 |
parents | 9cd2b8f81175 |
children | 27d270c9cb89 |
line wrap: on
line diff
--- a/ext/SbplibMakieExt.jl Fri Apr 26 22:19:30 2024 +0200 +++ b/ext/SbplibMakieExt.jl Mon Jun 24 08:40:57 2024 +0200 @@ -2,6 +2,7 @@ using Sbplib.Grids using Makie +using StaticArrays function verticies_and_faces_and_values(g::Grid{<:Any,2}, gf::AbstractArray{<:Any, 2}) @@ -67,5 +68,21 @@ ) end -Makie.convert_arguments(::Type{<:Scatter}, g::Grid) = (map(Tuple,collect(g)[:]),) + +Makie.convert_arguments(::Type{<:Scatter}, g::Grid) = (reshape(map(Point,g),:),) # (map(Point,collect(g)[:]),) +function Makie.convert_arguments(::Type{<:Lines}, g::Grid{<:Any,2}) + M = collect(g) + + function cat_with_NaN(a,b) + vcat(a,[@SVector[NaN,NaN]],b) + end + + xlines = reduce(cat_with_NaN, eachrow(M)) + ylines = reduce(cat_with_NaN, eachcol(M)) + + return (cat_with_NaN(xlines,ylines),) end + +Makie.plot!(plot::Plot(Grid{<:Any,2})) = lines!(plot, plot.attributes, plot[1]) +# Makie.convert_arguments(::PointBased, g::Grid) = (map(Tuple,collect(g)[:]),) +end