Skip to content
This repository was archived by the owner on Jul 13, 2021. It is now read-only.

Commit cbaa5f2

Browse files
authored
fix ylims bug and add limits tests (#688)
1 parent 71f9487 commit cbaa5f2

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

src/makielayout/layoutables/axis.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ function reset_limits!(ax; xauto = true, yauto = true)
429429
if yauto
430430
yautolimits(ax)
431431
else
432-
left(ax.targetlimits[]), right(ax.targetlimits[])
432+
bottom(ax.targetlimits[]), top(ax.targetlimits[])
433433
end
434434
else
435435
convert(Tuple{Float32, Float32}, mylims)

test/unit_tests/makielayout.jl

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,60 @@ end
3030
@test sc ax.scene.plots
3131
empty!(ax)
3232
@test isempty(ax.scene.plots)
33-
end
33+
end
34+
35+
@testset "Axis limits basics" begin
36+
f = Figure()
37+
ax = Axis(f[1, 1], targetlimits = BBox(0, 10, 0, 20), limits = (nothing, nothing))
38+
@test ax.finallimits[] == BBox(0, 10, 0, 20)
39+
@test ax.limits[] == (nothing, nothing)
40+
xlims!(ax, -10, 10)
41+
@test ax.limits[] == ((-10, 10), nothing)
42+
@test ax.finallimits[] == BBox(-10, 10, 0, 20)
43+
ylims!(ax, -20, 30)
44+
@test ax.limits[] == ((-10, 10), (-20, 30))
45+
@test ax.finallimits[] == BBox(-10, 10, -20, 30)
46+
limits!(ax, -5, 5, -10, 10)
47+
@test ax.finallimits[] == BBox(-5, 5, -10, 10)
48+
@test ax.limits[] == ((-5, 5), (-10, 10))
49+
ax.limits[] = (nothing, nothing)
50+
ax.xautolimitmargin = (0, 0)
51+
ax.yautolimitmargin = (0, 0)
52+
scatter!(Point2f0[(0, 0), (1, 2)])
53+
@test ax.limits[] == (nothing, nothing)
54+
@test ax.targetlimits[] == BBox(0, 1, 0, 2)
55+
@test ax.finallimits[] == BBox(0, 1, 0, 2)
56+
scatter!(Point2f0(3, 4))
57+
@test ax.limits[] == (nothing, nothing)
58+
@test ax.targetlimits[] == BBox(0, 3, 0, 4)
59+
@test ax.finallimits[] == BBox(0, 3, 0, 4)
60+
limits!(ax, -1, 1, 0, 2)
61+
@test ax.limits[] == ((-1, 1), (0, 2))
62+
@test ax.targetlimits[] == BBox(-1, 1, 0, 2)
63+
@test ax.finallimits[] == BBox(-1, 1, 0, 2)
64+
scatter!(Point2f0(5, 6))
65+
@test ax.limits[] == ((-1, 1), (0, 2))
66+
@test ax.targetlimits[] == BBox(-1, 1, 0, 2)
67+
@test ax.finallimits[] == BBox(-1, 1, 0, 2)
68+
autolimits!(ax)
69+
@test ax.limits[] == (nothing, nothing)
70+
@test ax.targetlimits[] == BBox(0, 5, 0, 6)
71+
@test ax.finallimits[] == BBox(0, 5, 0, 6)
72+
xlims!(-10, 10)
73+
@test ax.limits[] == ((-10, 10), nothing)
74+
@test ax.targetlimits[] == BBox(-10, 10, 0, 6)
75+
@test ax.finallimits[] == BBox(-10, 10, 0, 6)
76+
scatter!(Point2f0(11, 12))
77+
@test ax.limits[] == ((-10, 10), nothing)
78+
@test ax.targetlimits[] == BBox(-10, 10, 0, 12)
79+
@test ax.finallimits[] == BBox(-10, 10, 0, 12)
80+
autolimits!(ax)
81+
ylims!(ax, 5, 7)
82+
@test ax.limits[] == (nothing, (5, 7))
83+
@test ax.targetlimits[] == BBox(0, 11, 5, 7)
84+
@test ax.finallimits[] == BBox(0, 11, 5, 7)
85+
scatter!(Point2f0(-5, -7))
86+
@test ax.limits[] == (nothing, (5, 7))
87+
@test ax.targetlimits[] == BBox(-5, 11, 5, 7)
88+
@test ax.finallimits[] == BBox(-5, 11, 5, 7)
89+
end

0 commit comments

Comments
 (0)