Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/SpellCheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Spell Check

on: [pull_request]

jobs:
typos-check:
name: Spell Check with Typos
runs-on: ubuntu-latest
steps:
- name: Checkout Actions Repository
uses: actions/checkout@v4
- name: Check spelling
uses: crate-ci/typos@master

2 changes: 2 additions & 0 deletions _typos.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[default.extend-words]
Missings = "Missings"
7 changes: 4 additions & 3 deletions docs/src/makie.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The following function help to convert.
cm2inch
```

Figures often look well, if the ratio between length and hight corresponds
Figures often look well, if the ratio between length and height corresponds
to the [Golden ratio](https://en.wikipedia.org/wiki/Golden_ratio).
So we provide it here.

Expand All @@ -25,15 +25,16 @@ properties such as figure sizes, fontsizes, and graphics format.
The following class helps to collect them and provide them to functions below
```@docs
MakieConfig
paper_MakieConfig
```

### creating figures with adjusted sizes and font-sizes
### creating Makie Figures with adjusted sizes and font-sizes

```@docs
figure_conf
figure_conf_axis
```
### saving figures to correct format and dpi-resolution
### saving figures to correct format, subdirectory, and dpi-resolution

```@docs
save_with_config
Expand Down
2 changes: 1 addition & 1 deletion ext/FigureHelpersMakieAbstractMCMCExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ end
"""
Histogram of several variables of a 3D array, i.e. MCMCChain.

The desnity plot may give wrong impressions, if probability mass is concentrated
The density plot may give wrong impressions, if probability mass is concentrated
at the borders, which can be inspected by plotting histograms instead.
"""
function CP.histogram_params(chns, pars=names(chns, :parameters);
Expand Down
12 changes: 3 additions & 9 deletions ext/FigureHelpersMakieExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ function CP.figure_conf_axis(args...; makie_config::MakieConfig = MakieConfig(),
fig, Axis(fig[1,1]; kwargs...)
end

function get_size_from_config(cfg)
72 .* cfg.size_inches ./ cfg.pt_per_unit # size_pt
end
function get_fontsize_from_config(cfg)
cfg.fontsize ./ cfg.pt_per_unit
end

function CP.figure_conf(; makie_config::MakieConfig = MakieConfig())
size = get_size_from_config(makie_config)
fontsize = get_fontsize_from_config(makie_config)
Expand All @@ -48,8 +41,9 @@ function CP.save_with_config(filename::AbstractString, fig::Union{Figure, Makie.
filename_cfg = joinpath(dir,bname)
mkpath(dir)
#save(filename_cfg, fig, args...)
save(filename_cfg, fig, args...; pt_per_unit = makie_config.pt_per_unit)
filename_cfg
save(filename_cfg, fig, args...;
pt_per_unit = makie_config.pt_per_unit, px_per_unit = makie_config.px_per_unit)
abspath(filename_cfg)
end

CP.hidexdecoration!(ax; label = false, ticklabels = false, ticks = false, grid = false, minorgrid = false, minorticks = false, kwargs...) = hidexdecorations!(ax; label, ticklabels, ticks, grid, minorgrid, minorticks, kwargs...)
Expand Down
4 changes: 3 additions & 1 deletion src/FigureHelpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ include("util.jl")

include("makie_util.jl")
export cm_per_inch, cm2inch, golden_ratio, MakieConfig
export figure_conf, figure_conf_axis, save_with_config, ppt_MakieConfig, paper_MakieConfig
export figure_conf, figure_conf_axis, save_with_config
export ppt_MakieConfig, paper_MakieConfig, png_MakieConfig
export hidexdecoration!, hideydecoration!, axis_contents
export get_size_from_config, get_fontsize_from_config

include("aog_util.jl")
export set_default_AoGTheme!, draw_with_legend!
Expand Down
2 changes: 1 addition & 1 deletion src/aog_util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Setting sensible defaults with taking care of `pt_per_unit` in MakieConfig.

When saving png, there is a difference in size between the produced figure
in print and display on a monitor and its dpi settings.
This routine adjusts several seetings given in inch by deviding `makie_config.pt_per_unit`.
This routine adjusts several settings given in inch by dividing `makie_config.pt_per_unit`.
"""
function set_default_AoGTheme! end

Expand Down
87 changes: 64 additions & 23 deletions src/makie_util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,23 @@ const golden_ratio = 1.618
A collection of figure properties to tailor the same figure either
for presentation in a paper or a presentation.

ppt_MakieConfig(;
target = :presentation,
filetype = "png",
fontsize=18,
size_inches = (5.0,5.0/golden_ratio),
kwargs...)

paper_MakieConfig(;
size_inches = cm2inch.((8.3,8.3/golden_ratio)),
kwargs...)

Properties and defaults
- `pt_per_unit = 0.75`
- `filetype = "png"`
- `px_per_unit = 2.0`
- `filetype = "svg"`
- `fontsize = 9` (point units)
- `size_inches = cm2inch.((17.5,17.5/golden_ratio))` (witdth x height)
- `size_inches = cm2inch.((17.5,17.5/golden_ratio))` (width x height)

The default `px_per_unit` needs to rescale a png image in ppt to 50%, but
this gives better quality.
"""
@with_kw struct MakieConfig{FT,IT}
target::Symbol = :paper
pt_per_unit::FT = 0.75
filetype::String = "png"
target::Symbol = :tmp
pt_per_unit::FT = 0.75 # Makie default
px_per_unit::FT = 2.0 # Makie default is 2.0, but control here
filetype::String = "svg"
fontsize::IT = 9
size_inches::Tuple{FT,FT} = cm2inch.((17.5,17.5/golden_ratio))
size_inches::Tuple{FT,FT} = cm2inch.((17.5,17.5/golden_ratio)) # BG-two-column
end

# function MakieConfig(cfg::MakieConfig;
Expand All @@ -65,16 +59,63 @@ end
# MakieConfig(target, pt_per_unit, filetype, fontsize, size_inches)
# end

"""
Get the size in pixel from Config, taking care of pt_per_unit and dpi of
"""
function get_size_from_config(cfg; dpi=72)
dpi .* cfg.size_inches ./ cfg.pt_per_unit # size_pt for 72 dpi
end

function get_fontsize_from_config(cfg)
cfg.fontsize ./ cfg.pt_per_unit
end





#ppt_MakieConfig(;target = :presentation, pt_per_unit = 0.75/2, filetype = "png", fontsize=18, size_inches = cm2inch.((29,29/golden_ratio)), kwargs...) = MakieConfig(;target, pt_per_unit, filetype, fontsize, size_inches, kwargs...)
# size so that orginal size covers half a wide landscape slide of 33cm
# size so that original size covers half a wide landscape slide of 33cm
# svg does not work properly with fonts in ppt/wps
#ppt_MakieConfig(;target = :presentation, filetype = "png", fontsize=18, size_inches = cm2inch.((16,16/golden_ratio)), kwargs...) = MakieConfig(;target, filetype, fontsize, size_inches, kwargs...)
# target of 10inch wide screen slide
ppt_MakieConfig(;target = :presentation, filetype = "png", fontsize=18, size_inches = (5.0,5.0/golden_ratio), kwargs...) = MakieConfig(;target, filetype, fontsize, size_inches, kwargs...)
# target of 10inch wide screen slide (16:10)
#ppt_MakieConfig(;target = :presentation, filetype = "png", fontsize=18, size_inches = (5.0,5.0/golden_ratio), kwargs...) = MakieConfig(;target, filetype, fontsize, size_inches, kwargs...)
# target of 13.3inch wide screen slide (16:9): wide screen
"""
paper_MakieConfig(;
target = :paper, filetype = "pdf",
fontsize=9, size_inches = cm2inch.((8.3,8.3/golden_ratio)), ...)

ppt_MakieConfig(;
target = :presentation, filetype = "svg",
fontsize=18, size_inches = (6.65,6.65/golden_ratio), ...)

paper_MakieConfig(;size_inches = cm2inch.((8.3,8.3/golden_ratio)), filetype = "pdf", kwargs...) = MakieConfig(;size_inches, filetype, kwargs...)
png_MakieConfig(;target = :png, filetype = "png", ...)

Specialized configurations adapted to
- `paper_MakieConfig`: single column Biogeosciences paper (8.3cm)
- `ppt_MakieConfig`: half of a wide-screen ppt presentation (13.3 inch), either svg or png
Inserting generated svg yields better quality than copy (=png) from VScode preview.
- `png_MakieConfig`: same as ppt, but generating png images at 200% scale
By default, need to rescale the png to 50% when inserting into presentation.
"""
function paper_MakieConfig(;
target = :paper, filetype = "pdf",
fontsize=9, size_inches = cm2inch.((8.3,8.3/golden_ratio)),
kwargs...
)
MakieConfig(;target, filetype, fontsize, size_inches, kwargs...)
end;
function ppt_MakieConfig(;
target = :presentation, filetype = "svg",
fontsize=18, size_inches = (6.65,6.65/golden_ratio),
kwargs...
)
MakieConfig(;target, filetype, fontsize, size_inches, kwargs...)
end;
function png_MakieConfig(;target = :png, filetype = "png", kwargs...)
ppt_MakieConfig(;target, filetype)
end

"""
figure_conf(; makie_config)
Expand All @@ -91,7 +132,7 @@ the default x-width.

The last constructor sets the properties without referring to a config.
It uses by default `pt_per_unit=0.75` to conform to png display and save.
Remember to devide fontsize and other sizes specified elsewhere by this factor.
Remember to divide fontsize and other sizes specified elsewhere by this factor.
See also [`cm2inch`](@ref) and `save`.
"""
function figure_conf end;
Expand All @@ -110,7 +151,7 @@ function figure_conf_axis end;

Save figure with file updated extension `cfg.filetype` to subdirectory `cfg.filetype`
of given path of filename.
Sets `pt_per_unit` to `makie_config.pt_per_unit`.
Sets `pt_per_unit` and `px_per_unit` according to `makie_config`.
"""
function save_with_config end

Expand Down
2 changes: 1 addition & 1 deletion src/util.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# used in Extensions to pass limimits
"similar to passmissing, creates a function that retuns nothing, if any of its arguments is noting."
"similar to passmissing, creates a function that returns nothing, if any of its arguments is noting."
passnothing(f) = (xs...; kwargs...) -> any(isnothing, xs) ? nothing : f(xs...;kwargs...)

# function _getindex_keep(ax::CA.AbstractAxis, syms::NTuple{N,Symbol}) where N
Expand Down
27 changes: 25 additions & 2 deletions test/test_cairomakie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ using CairoMakie
fig0 = figure_conf(; makie_config = ppt_MakieConfig())
(x0,y0) = size(fig0.scene)
fig = figure_conf(0.5, 1.2; makie_config = ppt_MakieConfig())
@test size(fig.scene)[1] ≈ x0*1.2
@test size(fig.scene)[2] ≈ x0*1.2/0.5
@test size(fig.scene)[1] ≈ x0*1.2 atol=1.0
@test size(fig.scene)[2] ≈ x0*1.2/0.5 atol=1.0
#
makie_config = MakieConfig(filetype="png", target=:presentation)
# set_default_CMTheme!(;makie_config) # aog-specific
Expand All @@ -43,6 +43,29 @@ using CairoMakie
#
end;

check_pdf_size = () -> begin
makie_config = paper_MakieConfig()
fig = figure_conf(golden_ratio;makie_config);
data = cumsum(randn(4, 101), dims = 2)
series!(Axis(fig[1,1]), data, labels=["label $i" for i in 1:4])
save_with_config("tmp/tmp", fig; makie_config)
makie_config.size_inches
# load file and check property figure size-inces
end

check_ppt_png_size = () -> begin
makie_config = png_MakieConfig()
fig = figure_conf(golden_ratio;makie_config);
data = cumsum(randn(4, 101), dims = 2)
series!(Axis(fig[1,1]), data, labels=["label $i" for i in 1:4])
save_with_config("tmp/tmp", fig; makie_config)
makie_config.size_inches
# load files and check property figure size-inces is 2 times the inces
#
save_with_config("tmp/tmp", fig; makie_config=MakieConfig(makie_config; filetype="svg"))
end


i_test_larger_margins = () -> begin
makie_config = ppt_MakieConfig(filetype="png")
set_default_CMTheme!(;makie_config)
Expand Down
Loading