diff --git a/NAMESPACE b/NAMESPACE index 1157777..b4bae93 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -197,6 +197,9 @@ importFrom(ggrepel,geom_label_repel) importFrom(grid,arrow) importFrom(grid,convertX) importFrom(jsonlite,fromJSON) +importFrom(lifecycle,deprecate_warn) +importFrom(lifecycle,deprecated) +importFrom(lifecycle,is_present) importFrom(openxlsx,addStyle) importFrom(openxlsx,addWorksheet) importFrom(openxlsx,createStyle) diff --git a/NEWS.md b/NEWS.md index d5330d9..a434c98 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# grattantheme 1.5.1 +* `grattan_save()` now applies the slide font (Avenir Next) to non-fullslide chart types when `font = "slide"` is explicitly set. +* Fixed `grattan_label_repel()` border visibility caused by ggrepel switching from `label.size` to `linewidth` aesthetic for border control. Labels now explicitly set `linewidth = 0` to suppress borders. + # grattantheme 1.5 * New `grattan_write_ai_guide()` function writes a style guide for AI coding assistants (Claude, Codex, Gemini) to your project directory. * `theme_grattan()` now auto-detects horizontal/flipped charts and applies `flipped = TRUE` automatically. Detection triggers for `coord_flip()` and bar charts (discrete y + continuous x). A message is shown every 8 hours when auto-detection fires. Set `flipped = TRUE` explicitly to silence the message, or `flipped = FALSE` to opt out of auto-detection. diff --git a/R/grattan_label.R b/R/grattan_label.R index fb767e2..8130d4a 100644 --- a/R/grattan_label.R +++ b/R/grattan_label.R @@ -18,8 +18,8 @@ #' (see \code{?unit::grid}). Default is 0.1. #' @param lineheight Height of lines of text - smaller means the lines #' of text are closer together. Default is `0.8`. -#' @param linewidth Size of label border line for `grattan_label`, in mm. Default is `NA`, which means no border. -#' @param label.size Size of label border line for `grattan_label_repel`, in mm. Default is `NA`, which means no border. +#' @param linewidth Size of label border line, in mm. Default is `NA`, which means no border. +#' @param label.size `r lifecycle::badge("deprecated")` Use `linewidth` instead. #' @param fill Colour of label background; default is `"white"`. #' #' @examples @@ -44,6 +44,7 @@ #' #' #' @importFrom ggrepel geom_label_repel +#' @importFrom lifecycle deprecated is_present deprecate_warn #' @name grattan_label_functions #' @@ -67,14 +68,24 @@ grattan_label <- function(..., size = 18, padding = 0.1, lineheight = 0.8, #' @rdname grattan_label_functions #' @export grattan_label_repel <- function(..., size = 18, padding = 0.1, lineheight = 0.8, - label.size = NA, fill = "white") { + linewidth = NA, label.size = deprecated(), + fill = "white") { .size = size / ggplot2::.pt + if (lifecycle::is_present(label.size)) { + lifecycle::deprecate_warn("1.5.1", "grattan_label_repel(label.size)", + "grattan_label_repel(linewidth)") + linewidth <- label.size + } + + # ggrepel uses both label.size (geom param) and linewidth (aesthetic) for + # border control; set both to ensure no border regardless of ggrepel version ggrepel::geom_label_repel( ..., fill = fill, label.padding = unit(padding, "lines"), - label.size = label.size, + label.size = linewidth, + linewidth = if (is.na(linewidth)) 0 else linewidth, size = .size, lineheight = lineheight ) diff --git a/R/grattan_save.R b/R/grattan_save.R index 7aa1619..1813746 100644 --- a/R/grattan_save.R +++ b/R/grattan_save.R @@ -339,6 +339,13 @@ grattan_save_ <- function(filename, } else { # following code only applies if type != "fullslide" + # Apply slide font to non-fullslide charts when font = "slide" + if (!is.null(font) && font == "slide") { + slide_body_font <- get_grattan_font("slide", "body") + object <- object + + theme(text = element_text(family = slide_body_font)) + } + if (isFALSE(force_labs)) { # Unless force_labs == TRUE (indicating the user wishes # to retain their labels) diff --git a/Rplots.pdf b/Rplots.pdf new file mode 100644 index 0000000..69fdf56 Binary files /dev/null and b/Rplots.pdf differ diff --git a/inst/extdata/ai_guide_template.md b/inst/extdata/ai_guide_template.md index a22b6d8..5e1f350 100644 --- a/inst/extdata/ai_guide_template.md +++ b/inst/extdata/ai_guide_template.md @@ -51,8 +51,7 @@ grattan_label( ) ``` -Then set `legend.position = "none"` in theme or use `guide = "none"` in -scale functions. +Don't use bold or italicised labels unless specifically requested. ## Core Functions @@ -226,6 +225,11 @@ grattan_point_filled(data = . %>% filter(date == max(date))) ## Colour Palette +### Colour Scales + +Unless requested, leave `grattantheme` to do its own colour scales. Do not make +your own manual colour palette unless asked. + ### Core Colours Primary palette (use in this order for discrete scales): @@ -246,23 +250,14 @@ Additional colours: Each colour has faded variants (1-8), e.g. `grattan_orange3`, `grattan_red5`. -### Colour Scales - -Generally just leave `grattantheme` to do its own colour scales unless -you are specifically requested to take another approach. - If you need to create a manual colour palette, you can do as follows: ``` r -# For discrete scales (automatic ordering) -scale_colour_grattan(discrete = TRUE) -scale_fill_grattan(discrete = TRUE) - # For continuous scales scale_colour_grattan(discrete = FALSE, palette = "sequential") scale_fill_grattan(discrete = FALSE, palette = "diverging") -# Manual assignment (preferred for control) +# Manual assignment scale_fill_manual(values = c( "Category A" = grattan_yellow, "Category B" = grattan_orange, diff --git a/man/grattan_label_functions.Rd b/man/grattan_label_functions.Rd index 1f3f66f..6bf5e72 100644 --- a/man/grattan_label_functions.Rd +++ b/man/grattan_label_functions.Rd @@ -20,7 +20,8 @@ grattan_label_repel( size = 18, padding = 0.1, lineheight = 0.8, - label.size = NA, + linewidth = NA, + label.size = deprecated(), fill = "white" ) } @@ -37,11 +38,11 @@ case of `grattan_label()`) or `ggrepel::geom_label_repel()` (in the case of \item{lineheight}{Height of lines of text - smaller means the lines of text are closer together. Default is `0.8`.} -\item{linewidth}{Size of label border line for `grattan_label`, in mm. Default is `NA`, which means no border.} +\item{linewidth}{Size of label border line, in mm. Default is `NA`, which means no border.} \item{fill}{Colour of label background; default is `"white"`.} -\item{label.size}{Size of label border line for `grattan_label_repel`, in mm. Default is `NA`, which means no border.} +\item{label.size}{`r lifecycle::badge("deprecated")` Use `linewidth` instead.} } \description{ `grattan_label()` and `grattan_label_repel()` create labels using diff --git a/tests/testthat/_snaps/grattan-label/labelled-plot-with-repel.svg b/tests/testthat/_snaps/grattan-label/labelled-plot-with-repel.svg index 313f900..a9fdb6c 100644 --- a/tests/testthat/_snaps/grattan-label/labelled-plot-with-repel.svg +++ b/tests/testthat/_snaps/grattan-label/labelled-plot-with-repel.svg @@ -63,80 +63,80 @@ - - - - - - - - - - - - -Mazda RX4 - -Mazda RX4 Wag - -Datsun 710 - -Hornet 4 Drive - -Hornet Sportabout - -Valiant - -Duster 360 - -Merc 240D - -Merc 230 - -Merc 280 - -Merc 280C - + + + + + + + + + + + + +Mazda RX4 + +Mazda RX4 Wag + +Datsun 710 + +Hornet 4 Drive + +Hornet Sportabout + +Valiant + +Duster 360 + +Merc 240D + +Merc 230 + +Merc 280 + +Merc 280C + Merc 450SE - -Merc 450SL - -Merc 450SLC - + +Merc 450SL + +Merc 450SLC + Cadillac Fleetwood - + Lincoln Continental - + Chrysler Imperial - + Fiat 128 - -Honda Civic - + +Honda Civic + Toyota Corolla - -Toyota Corona - -Dodge Challenger - -AMC Javelin - -Camaro Z28 - -Pontiac Firebird - -Fiat X1-9 - -Porsche 914-2 - + +Toyota Corona + +Dodge Challenger + +AMC Javelin + +Camaro Z28 + +Pontiac Firebird + +Fiat X1-9 + +Porsche 914-2 + Lotus Europa - -Ford Pantera L - -Ferrari Dino - -Maserati Bora - + +Ford Pantera L + +Ferrari Dino + +Maserati Bora + Volvo 142E diff --git a/tests/testthat/multi_slide_fullslide.pptx b/tests/testthat/multi_slide_fullslide.pptx index 6057c4e..5fba637 100644 Binary files a/tests/testthat/multi_slide_fullslide.pptx and b/tests/testthat/multi_slide_fullslide.pptx differ diff --git a/tests/testthat/multi_slide_fullslide_43.pptx b/tests/testthat/multi_slide_fullslide_43.pptx index ebd8506..6168b2e 100644 Binary files a/tests/testthat/multi_slide_fullslide_43.pptx and b/tests/testthat/multi_slide_fullslide_43.pptx differ diff --git a/tests/testthat/temp.pptx b/tests/testthat/temp.pptx index 5dee3eb..fb415e7 100644 Binary files a/tests/testthat/temp.pptx and b/tests/testthat/temp.pptx differ diff --git a/tests/testthat/temp_fullslide.pptx b/tests/testthat/temp_fullslide.pptx index 08a8347..0861600 100644 Binary files a/tests/testthat/temp_fullslide.pptx and b/tests/testthat/temp_fullslide.pptx differ diff --git a/tests/testthat/temp_fullslide_43.pptx b/tests/testthat/temp_fullslide_43.pptx index 4e32a0a..24205d7 100644 Binary files a/tests/testthat/temp_fullslide_43.pptx and b/tests/testthat/temp_fullslide_43.pptx differ diff --git a/tests/testthat/temp_rich_fullslide.pptx b/tests/testthat/temp_rich_fullslide.pptx index 0c347a1..039c32f 100644 Binary files a/tests/testthat/temp_rich_fullslide.pptx and b/tests/testthat/temp_rich_fullslide.pptx differ diff --git a/tests/testthat/test/saved_plots.rda b/tests/testthat/test/saved_plots.rda index e02e9f6..0fd32dd 100644 Binary files a/tests/testthat/test/saved_plots.rda and b/tests/testthat/test/saved_plots.rda differ