From 564283d6e6d513c54d08ec468b8148bc6ead3da2 Mon Sep 17 00:00:00 2001 From: mrcaseb Date: Sat, 4 Oct 2025 21:00:51 +0200 Subject: [PATCH 1/2] use inline-block for text because it was broken on small devices --- DESCRIPTION | 2 +- R/gt_nfl.R | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 1ec900a..280c337 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: nflplotR Title: NFL Logo Plots in 'ggplot2' and 'gt' -Version: 1.5.0.9001 +Version: 1.5.0.9002 Authors@R: person("Sebastian", "Carl", , "mrcaseb@gmail.com", role = c("aut", "cre")) Description: A set of functions to visualize National Football League diff --git a/R/gt_nfl.R b/R/gt_nfl.R index 3709232..4f7084b 100644 --- a/R/gt_nfl.R +++ b/R/gt_nfl.R @@ -598,6 +598,7 @@ gt_pct_bar <- function( ## SET TEXT STYLE PROPERTIES default_text_style <- list( + "display" = "inline-block", "padding-left" = value_padding_left, "padding-right" = value_padding_right ) From c91eabe478a7266035df67c944a65f3f21347c91 Mon Sep 17 00:00:00 2001 From: mrcaseb Date: Sat, 4 Oct 2025 21:01:50 +0200 Subject: [PATCH 2/2] add tests --- tests/testthat/_snaps/gt_nfl.md | 1006 +++++++++++++++++++++++++++++++ tests/testthat/test-gt_nfl.R | 35 ++ 2 files changed, 1041 insertions(+) create mode 100644 tests/testthat/_snaps/gt_nfl.md create mode 100644 tests/testthat/test-gt_nfl.R diff --git a/tests/testthat/_snaps/gt_nfl.md b/tests/testthat/_snaps/gt_nfl.md new file mode 100644 index 0000000..735339f --- /dev/null +++ b/tests/testthat/_snaps/gt_nfl.md @@ -0,0 +1,1006 @@ +# gt_pct_bar works + + Code + tbl + Output +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
lettersvaluepctl
F113100
K27998
X15675
B10550
Y20345
B31120
M28110
I2645
C4921
Y3250
+
+ +--- + + Code + tbl + Output +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
lettersvaluepctl
F113100
K27998
X15675
B10550
Y20345
B31120
M28110
I2645
C4921
Y3250
+
+ diff --git a/tests/testthat/test-gt_nfl.R b/tests/testthat/test-gt_nfl.R new file mode 100644 index 0000000..23ee34d --- /dev/null +++ b/tests/testthat/test-gt_nfl.R @@ -0,0 +1,35 @@ +test_that("gt_pct_bar works", { + set.seed(20) + df <- data.frame( + letters = sample(LETTERS, 10, TRUE), + value = sample(100:500, 10, FALSE), + pctl = rev(c(0, 1, 5, 10, 20, 45, 50, 75, 98, 100)) + ) + + tbl <- gt::gt(df, id = "test1") |> + nflplotR::gt_pct_bar( + "value", "pctl", + hide_col_pct = FALSE, + value_padding_left = ifelse(df$pctl < 25, "110%", "10px"), + fill_border.radius = "3px", + background_border.radius = "5px" + ) |> + gt::cols_width(value ~ gt::px(200)) |> + gt::cols_align("left", "value") + + expect_snapshot(tbl) + + tbl <- gt::gt(df, id = "test2") |> + nflplotR::gt_pct_bar( + "value", "pctl", + hide_col_pct = FALSE, + value_position = "above", + # with value_position = "above", we need an absolute value of bar heights! + background_fill.height = "5px", + background_fill.color = "LightGray" + ) |> + gt::cols_width(value ~ gt::px(100)) |> + gt::cols_align("center", "value") + + expect_snapshot(tbl) +})