Skip to content

Commit

Permalink
refactor(theme): reorganize constants and add ISO paper sizes
Browse files Browse the repository at this point in the history
- Add comprehensive ISO 216 paper size constants for A, B, and C series
- Fix documentation clarity about slides vs beamer class differences
- Add tests for paper size constants
- Update test directory handling in PathSpec tests and mark test as
  broken locally as well
  • Loading branch information
kunzaatko committed Feb 5, 2025
1 parent 399301a commit 5fc71fc
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/src/workflows/savefig.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Themes.get_theme(:base, :appendix, :rotate_labels);
You should adjust the font sizes of the figure to match the document for the physical export sizes to match. For the
common, built-in sizes in ``\LaTeX`` and there correspondence with point sizes, look at the
[wiki](https://en.wikibooks.org/wiki/LaTeX/Fonts#Built-in_sizes). Importantly, there is a difference in the sizes
when using `slides` or `beamer` as the document class.
when using `slides` (not `beamer`) as the document class.

## Exporting figures

Expand Down
7 changes: 2 additions & 5 deletions src/theme/theme-constants.jl → src/theme/constants.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ using Unitful
using Unitful: Length
using MakieMaestro.Units

include("paper-sizes.jl")

const ALPHA = 1.0
const COLOR_SCHEME = ColorSchemes.seaborn_deep.colors
const COLORS = @. RGBAf(red(COLOR_SCHEME), green(COLOR_SCHEME), blue(COLOR_SCHEME), ALPHA)
Expand Down Expand Up @@ -36,11 +38,6 @@ const MARKERSIZE = 7
const CYCLE = Cycle([:color, :marker]; covary=true)
const WIDTH_DEFAULT = Ref{Union{Missing,Length}}(missing)
const HWRATIO_DEFAULT = Ref{Number}(float(2 / ((5) + 1)))

# TODO: Define via a macro all the other paper sizes <08-01-25>
const A4_WIDTH = 210u"mm"
const A4_HEIGHT = 297u"mm"

"""
hwratio!(val)
Expand Down
24 changes: 24 additions & 0 deletions src/theme/paper-sizes.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# TODO: Add a note of these constants existence into the documentation <05-02-25>
# NOTE: There are many conventions to what to refer to as the "width" and what to refer to as the "height". This defines
# the dimensions in the usual portrait orientation, hence the longer side is always the height contrary to the ISO 216
# standard where the "height" (and "width") are alternatingly shorter and longer. This means that in the ISO standard,
# A4's dimensions would be height=210mm and width=297mm and in ours it would be width=210mm and height=297mm. <05-02-25>
for (series, base_hw, count) in (
("A", (1189u"mm", 841u"mm"), 13),
("B", (1414u"mm", 1000u"mm"), 13),
("C", (1297u"mm", 917u"mm"), 10),
)
for i in 0:count
ph, pw = Symbol(series, i, "_HEIGHT"), Symbol(series, i, "_WIDTH")
h_true, w_true = (base_hw ./ (2^((1 + i) ÷ 2), 2^(i ÷ 2)))[[
i % 2 + 1, (i + 1) % 2 + 1
]]
ph_true, pw_true = map(a -> Symbol(a, "_TRUE"), (ph, pw))
@eval const $ph_true = $h_true
@eval const $pw_true = $w_true

h_standard, w_standard = floor.(Unitful.mm, (h_true, w_true))
@eval const $ph = $h_standard
@eval const $pw = $w_standard
end
end
9 changes: 8 additions & 1 deletion src/theme/theme.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# TODO: An interactive tool, where one can put his figure and change the attributes using the builtin block such as
# a sliders etc. to get the correct attributes. Changing sizes and colours, etc. The available sizes within the
# interactive figure can be configured using some config file that would hold all the attributes. Perhaps some
# attributes would not be possible to change like the figure sizes? <03-02-25>
# TODO: Assure that the gaps are set correctly such that if I use subfigures in LaTeX that the figures output is the
# same as when I generate a figure with multiple axes <18-10-24>
"""
Expand All @@ -22,7 +26,7 @@ using Makie: Theme
# a dictionary could be passed to the save-fig and the `with_theme` functions as a whole or via an accessor <18-10-24>
# TODO: Framework for setting the base theme and/or updating it etc. <18-10-24>

include("theme-constants.jl")
include("constants.jl")

# TODO: Theme generators should also be dynamic meaning that when one calls a generating function, it should be able to
# decide based on the previous attributes that were set. This can be done by a generic argument to the theme generating
Expand Down Expand Up @@ -148,6 +152,9 @@ function get_theme(themes::Vararg{Union{ThemeGenerator,Symbol}}; dict=THEME[])
return get_theme(collect(Union{ThemeGenerator,Symbol}, themes); dict=dict)
end

# FIX: Instead the difference between `update_theme!` and `update_theme` should be whether the attributes that are
# existent in `key` are left or overwritten. Maybe this could be instead driven by some enum similarly to lua type of
# table merge <03-02-25>
"""
update_theme!(key::Symbol, new::ThemeGenerator)
Update a specific theme component in the global theme.
Expand Down
15 changes: 14 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ include("./tools.jl")
end
end
@testset "Theming" begin
@testset "Constants" begin
using MakieMaestro.Themes
@test Themes.A4_HEIGHT == 297u"mm"
@test Themes.A11_WIDTH == 18u"mm" # Test for rounding down

@test Themes.A3_HEIGHT == Themes.A2_WIDTH == 420u"mm"
@test Themes.B6_WIDTH == 125u"mm"
@test Themes.C10_HEIGHT == 40u"mm"
end
@testset "merge_generate" begin
using MakieMaestro.Themes: merge_generate, ThemeGenerator, get_theme, THEME
@test THEME[][:base] isa ThemeGenerator
Expand Down Expand Up @@ -148,7 +157,11 @@ include("./tools.jl")

export_format!(Set([MakieMaestro.Pdf]))
if !haskey(ENV, "GITHUB_ACTIONS") # NOTE: tmp directories do not work as expected in the CI <31-01-25>
@test PathSpec("testpdf") isa PathSpec
# FIX: Somehow creating a temp dir and changing to it does not work either... <05-02-25>
temp_dir = mkdir(joinpath(tempdir(), "mm_test_dir/"))
cd(temp_dir)
@test_broken PathSpec("testpdf") isa PathSpec
rm(temp_dir; recursive=true)
end
@test MakieMaestro.Pdf in PathSpec(joinpath(dir, "testpdf")).formats
@test PathSpec("test", dir) isa PathSpec
Expand Down

0 comments on commit 5fc71fc

Please sign in to comment.