forked from MakieOrg/Makie.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipeline.jl
149 lines (120 loc) · 4.68 KB
/
pipeline.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# extracted from interfaces.jl
function test_copy(; kw...)
scene = Scene()
return Makie.merged_get!(
()-> Makie.default_theme(scene, Lines),
:lines, scene, Attributes(kw)
)
end
function test_copy2(attr; kw...)
return merge!(Attributes(kw), attr)
end
@testset "don't copy in theme merge" begin
x = Observable{Any}(1)
res=test_copy(linewidth=x)
res.linewidth === x
end
@testset "don't copy observables in when calling merge!" begin
x = Observable{Any}(1)
res=test_copy2(Attributes(linewidth=x))
res.linewidth === x
end
@testset "don't copy attributes in recipe" begin
fig = Figure()
ax = Axis(fig[1, 1])
list = Observable{Any}([1, 2, 3, 4])
xmax = Observable{Any}([0.25, 0.5, 0.75, 1])
p = hlines!(ax, list, xmax = xmax, color = :blue)
@test getfield(p, :args)[1] === list
@test p.xmax === xmax
fig
end
@testset "Figure / Axis / Gridposition creation test" begin
@testset "proper errors for wrongly used (non) mutating plot functions" begin
f = Figure()
x = range(0, 10, length=100)
@test_throws ErrorException scatter!(f[1, 1], x, sin)
@test_throws ErrorException scatter!(f[1, 2][1, 1], x, sin)
@test_throws ErrorException scatter!(f[1, 2][1, 2], x, sin)
@test_throws ErrorException meshscatter!(f[2, 1], x, sin; axis=(type=Axis3,))
@test_throws ErrorException meshscatter!(f[2, 2][1, 1], x, sin; axis=(type=Axis3,))
@test_throws ErrorException meshscatter!(f[2, 2][1, 2], x, sin; axis=(type=Axis3,))
@test_throws ErrorException meshscatter!(f[3, 1], rand(Point3f, 10); axis=(type=LScene,))
@test_throws ErrorException meshscatter!(f[3, 2][1, 1], rand(Point3f, 10); axis=(type=LScene,))
@test_throws ErrorException meshscatter!(f[3, 2][1, 2], rand(Point3f, 10); axis=(type=LScene,))
sub = f[4, :]
f = Figure()
@test_throws ErrorException scatter(Axis(f[1, 1]), x, sin)
@test_throws ErrorException meshscatter(Axis3(f[1, 1]), x, sin)
@test_throws ErrorException meshscatter(LScene(f[1, 1]), rand(Point3f, 10))
f
end
@testset "creating plot object for different (non) mutating plotting functions into figure" begin
f = Figure()
x = range(0, 10; length=100)
ax, pl = scatter(f[1, 1], x, sin)
@test ax isa Axis
@test pl isa AbstractPlot
ax, pl = scatter(f[1, 2][1, 1], x, sin)
@test ax isa Axis
@test pl isa AbstractPlot
ax, pl = scatter(f[1, 2][1, 2], x, sin)
@test ax isa Axis
@test pl isa AbstractPlot
ax, pl = meshscatter(f[2, 1], x, sin; axis=(type=Axis3,))
@test ax isa Axis3
@test pl isa AbstractPlot
ax, pl = meshscatter(f[2, 2][1, 1], x, sin; axis=(type=Axis3,))
@test ax isa Axis3
@test pl isa AbstractPlot
ax, pl = meshscatter(f[2, 2][1, 2], x, sin; axis=(type=Axis3,))
@test ax isa Axis3
@test pl isa AbstractPlot
ax, pl = meshscatter(f[3, 1], rand(Point3f, 10); axis=(type=LScene,))
@test ax isa LScene
@test pl isa AbstractPlot
ax, pl = meshscatter(f[3, 2][1, 1], rand(Point3f, 10); axis=(type=LScene,))
@test ax isa LScene
@test pl isa AbstractPlot
ax, pl = meshscatter(f[3, 2][1, 2], rand(Point3f, 10); axis=(type=LScene,))
@test ax isa LScene
@test pl isa AbstractPlot
sub = f[4, :]
pl = scatter!(Axis(sub[1, 1]), x, sin)
@test pl isa AbstractPlot
pl = meshscatter!(Axis3(sub[1, 2]), x, sin)
@test pl isa AbstractPlot
pl = meshscatter!(LScene(sub[1, 3]), rand(Point3f, 10))
@test pl isa AbstractPlot
f = Figure()
@test_throws ErrorException lines!(f, [1, 2])
end
end
@testset "Cycled" begin
# Test for https://github.com/MakieOrg/Makie.jl/issues/3266
f, ax, pl = lines(1:4; color=Cycled(2))
cpalette = ax.scene.theme.palette[:color][]
@test pl.calculated_colors[] == cpalette[2]
pl2 = lines!(ax, 1:4; color=Cycled(1))
@test pl2.calculated_colors[] == cpalette[1]
end
function test_default(arg)
_, _, pl1 = plot(arg)
fig = Figure()
_, pl2 = plot(fig[1, 1], arg)
fig = Figure()
ax = Axis(fig[1, 1])
pl3 = plot!(ax, arg)
return [pl1, pl2, pl3]
end
@testset "plot defaults" begin
plots = test_default([10, 15, 20])
@test all(x-> x isa Scatter, plots)
plots = test_default(rand(4, 4))
@test all(x -> x isa Heatmap, plots)
poly = Polygon(decompose(Point, Circle(Point2f(0), 1.0f0)))
plots = test_default(poly)
@test all(x -> x isa Poly, plots)
plots = test_default(rand(4, 4, 4))
@test all(x -> x isa Volume, plots)
end