Repository: JuliaPlots/Makie.jl (julia)

Issue:
Axislegend fails when given a tuple of numbers
I have always been able to give the position of an axislegend as a tuple of numbers.

<details><summary>The following works just fine:</summary>

```
julia> begin
          plot(1:10, 1:10, label="test")
          axislegend(position = :rt)
          current_figure()
       end

```
</details>

<details><summary>But this errors</summary>

```

julia> begin                                                               
           plot(1:10, 1:10, label="test")                                  
           axislegend(position = (1, 0))                               
           current_figure()                                        
       end
ERROR: MethodError: Cannot `convert` an object of type Int64 to an object of type Symbol
Closest candidates are:
  convert(::Type{T}, ::T) where T at C:\Users\Dennis Bal\.julia\juliaup\julia-1.7.2+0~x64\share\julia\base\essentials.jl:218
  Symbol(::Any...) at C:\Users\Dennis Bal\.julia\juliaup\julia-1.7.2+0~x64\share\julia\base\strings\basic.jl:229
Stacktrace:
  [1] setproperty!(x::Observable{Symbol}, f::Symbol, v::Int64)
    @ Base .\Base.jl:43
  [2] setindex!(observable::Observable, val::Any)
    @ Observables C:\Users\Dennis Bal\.julia\packages\Observables\ynr7h\src\Observables.jl:85
  [3] (::Observables.var"#17#18"{Observable{Symbol}})(x::Int64)
    @ Observables C:\Users\Dennis Bal\.julia\packages\Observables\ynr7h\src\Observables.jl:418
  [4] on(f::Any, observable::Observables.AbstractObservable; weak::Bool, priority::Int64, update::Bool)
    @ Observables C:\Users\Dennis Bal\.julia\packages\Observables\ynr7h\src\Observables.jl:281
  [5] connect!
    @ C:\Users\Dennis Bal\.julia\packages\Observables\ynr7h\src\Observables.jl:418 [inlined]
  [6] connect_block_layoutobservables!(leg::Legend, layout_width::Observable{Any}, layout_height::Observable{Any}, layout_tellwidth::Observable{Bool}, layout_tellheight::Observable{Bool}, layout_halign::Observable{Symbol}, layout_valign::Observable{Symbol}, layout_alignmode::Observable{Any})        
    @ Makie.MakieLayout C:\Users\Dennis Bal\.julia\packages\Makie\AW7kA\src\makielayout\blocks\legend.jl:244
  [7] _block(T::Type{Legend}, fig_or_scene::Figure, args::Observable{Vector{Tuple{Union{Nothing, AbstractString}, Vector{LegendEntry}}}}; bbox::Observable{GeometryBasics.HyperRectangle{2, Int64}}, kwargs::Base.Pairs{Symbol, Any, Tuple{Symbol, Symbol, Symbol}, NamedTuple{(:margin, :halign, :valign), Tuple{NTuple{4, Int64}, Int64, Int64}}})
    @ Makie.MakieLayout C:\Users\Dennis Bal\.julia\packages\Makie\AW7kA\src\makielayout\blocks.jl:413
  [8] #_#38
    @ C:\Users\Dennis Bal\.julia\packages\Makie\AW7kA\src\makielayout\blocks.jl:269 [inlined]
  [9] Legend(fig_or_scene::Figure, contents::Vector{AbstractPlot}, labels::Vector{String}, title::Nothing; kwargs::Base.Pairs{Symbol, Any, NTuple{4, Symbol}, NamedTuple{(:bbox, :margin, :halign, :valign), Tuple{Observable{GeometryBasics.HyperRectangle{2, Int64}}, NTuple{4, Int64}, Int64, Int64}}})  
    @ Makie.MakieLayout C:\Users\Dennis Bal\.julia\packages\Makie\AW7kA\src\makielayout\blocks\legend.jl:474
 [10] Legend(fig_or_scene::Figure, axis::Axis, title::Nothing; merge::Bool,
 unique::Bool, kwargs::Base.Pairs{Symbol, Any, NTuple{4, Symbol}, NamedTuple{(:bbox, :margin, :halign, :valign), Tuple{Observable{GeometryBasics.HyperRectangle{2, Int64}}, NTuple{4, Int64}, Int64, Int64}}})
    @ Makie.MakieLayout C:\Users\Dennis Bal\.julia\packages\Makie\AW7kA\src\makielayout\blocks\legend.jl:530
 [11] #axislegend#747
    @ C:\Users\Dennis Bal\.julia\packages\Makie\AW7kA\src\makielayout\blocks\legend.jl:595 [inlined]
 [12] #axislegend#745
    @ C:\Users\Dennis Bal\.julia\packages\Makie\AW7kA\src\makielayout\blocks\legend.jl:571 [inlined]
 [13] top-level scope
    @ REPL[18]:3
```
</details>

