Skip to content

Commit

Permalink
Move extensions to better namespace
Browse files Browse the repository at this point in the history
Extensions could have name collisions, adding ClimaAnalysis in front
dramatically reduces the likelihood and follows conventions.
  • Loading branch information
Sbozzolo committed Aug 29, 2024
1 parent b6671fe commit 354fda3
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 215 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ GeoMakie = "db073c08-6b98-4ee5-b6a4-5efafb3259c6"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"

[extensions]
GeoMakieExt = "GeoMakie"
MakieExt = "Makie"
ClimaAnalysisGeoMakieExt = "GeoMakie"
ClimaAnalysisMakieExt = "Makie"

[compat]
Aqua = "0.8"
Expand Down
17 changes: 12 additions & 5 deletions ext/MakieExt.jl → ext/ClimaAnalysisMakieExt.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module MakieExt
module ClimaAnalysisMakieExt

import Makie
import ClimaAnalysis
Expand Down Expand Up @@ -554,7 +554,7 @@ end
"""
_to_unitrange(x::Number, lo::Number, hi::Number)
Linearly transform x ∈ [lo, hi] to [0, 1].
Linearly transform x ∈ [lo, hi] to [0, 1].
"""
_to_unitrange(x::Number, lo::Number, hi::Number) = (x - lo) / (hi - lo)

Expand All @@ -581,18 +581,25 @@ symmetrically around zero maps the same color intensity to the same magnitude.
# Returns
- `cmap::Makie.ColorGradient`: a colormap
"""
function _constrained_cmap(
function Visualize._constrained_cmap(
cols::Vector,
lo,
hi;
mid = 0,
categorical = false,
rev = false,
)
_constrained_cmap(Makie.ColorScheme(cols), lo, hi; mid, categorical, rev)
Visualize._constrained_cmap(
Makie.ColorScheme(cols),
lo,
hi;
mid,
categorical,
rev,
)
end

function _constrained_cmap(
function Visualize._constrained_cmap(
cols::Makie.ColorScheme,
lo,
hi;
Expand Down
202 changes: 0 additions & 202 deletions ext/GeoMakieExt.jl

This file was deleted.

2 changes: 2 additions & 0 deletions src/Visualize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module Visualize

export plot!

function _constrained_cmap end

function heatmap2D! end

function sliced_heatmap! end
Expand Down
10 changes: 4 additions & 6 deletions test/test_GeoMakieExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,15 @@ using OrderedCollections
fig2,
var2D,
more_kwargs = Dict(
:plot =>
ClimaAnalysis.Utils.kwargs(colormap = Makie.colorschemes[:vik]),
:plot => ClimaAnalysis.Utils.kwargs(colormap = :vik),
),
)

output_name = joinpath(tmp_dir, "test_contours2D_globe.png")
Makie.save(output_name, fig2)

# Test cmap
MakieExt = Base.get_extension(ClimaAnalysis, :MakieExt)
test_cmap = MakieExt._constrained_cmap(
# Test cmap
test_cmap = ClimaAnalysis.Visualize._constrained_cmap(
Makie.colorschemes[:vik],
0.0,
15000.0 + (5000.0 / 3.0),
Expand All @@ -70,7 +68,7 @@ using OrderedCollections
output_name = joinpath(tmp_dir, "test_contours2D_globe_with_test_cmap.png")
Makie.save(output_name, fig3)

test_cmap = MakieExt._constrained_cmap(
test_cmap = ClimaAnalysis.Visualize._constrained_cmap(
range(Makie.colorant"red", stop = Makie.colorant"green", length = 15),
0.0,
15000.0 + (5000.0 / 3.0),
Expand Down

0 comments on commit 354fda3

Please sign in to comment.