From f2b8e8512ed3fdb9e7cfe0545a5d3270736130a4 Mon Sep 17 00:00:00 2001 From: Thatcher Chamberlin Date: Mon, 7 Dec 2020 10:10:43 -0500 Subject: [PATCH 1/7] Added font scaling tests --- test/test_components.jl | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/test_components.jl b/test/test_components.jl index 855d5c82..f1ba2afd 100644 --- a/test/test_components.jl +++ b/test/test_components.jl @@ -44,3 +44,28 @@ end end end end + +@testset "Fonts" begin + @testset "Scaling" begin + sizesToCheck = [:titlefontsize, :legendfontsize, :legendtitlefontsize, + :xtickfontsize, :ytickfontsize, :ztickfontsize, + :xguidefontsize, :yguidefontsize, :zguidefontsize,] + # get inital font sizes + initialSizes = [Plots.default(s) for s in sizesToCheck ] + + #scale up font sizes + scalefontsizes(2) + + # get inital font sizes + doubledSizes = [Plots.default(s) for s in sizesToCheck ] + + @test doubledSizes == initialSizes*2 + + # reset font sizes + resetfontsizes() + + finalSizes = [Plots.default(s) for s in sizesToCheck ] + + @test finalSizes == initialSizes + end +end From e57a9349f63808bd714887c40a623f6eb177bf95 Mon Sep 17 00:00:00 2001 From: Thatcher Chamberlin Date: Mon, 7 Dec 2020 10:10:43 -0500 Subject: [PATCH 2/7] Added font scaling tests --- test/test_components.jl | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/test_components.jl b/test/test_components.jl index 855d5c82..f1ba2afd 100644 --- a/test/test_components.jl +++ b/test/test_components.jl @@ -44,3 +44,28 @@ end end end end + +@testset "Fonts" begin + @testset "Scaling" begin + sizesToCheck = [:titlefontsize, :legendfontsize, :legendtitlefontsize, + :xtickfontsize, :ytickfontsize, :ztickfontsize, + :xguidefontsize, :yguidefontsize, :zguidefontsize,] + # get inital font sizes + initialSizes = [Plots.default(s) for s in sizesToCheck ] + + #scale up font sizes + scalefontsizes(2) + + # get inital font sizes + doubledSizes = [Plots.default(s) for s in sizesToCheck ] + + @test doubledSizes == initialSizes*2 + + # reset font sizes + resetfontsizes() + + finalSizes = [Plots.default(s) for s in sizesToCheck ] + + @test finalSizes == initialSizes + end +end From 0e73bcdc4ea4cf89b2a33eb9921c1f88a2047a69 Mon Sep 17 00:00:00 2001 From: Thatcher Chamberlin Date: Mon, 7 Dec 2020 20:00:55 -0500 Subject: [PATCH 3/7] Added some tests for shorthands.jl --- test/runtests.jl | 1 + test/test_shorthands.jl | 48 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 test/test_shorthands.jl diff --git a/test/runtests.jl b/test/runtests.jl index 120cd33d..6c3528cd 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -32,6 +32,7 @@ include("test_defaults.jl") include("test_axes.jl") include("test_axis_letter.jl") include("test_components.jl") +include("test_shorthands.jl") include("test_recipes.jl") include("test_hdf5plots.jl") include("test_pgfplotsx.jl") diff --git a/test/test_shorthands.jl b/test/test_shorthands.jl new file mode 100644 index 00000000..891c0c14 --- /dev/null +++ b/test/test_shorthands.jl @@ -0,0 +1,48 @@ +using Plots, Test + +@testset "Shorthands" begin + @testset "Set Lims" begin + p = plot(rand(10)) + + xlims!((1,20)) + @test xlims(p) == (1,20) + + ylims!((-1,1)) + @test ylims(p) == (-1,1) + + zlims!((-1,1)) + @test zlims(p) == (-1,1) + + xlims!(-1,11) + @test xlims(p) == (-1,11) + + ylims!((-10,10)) + @test ylims(p) == (-10,10) + + zlims!((-10,10)) + @test zlims(p) == (-10,10) + end + + @testset "Set Ticks" begin + p = plot([0,2,3,4,5,6,7,8,9,10]) + + xticks = 2:6 + xticks!(xticks) + @test Plots.get_subplot(current(),1).attr[:xaxis][:ticks] == xticks + + yticks = 0.2:0.1:0.7 + yticks!(yticks) + @test Plots.get_subplot(current(),1).attr[:yaxis][:ticks] == yticks + + xticks = [5,6,7.5] + xlabels = ["a","b","c"] + + xticks!(xticks, xlabels) + @test Plots.get_subplot(current(),1).attr[:xaxis][:ticks] == (xticks, xlabels) + + yticks = [.5,.6,.75] + ylabels = ["z","y","x"] + yticks!(yticks, ylabels) + @test Plots.get_subplot(current(),1).attr[:yaxis][:ticks] == (yticks, ylabels) + end +end From 38ada46a437e685a859ff5447cc30464c05c4033 Mon Sep 17 00:00:00 2001 From: Thatcher Chamberlin Date: Mon, 7 Dec 2020 20:01:09 -0500 Subject: [PATCH 4/7] Added an auto-label test --- test/runtests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index 6c3528cd..b37e91eb 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -133,7 +133,7 @@ const IMG_TOL = VERSION < v"1.4" && Sys.iswindows() ? 1e-1 : is_ci() ? 1e-2 : 1e @test isa(p, Plots.Plot) == true @test isa(display(p), Nothing) == true p = plot([Dates.Date(2019, 1, 1), Dates.Date(2019, 2, 1)], [3, 4]) - annotate!(p, [(Dates.Date(2019, 1, 15), 3.2, Plots.text("Test", :red, :center))]) + annotate!(p, [(Dates.Date(2019, 1, 15), 3.2, :auto)]) hline!(p, [3.1]) @test isa(p, Plots.Plot) == true @test isa(display(p), Nothing) == true From bc144b64c8b488f00ce9c39d412ab251e6ff93df Mon Sep 17 00:00:00 2001 From: Thatcher Chamberlin Date: Mon, 7 Dec 2020 20:52:46 -0500 Subject: [PATCH 5/7] Added Shape rotation tests --- test/test_components.jl | 55 ++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/test/test_components.jl b/test/test_components.jl index f1ba2afd..b6f14f7b 100644 --- a/test/test_components.jl +++ b/test/test_components.jl @@ -1,26 +1,47 @@ using Plots, Test -@testset "Shape Copy" begin - square = Shape([(0,0),(1,0),(1,1),(0,1)]) - square2 = Shape(square) - @test square2.x == square.x - @test square2.y == square.y -end +@testset "Shapes" begin + @testset "Copy" begin + square = Shape([(0,0),(1,0),(1,1),(0,1)]) + square2 = Shape(square) + @test square2.x == square.x + @test square2.y == square.y + end -@testset "Shape Center" begin - square = Shape([(0,0),(1,0),(1,1),(0,1)]) - @test Plots.center(square) == (0.5,0.5) -end + @testset "Center" begin + square = Shape([(0,0),(1,0),(1,1),(0,1)]) + @test Plots.center(square) == (0.5,0.5) + end -@testset "Shape Translate" begin - square = Shape([(0,0),(1,0),(1,1),(0,1)]) - squareUp = Shape([(0,1),(1,1),(1,2),(0,2)]) - squareUpRight = Shape([(1,1),(2,1),(2,2),(1,2)]) + @testset "Translate" begin + square = Shape([(0,0),(1,0),(1,1),(0,1)]) + squareUp = Shape([(0,1),(1,1),(1,2),(0,2)]) + squareUpRight = Shape([(1,1),(2,1),(2,2),(1,2)]) - @test Plots.translate(square,0,1).x == squareUp.x - @test Plots.translate(square,0,1).y == squareUp.y + @test Plots.translate(square,0,1).x == squareUp.x + @test Plots.translate(square,0,1).y == squareUp.y - @test Plots.center(translate!(square,1)) == (1.5,1.5) + @test Plots.center(translate!(square,1)) == (1.5,1.5) + end + + @testset "Rotate" begin + # 2 radians rotation matrix + R2 = [cos(2) sin(2); -sin(2) cos(2)] + coords = [0 0; 1 0; 1 1; 0 1]' + coordsRotated2 = R2*(coords.-0.5).+0.5 + + square = Shape([(0,0),(1,0),(1,1),(0,1)]) + + # make a new, rotated square + square2 = rotate(square, -2) + @test square2.x ≈ coordsRotated2[1,:] + @test square2.y ≈ coordsRotated2[2,:] + + # unrotate the new square in place + rotate!(square2, 2) + @test square2.x ≈ coords[1,:] + @test square2.y ≈ coords[2,:] + end end @testset "Brush" begin From f905d6b6978ed0ccd5081bdc706655dd259285be Mon Sep 17 00:00:00 2001 From: Thatcher Chamberlin Date: Mon, 7 Dec 2020 21:23:26 -0500 Subject: [PATCH 6/7] Fixed rotate test and added series_annotation tests --- test/test_components.jl | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/test/test_components.jl b/test/test_components.jl index b6f14f7b..1ade43d5 100644 --- a/test/test_components.jl +++ b/test/test_components.jl @@ -33,7 +33,7 @@ using Plots, Test square = Shape([(0,0),(1,0),(1,1),(0,1)]) # make a new, rotated square - square2 = rotate(square, -2) + square2 = Plots.rotate(square, -2) @test square2.x ≈ coordsRotated2[1,:] @test square2.y ≈ coordsRotated2[2,:] @@ -90,3 +90,22 @@ end @test finalSizes == initialSizes end end + +@testset "Series Annotations" begin + square = Shape([(0,0),(1,0),(1,1),(0,1)]) + @test_logs (:warn,"Unused SeriesAnnotations arg: triangle (Symbol)") begin + p = plot([1,2,3], + series_annotations=(["a"], + 2, # pass a scale factor + (1,4), # pass two scale factors (overwrites first one) + square, # pass a shape + font(:courier), # pass an annotation font + :triangle # pass an incorrect argument + )) + sa = p.series_list[1].plotattributes[:series_annotations] + @test sa.strs == ["a"] + @test sa.font.family == "courier" + @test sa.baseshape == square + @test sa.scalefactor == (1,4) + end +end From d1671ea6f0b1df5f488c873aad9b14958edfffc6 Mon Sep 17 00:00:00 2001 From: Thatcher Chamberlin Date: Mon, 7 Dec 2020 22:01:29 -0500 Subject: [PATCH 7/7] recheck coverage