From f1cd4a8b7bc176f8e9954887b151cbb8f22ac4c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Frie=C3=9F?= Date: Thu, 12 Sep 2024 08:31:12 +0200 Subject: [PATCH 1/3] update formatters --- R/columns.R | 102 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 98 insertions(+), 4 deletions(-) diff --git a/R/columns.R b/R/columns.R index 8517c02..f4a2483 100644 --- a/R/columns.R +++ b/R/columns.R @@ -57,16 +57,109 @@ add_filter_to_columns <- function(columns) { return(columns) } -# Formatters +# Formatters #### + +# Plain Text +#' @export +set_plaintext_formatter <- function(widget, column, number_of_stars, hoz_align = "left") { + col_update <- list(formatter = "plaintext", hozAlign = hoz_align) + modify_col_def(widget, column, col_update) +} + +# Text Area +#' @export +set_textarea_formatter <- function(widget, column, hoz_align = "left") { + col_update <- list(formatter = "textarea", hozAlign = hoz_align) + modify_col_def(widget, column, col_update) +} + +# HTML +#' @export +set_html_formatter <- function(widget, column, hoz_align = "left") { + col_update <- list(formatter = "html", hozAlign = hoz_align) + modify_col_def(widget, column, col_update) +} + +# Money +#' @export +set_money_formatter <- function(widget, column, decimal = ",", thousand = ".", + symbol = "£", symbolAfter = "p", + negativeSign = T, precision = F, + hoz_align = "left") { + col_update <- list( + formatter = "money", + formatterParams = list( + decimal = decimal, + thousand = thousand, + symbol = symbol, + symbolAfter = symbolAfter, + negativeSign = negativeSign, + precision = precision + ), + hozAlign = hoz_align + ) + modify_col_def(widget, column, col_update) +} + +# Image +#' @export +set_image_formatter <- function(widget, column, height = "50px", width = "50px", + urlPrefix = "http://website.com/images/", + urlSuffix = ".png", hoz_align = "center") { + col_update <- list( + formatter = "image", + formatterParams = list( + height = height, + width = width, + urlPrefix = urlPrefix, + urlSuffix = urlSuffix + ), + hozAlign = hoz_align + ) + modify_col_def(widget, column, col_update) +} + +# Link +#' @export + +set_link_formatter <- function(widget, column, labelField = "", urlPrefix = "", + target = "_blank", hoz_align = "left") { + col_update <- list( + formatter = "link", + formatterParams = list( + labelField = labelField, + urlPrefix = urlPrefix, + target = target + ) + ) + + modify_col_def(widget, column, col_update) +} + +# Star #' @export set_star_formatter <- function(widget, column, number_of_stars, hoz_align = "center") { - col_update <- list(formatter = "star", formatterParams = list(stars = number_of_stars), hozAlign = hoz_align) + col_update <- list( + formatter = "star", + formatterParams = list(stars = number_of_stars), + hozAlign = hoz_align + ) modify_col_def(widget, column, col_update) } + +# Progress #' @export -set_progress_formatter <- function(widget, column, hoz_align = "left") { - col_update <- list(formatter = "progress", hozAlign = hoz_align) +set_progress_formatter <- function(widget, column, min = 0, max = 10, color = c("green", "orange", "red"), + legendColor = "#000000", legendAlign = "center", hoz_align = "left") { + col_update <- list( + formatter = "progress", + formatterParams = list( + min = min, max = max, color = color, + legendColor = legendColor, legendAlign = legendAlign + ), + hozAlign = hoz_align + ) modify_col_def(widget, column, col_update) } @@ -76,6 +169,7 @@ set_tick_cross_formatter <- function(widget, column) { modify_col_def(widget, column, col_update) } + modify_col_def <- function(widget, column, col_update) { for (index in 1:length(widget$x$options$columns)) { if (widget$x$options$columns[[index]]$field == column) { From df328b302b1251750b828fe03d5a63a491fecc85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Frie=C3=9F?= Date: Thu, 12 Sep 2024 10:01:34 +0200 Subject: [PATCH 2/3] use data range as default for min and max --- R/columns.R | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/R/columns.R b/R/columns.R index 6e38475..07d127e 100644 --- a/R/columns.R +++ b/R/columns.R @@ -153,13 +153,21 @@ set_star_formatter <- function(widget, column, number_of_stars, hoz_align = "cen set_progress_formatter <- function( widget, column, - min = 0, - max = 10, + min = NULL, + max = NULL, color = c("green", "orange", "red"), legend = FALSE, - legend_color = "#000000", - legend_align = "center", + legendColor = "#000000", + legendAlign = "center", hoz_align = "left") { + + + if (is.null(min)){ + min <- min(widget$x$data[column]) + } + if (is.null(max)){ + max <- max(widget$x$data[column]) + } col_update <- list( formatter = "progress", formatterParams = list( @@ -167,8 +175,8 @@ set_progress_formatter <- function( max = max, color = color, legend = legend, - legendColor = legend_color, - legendAlign = legend_align + legendColor = legendColor, + legendAlign = legendAlign ), hozAlign = hoz_align ) From ae544a5140a6ee492109ba63dde51ddc24923c48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Frie=C3=9F?= Date: Thu, 12 Sep 2024 10:01:56 +0200 Subject: [PATCH 3/3] For no legend text you want to use "" not false --- R/columns.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/columns.R b/R/columns.R index 07d127e..8c85756 100644 --- a/R/columns.R +++ b/R/columns.R @@ -156,7 +156,7 @@ set_progress_formatter <- function( min = NULL, max = NULL, color = c("green", "orange", "red"), - legend = FALSE, + legend = "", legendColor = "#000000", legendAlign = "center", hoz_align = "left") {