Repository: JuliaPlots/Makie.jl (julia)

Issue:
Colorbar for contour fails
this used to work. Not anymore:

```Julia
using GLMakie
x = -1:0.02:1
y = -1.5:0.02:2
egg(x, y) = x^2 + y^2 / (1.4 + y / 5)^2
segg = [egg(x, y) for x in x, y in y]

fig, ax, obj = contour(x, y, segg; levels=0:0.02:1)
Colorbar(fig[1,2], obj)
fig
```

with this error message:

```
ERROR: MethodError: Cannot `convert` an object of type Vec{2, Float32} to an object of type Tuple{Float32, Float32}
Closest candidates are:
  convert(::Type{T}, ::T) where T<:Tuple at essentials.jl:331
  convert(::Type{T}, ::Tuple{Vararg{Any, N}}) where {N, T<:Tuple} at essentials.jl:332
  convert(::Type{T}, ::CartesianIndex) where T<:Tuple at multidimensional.jl:131
  ...
Stacktrace:
  [1] (::Makie.var"#1169#1182")(x::Vec{2, Float32})
    @ Makie ~/.julia/packages/Makie/Ppzqh/src/makielayout/lineaxis.jl:252
  [2] #map#19
    @ ~/.julia/packages/Observables/ynr7h/src/Observables.jl:444 [inlined]
  [3] Makie.LineAxis(parent::Scene, attrs::Attributes)
    @ Makie ~/.julia/packages/Makie/Ppzqh/src/makielayout/lineaxis.jl:252
  [4] #LineAxis#1157
    @ ~/.julia/packages/Makie/Ppzqh/src/makielayout/lineaxis.jl:3 [inlined]
  [5] initialize_block!(cb::Colorbar)
    @ Makie ~/.julia/packages/Makie/Ppzqh/src/makielayout/blocks/colorbar.jl:315
  [6] _block(::Type{Colorbar}, ::Figure; bbox::Nothing, kwargs::Base.Pairs{Symbol, Observable{Any}, Tuple{Symbol, Symbol}, NamedTuple{(:colormap, :limits), Tuple{Observable{Any}, Observable{Any}}}})
    @ Makie ~/.julia/packages/Makie/Ppzqh/src/makielayout/blocks.jl:403
  [7] _block(::Type{Colorbar}, ::GridPosition; kwargs::Base.Pairs{Symbol, Observable{Any}, Tuple{Symbol, Symbol}, NamedTuple{(:colormap, :limits), Tuple{Observable{Any}, Observable{Any}}}})
    @ Makie ~/.julia/packages/Makie/Ppzqh/src/makielayout/blocks.jl:294
  [8] #_#1005
    @ ~/.julia/packages/Makie/Ppzqh/src/makielayout/blocks.jl:279 [inlined]
  [9] Colorbar(fig_or_scene::GridPosition, plot::Combined{Makie.contour, Tuple{Vector{Float32}, Vector{Float32}, Matrix{Float32}}}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Makie ~/.julia/packages/Makie/Ppzqh/src/makielayout/blocks/colorbar.jl:29
 [10] Colorbar(fig_or_scene::GridPosition, plot::Combined{Makie.contour, Tuple{Vector{Float32}, Vector{Float32}, Matrix{Float32}}})
    @ Makie ~/.julia/packages/Makie/Ppzqh/src/makielayout/blocks/colorbar.jl:21
 [11] top-level scope
```

Pull request description:
So that legend works again for contour!
Fixes: https://github.com/MakieOrg/Makie.jl/issues/2278

Patch:
diff --git a/src/makielayout/lineaxis.jl b/src/makielayout/lineaxis.jl
index d21f849ca45..b3894fdb541 100644
--- a/src/makielayout/lineaxis.jl
+++ b/src/makielayout/lineaxis.jl
@@ -86,7 +86,7 @@ function create_linepoints(
             return [from, to]
         end
     end
-    
+
 end
 
 function calculate_real_ticklabel_align(al, horizontal, fl::Bool, rot::Number)
@@ -266,8 +266,8 @@ function LineAxis(parent::Scene, attrs::Attributes)
 
     pos_extents_horizontal = lift(calculate_horizontal_extends, endpoints; ignore_equal_values=true)
     horizontal = lift(x-> x[3], pos_extents_horizontal)
-
-    limits = lift(x-> convert(Tuple{Float32, Float32}, x), attrs.limits; ignore_equal_values=true)
+    # Tuple constructor converts more than `convert(Tuple{Float32, Float32}, x)` but we still need the conversion to Float32 tuple:
+    limits = lift(x-> convert(Tuple{Float32, Float32}, Tuple(x)), attrs.limits; ignore_equal_values=true)
     flipped = lift(x-> convert(Bool, x), attrs.flipped; ignore_equal_values=true)
 
     ticksnode = Observable(Point2f[]; ignore_equal_values=true)


Test patch:
diff --git a/test/makielayout.jl b/test/makielayout.jl
index 3adbdec0c7c..e81b306cfd6 100644
--- a/test/makielayout.jl
+++ b/test/makielayout.jl
@@ -160,6 +160,14 @@ end
     hmap = heatmap!(Axis(fig[1, 1]), rand(4, 4))
     cb1 = Colorbar(fig[1,2], hmap; height = Relative(0.65))
     @test cb1.height[] == Relative(0.65)
+    @testset "conversion" begin
+        # https://github.com/MakieOrg/Makie.jl/issues/2278
+        fig = Figure()
+        cbar = Colorbar(fig[1,1], colormap=:viridis, colorrange=Vec2f(0, 1))
+        ticklabel_strings = first.(cbar.axis.elements[:ticklabels][1][])
+        @test ticklabel_strings[1] == "0.0"
+        @test ticklabel_strings[end] == "1.0"
+    end
 end
 
 @testset "cycling" begin
@@ -246,7 +254,7 @@ end
     ax1 = Axis(f[1, 1])
     ax2 = Axis(f[1, 2])
     ax3 = Axis(f[1, 3])
-    
+
     linkaxes!(ax2, ax3)
     @test Set(ax1.xaxislinks) == Set([])
     @test Set(ax2.xaxislinks) == Set([ax3])