Skip to content

Commit 437e8d6

Browse files
authored
WIP Makie plotting (#449)
* Remove old Requires compatibility tricks * Semi ok Makie extension (first pass) This has an issue where calling a specific recipe will work fine, but calling `plot` will not utilize cycled color.
1 parent 60a3432 commit 437e8d6

6 files changed

+58
-30
lines changed

Project.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
1414
[weakdeps]
1515
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
1616
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
17+
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
1718
Optim = "429524aa-4258-5aef-a3af-852621145aeb"
1819
RegularizationTools = "29dad682-9a27-4bc3-9c72-016788665182"
1920
SparseConnectivityTracer = "9f842d2f-2579-4b1d-911e-f412cf18a3f5"
@@ -26,6 +27,7 @@ DataInterpolationsOptimExt = "Optim"
2627
DataInterpolationsRegularizationToolsExt = "RegularizationTools"
2728
DataInterpolationsSparseConnectivityTracerExt = ["SparseConnectivityTracer", "FillArrays"]
2829
DataInterpolationsSymbolicsExt = "Symbolics"
30+
DataInterpolationsMakieExt = "Makie"
2931

3032
[compat]
3133
Aqua = "0.8"
@@ -37,6 +39,7 @@ FindFirstFunctions = "1.3"
3739
FiniteDifferences = "0.12.31"
3840
ForwardDiff = "0.10.36, 1"
3941
LinearAlgebra = "1.10"
42+
Makie = "0.22, 0.23, 0.24"
4043
Optim = "1.6"
4144
PrettyTables = "2"
4245
QuadGK = "2.9.1"
@@ -58,6 +61,7 @@ BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
5861
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
5962
FiniteDifferences = "26cc04aa-876d-5657-8c51-4c34ba976000"
6063
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
64+
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
6165
Optim = "429524aa-4258-5aef-a3af-852621145aeb"
6266
QuadGK = "1fd47b50-473d-5c70-9696-f719f8f3bcdc"
6367
RegularizationTools = "29dad682-9a27-4bc3-9c72-016788665182"

ext/DataInterpolationsChainRulesCoreExt.jl

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
module DataInterpolationsChainRulesCoreExt
2-
if isdefined(Base, :get_extension)
3-
using DataInterpolations: _interpolate, derivative, AbstractInterpolation,
4-
LinearInterpolation, QuadraticInterpolation,
5-
LagrangeInterpolation, AkimaInterpolation,
6-
BSplineInterpolation, BSplineApprox, get_idx, get_parameters,
7-
munge_data
8-
using ChainRulesCore
9-
else
10-
using ..DataInterpolations: _interpolate, derivative, AbstractInterpolation,
11-
LinearInterpolation, QuadraticInterpolation,
12-
LagrangeInterpolation, AkimaInterpolation,
13-
BSplineInterpolation, BSplineApprox, get_parameters,
14-
munge_data
15-
using ..ChainRulesCore
16-
end
2+
3+
using DataInterpolations: _interpolate, derivative, AbstractInterpolation,
4+
LinearInterpolation, QuadraticInterpolation,
5+
LagrangeInterpolation, AkimaInterpolation,
6+
BSplineInterpolation, BSplineApprox, get_idx, get_parameters,
7+
munge_data
8+
using ChainRulesCore
179

1810
function ChainRulesCore.rrule(::typeof(munge_data), u, t)
1911
u_out, t_out = munge_data(u, t)

ext/DataInterpolationsMakieExt.jl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
module DataInterpolationsMakieExt
2+
3+
using DataInterpolations
4+
using DataInterpolations: AbstractInterpolation
5+
using Makie
6+
7+
# Define the default type of plot that you want
8+
Makie.plottype(::AbstractInterpolation) = Makie.ScatterLines
9+
10+
# Define the attributes that you want to use
11+
Makie.used_attributes(::Makie.PointBased, ::AbstractInterpolation) = (:plotdensity, :denseplot)
12+
Makie.used_attributes(::Type{<:Makie.ScatterLines}, ::AbstractInterpolation) = (:plotdensity, :denseplot)
13+
14+
# Define the conversion of the data to the plot
15+
function Makie.convert_arguments(
16+
::Makie.PointBased,
17+
A::AbstractInterpolation;
18+
plotdensity = 10_000,
19+
denseplot = true,
20+
)
21+
DataInterpolations.to_plottable(A; plotdensity = plotdensity, denseplot = denseplot)
22+
end
23+
24+
# Define the conversion of the data to the plot for the ScatterLines type
25+
# Note that this is a bit of a hack
26+
# and should actually be handled by a plot! method,
27+
# except that doesn't work anymore or does it?
28+
function Makie.convert_arguments(
29+
::Type{<:Makie.ScatterLines},
30+
A::AbstractInterpolation;
31+
plotdensity = 10_000,
32+
denseplot = true,
33+
)
34+
densex, densey = convert_arguments(Makie.PointBased(), A; plotdensity = plotdensity, denseplot = denseplot)
35+
return [
36+
Makie.SpecApi.Lines(densex, densey),
37+
Makie.SpecApi.Scatter(A.t, A.u)
38+
]
39+
end
40+
41+
end # module

ext/DataInterpolationsOptimExt.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import DataInterpolations: munge_data,
66
ExtrapolationError,
77
integral, IntegralNotFoundError, DerivativeNotFoundError
88

9-
isdefined(Base, :get_extension) ? (using Optim, ForwardDiff) :
10-
(using ..Optim, ..ForwardDiff)
9+
using Optim, ForwardDiff
1110

1211
### Curvefit
1312
function Curvefit(u,

ext/DataInterpolationsRegularizationToolsExt.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import DataInterpolations: munge_data, munge_extrapolation,
66
integral
77
using LinearAlgebra
88

9-
isdefined(Base, :get_extension) ? (import RegularizationTools as RT) :
10-
(import ..RegularizationTools as RT)
9+
import RegularizationTools as RT
1110

1211
# TODO:
1312
# x midpoint rule

ext/DataInterpolationsSymbolicsExt.jl

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
module DataInterpolationsSymbolicsExt
22

3-
if isdefined(Base, :get_extension)
4-
using DataInterpolations: AbstractInterpolation
5-
import DataInterpolations: derivative
6-
using Symbolics
7-
using Symbolics: Num, unwrap, SymbolicUtils
8-
else
9-
using ..DataInterpolations: AbstractInterpolation
10-
import ..DataInterpolations: derivative
11-
using ..Symbolics
12-
using ..Symbolics: Num, unwrap, SymbolicUtils
13-
end
3+
using DataInterpolations: AbstractInterpolation
4+
import DataInterpolations: derivative
5+
using Symbolics
6+
using Symbolics: Num, unwrap, SymbolicUtils
147

158
@register_symbolic (interp::AbstractInterpolation)(t)
169
Base.nameof(interp::AbstractInterpolation) = :Interpolation

0 commit comments

Comments
 (0)