Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Beforerr committed May 7, 2024
1 parent 97d5f0f commit 45caa5f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ authors = ["Beforerr <[email protected]> and contributors"]
version = "1.0.0-DEV"

[deps]
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
AlgebraOfGraphics = "cbdf2221-f076-402e-a563-3d30da359d67"
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"

[compat]
julia = "1"
Expand Down
5 changes: 3 additions & 2 deletions src/beforerr.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module beforerr

# Write your package code here.
export add_labels!
using AlgebraOfGraphics, CairoMakie

export add_labels!, pretty_legend!, easy_save

include("utils/makie.jl")

Expand Down
35 changes: 31 additions & 4 deletions src/utils/makie.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,41 @@
using CairoMakie

function add_label!(layout, label; position=TopLeft())
Label(layout[1, 1, position], label,
font=:bold,
padding = (0, 40, 0, 0),
halign=:right)
end

function add_labels!(layouts; labels)

"""
add labels to a grid of layouts
# Notes
- See `tag_facet` in `egg` for reference
"""
function add_labels!(layouts; labels = ('a':'z'), open = "(", close = ")")
for (label, layout) in zip(labels, layouts)
add_label!(layout, label)
tag = open * label * close
add_label!(layout, tag)
end
end

function pretty_legend!(fig, grid)
legend!(fig[0, 1:end], grid, titleposition=:left, orientation=:horizontal)
end

function easy_save(name, fig; dir="figures")
path = "$dir/$name"
mkpath(dir)

save("$path.png", fig, px_per_unit=4)
save("$path.pdf", fig)

# log the path saved
@info "Saved $(abspath(path)).png"
fig
end

function easy_save(name; dir="figures")
fig = current_figure()
easy_save(name, fig, dir=dir)
end

0 comments on commit 45caa5f

Please sign in to comment.