<details><summary>System info:</summary>

```
(drwatson) pkg> st
      Status `C:\Users\Dennis Bal\GeekyStuff\Julia\6. Sem\Statistical Machine Learning\drwatson\Project.toml`
  [aaaa29a8] Clustering v0.14.2
  [7806a523] DecisionTree v0.10.12
  [b4f34e82] Distances v0.10.7
  [634d3b9d] DrWatson v2.9.1
  [e9467ef8] GLMakie v0.6.2
  [add582a8] MLJ v0.18.2
  [c6f25543] MLJDecisionTreeInterface v0.2.2
  [1b6a4a23] MLJMultivariateStatsInterface v0.3.1
  [b8a86587] NearestNeighbors v0.4.10

julia> versioninfo()
Julia Version 1.7.2
Commit bf53498635 (2022-02-06 15:21 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, skylake)
Environment:
  JULIA_EDITOR = code
  JULIA_NUM_THREADS = 8
```
</details>

If this is indeed a bug, clearly tests should be added for the different possible calls to `axislegend`.

Pull request:
# Description

Fixes #1958 and fixes #2006

## Type of change

Delete options that do not apply:

- [x] Bug fix (non-breaking change which fixes an issue)

## Checklist

- [ ] Added an entry in NEWS.md (for new features and breaking changes)
- [x] Added unit tests for new algorithms, conversion methods, etc.

Patch:
diff --git a/NEWS.md b/NEWS.md
index fbe06ed1bda..18a8c81b161 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,5 +1,9 @@
 # News
 
+## master
+
+- Fixed regression where `Block` alignments could not be specified as numbers anymore [#2108](https://github.com/JuliaPlots/Makie.jl/pull/2108).
+
 ## v0.17.7
 
 - Improved `Menu` performance, now it should me much harder to reach the boundary of 255 scenes in GLMakie. `Menu` also takes a `default` keyword argument now and can be scrolled if there is too little space available.
diff --git a/src/makielayout/blocks.jl b/src/makielayout/blocks.jl
index f067b3cdf3b..81aaa9df34b 100644
--- a/src/makielayout/blocks.jl
+++ b/src/makielayout/blocks.jl
@@ -332,8 +332,8 @@ function _block(T::Type{<:Block}, fig_or_scene::Union{Figure, Scene},
     layout_height = Observable{Any}(nothing)
     layout_tellwidth = Observable(true)
     layout_tellheight = Observable(true)
-    layout_halign = Observable(:center)
-    layout_valign = Observable(:center)
+    layout_halign = Observable{Union{Symbol, Float64}}(:center)
+    layout_valign = Observable{Union{Symbol, Float64}}(:center)
     layout_alignmode = Observable{Any}(Inside())
 
     lobservables = LayoutObservables(


Test patch:
diff --git a/test/makielayout.jl b/test/makielayout.jl
index 31dccff4262..55b799caa74 100644
--- a/test/makielayout.jl
+++ b/test/makielayout.jl
@@ -175,3 +175,13 @@ end
     ax = Axis(f[1,1], xticks = 20:10:80)
     scatter!(ax, 30:10:100, rand(Float64, 8), color = :red)
 end
+
+# issues 1958 and 2006
+@testset "axislegend number align" begin
+    f = Figure()
+    ax = Axis(f[1,1], xticks = 20:10:80)
+    lines!(ax, 1:10, label = "A line")
+    leg = axislegend(ax, position = (0.4, 0.8))
+    @test leg.halign[] == 0.4
+    @test leg.valign[] == 0.8
+end
\ No newline at end of file