Skip to content

Commit

Permalink
Add integrations to make Legend(ga) work (#275)
Browse files Browse the repository at this point in the history
* Add integrations to make `Legend(ga)` work

* Add a "test"
  • Loading branch information
asinghvi17 authored Sep 20, 2024
1 parent e897be2 commit a191f21
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/makie-axis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a191f21

Please sign in to comment.