comparison 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
comparison
equal deleted inserted replaced
1628:9cd2b8f81175 1629:2fab141e4a9a
1 module SbplibMakieExt 1 module SbplibMakieExt
2 2
3 using Sbplib.Grids 3 using Sbplib.Grids
4 using Makie 4 using Makie
5 using StaticArrays
5 6
6 7
7 function verticies_and_faces_and_values(g::Grid{<:Any,2}, gf::AbstractArray{<:Any, 2}) 8 function verticies_and_faces_and_values(g::Grid{<:Any,2}, gf::AbstractArray{<:Any, 2})
8 ps = map(Tuple, g)[:] 9 ps = map(Tuple, g)[:]
9 values = gf[:] 10 values = gf[:]
65 mesh!(plot, v, f, color=c, 66 mesh!(plot, v, f, color=c,
66 shading = NoShading, 67 shading = NoShading,
67 ) 68 )
68 end 69 end
69 70
70 Makie.convert_arguments(::Type{<:Scatter}, g::Grid) = (map(Tuple,collect(g)[:]),) 71
72 Makie.convert_arguments(::Type{<:Scatter}, g::Grid) = (reshape(map(Point,g),:),) # (map(Point,collect(g)[:]),)
73 function Makie.convert_arguments(::Type{<:Lines}, g::Grid{<:Any,2})
74 M = collect(g)
75
76 function cat_with_NaN(a,b)
77 vcat(a,[@SVector[NaN,NaN]],b)
78 end
79
80 xlines = reduce(cat_with_NaN, eachrow(M))
81 ylines = reduce(cat_with_NaN, eachcol(M))
82
83 return (cat_with_NaN(xlines,ylines),)
71 end 84 end
85
86 Makie.plot!(plot::Plot(Grid{<:Any,2})) = lines!(plot, plot.attributes, plot[1])
87 # Makie.convert_arguments(::PointBased, g::Grid) = (map(Tuple,collect(g)[:]),)
88 end