forked from MakieOrg/Makie.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
figures.jl
171 lines (140 loc) · 5.3 KB
/
figures.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
@testset "Basic Figures" begin
fig = Figure()
@test current_figure() === fig
fig2 = Figure()
@test fig !== fig2
@test current_figure() === fig2
current_figure!(fig)
@test current_figure() === fig
end
@testset "FigureAxisPlot" begin
fap = scatter(rand(100, 2))
@test fap isa Makie.FigureAxisPlot
fig, ax, p = scatter(rand(100, 2))
@test fig isa Figure
@test ax isa Axis
@test p isa Scatter
fig2, ax2, p2 = scatter(rand(100, 3))
@test fig2 isa Figure
@test ax2 isa LScene # 3d plot
@test p2 isa Scatter
end
@testset "AxisPlot and Axes" begin
fig = Figure()
@test current_axis() === nothing
@test current_figure() === fig
gridpos = fig[1, 1]
@test gridpos isa GridPosition
ap = scatter(gridpos, rand(100, 2))
@test ap isa Makie.AxisPlot
@test current_axis() === ap.axis
ax2, p2 = scatter(fig[1, 2], rand(100, 2))
@test ax2 isa Axis
@test p2 isa Scatter
@test current_axis() === ax2
ax3, p3 = scatter(fig[1, 3], rand(100, 3))
@test ax3 isa LScene
@test p3 isa Scatter
@test current_axis() === ax3
@test ap.axis in fig.content
@test ax2 in fig.content
@test ax3 in fig.content
current_axis!(fig, ax2)
@test current_axis(fig) === ax2
@test current_axis() === ax2
fig2 = Figure()
@test current_figure() === fig2
@test current_axis() === nothing
@test current_axis(fig) === ax2
# current axis can also switch current figure when called without figure argument
current_axis!(ax2)
@test current_axis() === ax2
@test current_figure() === fig
end
@testset "Deleting from figures" begin
fig = Figure()
ax = fig[1, 1] = Axis(fig)
@test current_axis() === ax
@test ax in fig.content
delete!(ax)
@test !(ax in fig.content)
@test ax.parent === nothing
@test current_axis() === nothing
end
@testset "Clearing figures" begin
fig = Figure()
Label(fig[1, 1], "test")
ax = Axis(fig[2, 1])
scatter!(ax, rand(10))
@test !isempty(fig.scene.children)
@test !isempty(ax.scene.plots)
@test !isempty(fig.layout.content)
@test !isempty(fig.content)
@test current_axis() === ax
empty!(fig)
@test isempty(fig.scene.children)
@test isempty(ax.scene.plots)
@test isempty(fig.layout.content)
@test isempty(fig.content)
@test current_axis() === nothing
end
@testset "Getting figure content" begin
fig = Figure()
ax = fig[1, 1] = Axis(fig)
@test contents(fig[1, 1], exact = true) == [ax]
@test contents(fig[1, 1], exact = false) == [ax]
@test contents(fig[1:2, 1:2], exact = true) == []
@test contents(fig[1:2, 1:2], exact = false) == [ax]
@test content(fig[1, 1]) == ax
@test_throws ErrorException content(fig[2, 2])
@test_throws ErrorException content(fig[1:2, 1:2])
label = fig[1, 1] = Label(fig)
@test contents(fig[1, 1], exact = true) == [ax, label]
@test contents(fig[1, 1], exact = false) == [ax, label]
@test contents(fig[1:2, 1:2], exact = true) == []
@test contents(fig[1:2, 1:2], exact = false) == [ax, label]
@test_throws ErrorException content(fig[1, 1])
ax2 = fig[1, 2][1, 1] = Axis(fig)
@test contents(fig[1, 2][1, 1], exact = true) == [ax2]
@test contents(fig[1, 2][1, 1], exact = false) == [ax2]
@test contents(fig[1, 2][1:2, 1:2], exact = true) == []
@test contents(fig[1, 2][1:2, 1:2], exact = false) == [ax2]
label2 = fig[1, 2][1, 1] = Label(fig)
@test contents(fig[1, 2][1, 1], exact = true) == [ax2, label2]
@test contents(fig[1, 2][1, 1], exact = false) == [ax2, label2]
@test contents(fig[1, 2][1:2, 1:2], exact = true) == []
@test contents(fig[1, 2][1:2, 1:2], exact = false) == [ax2, label2]
@test_throws ErrorException content(fig[1, 2][1, 1])
end
@testset "Nested axis assignment" begin
fig = Figure()
@test Axis(fig[1, 1]) isa Axis
@test Axis(fig[1, 1][2, 3]) isa Axis
@test Axis(fig[1, 1][2, 3][4, 5]) isa Axis
@test_throws ErrorException scatter(fig[1, 1])
@test_throws ErrorException scatter(fig[1, 1][2, 3])
@test_throws ErrorException scatter(fig[1, 1][2, 3][4, 5])
@test scatter(fig[1, 2], 1:10) isa Makie.AxisPlot
@test scatter(fig[1, 1][1, 1], 1:10) isa Makie.AxisPlot
@test scatter(fig[1, 1][1, 1][1, 1], 1:10) isa Makie.AxisPlot
fig = Figure()
fig[1, 1] = GridLayout()
@test Axis(fig[1, 1][1, 1]) isa Axis
fig[1, 1] = GridLayout()
@test_throws ErrorException Axis(fig[1, 1][1, 1])
end
@testset "Not implemented error" begin
@test_throws ErrorException("Not implemented for scatter. You might want to put: `using Makie` into your code!") scatter()
end
@testset "Figure and axis kwargs validation" begin
@test_throws ArgumentError lines(1:10, axis = (aspect = DataAspect()), figure = (size = (100, 100)))
@test_throws ArgumentError lines(1:10, figure = (size = (100, 100)))
@test_throws ArgumentError lines(1:10, axis = (aspect = DataAspect()))
# these just shouldn't error
lines(1:10, axis = (aspect = DataAspect(),))
lines(1:10, axis = Attributes(aspect = DataAspect()))
lines(1:10, axis = Dict(:aspect => DataAspect()))
f = Figure()
@test_throws ArgumentError lines(f[1, 1], 1:10, axis = (aspect = DataAspect()))
@test_throws ArgumentError lines(f[1, 1][2, 2], 1:10, axis = (aspect = DataAspect()))
end