Chart/GGPlot/Theme/Defaults.pm

filter: Statementstmt 100% 81 / 81 Branchbran 57.6% 30 / 52 Conditioncond 41.6% 10 / 24 MC/DCmcdc 0.0% 0 / 16 Subroutinesub 100% 12 / 12 Podpod 100% 8 / 8 totaltotal 73.0% 141 / 193 CC 35 SCAR 18.9
CC
35
Cov
77%
theme_minimal
10.4
theme_void
10.1
theme_grey
8.1
CRAP 6.6
« Chart/GGPlot/Trans/Functions.pm ↑ Summary Chart/GGPlot/Coord/Cartesian.pm »
1 package Chart::GGPlot::Theme::Defaults;
2  
3 # ABSTRACT: Pre-defined themes
4  
5 3 ▶use Chart::GGPlot::Setup;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 our $VERSION = '0.002003'; # VERSION
8  
9 3 ▶use Chart::GGPlot::Theme;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Chart::GGPlot::Theme::Element::Functions qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 ▶use parent qw(Exporter::Tiny);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 3 my @theme_funcs = qw(
15 theme_grey theme_gray theme_bw
16 theme_linedraw theme_light theme_dark
17 theme_minimal theme_classic theme_void
18 );
19 3 our @EXPORT_OK = @theme_funcs;
20 3 our %EXPORT_TAGS = (
21 all => \@EXPORT_OK,
22 ggplot => \@theme_funcs,
23 );
24  
25  
26 8 ▶fun theme_grey (:$base_size=11, :$base_family="",
Subroutine theme_grey: called CC=8 SCAR=20.9
Pod documented
27 :$base_line_size=$base_size/22,
28 8 ▶ :$base_rect_size=$base_size/22) {
Branch: 6 branches
BranchTrueFalseTotal
@_ > 0 and @_ % 2 and Function::Parameters::_croak("Odd number of paired arguments for fun theme_grey") 0 8 8
exists ${__rest}{'base_size'} ? : 4 4 8
exists ${__rest}{'base_family'} ? : 1 7 8
exists ${__rest}{'base_line_size'} ? : 1 7 8
exists ${__rest}{'base_rect_size'} ? : 1 7 8
keys %{__rest} and Function::Parameters::_croak('In fun theme_grey: no such named parameter: ' . join(", ", sort(keys %{__rest}))) 0 8 8
Condition66%2/3
@_ > 0 and @_ % 2
!ll&&!rl&&r
440
MC/DC0%0/2
@_ > 0 and @_ % 2
@_ > 0 @_ % 2
Truth table66%2/3
A and B
A= @_ > 0B= @_ % 2
ABresult
0X0
100
111
29  
30 # The half-line (base-fontsize / 2) sets up the basic vertical
31 # rhythm of the theme.
32 8 my $half_line = $base_size / 2;
33  
34 8 return Chart::GGPlot::Theme->new(
35 line => element_line(
36 color => 'black',
37 size => $base_line_size,
38 linetype => 1,
39 lineend => "butt",
40 ),
41 rect => element_rect(
42 fill => 'white',
43 color => 'black',
44 size => $base_rect_size,
45 linetype => 1,
46 ),
47 text => element_text(
48 family => $base_family,
49 face => 'plain',
50 color => 'black',
51 size => $base_size,
52 lineheight => 0.9,
53 hjust => 0.5,
54 vjust => 0.5,
55 angle => 0,
56 # margin => margin(),
57 ),
58 axis_line => element_blank(),
59 axis_line_x => undef,
60 axis_line_y => undef,
61 axis_text => element_text( size => rel(0.8), color => "grey30" ),
62 axis_text_x => element_text(
63 # margin => margin( t => 0.8 * $half_line / 2 ),
64 vjust => 1
65 ),
66 axis_text_x_top => element_text(
67 # margin => margin( b => 0.8 * $half_line / 2 ),
68 vjust => 0
69 ),
70 axis_text_y => element_text(
71 # margin => margin( r => 0.8 * $half_line / 2 ),
72 hjust => 1
73 ),
74 axis_text_y_right => element_text(
75 # margin => margin( l => 0.8 * $half_line / 2 ),
76 hjust => 0
77 ),
78 axis_ticks => element_line( color => "grey20" ),
79 # axis_ticks_length => unit( $half_line / 2, "pt" ),
80 axis_title_x => element_text(
81 # margin => margin( t => $half_line / 2 ),
82 vjust => 1
83 ),
84 axis_title_x_top => element_text(
85 # margin => margin( b => $half_line / 2 ),
86 vjust => 0
87 ),
88 axis_title_y => element_text(
89 angle => 90,
90 # margin => margin( r => $half_line / 2 ),
91 vjust => 1
92 ),
93 axis_title_y_right => element_text(
94 angle => -90,
95 # margin => margin( l => $half_line / 2 ),
96 vjust => 0
97 ),
98  
99 # TODO: What would this NA behave?
100 #legend_background => element_rect(color = NA),
101 legend_background => element_rect(),
102 # legend_spacing => unit( 2 * $half_line, "pt" ),
103 # legend_spacing_x => undef,
104 # legend_spacing_y => undef,
105 # legend_margin =>
106 # margin( t => $half_line, r => $half_line, b => $half_line, l => $half_line ),
107 legend_key => element_rect( fill => "grey95", color => "white" ),
108 # legend_key_size => unit( 1.2, "lines" ),
109 # legend_key_height => undef,
110 # legend_key_width => undef,
111 legend_text => element_text( size => rel(0.8) ),
112 legend_text_align => undef,
113 legend_title => element_text( hjust => 0 ),
114 legend_title_align => undef,
115 legend_position => "right",
116 legend_direction => undef,
117 legend_justification => "center",
118 legend_box => undef,
119 # legend_box_margin => margin(),
120 legend_box_background => element_blank(),
121 # legend_box_spacing => unit( 2 * $half_line, "pt" ),
122  
123 # TODO: What would this NA behave?
124 #panel_background => element_rect(fill => "grey92", color => NA),
125 panel_background => element_rect( fill => "grey92" ),
126 panel_border => element_blank(),
127 panel_grid => element_line( color => "white" ),
128 panel_grid_minor => element_line( size => rel(0.5) ),
129 # panel_spacing => unit( $half_line, "pt" ),
130 # panel_spacing_x => undef,
131 # panel_spacing_y => undef,
132 panel_ontop => false,
133  
134 #strip_background = element_rect(fill => "grey85", color => NA),
135 strip_background => element_rect( fill => "grey85" ),
136 strip_text => element_text(
137 color => "grey10",
138 size => rel(0.8),
139 # margin => margin(
140 # t => 0.8 * $half_line,
141 # r => 0.8 * $half_line,
142 # b => 0.8 * $half_line,
143 # l => 0.8 * $half_line
144 # )
145 ),
146 strip_text_x => undef,
147 strip_text_y => element_text( angle => -90 ),
148 strip_placement => "inside",
149 strip_placement_x => undef,
150 strip_placement_y => undef,
151 # strip_switch_pad_grid => unit( $half_line / 2, "pt" ),
152 # strip_switch_pad_wrap => unit( $half_line / 2, "pt" ),
153  
154 plot_background => element_rect( color => "white" ),
155 plot_title => element_text( # font size "large"
156 size => rel(1.2),
157 hjust => 0,
158 vjust => 1,
159 # margin => margin( b => $half_line )
160 ),
161 plot_subtitle => element_text( # font size "regular"
162 hjust => 0,
163 vjust => 1,
164 # margin => margin( b => $half_line )
165 ),
166 plot_caption => element_text( # font size "small"
167 size => rel(0.8),
168 hjust => 1,
169 vjust => 1,
170 # margin => margin( t => $half_line )
171 ),
172 plot_tag => element_text(
173 size => rel(1.2),
174 hjust => 0.5,
175 vjust => 0.5
176 ),
177 plot_tag_position => 'topleft',
178 # plot_margin => margin( t => $half_line, r => $half_line, b => $half_line, l => $half_line ),
179  
180 complete => true,
181 );
182 3 }
183  
184 3 *theme_gray = \&theme_grey;
185  
186  
187 4 ▶fun theme_bw (%rest) {
Subroutine theme_bw: called CC=3 SCAR=11.3
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ > 0 and @_ % 2 and Function::Parameters::_croak("Odd number of paired arguments for fun theme_bw") 0 4 4
Condition66%2/3
@_ > 0 and @_ % 2
!ll&&!rl&&r
220
MC/DC0%0/2
@_ > 0 and @_ % 2
@_ > 0 @_ % 2
Truth table66%2/3
A and B
A= @_ > 0B= @_ % 2
ABresult
0X0
100
111
188  
189 # Starts with theme_grey and then modify some parts
190 4 return theme_grey(%rest)->replace(
191 Chart::GGPlot::Theme->new(
192  
193 # white background and dark border
194 panel_background => element_rect( fill => "white" ),
195 panel_border => element_rect( color => "grey20" ),
196  
197 # make gridlines dark, same contrast with white as in theme_grey
198 panel_grid => element_line( color => "grey92" ),
199 panel_grid_minor => element_line( size => rel(0.5) ),
200  
201 # contour strips to match panel contour
202 strip_background =>
203 element_rect( fill => "grey85", color => "grey20" ),
204  
205 # match legend key to background
206 legend_key => element_rect( fill => "white" ),
207  
208 complete => true,
209 )
210 );
211 3 }
212  
213  
214 1 ▶fun theme_linedraw ( :$base_size = 11, %rest ) {
Subroutine theme_linedraw: called CC=4 SCAR=15.0
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
@_ > 0 and @_ % 2 and Function::Parameters::_croak("Odd number of paired arguments for fun theme_linedraw") 0 1 1
exists $rest{'base_size'} ? : 0 1 1
Condition33%1/3
@_ > 0 and @_ % 2
!ll&&!rl&&r
100
MC/DC0%0/2
@_ > 0 and @_ % 2
@_ > 0 @_ % 2
Truth table33%1/3
A and B
A= @_ > 0B= @_ % 2
ABresult
0X0
100
111
215 1 my $half_line = $base_size / 2;
216  
217 # Starts with theme_bw and then modify some parts
218 # = replace all greys with pure black or white
219 1 theme_bw( base_size => $base_size, %rest )->replace(
220 Chart::GGPlot::Theme->new(
221  
222 # black text and ticks on the axes
223 axis_text => element_text( color => "black", size => rel(0.8) ),
224 axis_ticks => element_line( color => "black", size => rel(0.5) ),
225  
226 # NB: match the *visual* thickness of axis ticks to the panel border
227 # 0.5 clipped looks like 0.25
228  
229 # pure black panel border and grid lines, but thinner
230 panel_border => element_rect( color => "black", size => rel(1) ),
231 panel_grid => element_line( color => "black" ),
232 panel_grid_major => element_line( size => rel(0.1) ),
233 panel_grid_minor => element_line( size => rel(0.05) ),
234  
235 # strips with black background and white text
236 strip_background => element_rect( fill => "black" ),
237 strip_text => element_text(
238 color => "white",
239 size => rel(0.8),
240 # margin => margin(
241 # t => 0.8 * $half_line,
242 # r => 0.8 * $half_line,
243 # b => 0.8 * $half_line,
244 # l => 0.8 * $half_line
245 # ),
246  
247 ),
248 complete => true,
249 )
250 );
251 3 }
252  
253  
254 1 ▶fun theme_light (:$base_size = 11, %rest) {
Subroutine theme_light: called CC=4 SCAR=15.0
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
@_ > 0 and @_ % 2 and Function::Parameters::_croak("Odd number of paired arguments for fun theme_light") 0 1 1
exists $rest{'base_size'} ? : 0 1 1
Condition33%1/3
@_ > 0 and @_ % 2
!ll&&!rl&&r
100
MC/DC0%0/2
@_ > 0 and @_ % 2
@_ > 0 @_ % 2
Truth table33%1/3
A and B
A= @_ > 0B= @_ % 2
ABresult
0X0
100
111
255 1 my $half_line = $base_size / 2;
256  
257 # Starts with theme_grey and then modify some parts
258 1 theme_grey( base_size => $base_size, %rest )->replace(
259 Chart::GGPlot::Theme->new(
260  
261 # white panel with light grey border
262 panel_background => element_rect( fill => "white" ),
263 panel_border => element_rect( color => "grey70", size => rel(1) ),
264  
265 # light grey, thinner gridlines
266 # => make them slightly darker to keep acceptable contrast
267 panel_grid => element_line( color => "grey87" ),
268 panel_grid_major => element_line( size => rel(0.5) ),
269 panel_grid_minor => element_line( size => rel(0.25) ),
270  
271 # match axes ticks thickness to gridlines and color to panel border
272 axis_ticks => element_line( color => "grey70", size => rel(0.5) ),
273  
274 # match legend key to panel.background
275 legend_key => element_rect( fill => "white" ),
276  
277 # dark strips with light text (inverse contrast compared to theme_grey)
278 strip_background => element_rect( fill => "grey70" ),
279 strip_text => element_text(
280 color => "white",
281 size => rel(0.8),
282 # margin => margin(
283 # t => 0.8 * $half_line,
284 # r => 0.8 * $half_line,
285 # b => 0.8 * $half_line,
286 # l => 0.8 * $half_line
287 # )
288 ),
289  
290 complete => true,
291 )
292 );
293 3 }
294  
295  
296 1 ▶fun theme_dark (:$base_size = 11, %rest) {
Subroutine theme_dark: called CC=4 SCAR=15.0
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
@_ > 0 and @_ % 2 and Function::Parameters::_croak("Odd number of paired arguments for fun theme_dark") 0 1 1
exists $rest{'base_size'} ? : 0 1 1
Condition33%1/3
@_ > 0 and @_ % 2
!ll&&!rl&&r
100
MC/DC0%0/2
@_ > 0 and @_ % 2
@_ > 0 @_ % 2
Truth table33%1/3
A and B
A= @_ > 0B= @_ % 2
ABresult
0X0
100
111
297 1 my $half_line = $base_size / 2;
298  
299 # Starts with theme_grey and then modify some parts
300 1 return theme_grey( base_size => $base_size, %rest )->replace(
301 Chart::GGPlot::Theme->new(
302  
303 # dark panel
304 panel_background => element_rect( fill => "grey50" ),
305  
306 # inverse grid lines contrast compared to theme_grey
307 # make them thinner and try to keep the same visual contrast as in theme_light
308 panel_grid => element_line( color => "grey42" ),
309 panel_grid_major => element_line( size => rel(0.5) ),
310 panel_grid_minor => element_line( size => rel(0.25) ),
311  
312 # match axes ticks thickness to gridlines
313 axis_ticks => element_line( color => "grey20", size => rel(0.5) ),
314  
315 # match legend key to panel.background
316 legend_key => element_rect( fill => "grey50" ),
317  
318 # dark strips with light text (inverse contrast compared to theme_grey)
319 strip_background => element_rect( fill => "grey15" ),
320 strip_text => element_text(
321 color => "grey90",
322 size => rel(0.8),
323 # margin => margin(
324 # t => 0.8 * $half_line,
325 # r => 0.8 * $half_line,
326 # b => 0.8 * $half_line,
327 # l => 0.8 * $half_line
328 # )
329 ),
330  
331 complete => true,
332 )
333 );
334 3 }
335  
336  
337 1 ▶fun theme_minimal (:$base_size=11, :$base_family="",
Subroutine theme_minimal: called CC=8 SCAR=23.4
Pod documented
338 :$base_line_size=$base_size/22,
339 1 ▶ :$base_rect_size=$base_size/22) {
Branch: 6 branches
BranchTrueFalseTotal
@_ > 0 and @_ % 2 and Function::Parameters::_croak("Odd number of paired arguments for fun theme_minimal") 0 1 1
exists ${__rest}{'base_size'} ? : 0 1 1
exists ${__rest}{'base_family'} ? : 0 1 1
exists ${__rest}{'base_line_size'} ? : 0 1 1
exists ${__rest}{'base_rect_size'} ? : 0 1 1
keys %{__rest} and Function::Parameters::_croak('In fun theme_minimal: no such named parameter: ' . join(", ", sort(keys %{__rest}))) 0 1 1
Condition33%1/3
@_ > 0 and @_ % 2
!ll&&!rl&&r
100
MC/DC0%0/2
@_ > 0 and @_ % 2
@_ > 0 @_ % 2
Truth table33%1/3
A and B
A= @_ > 0B= @_ % 2
ABresult
0X0
100
111
340  
341 # Starts with theme_bw and remove most parts
342 1 return theme_bw(
343 base_size => $base_size,
344 base_family => $base_family,
345 base_line_size => $base_line_size,
346 base_rect_size => $base_rect_size
347 )->replace(
348 Chart::GGPlot::Theme->new(
349 axis_ticks => element_blank(),
350 legend_background => element_blank(),
351 legend_key => element_blank(),
352 panel_background => element_blank(),
353 panel_border => element_blank(),
354 strip_background => element_blank(),
355 plot_background => element_blank(),
356  
357 complete => true,
358 )
359 );
360 3 }
361  
362  
363 1 ▶fun theme_classic (%rest) {
Subroutine theme_classic: called CC=3 SCAR=12.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ > 0 and @_ % 2 and Function::Parameters::_croak("Odd number of paired arguments for fun theme_classic") 0 1 1
Condition33%1/3
@_ > 0 and @_ % 2
!ll&&!rl&&r
100
MC/DC0%0/2
@_ > 0 and @_ % 2
@_ > 0 @_ % 2
Truth table33%1/3
A and B
A= @_ > 0B= @_ % 2
ABresult
0X0
100
111
364 1 return theme_bw(%rest)->replace(
365 Chart::GGPlot::Theme->new(
366  
367 # no background and no grid
368 panel_border => element_blank(),
369 panel_grid_major => element_blank(),
370 panel_grid_minor => element_blank(),
371  
372 # show axes
373 axis_line => element_line( color => "black", size => rel(1) ),
374  
375 # match legend key to panel.background
376 legend_key => element_blank(),
377  
378 # simple, black and white strips
379 strip_background => element_rect(
380 fill => "white",
381 color => "black",
382 size => rel(2)
383 ),
384  
385 # NB: size is 1 but clipped, it looks like the 0.5 of the axes
386  
387 complete => true,
388 )
389 );
390 3 }
391  
392  
393 1 ▶fun theme_void (:$base_size=11, :$base_family="",
Subroutine theme_void: called CC=8 SCAR=23.1
Pod documented
394 :$base_line_size=$base_size / 22,
395 1 ▶ :$base_rect_size=$base_size / 22) {
Branch: 6 branches
BranchTrueFalseTotal
@_ > 0 and @_ % 2 and Function::Parameters::_croak("Odd number of paired arguments for fun theme_void") 0 1 1
exists ${__rest}{'base_size'} ? : 0 1 1
exists ${__rest}{'base_family'} ? : 0 1 1
exists ${__rest}{'base_line_size'} ? : 0 1 1
exists ${__rest}{'base_rect_size'} ? : 0 1 1
keys %{__rest} and Function::Parameters::_croak('In fun theme_void: no such named parameter: ' . join(", ", sort(keys %{__rest}))) 0 1 1
Condition33%1/3
@_ > 0 and @_ % 2
!ll&&!rl&&r
100
MC/DC0%0/2
@_ > 0 and @_ % 2
@_ > 0 @_ % 2
Truth table33%1/3
A and B
A= @_ > 0B= @_ % 2
ABresult
0X0
100
111
396 1 my $half_line = $base_size / 2;
397  
398 # Only keep indispensable text: legend and plot titles
399 1 return Chart::GGPlot::Theme->new(
400 line => element_blank(),
401 rect => element_blank(),
402 text => element_text(
403 family => $base_family,
404 face => "plain",
405 color => "black",
406 size => $base_size,
407 lineheight => 0.9,
408 hjust => 0.5,
409 vjust => 0.5,
410 angle => 0,
411 # margin => margin()
412 ),
413 axis_text => element_blank(),
414 axis_title => element_blank(),
415 # axis_ticks_length => unit( 0, "pt" ),
416 legend_box => undef,
417 # legend_key_size => unit( 1.2, "lines" ),
418 legend_position => "right",
419 legend_text => element_text( size => rel(0.8) ),
420 legend_title => element_text( hjust => 0 ),
421 strip_text => element_text( size => rel(0.8) ),
422 # strip_switch_pad_grid => unit( $half_line / 2, "pt" ),
423 # strip_switch_pad_wrap => unit( $half_line / 2, "pt" ),
424 panel_ontop => false,
425 # panel_spacing => unit( $half_line, "pt" ),
426 # plot_margin => margin(unit => "lines"),
427 plot_title => element_text(
428 size => rel(1.2),
429 hjust => 0,
430 vjust => 1,
431 # margin => margin( t => $half_line )
432 ),
433 plot_subtitle => element_text(
434 hjust => 0,
435 vjust => 1,
436 # margin => margin( t => $half_line )
437 ),
438 plot_caption => element_text(
439 size => rel(0.8),
440 hjust => 1,
441 vjust => 1,
442 # margin => margin( t => $half_line )
443 ),
444 plot_tag => element_text(
445 size => rel(1.2),
446 hjust => 0.5,
447 vjust => 0.5
448 ),
449 plot_tag_position => 'topleft',
450  
451 complete => true,
452 );
453 3 }
454  
455 3 1;
456  
457 __END__
« Chart/GGPlot/Trans/Functions.pm ↑ Summary Chart/GGPlot/Coord/Cartesian.pm »