From 82e9ce0147387b16fb2147c5403abca3a4b8f64a Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Thu, 19 Sep 2024 02:00:48 -0700 Subject: [PATCH 1/2] Add integrations to make `Legend(ga)` work --- src/makie-axis.jl | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/makie-axis.jl b/src/makie-axis.jl index cb2daf6a..a8a9f1ea 100644 --- a/src/makie-axis.jl +++ b/src/makie-axis.jl @@ -553,3 +553,15 @@ Makie.hidedecorations!(ax::GeoAxis; kw...) = begin hidexdecorations!(ax; kw...) hideydecorations!(ax; kw...) end + +# Legend API + +function Makie.get_plots(ax::GeoAxis) + return Makie.get_plots(ax.scene)[3:end] +end + +function Makie.Legend(fig_or_scene, axis::GeoAxis, title = nothing; merge = false, unique = false, kwargs...) + plots, labels = Makie.get_labeled_plots(axis, merge = merge, unique = unique) + isempty(plots) && error("There are no plots with labels in the given axis that can be put in the legend. Supply labels to plotting functions like `plot(args...; label = \"My label\")`") + Makie.Legend(fig_or_scene, plots, labels, title; kwargs...) +end From 6fa63b83c2c5a7ec0128039c1776bf1830b49d8d Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Thu, 19 Sep 2024 19:47:03 -0700 Subject: [PATCH 2/2] Add a "test" --- test/runtests.jl | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index 60a6c8d2..196f3289 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -34,4 +34,13 @@ Makie.set_theme!(Theme( @test GeoMakie.coastlines(ga) isa Observable @test GeoMakie.coastlines(ga)[] isa AbstractVector end + + @testset "Legend" begin + fig = Figure() + ga = GeoAxis(fig[1, 1]) + lines!(ga, 1:10, 1:10; label = "series 1") + scatter!(ga, 1:19, 2:20; label= "series 2") + @test_nowarn Legend(fig[1, 2], ga) + fig + end end