Skip to content

Commit cda63bd

Browse files
authored
new constructorof; rework plot recipe (#376)
* new constructor; rework plot recipe * make test support v1
1 parent 687d788 commit cda63bd

File tree

4 files changed

+22
-16
lines changed

4 files changed

+22
-16
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name = "Polynomials"
22
uuid = "f27b6e38-b328-58d1-80ce-0feddd5e7a45"
33
license = "MIT"
44
author = "JuliaMath"
5-
version = "2.0.20"
5+
version = "2.0.21"
66

77
[deps]
88
Intervals = "d8418881-c3e1-53bb-8760-2df7ec849ed5"

src/contrib.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ end
127127
## trick from [ConstructionBase.jl](https://github.com/JuliaObjects/ConstructionBase.jl/blob/b5686b755bd3bee29b181b3cb18fe2effa0f10a2/src/ConstructionBase.jl#L25)
128128
## as noted in https://discourse.julialang.org/t/get-new-type-with-different-parameter/37253/4
129129
##
130-
@generated function constructorof(::Type{T}) where T
131-
getfield(parentmodule(T), nameof(T))
132-
end
130+
#@generated function constructorof(::Type{T}) where T
131+
# getfield(parentmodule(T), nameof(T))
132+
#end
133+
134+
# https://discourse.julialang.org/t/how-do-a-i-get-a-type-stripped-of-parameters/73465/11
135+
constructorof(::Type{T}) where T = Base.typename(T).wrapper

src/plots.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,15 @@ end
3232

3333
poly_label(p::AbstractPolynomial) = sprint(printpoly, p)
3434

35-
@recipe function f(p::AbstractPolynomial, x = poly_interval(p))
35+
#@recipe function f(p::AbstractPolynomial, x = poly_interval(p))
36+
# label --> poly_label(p)
37+
# x, p.(x)
38+
#end
39+
40+
@recipe function f(p::AbstractPolynomial)
3641
label --> poly_label(p)
37-
x, p.(x)
42+
xlims --> extrema(poly_interval(p))
43+
x -> p(x)
3844
end
3945

4046
@recipe function f(p::AbstractPolynomial, a, b)

test/StandardBasis.jl

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,21 +1376,18 @@ end
13761376

13771377
@testset "Plotting" begin
13781378
p = fromroots([-1, 1]) # x^2 - 1
1379-
r = -1.4:0.055999999999999994:1.4
13801379
rec = apply_recipe(Dict{Symbol,Any}(), p)
1381-
@test getfield(rec[1], 1) == Dict{Symbol,Any}(:label => "-1 + x^2")
1382-
@test rec[1].args == (r, p.(r))
1380+
@test rec[1].plotattributes[:label] == "-1 + x^2"
1381+
@test rec[1].plotattributes[:xlims] == (-1.4, 1.4)
1382+
13831383

1384-
r = -1:0.02:1
13851384
rec = apply_recipe(Dict{Symbol,Any}(), p, -1, 1)
1386-
@test getfield(rec[1], 1) == Dict{Symbol,Any}(:label => "-1 + x^2")
1387-
@test rec[1].args == (r, p.(r))
1385+
@test rec[1].plotattributes[:label] == "-1 + x^2"
13881386

13891387
p = ChebyshevT([1,1,1])
13901388
rec = apply_recipe(Dict{Symbol,Any}(), p)
1391-
r = -1.0:0.02:1.0 # uses domain(p)
1392-
@test rec[1].args == (r, p.(r))
1393-
1389+
@test match(r"T_0", rec[1].plotattributes[:label]) !== nothing
1390+
@test rec[1].plotattributes[:xlims] == (-1.0, 1.0) # uses domain(p)
13941391
end
13951392

13961393
@testset "Promotion" begin
@@ -1458,7 +1455,7 @@ end
14581455
end
14591456
end
14601457

1461-
using MutableArithmetics
1458+
import MutableArithmetics
14621459
const MA = MutableArithmetics
14631460

14641461
function alloc_test(f, n)

0 commit comments

Comments
 (0)