Skip to content

Commit 00150a4

Browse files
committed
update to reference px instead of %
1 parent 85470ca commit 00150a4

41 files changed

Lines changed: 173 additions & 117 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

R/fmt_pad_num.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#' gt() %>%
1919
#' fmt_pad_num(columns = numbers, nsmall = 4)
2020
#' @section Figures:
21-
#' \if{html}{\figure{fmt_pad_num.png}{options: style="width=20\%;"}}
21+
#' \if{html}{\figure{fmt_pad_num.png}{options: style="width:500px;"}}
2222
#'
2323
#' @family Utilities
2424
#' @section Function ID:

R/fmt_symbol_first.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#' fmt_symbol_first(hp, symbol = "°", suffix = "F", symbol_first = TRUE)
2929
#'
3030
#' @section Figures:
31-
#' \if{html}{\figure{gt_fmt_first.png}{options: style="width=100\%;"}}
31+
#' \if{html}{\figure{gt_fmt_first.png}{options: style="width:500px;"}}
3232
#'
3333
#' @family Utilities
3434
#' @section Function ID:

R/fontawesome-icons.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
# #' gt_fa_repeats(cyl, name = "car")
2525
# #' ```
2626
# #' @section Figures:
27-
# #' \if{html}{\figure{fa-cars.png}{options: width=50\%}}
27+
# #' \if{html}{\figure{fa-cars.png}{options: width:500px}}
2828
# #'
2929
# #' @family Utilities
3030
# #' @section Function ID:
@@ -120,7 +120,7 @@
120120
# #' gt_fa_column(man)
121121
# #' ```
122122
# #' @section Figures:
123-
# #' \if{html}{\figure{fa-column-cars.png}{options: width=50\%}}
123+
# #' \if{html}{\figure{fa-column-cars.png}{options: width:500px}}
124124
# #'
125125
# #' @family Utilities
126126
# #' @section Function ID:
@@ -225,7 +225,7 @@
225225
#' gt_fa_rating(rating, icon = "r-project")
226226
#' ```
227227
#' @section Figures:
228-
#' \if{html}{\figure{fa-stars.png}{options: style="width=60\%;"}}
228+
#' \if{html}{\figure{fa-stars.png}{options: style="width:500px;"}}
229229
#'
230230
#' @family Utilities
231231
#' @section Function ID:
@@ -304,7 +304,7 @@ gt_fa_rating <- function(
304304
#' gt_fa_rank_change(x, font_color = "match")
305305
#' ```
306306
#' @section Figures:
307-
#' \if{html}{\figure{fa_rank_change.png}{options: style="width=5\%;"}}
307+
#' \if{html}{\figure{fa_rank_change.png}{options: style="width:500px;"}}
308308
#'
309309
#' @family Utilities
310310
gt_fa_rank_change <- function(

R/get_row_index.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
#' row_sty(3) %>%
6565
#' row_sty(5)
6666
#' ```
67-
#' \if{html}{\figure{ungrouped-tab.png}{options: style="width=40\%;"}}
67+
#' \if{html}{\figure{ungrouped-tab.png}{options: style="width:500px;"}}
6868
#' ### Grouped data
6969
#'
7070
#' However, for grouped data, the row indices are representative of the underlying
@@ -77,7 +77,7 @@
7777
#' row_sty(3) %>% ## actually row 5
7878
#' row_sty(5) ## actually row 2
7979
#' ```
80-
#' \if{html}{\figure{grouped-tab.png}{options: style="width=40\%;"}}
80+
#' \if{html}{\figure{grouped-tab.png}{options: style="width:500px;"}}
8181
#'
8282
#' The `get_row_index()` function gives ability to create an index of the final
8383
#' output, so you can reference specific rows by number.
@@ -89,14 +89,14 @@
8989
#' row_sty(4) %>% ## wrong row, actually row 6 visually
9090
#' row_sty(tab_index[4]) ## correct row, actually row 4
9191
#' ```
92-
#' \if{html}{\figure{grouped-tab-row4.png}{options: style="width=40\%;"}}
92+
#' \if{html}{\figure{grouped-tab-row4.png}{options: style="width:500px;"}}
9393
#' ```r
9494
#' tab2 %>%
9595
#' row_sty(tab_index[1]) %>%
9696
#' row_sty(tab_index[3]) %>%
9797
#' row_sty(tab_index[5])
9898
#' ```
99-
#' \if{html}{\figure{grouped-tab-index.png}{options: style="width=40\%;"}}
99+
#' \if{html}{\figure{grouped-tab-index.png}{options: style="width:500px;"}}
100100
#'
101101
get_row_index <- function(gt_object) {
102102
is_gt_stop(gt_object)

R/gt-bar-html.R

Lines changed: 92 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#' Add HTML-based bar plots into rows of a `gt` table
32
#' @description
43
#' The `gt_plt_bar_pct` function takes an existing `gt_tbl` object and
@@ -45,37 +44,44 @@
4544
#' )
4645
#' ```
4746
#' @section Figures:
48-
#' \if{html}{\figure{gt_bar_plot.png}{options: width=100\%}}
47+
#' \if{html}{\figure{gt_bar_plot.png}{options: width:500px}}
4948
#'
5049
#' @family Plotting
5150
#' @section Function ID:
5251
#' 3-5
5352

5453
gt_plt_bar_pct <- function(
55-
gt_object,
56-
column,
57-
height = 16,
58-
width = 100,
59-
fill = "purple",
60-
background = "#e1e1e1",
61-
scaled = FALSE,
62-
labels = FALSE,
63-
label_cutoff = 0.40,
64-
decimals = 1,
65-
font_style = "bold",
66-
font_size = "10px") {
67-
68-
69-
stopifnot(`'gt_object' must be a 'gt_tbl', have you accidentally passed raw data?` = "gt_tbl" %in%
70-
class(gt_object))
54+
gt_object,
55+
column,
56+
height = 16,
57+
width = 100,
58+
fill = "purple",
59+
background = "#e1e1e1",
60+
scaled = FALSE,
61+
labels = FALSE,
62+
label_cutoff = 0.40,
63+
decimals = 1,
64+
font_style = "bold",
65+
font_size = "10px"
66+
) {
67+
stopifnot(
68+
`'gt_object' must be a 'gt_tbl', have you accidentally passed raw data?` = "gt_tbl" %in%
69+
class(gt_object)
70+
)
7171

72-
stopifnot('label_cutoff must be a number between 0 and 1' = dplyr::between(label_cutoff, 0, 1))
72+
stopifnot(
73+
'label_cutoff must be a number between 0 and 1' = dplyr::between(
74+
label_cutoff,
75+
0,
76+
1
77+
)
78+
)
7379

7480
# ensure font_style is one of the accepted values
7581
stopifnot(
76-
'`font_style` argument must be "bold", "normal", or "italic"' =
77-
font_style %in% c("bold", "normal", "italic")
78-
)
82+
'`font_style` argument must be "bold", "normal", or "italic"' = font_style %in%
83+
c("bold", "normal", "italic")
84+
)
7985

8086
all_cols <- gt_index(gt_object, column = {{ column }}, as_vector = FALSE)
8187

@@ -89,24 +95,22 @@ gt_plt_bar_pct <- function(
8995
col_to_widen <- rlang::new_formula(col_name, px(width))
9096

9197
bar_plt_html <- function(xy) {
92-
9398
if (length(na.omit(xy)) == 0) {
9499
max_x <- 0
95100
} else {
96101
max_x <- max(as.double(xy), na.rm = TRUE)
97102
}
98103

99104
bar <- lapply(data_in, function(x) {
100-
101-
scaled_value <- if(isFALSE(scaled)) {
105+
scaled_value <- if (isFALSE(scaled)) {
102106
x / max_x * 100
103107
} else {
104108
x
105109
}
106110

107111
if (labels) {
108112
# adjust values for labeling // scale_label
109-
label_values <- if(scaled) {
113+
label_values <- if (scaled) {
110114
x
111115
} else {
112116
x / max_x * 100
@@ -116,70 +120,102 @@ gt_plt_bar_pct <- function(
116120
label <- glue::glue("{round(label_values, decimals)}%")
117121

118122
if (x < (label_cutoff * max_x)) {
119-
120123
css_styles <- paste0(
121-
"background:", fill,";",
122-
"width:", scaled_value, "%;",
123-
"height:", height, "px;",
124+
"background:",
125+
fill,
126+
";",
127+
"width:",
128+
scaled_value,
129+
"%;",
130+
"height:",
131+
height,
132+
"px;",
124133
"display:flex;",
125134
"align-items:center;",
126135
"justify-content:center;",
127-
"color:", ideal_fgnd_color(background),";",
128-
"font-weight:", font_style,";",
129-
"font-size:", font_size, ";",
136+
"color:",
137+
ideal_fgnd_color(background),
138+
";",
139+
"font-weight:",
140+
font_style,
141+
";",
142+
"font-size:",
143+
font_size,
144+
";",
130145
"position:relative;"
131146
)
132147

133148
span_styles <- paste0(
134-
"color:", ideal_fgnd_color(background),";",
149+
"color:",
150+
ideal_fgnd_color(background),
151+
";",
135152
"position:absolute;",
136153
"left:0%;",
137-
"margin-left:", scaled_value * width/100, "px;",
138-
"font-weight:", font_style,";",
139-
"font-size:", font_size,";"
154+
"margin-left:",
155+
scaled_value * width / 100,
156+
"px;",
157+
"font-weight:",
158+
font_style,
159+
";",
160+
"font-size:",
161+
font_size,
162+
";"
140163
)
141164

142165
glue::glue(
143166
"<div style='{css_styles}'>",
144167
"<span style='{span_styles}'>{label}</span></div>"
145168
)
146169
} else {
147-
148170
css_styles <- paste0(
149-
"background:", fill,";",
150-
"width:", scaled_value, "%;",
151-
"height:", height, "px;",
171+
"background:",
172+
fill,
173+
";",
174+
"width:",
175+
scaled_value,
176+
"%;",
177+
"height:",
178+
height,
179+
"px;",
152180
"display:flex;",
153181
"align-items:center;",
154182
"justify-content:flex-start;",
155183
"position:relative;"
156184
)
157185

158186
span_styles <- paste0(
159-
"color:", ideal_fgnd_color(fill),";",
187+
"color:",
188+
ideal_fgnd_color(fill),
189+
";",
160190
"position:absolute;",
161191
"left:0px;",
162192
"margin-left:5px;",
163-
"font-weight:", font_style,";",
164-
"font-size:", font_size,";"
193+
"font-weight:",
194+
font_style,
195+
";",
196+
"font-size:",
197+
font_size,
198+
";"
165199
)
166200

167201
glue::glue(
168202
"<div style='{css_styles}'>",
169203
"<span style='{span_styles}'>{label}</span></div>"
170204
)
171205
}
172-
} else if(!is.na(x)) {
206+
} else if (!is.na(x)) {
173207
glue::glue(
174208
"<div style='background:{fill};width:{scaled_value}%;height:{height}px;'></div>" # no labels added
175209
)
176-
} else if(is.na(x)){
210+
} else if (is.na(x)) {
177211
"<div style='background:transparent;width:0%;height:{height}px;'></div>" # no labels added
178212
}
179213
})
180214

181215
chart <- lapply(bar, function(bar) {
182-
glue::glue("<div style='flex-grow:1;margin-left:8px;background:{background};'>{bar}</div>")
216+
glue::glue(
217+
"<div style='flex-grow:1;margin-left:8px;background:{background};'>{bar}</div>"
218+
)
183219
})
184220

185221
chart
@@ -192,11 +228,13 @@ gt_plt_bar_pct <- function(
192228
invisible(force(x))
193229
}
194230

195-
quiet(gt_object %>%
196-
cols_width(col_to_widen) %>%
197-
text_transform(
198-
locations = cells_body(columns = {{ column }}),
199-
fn = quiet(bar_plt_html)
200-
) %>%
201-
cols_align(align = "left", columns = {{ column }}))
231+
quiet(
232+
gt_object %>%
233+
cols_width(col_to_widen) %>%
234+
text_transform(
235+
locations = cells_body(columns = {{ column }}),
236+
fn = quiet(bar_plt_html)
237+
) %>%
238+
cols_align(align = "left", columns = {{ column }})
239+
)
202240
}

R/gt_add_divider.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#' gt_add_divider(columns = "cyl", style = "dashed")
1818
#' ```
1919
#' @section Figures:
20-
#' \if{html}{\figure{add-divider.png}{options: style="width=70\%;"}}
20+
#' \if{html}{\figure{add-divider.png}{options: style="width:500px;"}}
2121
#'
2222
#' @family Utilities
2323
#' @section Function ID:

R/gt_alert_icon.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#' gt::gt() %>%
2525
#' gt_alert_icon(warn)
2626
#' ```
27-
#' \if{html}{\figure{man/figures/gt_alert_icon-binary.png}{options: style="width=100\%;"}}
27+
#' \if{html}{\figure{man/figures/gt_alert_icon-binary.png}{options: style="width:500px;"}}
2828
gt_alert_icon <- function(gt_object,
2929
column,
3030
palette = c("#a962b6", "#f1f1f1", "#378e38"),

R/gt_color_box.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#' palette = c("purple", "lightgrey", "green"))
2828
#' ```
2929
#' @section Figures:
30-
#' \if{html}{\figure{color_box.png}{options: style="width=30\%;"}}
30+
#' \if{html}{\figure{color_box.png}{options: style="width:500px;"}}
3131
#'
3232
#' @family Colors
3333
#' @section Function ID:

R/gt_color_rows.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@
5353
#' palette = "colorblindr::OkabeIto_black", domain = c(3,4,5))
5454
#' ```
5555
#' @section Figures:
56-
#' \if{html}{\figure{basic-pal.png}{options: style="width=100\%;"}}
56+
#' \if{html}{\figure{basic-pal.png}{options: style="width:500px;"}}
5757
#'
58-
#' \if{html}{\figure{blue-pal.png}{options: style="width=100\%;"}}
58+
#' \if{html}{\figure{blue-pal.png}{options: style="width:500px;"}}
5959
#'
60-
#' \if{html}{\figure{custom-pal.png}{options: style="width=100\%;"}}
60+
#' \if{html}{\figure{custom-pal.png}{options: style="width:500px;"}}
6161
#'
62-
#' \if{html}{\figure{discrete-pal.png}{options: style="width=100\%;"}}
62+
#' \if{html}{\figure{discrete-pal.png}{options: style="width:500px;"}}
6363
#'
6464
#' @family Colors
6565
#' @section Function ID:

R/gt_dot_bar.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#' cols_width(cars ~ px(125))
2323
#' ```
2424
#' @section Figures:
25-
#' \if{html}{\figure{gt_dot_bar.png}{options: style="width=50\%;"}}
25+
#' \if{html}{\figure{gt_dot_bar.png}{options: style="width:500px;"}}
2626
#'
2727
#' @family Themes
2828

0 commit comments

Comments
 (0)