Skip to content

Commit cae790e

Browse files
authored
Move RecipesBase dependency to an extension (#618)
* Move RecipesBase dependency to an extension * whoops * More whoops * whoops again * I really should have run the tests locally first
1 parent ae3f434 commit cae790e

File tree

7 files changed

+80
-75
lines changed

7 files changed

+80
-75
lines changed

Project.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ version = "4.1.0"
77
[deps]
88
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
99
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
10-
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
1110
Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46"
1211
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1312

@@ -16,12 +15,14 @@ ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
1615
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
1716
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
1817
MutableArithmetics = "d8a4904e-b15c-11e9-3269-09a3773c0cb0"
18+
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
1919

2020
[extensions]
2121
PolynomialsChainRulesCoreExt = "ChainRulesCore"
2222
PolynomialsFFTWExt = "FFTW"
2323
PolynomialsMakieExt = "Makie"
2424
PolynomialsMutableArithmeticsExt = "MutableArithmetics"
25+
PolynomialsRecipesBaseExt = "RecipesBase"
2526

2627
[compat]
2728
Aqua = "0.8"
@@ -51,9 +52,10 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
5152
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
5253
MutableArithmetics = "d8a4904e-b15c-11e9-3269-09a3773c0cb0"
5354
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
55+
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
5456
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
5557
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
5658
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
5759

5860
[targets]
59-
test = ["Aqua", "ChainRulesCore", "DualNumbers", "FFTW", "LinearAlgebra", "MutableArithmetics", "SparseArrays", "OffsetArrays", "SpecialFunctions", "Test"]
61+
test = ["Aqua", "ChainRulesCore", "DualNumbers", "FFTW", "LinearAlgebra", "MutableArithmetics", "SparseArrays", "OffsetArrays", "RecipesBase", "SpecialFunctions", "Test"]

src/rational-functions/plot-recipes.jl renamed to ext/PolynomialsRecipesBaseExt.jl

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,64 @@
1+
module PolynomialsRecipesBaseExt
2+
3+
using Polynomials
4+
using Polynomials: domain
5+
using RecipesBase
6+
7+
function poly_interval(p::AbstractPolynomial)
8+
9+
# use restricted domain, if finite
10+
A,B = first(domain(p)), last(domain(p))
11+
if !isinf(A) && !isinf(B)
12+
if isopen(domain(p))
13+
Delta = (B-A)/100
14+
A += Delta
15+
B -= Delta
16+
end
17+
return A:(B-A)/100:B
18+
end
19+
20+
21+
# Find points of interest
22+
zero_pts = roots(p)
23+
crit_pts = roots(derivative(p, 1))
24+
infl_pts = roots(derivative(p, 2))
25+
pts = sort([ real(pt) for pt in [zero_pts; crit_pts; infl_pts] if isreal(pt) ])
26+
# Choose a range that shows all interesting points with some margin
27+
min_x, max_x = length(pts) > 0 ? (pts[1], pts[end]) : (-1, 1)
28+
d = max(max_x - min_x, 1)
29+
a = min_x - d / 5
30+
b = max_x + d / 5
31+
32+
Delta = b - a
33+
34+
return a:Delta/50:b
35+
end
36+
37+
poly_label(p::AbstractPolynomial) = sprint(printpoly, p)
38+
39+
#@recipe function f(p::AbstractPolynomial, x = poly_interval(p))
40+
# label --> poly_label(p)
41+
# x, p.(x)
42+
#end
43+
44+
@recipe function f(p::AbstractPolynomial)
45+
label --> poly_label(p)
46+
xlims --> extrema(poly_interval(p))
47+
x -> p(x)
48+
end
49+
50+
@recipe function f(p::AbstractPolynomial, a, b)
51+
label --> poly_label(p)
52+
step = (b - a) / 100
53+
xs = a:step:b
54+
ys = p.(xs)
55+
xs, ys
56+
end
57+
158
## Plot recipe
259
## define a heuristic to work around asymptotes
360
## just sort of successful
4-
@recipe function f(pq::AbstractRationalFunction{T}, a=nothing, b=nothing) where {T}
61+
@recipe function f(pq::Polynomials.AbstractRationalFunction{T}, a=nothing, b=nothing) where {T}
562

663
xlims = get(plotattributes, :xlims, (nothing, nothing))
764
ylims = get(plotattributes, :ylims, (nothing, nothing))
@@ -64,3 +121,4 @@ function rational_function_trim(pq, a, b, xlims, ylims)
64121
xs, ys′
65122

66123
end
124+
end

src/Polynomials.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ using OrderedCollections
1414

1515
include("abstract.jl")
1616
include("show.jl")
17-
include("plots.jl")
1817
include("contrib.jl")
1918

2019
# Interface for all AbstractPolynomials
@@ -55,7 +54,6 @@ include("rational-functions/common.jl")
5554
include("rational-functions/rational-function.jl")
5655
include("rational-functions/fit.jl")
5756
#include("rational-functions/rational-transfer-function.jl")
58-
include("rational-functions/plot-recipes.jl")
5957

6058
# compat; opt-in with `using Polynomials.PolyCompat`
6159
include("legacy/misc.jl")

src/plots.jl

Lines changed: 0 additions & 53 deletions
This file was deleted.

test/StandardBasis.jl

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,22 +1687,6 @@ end
16871687
@test printpoly_to_string(SparsePolynomial(Dict(.=>(-2:2, -1:3)))) == "-x^-2 + 1 + 2*x + 3*x^2"
16881688
end
16891689

1690-
@testset "Plotting" begin
1691-
p = fromroots([-1, 1]) # x^2 - 1
1692-
rec = apply_recipe(Dict{Symbol,Any}(), p)
1693-
@test rec[1].plotattributes[:label] == "-1 + x^2"
1694-
@test rec[1].plotattributes[:xlims] == (-1.4, 1.4)
1695-
1696-
1697-
rec = apply_recipe(Dict{Symbol,Any}(), p, -1, 1)
1698-
@test rec[1].plotattributes[:label] == "-1 + x^2"
1699-
1700-
p = ChebyshevT([1,1,1])
1701-
rec = apply_recipe(Dict{Symbol,Any}(), p)
1702-
@test !isnothing(match(r"T_0", rec[1].plotattributes[:label]))
1703-
@test rec[1].plotattributes[:xlims] == (-1.0, 1.0) # uses domain(p)
1704-
end
1705-
17061690
@testset "Promotion" begin
17071691

17081692
# Test different types work together

test/runtests.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ using Test
33
using LinearAlgebra
44
using Polynomials
55
using SpecialFunctions
6-
using RecipesBase: apply_recipe
76

87
import SparseArrays: sparse, nnz
98
using OffsetArrays

test/test-extensions.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
11
using FFTW
22
using Makie
33
using ChainRulesCore
4+
using RecipesBase: apply_recipe
5+
6+
@testset "Plotting" begin
7+
p = fromroots([-1, 1]) # x^2 - 1
8+
rec = apply_recipe(Dict{Symbol,Any}(), p)
9+
@test rec[1].plotattributes[:label] == "-1 + x^2"
10+
@test rec[1].plotattributes[:xlims] == (-1.4, 1.4)
11+
12+
13+
rec = apply_recipe(Dict{Symbol,Any}(), p, -1, 1)
14+
@test rec[1].plotattributes[:label] == "-1 + x^2"
15+
16+
p = ChebyshevT([1,1,1])
17+
rec = apply_recipe(Dict{Symbol,Any}(), p)
18+
@test !isnothing(match(r"T_0", rec[1].plotattributes[:label]))
19+
@test rec[1].plotattributes[:xlims] == (-1.0, 1.0) # uses domain(p)
20+
end

0 commit comments

Comments
 (0)