Skip to content

Commit

Permalink
Merge pull request #73 from ovanvincq/master
Browse files Browse the repository at this point in the history
Compatibility with Makie 0.21
  • Loading branch information
JordiManyer authored Sep 6, 2024
2 parents 9c5ba53 + 092137f commit e79375e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 33 deletions.
10 changes: 4 additions & 6 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ authors = ["Alberto F. Martín <[email protected]>", "Eric Neiva <enei
version = "0.1.3"

[deps]
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
Expand All @@ -13,13 +12,12 @@ Gridap = "56d4f2e9-7ea1-5844-9cf6-b9c51ca7ce8e"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"

[compat]
CairoMakie = "0.5, 0.6, 0.8"
FileIO = "1"
FillArrays = "0.11, 0.12, 0.13, 1"
GLMakie = "0.3, 0.4, 0.6"
FillArrays = "1"
GLMakie = "0.10"
GeometryBasics = "0.3, 0.4"
Gridap = "0.16, 0.17, 0.18"
Makie = "0.13, 0.15, 0.17"
Gridap = "0.16, 0.17,0.18"
Makie = "0.21"
julia = "1.6"

[extras]
Expand Down
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Therefore, we may as well visualize such mesh
model = DiscreteModelFromFile("models/model.json")
Ω = Triangulation(model)
∂Ω = BoundaryTriangulation(model)
fig = plot, shading=true)
fig = plot(Ω)
wireframe!(∂Ω, color=:black)
save("images/3d_Fig1.png", fig)
````
Expand All @@ -146,7 +146,7 @@ save("images/3d_Fig1.png", fig)

````julia
v(x) = sin*(x[1]+x[2]+x[3]))
fig, ax, plt = plot(Ω, v, shading=true)
fig, ax, plt = plot(Ω, v)
Colorbar(fig[1,2], plt)
save("images/3d_Fig2.png", fig)
````
Expand All @@ -159,7 +159,7 @@ we can even plot functions in certain subdomains, e.g.

````julia
Γ = BoundaryTriangulation(model, tags=["square", "triangle", "circle"])
fig = plot(Γ, v, colormap=:rainbow, shading=true)
fig = plot(Γ, v, colormap=:rainbow)
wireframe!(∂Ω, linewidth=0.5, color=:gray)
save("images/3d_Fig3.png", fig)
````
Expand All @@ -178,7 +178,7 @@ t = Observable(0.0)
u = lift(t) do t
x->sin*(x[1]+x[2]+x[3]))*cos*t)
end
fig = plot(Ω, u, colormap=:rainbow, shading=true, colorrange=(-1,1))
fig = plot(Ω, u, colormap=:rainbow, colorrange=(-1,1))
wireframe!(∂Ω, color=:black, linewidth=0.5)
framerate = 30
timestamps = range(0, 2, step=1/framerate)
Expand All @@ -194,4 +194,3 @@ end
---

