-
-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Improve Barplot Label Alignment * Barplot Label Alignment tests and NEWS.md * Refactor calculate_bar_label_align with simpler code --------- Co-authored-by: Matthijs Cox <matthijs.cox@asml.com> Co-authored-by: Simon <sdanisch@protonmail.com>
- Loading branch information
1 parent
1e3190a
commit fc95b21
Showing
4 changed files
with
93 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
@testset "Barplot label align" begin | ||
@testset "automatic" begin | ||
# for more info see https://github.com/MakieOrg/Makie.jl/issues/3160 | ||
# below is the best square angles behavior for bar labels | ||
|
||
al = Makie.automatic | ||
|
||
y_dir, flip = false, false | ||
@test Makie.calculate_bar_label_align(al, 0.0, y_dir, flip) ≈ Vec2f(0.0, 0.5) | ||
@test Makie.calculate_bar_label_align(al, π, y_dir, flip) ≈ Vec2f(1.0, 0.5) | ||
@test Makie.calculate_bar_label_align(al, π/2, y_dir, flip) ≈ Vec2f(0.5, 1.0) | ||
@test Makie.calculate_bar_label_align(al, -π/2, y_dir, flip) ≈ Vec2f(0.5, 0.0) | ||
|
||
y_dir, flip = true, false | ||
@test Makie.calculate_bar_label_align(al, 0.0, y_dir, flip) ≈ Vec2f(0.5, 0.0) | ||
@test Makie.calculate_bar_label_align(al, π, y_dir, flip) ≈ Vec2f(0.5, 1.0) | ||
@test Makie.calculate_bar_label_align(al, π/2, y_dir, flip) ≈ Vec2f(0.0, 0.5) | ||
@test Makie.calculate_bar_label_align(al, -π/2, y_dir, flip) ≈ Vec2f(1.0, 0.5) | ||
|
||
y_dir, flip = false, true | ||
@test Makie.calculate_bar_label_align(al, 0.0, y_dir, flip) ≈ Vec2f(1.0, 0.5) | ||
@test Makie.calculate_bar_label_align(al, π, y_dir, flip) ≈ Vec2f(0.0, 0.5) | ||
@test Makie.calculate_bar_label_align(al, π/2, y_dir, flip) ≈ Vec2f(0.5, 0.0) | ||
@test Makie.calculate_bar_label_align(al, -π/2, y_dir, flip) ≈ Vec2f(0.5, 1.0) | ||
|
||
y_dir, flip = true, true | ||
@test Makie.calculate_bar_label_align(al, 0.0, y_dir, flip) ≈ Vec2f(0.5, 1.0) | ||
@test Makie.calculate_bar_label_align(al, π, y_dir, flip) ≈ Vec2f(0.5, 0.0) | ||
@test Makie.calculate_bar_label_align(al, π/2, y_dir, flip) ≈ Vec2f(1.0, 0.5) | ||
@test Makie.calculate_bar_label_align(al, -π/2, y_dir, flip) ≈ Vec2f(0.0, 0.5) | ||
end | ||
|
||
@testset "manual" begin | ||
input = 0.0, false, false | ||
for align in (Vec2f(1.0, 0.5), Point2f(1.0, 0.5), (1.0, 0.5), (1, 0), (1.0, 0)) | ||
@test Makie.calculate_bar_label_align(align, input...) ≈ Vec2f(align) | ||
end | ||
end | ||
|
||
@testset "symbols" begin | ||
input = 0.0, false, false | ||
@test Makie.calculate_bar_label_align((:center, :center), input...) ≈ Makie.calculate_bar_label_align((0.5, 0.5), input...) | ||
end | ||
|
||
@testset "error" begin | ||
input = 0.0, false, false | ||
for align in ("center", 0.5, ("center", "center"), (0.5, :center)) | ||
msg = "`label_align` needs to be of type NTuple{2, <:Real}, not of type $(typeof(align))" | ||
@test_throws ErrorException(msg) Makie.calculate_bar_label_align(align, input...) | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters