Skip to content

Commit 59d277b

Browse files
committed
Add a MakiePlotsExt to be able to specify a plotting backend.
uses Preferences.jl for a persistent state.
1 parent 8699b27 commit 59d277b

4 files changed

Lines changed: 46 additions & 2 deletions

File tree

NEWS.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [2.3.6] unreleased
8+
## [2.4.0] unreleased
9+
10+
### Added
11+
12+
* an extension to also perform the numerical checks plots with [`Makie.jl](https://https://makie.org/).
913

1014
### Fixed
1115

Project.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ projects = ["test", "docs", "tutorials"]
99
[deps]
1010
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1111
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
12+
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
1213
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
1314
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1415

@@ -21,6 +22,7 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
2122

2223
[extensions]
2324
ManifoldsBaseMakieExt = "Makie"
25+
ManifoldsBaseMakiePlotsExt = ["Makie", "Plots"]
2426
ManifoldsBasePlotsExt = "Plots"
2527
ManifoldsBaseQuaternionsExt = "Quaternions"
2628
ManifoldsBaseRecursiveArrayToolsExt = "RecursiveArrayTools"
@@ -31,9 +33,10 @@ LinearAlgebra = "1.6"
3133
Makie = "0.24"
3234
Markdown = "1.6"
3335
Plots = "1"
36+
Preferences = "1.4"
3437
Printf = "1.6"
38+
Quaternions = "0.7"
3539
Random = "1.6"
3640
RecursiveArrayTools = "2, 3, 4"
37-
Quaternions = "0.7"
3841
Statistics = "1.6"
3942
julia = "1.10"

ext/ManifoldsBaseMakiePlotsExt.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module ManifoldsBaseMakiePlotsExt
2+
#
3+
#
4+
# For the case where one actually loads both plotting libraries,
5+
# this uses Preferences.jl to persistently specify which backend to use
6+
using ManifoldsBase
7+
8+
function _preferred_plotting_ext()
9+
if Symbol(ManifoldsBase.get_plotting_backend()) === :Makie
10+
return Base.get_extension(ManifoldsBase, :ManifoldsBasePlotsExt)
11+
else
12+
return Base.get_extension(ManifoldsBase, :ManifoldsBaseMakieExt)
13+
end
14+
end
15+
function ManifoldsBase.plot_slope(
16+
x, y; slope = 2, line_base = 0, a = 0, b = 2.0, i = 1, j = length(x),
17+
)
18+
return _preferred_plotting_ext().plot_slope(x, y; slope, line_base, a, b, i, j)
19+
end
20+
function ManifoldsBase.plot_check_geodesic(T, N, e_norm, e_pt, e_alpha)
21+
return _preferred_plotting_ext().plot_check_geodesic(T, N, e_norm, e_pt, e_alpha)
22+
end
23+
24+
end # module ManifoldsBasePlotsMakieExt

src/ManifoldsBase.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import Random: rand, rand!
2424

2525
using LinearAlgebra
2626
using Markdown: @doc_str
27+
using Preferences
2728
using Printf: @sprintf
2829
using Random
2930

@@ -1219,6 +1220,18 @@ function zero_vector(M::AbstractManifold, p)
12191220
zero_vector!(M, X, p)
12201221
return X
12211222
end
1223+
1224+
#
1225+
#
1226+
# Internal function to set plotting backend
1227+
function set_plotting_backend!(e::String)
1228+
(length(e) == 0) && return Preferences.@delete_preferences!("PlottingBackend")
1229+
return Preferences.@set_preferences!("PlottingBackend" => e)
1230+
end
1231+
# Internal function to set plotting backend
1232+
function get_plotting_backend()
1233+
return Preferences.@load_preference("PlottingBackend", "Makie")
1234+
end
12221235
include("errors.jl")
12231236
include("parallel_transport.jl")
12241237
include("vector_transport.jl")

0 commit comments

Comments
 (0)