From 473a2b8f145c96c60d346ede1e52cca42b53979c Mon Sep 17 00:00:00 2001 From: mpadge Date: Mon, 18 Mar 2024 13:54:37 +0100 Subject: [PATCH] separate 'urgency_style' fn from gt-table main block --- DESCRIPTION | 2 +- R/gt-table.R | 53 +++++++++++++++++---------------------------------- codemeta.json | 2 +- 3 files changed, 20 insertions(+), 37 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index d76b3cd..c930e65 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: dashboard Title: What the Package Does (One Line, Title Case) -Version: 0.0.3.025 +Version: 0.0.3.026 Authors@R: person(given = "First", family = "Last", diff --git a/R/gt-table.R b/R/gt-table.R index 2ca95d2..9e57d49 100644 --- a/R/gt-table.R +++ b/R/gt-table.R @@ -61,6 +61,7 @@ open_gt_table <- function (dat) { dat_url$urgency [dat_url$urgency > ncols] <- ncols dat_url$urgency [grepl ("holding", dat_url$labels)] <- 0 + urgency_cols <- c ("number", "title", "stage_date", "labels") gt::gt ( dat_url, @@ -113,44 +114,26 @@ open_gt_table <- function (dat) { spanners = c ("ed_span", "rev1span") ) ) |> + add_urgency_style (1, "#FFFF8088", urgency_cols) |> + add_urgency_style (2, "#FFFF0088", urgency_cols) |> + add_urgency_style (3, "#FFAA0088", urgency_cols) |> + add_urgency_style (4, "#FF550088", urgency_cols) |> + add_urgency_style (5, "#FF000088", urgency_cols) |> + add_bg_colours () +} + +#' styles for "stage_date" columns to highlight need for action. +#' @noRd +add_urgency_style <- function (tab, urgency_val, colour, col_names) { + urgency <- NULL # suppress no visible binding note + tab |> gt::tab_style ( - # Finally styles for "stage_date" columns to highlight need for - # action. Each grade of "urgency" has to be individually specified. - style = list (gt::cell_fill (color = "#FFFF8088")), - locations = gt::cells_body ( - columns = c (`number`, `title`, `stage_date`, `labels`), - rows = urgency == 1 - ) - ) |> - gt::tab_style ( - style = list (gt::cell_fill (color = "#FFFF0088")), - locations = gt::cells_body ( - columns = c (`number`, `title`, `stage_date`, `labels`), - rows = urgency == 2 - ) - ) |> - gt::tab_style ( - style = list (gt::cell_fill (color = "#FFAA0088")), - locations = gt::cells_body ( - columns = c (`number`, `title`, `stage_date`, `labels`), - rows = urgency == 3 - ) - ) |> - gt::tab_style ( - style = list (gt::cell_fill (color = "#FF550088")), - locations = gt::cells_body ( - columns = c (`number`, `title`, `stage_date`, `labels`), - rows = urgency == 4 - ) - ) |> - gt::tab_style ( - style = list (gt::cell_fill (color = "#FF000088")), + style = list (gt::cell_fill (color = colour)), locations = gt::cells_body ( - columns = c (`number`, `title`, `stage_date`, `labels`), - rows = urgency == 5 + columns = col_names, + rows = urgency == urgency_val ) - ) |> - add_bg_colours () + ) } add_bg_colours <- function (tab) { diff --git a/codemeta.json b/codemeta.json index 1b8f6a4..7db34b0 100644 --- a/codemeta.json +++ b/codemeta.json @@ -6,7 +6,7 @@ "name": "dashboard: What the Package Does (One Line, Title Case)", "codeRepository": "https://github.com/ropensci-review-tools/dashboard", "license": "https://spdx.org/licenses/MIT", - "version": "0.0.3.025", + "version": "0.0.3.026", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R",