From 801ce09b1fbb062b4cf8ee0f9024b61b4473243f Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Tue, 10 Jun 2025 19:11:01 +0200 Subject: [PATCH 1/6] loosen type expectations with snapshot test --- tests/testthat/_snaps/coord_curvedpolar.md | 14 ++++++++++++++ tests/testthat/test-coord_curvedpolar.R | 9 ++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 tests/testthat/_snaps/coord_curvedpolar.md diff --git a/tests/testthat/_snaps/coord_curvedpolar.md b/tests/testthat/_snaps/coord_curvedpolar.md new file mode 100644 index 0000000..2afbff3 --- /dev/null +++ b/tests/testthat/_snaps/coord_curvedpolar.md @@ -0,0 +1,14 @@ +# wrapping first and last labels works as expected + + Code + axis_labels$textpath$label[[9]]$glyph + Output + [1] "1" "/" "1" "0" + +--- + + Code + make_label(axis_labels$textpath$label[[9]]$glyph) + Output + [1] "1" "/" "1" "0" + diff --git a/tests/testthat/test-coord_curvedpolar.R b/tests/testthat/test-coord_curvedpolar.R index 53d2104..200ec11 100644 --- a/tests/testthat/test-coord_curvedpolar.R +++ b/tests/testthat/test-coord_curvedpolar.R @@ -66,7 +66,9 @@ test_that("wrapping first and last labels works as expected", { panel <- out$grobs[[which(out$layout$name == "panel")]] axis_labels <- panel$children[[5]]$children[[1]] - expect_equal(axis_labels$textpath$label[[9]]$glyph, c("1", "/", "1", "0")) + expect_snapshot( + axis_labels$textpath$label[[9]]$glyph + ) out <- ggplot_gtable(ggplot_build( p + scale_x_continuous(breaks = seq(1, 10, by = 1), @@ -75,6 +77,7 @@ test_that("wrapping first and last labels works as expected", { panel <- out$grobs[[which(out$layout$name == "panel")]] axis_labels <- panel$children[[5]]$children[[1]] - expect_identical(make_label(axis_labels$textpath$label[[9]]$glyph), - expression(paste(1, "/", 10))) + expect_snapshot( + make_label(axis_labels$textpath$label[[9]]$glyph) + ) }) From 4a1d03550404a50374ec75120323901945f131b7 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Tue, 10 Jun 2025 19:52:44 +0200 Subject: [PATCH 2/6] delayed registration of S3 methods of external generic --- DESCRIPTION | 3 ++- R/onload.R | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index d519797..8b772c9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -28,7 +28,8 @@ Imports: scales, systemfonts, rlang, - textshaping (>= 0.4.0) + textshaping (>= 0.4.0), + vctrs RoxygenNote: 7.3.2 Suggests: testthat (>= 3.0.0), diff --git a/R/onload.R b/R/onload.R index 5580cc8..b5e1471 100644 --- a/R/onload.R +++ b/R/onload.R @@ -28,4 +28,7 @@ systemfonts::register_font("fallback", systemfonts::font_info("")$path[1]) } + # Only register once sf is loaded + vctrs::s3_register("sf::st_as_grob", "sfc_labelled") + vctrs::s3_register("sf::st_as_grob", "sfc_textbox") } From 1c1b45e4cf03b7bf5440d6fa1477d3272c72578e Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Tue, 10 Jun 2025 19:53:13 +0200 Subject: [PATCH 3/6] stabilise geom defaults --- DESCRIPTION | 2 +- R/geom_textsf.R | 14 +++++--------- R/sf_helpers.R | 6 +++--- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 8b772c9..49cc983 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -21,7 +21,7 @@ URL: https://allancameron.github.io/geomtextpath/ BugReports: https://github.com/AllanCameron/geomtextpath/issues Encoding: UTF-8 Depends: - ggplot2 (>= 3.5.0), + ggplot2 (>= 3.5.2), R (>= 3.6.0) Imports: grid, diff --git a/R/geom_textsf.R b/R/geom_textsf.R index b15be3a..896663d 100644 --- a/R/geom_textsf.R +++ b/R/geom_textsf.R @@ -141,20 +141,16 @@ GeomTextsf <- ggproto("GeomTextSf", GeomSf, required_aes = c("geometry", "label"), + + default_aes = aes( - shape = NULL, - colour = "gray30", - fill = "gray90", - linetype = 1, - stroke = 0.5, - size = 3.88, + !!!GeomSf$default_aes[-which(names(GeomSf$default_aes) %in% c("size", "linewidth"))], + !!!GeomText$default_aes[c("family", "size")], + linewidth = !!GeomLine$default_aes$linewidth, hjust = 0.5, vjust = 0.5, - family = "", fontface = 1, lineheight = 1.2, - alpha = NA, - linewidth = 0.5, spacing = 0, linecolour = "gray30", angle = 0), diff --git a/R/sf_helpers.R b/R/sf_helpers.R index 4480360..8ae820c 100644 --- a/R/sf_helpers.R +++ b/R/sf_helpers.R @@ -37,9 +37,9 @@ sf_types <- c(GEOMETRY = "other", sf_defaults <- function() { - point_aes <- GeomPoint$default_aes - textpath_aes <- GeomTextpath$default_aes - polygon_aes <- GeomPolygon$default_aes + point_aes <- get_geom_defaults(GeomPoint) + textpath_aes <- get_geom_defaults(GeomTextpath) + polygon_aes <- get_geom_defaults(GeomPolygon) polygon_aes$fill <- "grey90" polygon_aes$colour <- "grey35" collection_aes <- rename(textpath_aes, From cd50b7624149ab738587e7d0d4d427d44881cfee Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Tue, 10 Jun 2025 20:51:11 +0200 Subject: [PATCH 4/6] give option to muffle warning (fix #128) --- R/text_placement.R | 2 +- R/utils.R | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/R/text_placement.R b/R/text_placement.R index 87cab2e..ef25653 100644 --- a/R/text_placement.R +++ b/R/text_placement.R @@ -62,7 +62,7 @@ place_text <- function( df$xoffset <- label$xoffset df$yoffset <- label$yoffset - if (any(df$exceed != 0) & !is.multichar(label$glyph)) { + if (any(df$exceed != 0) & !is.multichar(label$glyph) && ticker()) { warn(paste( "The text offset exceeds the curvature in one or more paths.", diff --git a/R/utils.R b/R/utils.R index 041a7d0..593179f 100644 --- a/R/utils.R +++ b/R/utils.R @@ -740,3 +740,16 @@ warn_overwritten_args <- function ( ": Ignoring ", overwritten_arg_text, " because ", provided_arg_text, " ", verb, " provided.")) } + +ticker <- local({ + i <- NULL + function(nseconds = getOption("geomtextpath_warninterval", 5)) { + old <- i + new <- Sys.time() + i <<- new + if (is.null(old)) { + return(TRUE) + } + (new - old) > nseconds + } +}) From b7c63e718d3d0288b79d28fefa83bd9445b6ecc0 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Tue, 10 Jun 2025 21:30:53 +0200 Subject: [PATCH 5/6] readapt snapshot to 3.5.2 --- tests/testthat/_snaps/coord_curvedpolar.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/_snaps/coord_curvedpolar.md b/tests/testthat/_snaps/coord_curvedpolar.md index 2afbff3..063e110 100644 --- a/tests/testthat/_snaps/coord_curvedpolar.md +++ b/tests/testthat/_snaps/coord_curvedpolar.md @@ -10,5 +10,5 @@ Code make_label(axis_labels$textpath$label[[9]]$glyph) Output - [1] "1" "/" "1" "0" + expression(paste(1, "/", 10)) From b476fd1580e1f3213b4798ebec3ba1797a4b797e Mon Sep 17 00:00:00 2001 From: Anka Date: Tue, 10 Jun 2025 19:32:35 +0000 Subject: [PATCH 6/6] Re-build README.Rmd --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a93225f..050c35e 100644 --- a/README.md +++ b/README.md @@ -233,7 +233,7 @@ such as rivers and roads can be given (curved) text labels: ``` r library(sf) -#> Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE +#> Linking to GEOS 3.13.0, GDAL 3.8.5, PROJ 9.5.1; sf_use_s2() is TRUE df <- data.frame(x = c(-4.2518, -3.1883), y = c(55.8642, 55.9533),