Skip to content

Commit de3b770

Browse files
committed
fix: stop using internal functions inside the qenv
1 parent 95310d3 commit de3b770

File tree

4 files changed

+52
-43
lines changed

4 files changed

+52
-43
lines changed

R/tm_p_spiderplot.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,8 @@ srv_p_spiderplot <- function(id,
283283
)
284284
} else {
285285
tooltip_lines <- sapply(tooltip_vars, function(col) {
286-
label <- .get_column_label(.data, col)
286+
label <- attr(dataname[[col]], "label")
287+
if (!length(label)) label <- col
287288
value <- .data[[col]]
288289
paste0(label, ": ", value)
289290
})

R/tm_p_swimlane.R

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -244,23 +244,37 @@ srv_p_swimlane <- function(id,
244244
dplyr::group_by(!!as.name(subject_var), !!as.name(time_var)) %>%
245245
dplyr::mutate(
246246
tooltip = {
247-
if (is.null(tooltip_vars)) {
248-
paste(
249-
unique(
250-
c(
251-
paste(subject_var_label, !!as.name(subject_var)),
252-
paste(time_var_label, !!as.name(time_var)),
253-
sprintf(
254-
"%s: %s",
255-
tools::toTitleCase(gsub("[^0-9A-Za-z]+", " ", !!as.name(group_var))),
256-
!!as.name(color_var)
257-
)
247+
default_tip <- paste(
248+
unique(
249+
c(
250+
paste(subject_var_label, !!as.name(subject_var)),
251+
paste(time_var_label, !!as.name(time_var)),
252+
sprintf(
253+
"%s: %s",
254+
tools::toTitleCase(gsub("[^0-9A-Za-z]+", " ", !!as.name(group_var))),
255+
!!as.name(color_var)
258256
)
259-
),
260-
collapse = "<br>"
261-
)
257+
)
258+
),
259+
collapse = "<br>"
260+
)
261+
if (is.null(tooltip_vars)) {
262+
default_tip
262263
} else {
263-
.generate_tooltip(.data, tooltip_vars)
264+
cur_data <- dplyr::pick(dplyr::everything())
265+
cols <- intersect(tooltip_vars, names(cur_data))
266+
if (!length(cols)) {
267+
default_tip
268+
} else {
269+
sub <- cur_data[cols]
270+
labels <- vapply(cols, function(cn) {
271+
lb <- attr(sub[[cn]], "label")
272+
if (length(lb) && !is.null(lb) && !is.na(lb)) as.character(lb) else cn
273+
}, character(1))
274+
values <- lapply(sub, as.character)
275+
parts <- Map(function(v, l) paste0(l, ": ", v), values, labels)
276+
do.call(paste, c(parts, sep = "<br>"))
277+
}
264278
}
265279
}
266280
) %>%

R/tm_p_waterfall.R

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,15 +204,29 @@ srv_p_waterfall <- function(id,
204204
},
205205
!!as.name(subject_var) := factor(!!as.name(subject_var), levels = unique(!!as.name(subject_var))),
206206
tooltip = {
207+
default_tip <- sprintf(
208+
"%s: %s <br>%s: %s%% <br>%s: %s",
209+
subject_var_label, !!as.name(subject_var),
210+
value_var_label, !!as.name(value_var),
211+
color_var_label, !!as.name(color_var)
212+
)
207213
if (is.null(tooltip_vars)) {
208-
sprintf(
209-
"%s: %s <br>%s: %s%% <br>%s: %s",
210-
subject_var_label, !!as.name(subject_var),
211-
value_var_label, !!as.name(value_var),
212-
color_var_label, !!as.name(color_var)
213-
)
214+
default_tip
214215
} else {
215-
.generate_tooltip(.data, tooltip_vars)
216+
cur_data <- dplyr::pick(dplyr::everything())
217+
cols <- intersect(tooltip_vars, names(cur_data))
218+
if (!length(cols)) {
219+
default_tip
220+
} else {
221+
sub <- cur_data[cols]
222+
labels <- vapply(cols, function(cn) {
223+
lb <- attr(sub[[cn]], "label")
224+
if (length(lb) && !is.null(lb) && !is.na(lb)) as.character(lb) else cn
225+
}, character(1))
226+
values <- lapply(sub, as.character)
227+
parts <- Map(function(v, l) paste0(l, ": ", v), values, labels)
228+
do.call(paste, c(parts, sep = "<br>"))
229+
}
216230
}
217231
}
218232
) %>%

R/utils.R

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -433,26 +433,6 @@ children <- function(x, dataset_name = character(0)) {
433433
if (length(cs$choices) < 2) shinyjs::hide(inputId)
434434
}
435435

436-
.get_column_label <- function(data, column) {
437-
column_label <- attr(data[[column]], "label")
438-
if (!length(column_label)) column_label <- column
439-
column_label
440-
}
441-
442-
443-
.generate_tooltip <- function(data, tooltip_cols) {
444-
tooltip_lines <- sapply(tooltip_cols, function(col) {
445-
label <- .get_column_label(data, col)
446-
value <- data[[col]]
447-
paste0(label, ": ", value)
448-
})
449-
if (is.vector(tooltip_lines)) {
450-
paste(tooltip_lines, collapse = "<br>")
451-
} else {
452-
apply(tooltip_lines, 1, function(row) paste(row, collapse = "<br>"))
453-
}
454-
}
455-
456436

457437
#' @keywords internal
458438
#' @noRd

0 commit comments

Comments
 (0)