*This page was generated using [Literate.jl](https://github.com/fredrikekre/Literate.jl).*

42 changes: 22 additions & 20 deletions src/recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,24 @@ end
mesh_theme = Makie.Theme(
color = :pink,
colormap = :bluesreds,
shading = false,
shading = Makie.NoShading,
cycle = nothing
)

# By merging the default theme for the Mesh type and some attributes whose values we want to impose from mesh_theme
# (in this case: color, colormap, etc.), we may override the current default theme and use our settings.
# Note: Makie.Theme() returns an Attributes type.
function Makie.default_theme(scene,::Type{<:Makie.Mesh{<:Tuple{PlotGrid}}})
@Makie.recipe(PlotGridMesh) do scene
merge!(
mesh_theme,
Makie.default_theme(scene, Makie.Mesh)
)
end


# The lift function is necessary when dealing with reactive attributes or Observables.
function Makie.plot!(plot::Makie.Mesh{<:Tuple{PlotGrid}})
#function Makie.plot!(plot::Makie.Mesh{<:Tuple{PlotGrid}})
function Makie.plot!(plot::PlotGridMesh{<:Tuple{PlotGrid}})
grid = Makie.lift(get_grid, plot[1])
D = num_cell_dims(grid[])
if D in (0,1,2)
Expand All @@ -66,20 +68,17 @@ function Makie.plot!(plot::Makie.Mesh{<:Tuple{PlotGrid}})
# plot.attributes.attributes returns a Dict{Symbol, Observable} to be called by any function.
# plot.attributes returns an Attributes type.
if D in (2,3)
Makie.mesh!(plot, mesh;
plot.attributes.attributes...,
color = color,
)
valid_attributes = Makie.shared_attributes(plot,Makie.Mesh)
valid_attributes[:color] = color
Makie.mesh!(plot, valid_attributes, mesh)
elseif D == 1
Makie.linesegments!(plot, mesh;
plot.attributes.attributes...,
color = color,
)
valid_attributes = Makie.shared_attributes(plot,Makie.LineSegments)
valid_attributes[:color] = color
Makie.linesegments!(plot, valid_attributes, mesh )
elseif D == 0
Makie.scatter!(plot, mesh;
plot.attributes.attributes...,
color = color,
)
valid_attributes = Makie.shared_attributes(plot,Makie.Scatter)
valid_attributes[:color] = color
Makie.scatter!(plot, valid_attributes, mesh )
else
@unreachable
end
Expand All @@ -99,7 +98,7 @@ function Makie.convert_arguments(::Type{<:Makie.Scatter}, pg::PlotGrid)
(x, )
end

function Makie.convert_arguments(::Type{<:Makie.Mesh}, trian::Triangulation)
function Makie.convert_arguments(::Type{PlotGridMesh}, trian::Triangulation)
grid = to_grid(trian)
(PlotGrid(grid), )
end
Expand All @@ -110,7 +109,10 @@ function Makie.convert_arguments(t::Type{<:Union{Makie.Wireframe, Makie.Scatter}
end

# Set default plottype as mesh if argument is type Triangulation, i.e., mesh(Ω) == plot(Ω).
Makie.plottype(::Triangulation) = Makie.Mesh
Makie.plottype(::Triangulation) = PlotGridMesh
Makie.args_preferred_axis(t::Triangulation)= num_point_dims(t)<=2 ? Makie.Axis : Makie.LScene
Makie.plottype(::PlotGrid) = PlotGridMesh
Makie.args_preferred_axis(pg::PlotGrid)= num_point_dims(pg.Grid)<=2 ? Makie.Axis : Makie.LScene

@Makie.recipe(MeshField) do scene
merge!(
Expand All @@ -131,7 +133,7 @@ function Makie.plot!(p::MeshField{<:Tuple{Triangulation, Any}})
if p[:colorrange][] === Makie.automatic
p[:colorrange] = Makie.lift(extrema, p[:color])
end
Makie.mesh!(p, pg;
Makie.plot!(p, pg;
p.attributes.attributes...
)
end
Expand All @@ -147,13 +149,13 @@ function Makie.plot!(p::MeshField{<:Tuple{CellField}})
if p[:colorrange][] === Makie.automatic
p[:colorrange] = Makie.lift(extrema, p[:color])
end
Makie.mesh!(p, pg;
Makie.plot!(p, pg;
p.attributes.attributes...
)
end

Makie.plottype(::CellField) = MeshField

Makie.args_preferred_axis(c::CellField)= num_point_dims(get_triangulation(c))<=2 ? Makie.Axis : Makie.LScene

function Makie.point_iterator(pg::PlotGrid)
UnstructuredGrid(pg.grid) |> to_dg_points
Expand Down
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ end
fig
end
@test savefig("3d_Fig13") do
fig, _ , plt = plot(Ω, color=3*celldata, colormap=:heat)
fig, _ , plt = plot(Ω, color=3*celldata, colormap=:heat)
Colorbar(fig[1,2], plt)
fig
end
Expand All @@ -119,7 +119,7 @@ end
fig
end
@test savefig("3d_fig15") do
fig, _ , plt = plot(uh, colormap=:Spectral, colorrange=(0,1))
fig, _ , plt = plot(uh, colormap=:Spectral, colorrange=(0,1))
Colorbar(fig[1,2], plt)
fig
end
Expand Down

0 comments on commit e79375e

Please sign in to comment.