Solve #24 – use font
gpar instead of fontface
to work with R 4.2.0
Showing 2 of 3 files from the diff.
R/drawing-context.R
changed.
R/text-details.R
changed.
Other files ignored by Codecov
NEWS.md
has changed.
@@ -46,8 +46,8 @@
Loading
46 | 46 | update_gpar <- function(gp, gp_new) { |
|
47 | 47 | names_new <- names(gp_new) |
|
48 | 48 | names_old <- names(gp) |
|
49 | - | gp[c(intersect(names_old, names_new), "font")] <- NULL |
|
50 | - | gp_new["font"] <- NULL |
|
49 | + | gp[c(intersect(names_old, names_new), "fontface")] <- NULL |
|
50 | + | gp_new["fontface"] <- NULL |
|
51 | 51 | do.call(gpar, c(gp, gp_new)) |
|
52 | 52 | } |
|
53 | 53 |
@@ -70,13 +70,13 @@
Loading
70 | 70 | ||
71 | 71 | # update the fontface of a drawing context |
|
72 | 72 | set_context_fontface <- function(drawing_context, fontface = "plain", overwrite = FALSE) { |
|
73 | - | fontface_old <- drawing_context$gp$fontface |
|
73 | + | font_old <- drawing_context$gp$font |
|
74 | 74 | ||
75 | 75 | # combine bold and italic if needed |
|
76 | 76 | if (!isTRUE(overwrite)) { |
|
77 | - | if (isTRUE(fontface == "italic") && isTRUE(fontface_old == "bold")) { |
|
77 | + | if (isTRUE(fontface == "italic") && isTRUE(font_old == 2)) { # see ?grid::gpar for fontface codes |
|
78 | 78 | fontface <- "bold.italic" |
|
79 | - | } else if (isTRUE(fontface == "bold") && isTRUE(fontface_old == "italic")) { |
|
79 | + | } else if (isTRUE(fontface == "bold") && isTRUE(font_old == 3)) { |
|
80 | 80 | fontface <- "bold.italic" |
|
81 | 81 | } |
|
82 | 82 | } |
@@ -3,7 +3,7 @@
Loading
3 | 3 | #' Calculate text details for a given text label |
|
4 | 4 | #' @param label Character vector containing the label. Can handle only one label at a time. |
|
5 | 5 | #' @param gp Grid graphical parameters defining the font (`fontfamily`, `fontface`, and |
|
6 | - | #' `fontface` should be defined). |
|
6 | + | #' `fontsize` should be defined). |
|
7 | 7 | #' @examples |
|
8 | 8 | #' text_details("Hello world!", grid::gpar(fontfamily = "", fontface = "plain", fontsize = 12)) |
|
9 | 9 | #' text_details("Hello world!", grid::gpar(fontfamily = "", fontface = "plain", fontsize = 24)) |
@@ -14,11 +14,11 @@
Loading
14 | 14 | #' @noRd |
|
15 | 15 | text_details <- function(label, gp = gpar()) { |
|
16 | 16 | fontfamily <- gp$fontfamily %||% grid::get.gpar("fontfamily")$fontfamily |
|
17 | - | fontface <- gp$fontface %||% grid::get.gpar("fontface")$fontface |
|
17 | + | font <- gp$font %||% grid::get.gpar("font")$font |
|
18 | 18 | fontsize <- gp$fontsize %||% grid::get.gpar("fontsize")$fontsize |
|
19 | 19 | ||
20 | 20 | devname <- names(grDevices::dev.cur()) |
|
21 | - | fontkey <- paste0(devname, fontfamily, fontface, fontsize) |
|
21 | + | fontkey <- paste0(devname, fontfamily, font, fontsize) |
|
22 | 22 | if (devname == "null device") { |
|
23 | 23 | cache <- FALSE # don't cache if no device open |
|
24 | 24 | } else { |
@@ -30,16 +30,16 @@
Loading
30 | 30 | } |
|
31 | 31 | ||
32 | 32 | # ascent and width depend on label and font |
|
33 | - | l1 <- text_info(label, fontkey, fontfamily, fontface, fontsize, cache) |
|
33 | + | l1 <- text_info(label, fontkey, fontfamily, font, fontsize, cache) |
|
34 | 34 | # descent and space width depend only on font |
|
35 | - | l2 <- font_info(fontkey, fontfamily, fontface, fontsize, cache) |
|
35 | + | l2 <- font_info(fontkey, fontfamily, font, fontsize, cache) |
|
36 | 36 | ||
37 | 37 | # concatenate, result is a list with four members, width_pt, ascent_pt, descent_pt, space_pt |
|
38 | 38 | c(l1, l2) |
|
39 | 39 | } |
|
40 | 40 | ||
41 | 41 | font_info_cache <- new.env(parent = emptyenv()) |
|
42 | - | font_info <- function(fontkey, fontfamily, fontface, fontsize, cache) { |
|
42 | + | font_info <- function(fontkey, fontfamily, font, fontsize, cache) { |
|
43 | 43 | info <- font_info_cache[[fontkey]] |
|
44 | 44 | ||
45 | 45 | if (is.null(info)) { |
@@ -48,7 +48,7 @@
Loading
48 | 48 | gp = gpar( |
|
49 | 49 | fontsize = fontsize, |
|
50 | 50 | fontfamily = fontfamily, |
|
51 | - | fontface = fontface, |
|
51 | + | font = font, |
|
52 | 52 | cex = 1 |
|
53 | 53 | ) |
|
54 | 54 | )), "pt", valueOnly = TRUE) |
@@ -58,7 +58,7 @@
Loading
58 | 58 | gp = gpar( |
|
59 | 59 | fontsize = fontsize, |
|
60 | 60 | fontfamily = fontfamily, |
|
61 | - | fontface = fontface, |
|
61 | + | font = font, |
|
62 | 62 | cex = 1 |
|
63 | 63 | ) |
|
64 | 64 | )), "pt", valueOnly = TRUE) |
@@ -73,7 +73,7 @@
Loading
73 | 73 | } |
|
74 | 74 | ||
75 | 75 | text_info_cache <- new.env(parent = emptyenv()) |
|
76 | - | text_info <- function(label, fontkey, fontfamily, fontface, fontsize, cache) { |
|
76 | + | text_info <- function(label, fontkey, fontfamily, font, fontsize, cache) { |
|
77 | 77 | key <- paste0(label, fontkey) |
|
78 | 78 | info <- text_info_cache[[key]] |
|
79 | 79 |
@@ -83,7 +83,7 @@
Loading
83 | 83 | gp = gpar( |
|
84 | 84 | fontsize = fontsize, |
|
85 | 85 | fontfamily = fontfamily, |
|
86 | - | fontface = fontface, |
|
86 | + | font = font, |
|
87 | 87 | cex = 1 |
|
88 | 88 | ) |
|
89 | 89 | )), "pt", valueOnly = TRUE) |
@@ -93,7 +93,7 @@
Loading
93 | 93 | gp = gpar( |
|
94 | 94 | fontsize = fontsize, |
|
95 | 95 | fontfamily = fontfamily, |
|
96 | - | fontface = fontface, |
|
96 | + | font = font, |
|
97 | 97 | cex = 1 |
|
98 | 98 | ) |
|
99 | 99 | )), "pt", valueOnly = TRUE) |
2209588440
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file.
The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files.
The size and color of each slice is representing the number of statements and the coverage, respectively.