Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ 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,
scales,
systemfonts,
rlang,
textshaping (>= 0.4.0)
textshaping (>= 0.4.0),
vctrs
RoxygenNote: 7.3.2
Suggests:
testthat (>= 3.0.0),
Expand Down
14 changes: 5 additions & 9 deletions R/geom_textsf.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Comment on lines +144 to +149

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new ggplot2 version has more unevaluated expressions that take their values from the theme.
We should ideally copy defaults from ggplot2's Geoms wherever we can, but it'd be easier when the new release is out.

hjust = 0.5,
vjust = 0.5,
family = "",
fontface = 1,
lineheight = 1.2,
alpha = NA,
linewidth = 0.5,
spacing = 0,
linecolour = "gray30",
angle = 0),
Expand Down
3 changes: 3 additions & 0 deletions R/onload.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Comment on lines +31 to +33

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We didn't register these methods anywhere, but somehow it worked anyway. It is better to register them, and to do that we need to register when {sf} is loaded. We could technically avoid a dependency on {vctrs} for this, but it might have uses in the future and it is a 'free' dependency as ggplot2 also takes it as a dependency.

}
6 changes: 3 additions & 3 deletions R/sf_helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Comment on lines +40 to +42

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also to deal with the unevaluated expressions and the reason we'd require ggplot2 3.5.2

polygon_aes$fill <- "grey90"
polygon_aes$colour <- "grey35"
collection_aes <- rename(textpath_aes,
Expand Down
2 changes: 1 addition & 1 deletion R/text_placement.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
13 changes: 13 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
})
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
14 changes: 14 additions & 0 deletions tests/testthat/_snaps/coord_curvedpolar.md
Original file line number Diff line number Diff line change
@@ -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
expression(paste(1, "/", 10))

9 changes: 6 additions & 3 deletions tests/testthat/test-coord_curvedpolar.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Comment on lines +69 to +71

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed these to snapshots because there is some type instability across versions. They're not run on CRAN by default, but that is fine.


out <- ggplot_gtable(ggplot_build(
p + scale_x_continuous(breaks = seq(1, 10, by = 1),
Expand All @@ -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)
)
})