Skip to content

Commit

Permalink
Add Makie package extension (#51)
Browse files Browse the repository at this point in the history
* move Makie-based visualization routines into ext/ folder

* fix some comments

* remove unused legacy function

* cleanup to remove unused function and move docstrings

* remove unnecessary test

* Apply suggestions from code review

Co-authored-by: Hendrik Ranocha <[email protected]>

* revert to include legacy version of updatePlot function to avoid breaking changes

* Apply suggestions from code review

Co-authored-by: Michael Schlottke-Lakemper <[email protected]>

---------

Co-authored-by: Hendrik Ranocha <[email protected]>
Co-authored-by: Michael Schlottke-Lakemper <[email protected]>
  • Loading branch information
3 people authored Apr 10, 2024
1 parent e05584a commit 1fb6471
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 45 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ jobs:
env:
PYTHON: ""
- uses: julia-actions/julia-processcoverage@v1
with:
directories: src,examples,ext
- uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
10 changes: 10 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@ version = "0.2.4-pre"
HOHQMesh_jll = "1d5cbd98-5122-5a8a-bea1-c186d986ee7f"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"

[weakdeps]
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"

[extensions]
HOHQMeshMakieExt = "Makie"

[compat]
HOHQMesh_jll = "1.0"
Makie = "0.20"
Requires = "1.1.3"
julia = "1.6"

[extras]
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
24 changes: 24 additions & 0 deletions ext/HOHQMeshMakieExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Package extension for adding Makie-based features to HOHQMesh.jl
module HOHQMeshMakieExt

# Required for visualization code
if isdefined(Base, :get_extension)
using Makie
else
# Until Julia v1.9 is the minimum required version for HOHQMesh.jl, we still support Requires.jl
using ..Makie
end

# Use all exported symbols to avoid having to rewrite all the visualization routines
using HOHQMesh

# Use additional symbols that are not exported
using HOHQMesh: Project, hasBackgroundGrid, projectBounds, projectGrid

# Import functions such that they can be extended with new methods
import HOHQMesh: plotProject!, updatePlot!

include("VizMesh.jl")
include("VizProject.jl")

end
File renamed without changes.
33 changes: 2 additions & 31 deletions src/Viz/VizProject.jl → ext/VizProject.jl
Original file line number Diff line number Diff line change
@@ -1,21 +1,4 @@

const MODEL = 1; const GRID = 2; const MESH = 4; const EMPTY = 0
const REFINEMENTS = 8; const ALL = 15


"""
plotProject!(proj::Project, plotOptions::Int = 0)
Plot objects specified by the `plotOptions`. Construct the `plotOptions` by the sum
of what is to be drawn from the choices `MODEL`, `GRID`, `MESH`, `REFINEMENTS`.
Example: To plot the model and the grid, `plotOptions = MODEL + GRID`. To plot
just the mesh, `plotOptions = MESH`.
To plot everything, `plotOptions = MODEL + GRID + MESH + REFINEMENTS`
Contents are overlaid in the order: GRID, MESH, MODEL, REFINEMENTS
"""
function plotProject!(proj::Project, plotOptions::Int = 0)

if isnothing(proj.plt)
Expand Down Expand Up @@ -113,11 +96,8 @@ function plotProject!(proj::Project, plotOptions::Int = 0)
end


"""
updatePlot!(proj::Project)
This version replots the figure with the current options. Legacy.
"""
# updatePlot!(proj::Project)
# This version replots the figure with the current options. Legacy.
function updatePlot!(proj::Project)
if !isnothing(proj.plt)
proj.plt = Figure(size = (1000, 1000))
Expand All @@ -127,15 +107,6 @@ function updatePlot!(proj::Project)
end


"""
updatePlot!(proj::Project, plotOptions::Int)
Replot with the new plotOptions = combinations (sums) of
GRID, MESH, MODEL, REFINEMENTS
Example: updatePlot!(p, MESH + MODEL)
"""
function updatePlot!(proj::Project, plotOptions::Int)
if !isnothing(proj.plt)
proj.plt = Figure(size = (1000, 1000))
Expand Down
28 changes: 14 additions & 14 deletions src/HOHQMesh.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,19 @@ using HOHQMesh_jll: HOHQMesh_jll
using Requires: @require

function __init__()
# Enable features that depend on the availability of the Makie package
@require Makie="ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" begin
using .Makie
if isdefined(Makie, :to_textsize)
@warn "You seem to be using an older version of Makie (< v0.19). Some plotting functions may not work."
# Enable features that depend on the availability of the Makie package
# Until Julia v1.9 is the minimum required version for HOHQMesh.jl, we still support Requires.jl
@static if !isdefined(Base, :get_extension)
@require Makie="ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" begin
include("../ext/HOHQMeshMakieExt.jl")
end
end
include("Viz/VizProject.jl")
include("Viz/VizMesh.jl")
# Make the actual plotting routines available
export plotProject!, updatePlot!
# Make plotting constants available for easier use
export MODEL, GRID, MESH, EMPTY, REFINEMENTS, ALL
end
end

#
# Include interactive mesh functionality for creating, reading, and writing a model for HOHQMesh.
# Note, The visualization routines are included above in the `__init__` because
# Makie is required.
# Note, Empty visualization routines are included and exported below but are extended within
# `../ext/HOHQMeshMakieExt.jl`
#

# Core interactive tool routines for control file readin, curve evaluation, etc.
Expand Down Expand Up @@ -53,6 +47,9 @@ include("Project/SmootherAPI.jl")
# Main routine that uses HOHQMesh to generate a mesh from an interactive `Project`
include("Mesh/Meshing.jl")

# Empty routines for visualization extended in `ext/HOHQMeshMakieExt.jl`
include("Viz/visualization.jl")

# Generic main function to generate a mesh from a control file
# or an interactive mesh `Project`
export generate_mesh
Expand Down Expand Up @@ -149,6 +146,9 @@ export undo, undoActionName,
# Functions from `Meshing.jl`, generate_mesh is already exported
export remove_mesh!

# Functions and constants for visualization purposes
export plotProject!, updatePlot!
export MODEL, GRID, MESH, EMPTY, REFINEMENTS, ALL

"""
generate_mesh(control_file;
Expand Down
45 changes: 45 additions & 0 deletions src/Viz/visualization.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

# Convenience constants to make plotting easier
const MODEL = 1; const GRID = 2; const MESH = 4; const EMPTY = 0
const REFINEMENTS = 8; const ALL = 15

# Add function definitions here such that they can be exported from HOHQMesh.jl
# and extended in the HOHQMeshMakieExt package extension or by the
# Makie-specific code loaded by Requires.jl

"""
plotProject!(proj::Project, plotOptions::Int = 0)
Plot objects specified by the `plotOptions`. Construct the `plotOptions` by the sum
of what is to be drawn from the choices `MODEL`, `GRID`, `MESH`, `REFINEMENTS`.
Example: To plot the model and the grid, `plotOptions = MODEL + GRID`. To plot
just the mesh, `plotOptions = MESH`.
To plot everything, `plotOptions = MODEL + GRID + MESH + REFINEMENTS`
Contents are overlaid in the order: `GRID`, `MESH`, `MODEL`, `REFINEMENTS`
!!! note "Requires Makie.jl"
Please note that for this function to work, you need to load Makie.jl
in your REPL (e.g., by calling `using GLMakie`).
"""
function plotProject! end
# Note: The function implementation is found in `ext/VizProject.jl`.


"""
updatePlot!(proj::Project, plotOptions::Int)
Replot with the new plotOptions = combinations (sums) of
GRID, MESH, MODEL, REFINEMENTS
Example: `updatePlot!(p, MESH + MODEL)`
!!! note "Requires Makie.jl"
Please note that for this function to work, you need to load Makie.jl
in your REPL (e.g., by calling `using GLMakie`).
"""
function updatePlot! end
# Note: The function implementation is found in `ext/VizProject.jl`.

0 comments on commit 1fb6471

Please sign in to comment.