Skip to content

Commit

Permalink
fix linked axis regression and add unit test (#2039)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkrumbiegel authored Jun 10, 2022
1 parent 57e1306 commit d055f0c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions ReferenceTests/src/tests/figures_and_makielayout.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,28 @@ end

f
end

@testset "Linked axes" begin
# this tests a bug in 0.17.4 where the first axis targetlimits
# don't change because the second axis has limits contained inside those
# of the first, so the axis linking didn't proliferate
f = Figure()
ax1 = Axis(f[1, 1], xautolimitmargin = (0, 0), yautolimitmargin = (0, 0))
ax2 = Axis(f[2, 1], xautolimitmargin = (0, 0), yautolimitmargin = (0, 0))
scatter!(ax1, 1:5, 2:6)
scatter!(ax2, 2:3, 3:4)
@test first.(extrema(ax1.finallimits[])) == (1, 5)
@test last.(extrema(ax1.finallimits[])) == (2, 6)
@test first.(extrema(ax2.finallimits[])) == (2, 3)
@test last.(extrema(ax2.finallimits[])) == (3, 4)
linkxaxes!(ax1, ax2)
@test first.(extrema(ax1.finallimits[])) == (1, 5)
@test last.(extrema(ax1.finallimits[])) == (2, 6)
@test first.(extrema(ax2.finallimits[])) == (1, 5)
@test last.(extrema(ax2.finallimits[])) == (3, 4)
linkyaxes!(ax1, ax2)
@test first.(extrema(ax1.finallimits[])) == (1, 5)
@test last.(extrema(ax1.finallimits[])) == (2, 6)
@test first.(extrema(ax2.finallimits[])) == (1, 5)
@test last.(extrema(ax2.finallimits[])) == (2, 6)
end
2 changes: 1 addition & 1 deletion src/makielayout/blocks/axis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ function initialize_block!(ax::Axis; palette = nothing)

# initialize either with user limits, or pick defaults based on scales
# so that we don't immediately error
targetlimits = Observable{Rect2f}(defaultlimits(ax.limits[], ax.xscale[], ax.yscale[]); ignore_equal_values=true)
targetlimits = Observable{Rect2f}(defaultlimits(ax.limits[], ax.xscale[], ax.yscale[]))
finallimits = Observable{Rect2f}(targetlimits[]; ignore_equal_values=true)
setfield!(ax, :targetlimits, targetlimits)
setfield!(ax, :finallimits, finallimits)
Expand Down

0 comments on commit d055f0c

Please sign in to comment.