forked from MakieOrg/Makie.jl
/
PolarAxis.jl
152 lines (130 loc) · 5.57 KB
/
PolarAxis.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
@testset "PolarAxis" begin
@testset "rtick rotations" begin
f = Figure()
angles = [
7pi/4+0.01, 0, pi/4-0.01,
pi/4+0.01, pi/2, 3pi/4-0.01,
3pi/4+0.01, pi, 5pi/4-0.01,
5pi/4+0.01, 3pi/2, 7pi/4-0.01,
]
po = PolarAxis(
f[1, 1], thetalimits = (0, pi/4), rticklabelrotation = Makie.automatic,
rticklabelpad = 10f0
)
rticklabelplot = po.overlay.plots[5].plots[1]
# Mostly for verfication that we got the right plot
@test po.overlay.plots[5][1][] == [("0.0", Point2f(0.0, 0.0)), ("2.5", Point2f(0.25, 0.0)), ("5.0", Point2f(0.5, 0.0)), ("7.5", Point2f(0.75, 0.0)), ("10.0", Point2f(1.0, 0.0))]
# automatic
for i in 1:4
align = (Vec2f(0.5, 1.0), Vec2f(0.0, 0.5), Vec2f(0.5, 0.0), Vec2f(1.0, 0.5))[i]
for j in 1:3
po.theta_0[] = angles[j + 3(i-1)]
s, c = sincos(angles[j + 3(i-1)] - pi/2)
@test rticklabelplot.plots[1].offset[] ≈ 10f0 * Vec2f(c, s)
@test rticklabelplot.align[] ≈ align
@test isapprox(mod(rticklabelplot.rotation[], -pi..pi), (-pi/4+0.01, 0, pi/4-0.01)[j], atol = 1e-3)
end
end
# value
v = 2pi * rand()
po.rticklabelrotation[] = v
s, c = sincos(po.theta_0[] - pi/2)
@test rticklabelplot.plots[1].offset[] ≈ 10f0 * Vec2f(c, s)
scale = 1 / max(abs(s), abs(c))
@test rticklabelplot.align[] ≈ Point2f(0.5 - 0.5scale * c, 0.5 - 0.5scale * s)
@test rticklabelplot.rotation[] ≈ v
# horizontal
po.rticklabelrotation[] = :horizontal
@test rticklabelplot.plots[1].offset[] ≈ 10f0 * Vec2f(c, s)
@test rticklabelplot.align[] ≈ Point2f(0.5 - 0.5scale * c, 0.5 - 0.5scale * s)
@test rticklabelplot.rotation[] ≈ 0f0
# radial
po.rticklabelrotation[] = :radial
@test rticklabelplot.plots[1].offset[] ≈ 10f0 * Vec2f(c, s)
@test rticklabelplot.align[] ≈ Vec2f(0, 0.5)
@test rticklabelplot.rotation[] ≈ po.theta_0[] - pi/2
# aligned
po.rticklabelrotation[] = :aligned
@test rticklabelplot.plots[1].offset[] ≈ 10f0 * Vec2f(c, s)
@test rticklabelplot.align[] ≈ Vec2f(1, 0.5)
@test rticklabelplot.rotation[] ≈ po.theta_0[] - 3pi/2
end
@testset "Limits" begin
# Should not error (0 width limits)
fig = Figure()
ax = PolarAxis(fig[1, 1])
p = scatter!(ax, Point2f(0))
# verify defaults
@test ax.rautolimitmargin[] == (0.05, 0.05)
@test ax.thetaautolimitmargin[] == (0.05, 0.05)
# default should have mostly set default limits
@test ax.rlimits[] == (:origin, nothing)
@test ax.thetalimits[] == (0.0, 2pi)
@test ax.target_rlims[] == (0.0, 10.0)
@test ax.target_thetalims[] == (0.0, 2pi)
# but we want to test automatic limits here
autolimits!(ax)
reset_limits!(ax) # needed because window isn't open
@test ax.rlimits[] == (nothing, nothing)
@test ax.thetalimits[] == (nothing, nothing)
@test ax.target_rlims[] == (0.0, 10.0)
@test ax.target_thetalims[] == (0.0, 2pi)
# derived r, default theta
scatter!(ax, Point2f(0, 1))
reset_limits!(ax)
@test ax.target_rlims[] == (0.0, 1.05)
@test ax.target_thetalims[] == (0.0, 2pi)
# back to full default
delete!(ax, p)
reset_limits!(ax)
@test ax.target_rlims[] == (0.0, 10.0)
@test ax.target_thetalims[] == (0.0, 2pi)
# default r, derived theta
scatter!(ax, Point2f(0.5pi, 1))
reset_limits!(ax)
@test ax.target_rlims[] == (0.0, 10.0)
@test all(isapprox.(ax.target_thetalims[], (-0.025pi, 0.525pi), rtol=1e-6))
# derive both
scatter!(ax, Point2f(pi, 2))
reset_limits!(ax)
@test all(isapprox.(ax.target_rlims[], (0.95, 2.05), rtol=1e-6))
@test all(isapprox.(ax.target_thetalims[], (-0.05pi, 1.05pi), rtol=1e-6))
# set limits
rlims!(ax, 0.0, 3.0)
reset_limits!(ax)
@test ax.rlimits[] == (0.0, 3.0)
@test ax.target_rlims[] == (0.0, 3.0)
@test all(isapprox.(ax.target_thetalims[], (-0.05pi, 1.05pi), rtol=1e-6))
thetalims!(ax, 0.0, 2pi)
reset_limits!(ax)
@test ax.rlimits[] == (0.0, 3.0)
@test ax.target_rlims[] == (0.0, 3.0)
@test ax.thetalimits[] == (0.0, 2pi)
@test ax.target_thetalims[] == (0.0, 2pi)
# test tightlimits
fig = Figure()
ax = PolarAxis(fig[1, 1])
surface!(ax, 0.5pi..pi, 2..5, rand(10, 10))
tightlimits!(ax)
@test ax.rautolimitmargin[] == (0.0, 0.0)
@test ax.thetaautolimitmargin[] == (0.0, 0.0)
# with default limits
reset_limits!(ax)
@test ax.rlimits[] == (:origin, nothing)
@test ax.thetalimits[] == (0.0, 2pi)
@test ax.target_rlims[] == (0.0, 5.0)
@test ax.target_thetalims[] == (0.0, 2pi)
# with fully automatic limits
autolimits!(ax)
reset_limits!(ax)
@test ax.rlimits[] == (nothing, nothing)
@test ax.thetalimits[] == (nothing, nothing)
@test ax.target_rlims[] == (2.0, 5.0)
@test all(isapprox.(ax.target_thetalims[], (0.5pi, 1.0pi), rtol=1e-6))
end
@testset "Radial Offset" begin
fig = Figure()
ax = PolarAxis(fig[1, 1], radius_at_origin = -1.0, rlimits = (0, 10))
@test ax.scene.transformation.transform_func[].r0 == -1.0
end
end