Skip to content

Commit

Permalink
feat: Add guides_position function
Browse files Browse the repository at this point in the history
  • Loading branch information
Beforerr committed Oct 23, 2024
1 parent f6a42a2 commit 3e9fcf6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ version = "0.1.1"
[deps]
AlgebraOfGraphics = "cbdf2221-f076-402e-a563-3d30da359d67"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
Match = "7eb4fadd-790c-5f42-8a69-bfa0b872bfbf"

[compat]
Match = "2.1.0"
julia = "1.9"

[extras]
Expand Down
1 change: 1 addition & 0 deletions src/Beforerr.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Beforerr

using AlgebraOfGraphics, Makie
using Match

export add_labels!, hideylabels!, pretty_legend!
export AxsOpts, FigureGridOpts, PlotOpts, process_opts!
Expand Down
23 changes: 21 additions & 2 deletions src/utils/aog.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
const SUPPORTED_POS = [:top, :bottom, :left, :right]

Base.:*(l::Layer, p::NamedTuple) = l * mapping(; p...)
Base.:*(l::Layer, p::Tuple) = l * mapping(p...)

"""
guides_position(f, position)
Return the position of the guides for the given `position` in the `f`.
"""
function guides_position(f, position)
position = Symbol(position)
position SUPPORTED_POS && throw(ArgumentError("Legend position $position$SUPPORTED_POS"))

@match position begin
:bottom => f[end+1, :]
:top => f[0, :]
:right => f[:, end+1]
:left => f[:, 0]
end
end

"""
cdraw!(f, args...; position=:right, kwargs...)
Like `AlgebraOfGraphics.draw!`, but adds a colorbar.
"""
function cdraw!(f::GridLayout, args...; position=:right, kw...)
grids = draw!(f[1, 1], args...; kw...)
guide_pos = f[:, end+1]
guide_pos = guides_position(f, position)
colorbar!(guide_pos, grids)
return grids
end

cdraw!(f::Union{GridPosition, GridSubposition}, args...; kw...) = cdraw!(GridLayout(f), args...; kw...)
cdraw!(f::Union{GridPosition,GridSubposition}, args...; kw...) = cdraw!(GridLayout(f), args...; kw...)

0 comments on commit 3e9fcf6

Please sign in to comment.