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
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
19 changes: 15 additions & 4 deletions R/grattan_label.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -44,6 +44,7 @@
#'
#'
#' @importFrom ggrepel geom_label_repel
#' @importFrom lifecycle deprecated is_present deprecate_warn
#' @name grattan_label_functions
#'

Expand All @@ -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
)
Expand Down
7 changes: 7 additions & 0 deletions R/grattan_save.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Binary file added Rplots.pdf
Binary file not shown.
19 changes: 7 additions & 12 deletions inst/extdata/ai_guide_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand All @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions man/grattan_label_functions.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading