diff --git a/test/conversions.jl b/test/conversions.jl index 881062c02c3..758f0614aca 100644 --- a/test/conversions.jl +++ b/test/conversions.jl @@ -287,3 +287,66 @@ end pl[1] = [points] @test pl.plots[1][1][] == Makie.poly_convert(points) end + + +@testset "GridBased and ImageLike conversions" begin + # type tree + @test GridBased <: ConversionTrait + @test CellBasedGrid <: GridBased + @test VertexBasedGrid <: GridBased + @test ImageLike <: ConversionTrait + + # Plot to trait + @test conversion_trait(Image) === ImageLike() + @test conversion_trait(Heatmap) === CellBasedGrid() + @test conversion_trait(Surface) === VertexBasedGrid() + @test conversion_trait(Contour) === VertexBasedGrid() + @test conversion_trait(Contourf) === VertexBasedGrid() + + m1 = [x for x in 1:10, y in 1:6] + m2 = [y for x in 1:10, y in 1:6] + m3 = rand(10, 6) + + r1 = 1:10 + r2 = 1:6 + + v1 = collect(1:10) + v2 = collect(1:6) + + i1 = 1..10 + i2 = 1..6 + + o3 = Float32.(m3) + + # Conversions + @testset "ImageLike conversion" begin + @test convert_arguments(Image, m3) == (0f0..10f0, 0f0..6f0, o3) + @test convert_arguments(Image, v1, r2, m3) == (1f0..10f0, 1f0..6f0, o3) + @test convert_arguments(Image, i1, v2, m3) == (1f0..10f0, 1f0..6f0, o3) + @test_throws ErrorException convert_arguments(Image, m1, m2, m3) + @test_throws ErrorException convert_arguments(Heatmap, m1, m2) + end + + @testset "VertexBasedGrid conversion" begin + vo1 = Float32.(v1) + vo2 = Float32.(v2) + mo1 = Float32.(m1) + mo2 = Float32.(m2) + @test convert_arguments(Surface, m3) == (vo1, vo2, o3) + @test convert_arguments(Contour, i1, v2, m3) == (vo1, vo2, o3) + @test convert_arguments(Contourf, v1, r2, m3) == (vo1, vo2, o3) + @test convert_arguments(Surface, m1, m2, m3) == (mo1, mo2, o3) + @test convert_arguments(Surface, m1, m2) == (mo1, mo2, zeros(Float32, size(o3))) + end + + @testset "CellBasedGrid conversion" begin + o1 = Float32.(0.5:1:10.5) + o2 = Float32.(0.5:1:6.5) + @test convert_arguments(Heatmap, m3) == (o1, o2, o3) + @test convert_arguments(Heatmap, r1, i2, m3) == (o1, o2, o3) + @test convert_arguments(Heatmap, v1, r2, m3) == (o1, o2, o3) + @test convert_arguments(Heatmap, 0:10, v2, m3) == (collect(0f0:10f0), o2, o3) + @test_throws ErrorException convert_arguments(Heatmap, m1, m2, m3) + @test_throws ErrorException convert_arguments(Heatmap, m1, m2) + end +end \ No newline at end of file