From ce530ef518a78a4e17e73d25c61b6e1e116448d4 Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Thu, 20 May 2021 20:42:31 +0200 Subject: [PATCH] fix vector of shapes (#3517) --- src/components.jl | 2 +- src/recipes.jl | 6 +++--- test/test_components.jl | 11 +++++++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/components.jl b/src/components.jl index 34cafdc41..7520ae775 100644 --- a/src/components.jl +++ b/src/components.jl @@ -43,7 +43,7 @@ function coords(shape::Shape) end #coords(shapes::AVec{Shape}) = unzip(map(coords, shapes)) -function coords(shapes::AVec{Shape}) +function coords(shapes::AVec{<:Shape}) c = map(coords, shapes) x = [q[1] for q in c] y = [q[2] for q in c] diff --git a/src/recipes.jl b/src/recipes.jl index 952bf0aac..c2911db9c 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -1428,9 +1428,9 @@ end coords(shape) end -@recipe function f(shapes::AVec{Shape}) +@recipe function f(shapes::AVec{<:Shape}) seriestype --> :shape - # For backwards compatibility, column vectors of segmenting attributes are + # For backwards compatibility, column vectors of segmenting attributes are # interpreted as having one element per shape for attr in union(_segmenting_array_attributes, _segmenting_vector_attributes) v = get(plotattributes, attr, nothing) @@ -1443,7 +1443,7 @@ end coords(shapes) end -@recipe function f(shapes::AMat{Shape}) +@recipe function f(shapes::AMat{<:Shape}) seriestype --> :shape for j in axes(shapes, 2) @series coords(vec(shapes[:, j])) diff --git a/test/test_components.jl b/test/test_components.jl index 2fb7355b3..775101816 100644 --- a/test/test_components.jl +++ b/test/test_components.jl @@ -4,6 +4,7 @@ using Plots, Test @testset "Type" begin square = Shape([(0,0.0),(1,0.0),(1,1.0),(0,1.0)]) @test isa(square, Shape{Int64, Float64}) + @test coords(square) isa Tuple{Vector{S}, Vector{T}} where {T,S} end @testset "Copy" begin @@ -47,6 +48,16 @@ using Plots, Test @test square2.x ≈ coords[1,:] @test square2.y ≈ coords[2,:] end + + @testset "Plot" begin + ang = range(0, 2π, length = 60) + ellipse(x, y, w, h) = Shape(w*sin.(ang).+x, h*cos.(ang).+y) + myshapes = [ellipse(x,rand(),rand(),rand()) for x = 1:4] + @test coords(myshapes) isa Tuple{Vector{Vector{S}}, Vector{Vector{T}}} where {T,S} + local p + @test_nowarn p = plot(myshapes) + @test p[1][1][:seriestype] == :shape + end end @testset "Brush" begin