add tests for series_annotations in layouts

This commit is contained in:
Simon Christ 2021-06-12 11:04:41 +02:00
parent 7ca32b5edd
commit 6e00be5840
2 changed files with 66 additions and 42 deletions

View File

@ -1,4 +1,4 @@
using Plots: guidefont using Plots: guidefont, series_annotations
import ImageMagick import ImageMagick
using VisualRegressionTests using VisualRegressionTests
using Plots using Plots

View File

@ -84,9 +84,17 @@ end
@testset "Fonts" begin @testset "Fonts" begin
@testset "Scaling" begin @testset "Scaling" begin
sizesToCheck = [:titlefontsize, :legendfontsize, :legendtitlefontsize, sizesToCheck = [
:xtickfontsize, :ytickfontsize, :ztickfontsize, :titlefontsize,
:xguidefontsize, :yguidefontsize, :zguidefontsize,] :legendfontsize,
:legendtitlefontsize,
:xtickfontsize,
:ytickfontsize,
:ztickfontsize,
:xguidefontsize,
:yguidefontsize,
:zguidefontsize,
]
# get inital font sizes # get inital font sizes
initialSizes = [Plots.default(s) for s in sizesToCheck] initialSizes = [Plots.default(s) for s in sizesToCheck]
@ -110,18 +118,34 @@ end
@testset "Series Annotations" begin @testset "Series Annotations" begin
square = Shape([(0, 0), (1, 0), (1, 1), (0, 1)]) square = Shape([(0, 0), (1, 0), (1, 1), (0, 1)])
@test_logs (:warn, "Unused SeriesAnnotations arg: triangle (Symbol)") begin @test_logs (:warn, "Unused SeriesAnnotations arg: triangle (Symbol)") begin
p = plot([1,2,3], p = plot(
series_annotations=(["a"], [1, 2, 3],
series_annotations = (
["a"],
2, # pass a scale factor 2, # pass a scale factor
(1, 4), # pass two scale factors (overwrites first one) (1, 4), # pass two scale factors (overwrites first one)
square, # pass a shape square, # pass a shape
font(:courier), # pass an annotation font font(:courier), # pass an annotation font
:triangle # pass an incorrect argument :triangle, # pass an incorrect argument
)) ),
)
sa = p.series_list[1].plotattributes[:series_annotations] sa = p.series_list[1].plotattributes[:series_annotations]
@test sa.strs == ["a"] @test sa.strs == ["a"]
@test sa.font.family == "courier" @test sa.font.family == "courier"
@test sa.baseshape == square @test sa.baseshape == square
@test sa.scalefactor == (1, 4) @test sa.scalefactor == (1, 4)
end end
spl = scatter(
4.53 .* [1/1 1/2 1/3 1/4 1/5],
[0 0 0 0 0],
layout = (5, 1),
ylims = (-1.1, 1.1),
xlims = (0, 5),
series_annotations = ["1/1" "1/2" "1/3" "1/4" "1/5"],
)
@test spl.series_list[1].plotattrubtes[:series_annotations].strs == ["1/1"]
@test spl.series_list[2].plotattrubtes[:series_annotations].strs == ["1/2"]
@test spl.series_list[3].plotattrubtes[:series_annotations].strs == ["1/3"]
@test spl.series_list[4].plotattrubtes[:series_annotations].strs == ["1/4"]
@test spl.series_list[5].plotattrubtes[:series_annotations].strs == ["1/5"]
end end