@@ -46,6 +46,31 @@ arguments of either `legend` or `colorbar`.
46
46
47
47
For finer control, use [`draw!`](@ref),
48
48
[`legend!`](@ref), and [`colorbar!`](@ref) independently.
49
+
50
+ ## Figure options
51
+
52
+ AlgebraOfGraphics accepts the following special keywords under the `figure` keyword,
53
+ the remaining attributes are forwarded to Makie's `Figure` constructor.
54
+ The `title`, `subtitle` and `footnotes` arguments accept objects of any kind that Makie's
55
+ `Label` or `text` function can handle, such as `rich` text.
56
+
57
+ - `title`
58
+ - `subtitle`
59
+ - `titlesize::Union{Nothing,Float64}`
60
+ - `subtitlesize::Union{Nothing,Float64}`
61
+ - `titlealign::Union{Nothing,Symbol}`
62
+ - `titlecolor`
63
+ - `subtitlecolor`
64
+ - `titlefont`
65
+ - `subtitlefont`
66
+ - `titlelineheight`
67
+ - `subtitlelineheight`
68
+ - `footnotes::Union{Nothing,Vector{Any}}`
69
+ - `footnotesize::Union{Nothing,Float64}`
70
+ - `footnotefont`
71
+ - `footnotecolor`
72
+ - `footnotealign`
73
+ - `footnotelineheight`
49
74
"""
50
75
function draw (d:: AbstractDrawable , scales:: Scales = scales ();
51
76
axis= NamedTuple (), figure= NamedTuple (),
62
87
63
88
_remove_show_kw (pairs) = filter (((key, value),) -> key != = :show , pairs)
64
89
90
+ struct FigureSettings
91
+ title
92
+ subtitle
93
+ titlesize:: Union{Nothing,Float64}
94
+ subtitlesize:: Union{Nothing,Float64}
95
+ titlealign:: Union{Nothing,Symbol}
96
+ titlecolor
97
+ subtitlecolor
98
+ titlefont
99
+ subtitlefont
100
+ titlelineheight
101
+ subtitlelineheight
102
+ footnotes:: Union{Nothing,Vector{Any}}
103
+ footnotesize:: Union{Nothing,Float64}
104
+ footnotefont
105
+ footnotecolor
106
+ footnotealign
107
+ footnotelineheight
108
+ end
109
+
110
+ function figure_settings (;
111
+ title = nothing ,
112
+ subtitle = nothing ,
113
+ titlefont = nothing ,
114
+ subtitlefont = nothing ,
115
+ titlecolor = nothing ,
116
+ subtitlecolor = nothing ,
117
+ titlesize = nothing ,
118
+ subtitlesize = nothing ,
119
+ titlealign = nothing ,
120
+ titlelineheight = nothing ,
121
+ subtitlelineheight = nothing ,
122
+ footnotes = nothing ,
123
+ footnotesize = nothing ,
124
+ footnotefont = nothing ,
125
+ footnotecolor = nothing ,
126
+ footnotealign = nothing ,
127
+ footnotelineheight = nothing ,
128
+ kwargs... ,
129
+ )
130
+
131
+ f = FigureSettings (
132
+ title,
133
+ subtitle,
134
+ titlesize,
135
+ subtitlesize,
136
+ titlealign,
137
+ titlecolor,
138
+ subtitlecolor,
139
+ titlefont,
140
+ subtitlefont,
141
+ titlelineheight,
142
+ subtitlelineheight,
143
+ footnotes,
144
+ footnotesize,
145
+ footnotefont,
146
+ footnotecolor,
147
+ footnotealign,
148
+ footnotelineheight,
149
+ )
150
+
151
+ return f, kwargs
152
+ end
153
+
65
154
function _draw (d:: AbstractDrawable , scales:: Scales ;
66
155
axis, figure, facet, legend, colorbar)
67
156
68
- return update (Figure (; pairs (figure)... )) do f
157
+ fs, remaining_figure_kw = figure_settings (; pairs (figure)... )
158
+
159
+ _filter_nothings (; kwargs... ) = (key => value for (key, value) in kwargs if value != = nothing )
160
+
161
+ return update (Figure (; pairs (remaining_figure_kw)... )) do f
69
162
grid = plot! (f, d, scales; axis)
70
163
fg = FigureGrid (f, grid)
71
164
facet! (fg; facet)
@@ -75,6 +168,25 @@ function _draw(d::AbstractDrawable, scales::Scales;
75
168
if get (legend, :show , true )
76
169
legend! (fg; _remove_show_kw (pairs (legend))... )
77
170
end
171
+
172
+ base_fontsize = Makie. theme (fg. figure. scene)[:fontsize ][]
173
+
174
+ if fs. subtitle != = nothing
175
+ Label (fg. figure[begin - 1 , :], fs. subtitle; tellwidth = false , halign = :left , _filter_nothings (; font = fs. subtitlefont, color = fs. subtitlecolor, fontsize = fs. subtitlesize, halign = fs. titlealign, lineheight = fs. subtitlelineheight)... )
176
+ end
177
+ if fs. title != = nothing
178
+ Label (fg. figure[begin - 1 , :], fs. title; tellwidth = false , fontsize = base_fontsize * 1.15 , font = :bold , halign = :left , _filter_nothings (; font = fs. titlefont, color = fs. titlecolor, fontsize = fs. titlesize, halign = fs. titlealign, lineheight = fs. titlelineheight)... )
179
+ end
180
+ if fs. subtitle != = nothing
181
+ fg. figure. layout. addedrowgaps[1 ] = Fixed (0 )
182
+ end
183
+ if fs. footnotes != = nothing
184
+ fgl = GridLayout (fg. figure[end + 1 , :]; halign = :left , _filter_nothings (; halign = fs. footnotealign)... )
185
+ for (i, note) in enumerate (fs. footnotes)
186
+ Label (fgl[i, 1 ], note; tellwidth = false , halign = :left , fontsize = base_fontsize / 1.15 , _filter_nothings (; halign = fs. footnotealign, font = fs. footnotefont, color = fs. footnotecolor, fontsize = fs. footnotesize, lineheight = fs. footnotelineheight)... )
187
+ end
188
+ fgl. addedrowgaps .= Ref (Fixed (0 ))
189
+ end
78
190
resize_to_layout! (fg)
79
191
return fg
80
192
end
0 commit comments