Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add recipe for Vec #695

Merged
merged 2 commits into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ext/MeshesMakieExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
# choose between 2D and 3D axis
Makie.args_preferred_axis(::Geometry{Dim}) where {Dim} = Dim === 3 ? Makie.LScene : Makie.Axis
Makie.args_preferred_axis(::Domain{Dim}) where {Dim} = Dim === 3 ? Makie.LScene : Makie.Axis
Makie.args_preferred_axis(::AbstractVector{<:Vec{Dim}}) where {Dim} = Dim === 3 ? Makie.LScene : Makie.Axis

Check warning on line 33 in ext/MeshesMakieExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/MeshesMakieExt.jl#L33

Added line #L33 was not covered by tests

# color handling
include("colors.jl")
Expand All @@ -42,6 +43,7 @@
include("simplemesh.jl")
include("subcartesiangrid.jl")
include("geometryset.jl")
include("vector.jl")
include("fallbacks.jl")

end
4 changes: 4 additions & 0 deletions ext/fallbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@

Makie.plottype(::Geometry) = Viz{<:Tuple{Geometry}}
Makie.plottype(::Domain) = Viz{<:Tuple{Domain}}
Makie.plottype(::Vec) = Viz{<:Tuple{Vec}}
Makie.plottype(::AbstractVector{<:Vec}) = Viz{<:Tuple{AbstractVector{<:Vec}}}

Check warning on line 8 in ext/fallbacks.jl

View check run for this annotation

Codecov / codecov/patch

ext/fallbacks.jl#L7-L8

Added lines #L7 - L8 were not covered by tests

Makie.convert_arguments(::Type{<:Viz}, geom::Geometry) = (GeometrySet([geom]),)
Makie.convert_arguments(::Type{<:Viz}, domain::Domain) = (GeometrySet(collect(domain)),)
Makie.convert_arguments(::Type{<:Viz}, mesh::Mesh) = (convert(SimpleMesh, mesh),)
Makie.convert_arguments(::Type{<:Viz}, vec::Vec) = ([vec],)

Check warning on line 13 in ext/fallbacks.jl

View check run for this annotation

Codecov / codecov/patch

ext/fallbacks.jl#L13

Added line #L13 was not covered by tests

# skip conversion for these types
Makie.convert_arguments(::Type{<:Viz}, gset::GeometrySet) = (gset,)
Makie.convert_arguments(::Type{<:Viz}, mesh::SimpleMesh) = (mesh,)
Makie.convert_arguments(::Type{<:Viz}, grid::Grid) = (grid,)
Makie.convert_arguments(::Type{<:Viz}, grid::SubCartesianGrid) = (grid,)
Makie.convert_arguments(::Type{<:Viz}, vecs::AbstractVector{<:Vec}) = (vecs,)

Check warning on line 20 in ext/fallbacks.jl

View check run for this annotation

Codecov / codecov/patch

ext/fallbacks.jl#L20

Added line #L20 was not covered by tests

# vector of geometries for convenience
Makie.plottype(::AbstractVector{<:Geometry}) = Viz{<:Tuple{AbstractVector{<:Geometry}}}
Expand Down
22 changes: 22 additions & 0 deletions ext/vector.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# ------------------------------------------------------------------
# Licensed under the MIT License. See LICENSE in the project root.
# ------------------------------------------------------------------

function Makie.plot!(plot::Viz{<:Tuple{AbstractVector{Vec{Dim,T}}}}) where {Dim,T}
vecs = plot[:object]
color = plot[:color]
alpha = plot[:alpha]
colorscheme = plot[:colorscheme]

Check warning on line 9 in ext/vector.jl

View check run for this annotation

Codecov / codecov/patch

ext/vector.jl#L5-L9

Added lines #L5 - L9 were not covered by tests

if Dim ∉ (2, 3)
error("not implemented")

Check warning on line 12 in ext/vector.jl

View check run for this annotation

Codecov / codecov/patch

ext/vector.jl#L11-L12

Added lines #L11 - L12 were not covered by tests
end

# process color spec into colorant
colorant = Makie.@lift process($color, $colorscheme, $alpha)

Check warning on line 16 in ext/vector.jl

View check run for this annotation

Codecov / codecov/patch

ext/vector.jl#L16

Added line #L16 was not covered by tests

# visualize as built-in arrows
origins = Makie.@lift fill(zero(Makie.Point{Dim,T}), length($vecs))
directions = Makie.@lift asmakie.($vecs)
Makie.arrows!(plot, origins, directions, color=colorant)

Check warning on line 21 in ext/vector.jl

View check run for this annotation

Codecov / codecov/patch

ext/vector.jl#L19-L21

Added lines #L19 - L21 were not covered by tests
end