diff --git a/test/runtests.jl b/test/runtests.jl index 9a3c1a022..09ec3a31d 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("integration_dates.jl") include("test_recipes.jl") include("test_hdf5plots.jl") @@ -132,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 diff --git a/test/test_components.jl b/test/test_components.jl index 855d5c82c..1ade43d53 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 = Plots.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 @@ -44,3 +65,47 @@ 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 + +@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 diff --git a/test/test_shorthands.jl b/test/test_shorthands.jl new file mode 100644 index 000000000..891c0c14c --- /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