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 Makie package extension #51

Merged
merged 8 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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 .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.
40 changes: 0 additions & 40 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,29 +96,6 @@ function plotProject!(proj::Project, plotOptions::Int = 0)
end


"""
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))
plotOptions = proj.plotOptions
plotProject!(proj, plotOptions)
end
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 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."
ranocha marked this conversation as resolved.
Show resolved Hide resolved
# 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)

Check warning on line 12 in src/HOHQMesh.jl

View check run for this annotation

Codecov / codecov/patch

src/HOHQMesh.jl#L12

Added line #L12 was not covered by tests
@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 @@
# 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 @@
# 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
40 changes: 40 additions & 0 deletions src/Viz/visualization.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

# Convenience constants to make plotting easier
const MODEL = 1; const GRID = 2; const MESH = 4; const EMPTY = 0
const REFINEMENTS = 8; const ALL = 15
ranocha marked this conversation as resolved.
Show resolved Hide resolved

# 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
The function implementation is found in `ext/VizProject.jl`.
"""
function plotProject! end
andrewwinters5000 marked this conversation as resolved.
Show resolved Hide resolved


"""
updatePlot!(proj::Project, plotOptions::Int)

Replot with the new plotOptions = combinations (sums) of

GRID, MESH, MODEL, REFINEMENTS

Example: updatePlot!(p, MESH + MODEL)

!!! note
The function implementation is found in `ext/VizProject.jl`.
"""
function updatePlot! end
andrewwinters5000 marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 0 additions & 2 deletions test/test_visualization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ using CairoMakie
meshFileFormat = getMeshFileFormat(p_visu)
setFileNames!(p_visu, meshFileFormat)

@test_nowarn updatePlot!(p_visu)

andrewwinters5000 marked this conversation as resolved.
Show resolved Hide resolved
# Create the mesh which contains a plotting update for ISM-V2
@test_nowarn generate_mesh(p_visu)

Expand Down
Loading