Skip to content

Commit

Permalink
move plotting logic to extension
Browse files Browse the repository at this point in the history
  • Loading branch information
daanhb committed Sep 23, 2024
1 parent fb01c6b commit bcaff85
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fail-fast: false
matrix:
version:
- '1.6'
- '1.9'
- '1'
os:
- ubuntu-latest
Expand Down
14 changes: 11 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
name = "GridArrays"
uuid = "356ae075-8bc9-5ef9-a342-46c9ba26438c"
version = "0.2.2"
version = "0.2.3"

[deps]
CompositeTypes = "b152e2b5-7a66-4b01-a709-34e65c35f657"
DomainSets = "5b8099bc-c8ec-5219-889f-1d9e522a28bf"
FastGaussQuadrature = "442a2c76-b920-505d-bb47-c5924d526838"
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
GaussQuadrature = "d54b0c1a-921d-58e0-8e36-89d8069c0969"
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[weakdeps]
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"

[extensions]
GridArraysRecipesBaseExt = "RecipesBase"

[compat]
CompositeTypes = "0.1.3"
DomainSets = "0.6.2,0.7"
FastGaussQuadrature = "0.4,0.5"
FillArrays = "0.13,1"
GaussQuadrature = "0.5.7"
LinearAlgebra = "1"
Plots = "1"
RecipesBase = "1.0"
StaticArrays = "1.0"
julia = "1.6"
Test = "1"
julia = "1.9"

[extras]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

| **Documentation** | **Build Status** | **Coverage** |
|-------------------|------------------|--------------|
| [![Documentation](https://img.shields.io/badge/docs-stable-blue.svg)](https://JuliaApproximation.github.io/GridArrays.jl/stable) [![Documentation](https://img.shields.io/badge/docs-dev-blue.svg)](https://JuliaApproximation.github.io/GridArrays.jl/dev) | [![Build Status](https://github.com/JuliaApproximation/GridArrays.jl/workflows/CI/badge.svg?branch=master)](https://github.com/JuliaApproximation/GridArrays.jl/actions/workflows/ci.yml) | [![Coverage](https://codecov.io/gh/JuliaApproximation/GridArrays.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/JuliaApproximation/GridArrays.jl) |
| [![Documentation](https://img.shields.io/badge/docs-stable-blue.svg)](https://JuliaApproximation.github.io/GridArrays.jl/stable) [![Documentation](https://img.shields.io/badge/docs-dev-blue.svg)](https://JuliaApproximation.github.io/GridArrays.jl/dev) | [![Build Status](https://github.com/JuliaApproximation/GridArrays.jl/workflows/CI/badge.svg)](https://github.com/JuliaApproximation/GridArrays.jl/actions/workflows/ci.yml) | [![Coverage](https://codecov.io/gh/JuliaApproximation/GridArrays.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/JuliaApproximation/GridArrays.jl) |

GridArrays defines a collection of basic grids that act as an array. These
arrays are also associated with a domain as defined by [DomainSets.jl](https://github.com/JuliaApproximation/DomainSets.jl).
Expand Down
53 changes: 53 additions & 0 deletions ext/GridArraysRecipesBaseExt/GridArraysRecipesBaseExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
module GridArraysRecipesBaseExt

using GridArrays, RecipesBase

using GridArrays:
component,
endpoints

@recipe function f(grid::AbstractGrid{T,N}, vals::AbstractMatrix) where {T,N}
seriestype --> :surface
size --> (500,400)
xrange = LinRange(endpoints(covering(component(grid,1)))..., size(grid,1))
yrange = LinRange(endpoints(covering(component(grid,2)))..., size(grid,2))
xrange, yrange, vals'
end

@recipe function f(grid::AbstractGrid{<:AbstractVector}, vals::AbstractVector)
seriestype --> :surface
legend=false
size --> (500,400)
xrange = [x[1] for x in grid]
yrange = [x[2] for x in grid]
xrange, yrange, vals
end

# Plot an Nd grid
@recipe function f(grid::AbstractGrid)
seriestype --> :scatter
size --> (500,400)
legend --> false
broadcast(x->tuple(x...),collect(grid)[1:end])
end

# Plot a 1D grid
@recipe function f(grid::AbstractGrid1d)
seriestype --> :scatter
yticks --> []
ylims --> [-1 1]
size --> (500,200)
legend --> false
collect(grid), zeros(size(grid))
end

# Disregarded as this recipe does not involve a type specific to GridArrays
# @recipe function f(a::Vector{SArray{Tuple{2},T,1,2}}) where T
# A = zeros(T,length(a),2)
# for (l,e) in enumerate(a)
# A[l,:] .= e
# end
# A[:,1],A[:,2]
# end

end
14 changes: 8 additions & 6 deletions src/GridArrays.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
module GridArrays

using DomainSets, StaticArrays, RecipesBase, Test, FastGaussQuadrature,
GaussQuadrature, FillArrays

using CompositeTypes, CompositeTypes.Display
using CompositeTypes,
CompositeTypes.Display,
DomainSets,
FastGaussQuadrature,
FillArrays,
GaussQuadrature,
StaticArrays,
Test

using DomainSets: endpoints

Expand Down Expand Up @@ -99,8 +103,6 @@ include("subgrid/subgrid.jl")

include("applications/gauss.jl")

include("util/recipes.jl")

# We define some testing routines inside the package, so that they
# can also be used in the tests of other packages that extend grids
include("test/Test.jl")
Expand Down

2 comments on commit bcaff85

@daanhb
Copy link
Member Author

@daanhb daanhb commented on bcaff85 Sep 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/115759

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.3 -m "<description of version>" bcaff85ad86098b03747f4f339fe987be984d48f
git push origin v0.2.3

Please sign in to comment.