4 Commits
Author SHA1 Message Date
jaredandClaude Sonnet 5.5 b0a7b618a7 docs: record session (#28, #29)
R-CMD-check / R CMD check (push) Successful in 5m9s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-15 15:46:05 -04:00
jaredandClaude Sonnet 5.5 119aa7aa0f feat(theme): add a showtext switch to civilytics_load_fonts() for ragg users (#29)
R-CMD-check / R CMD check (push) Successful in 5m7s
civilytics_load_fonts(showtext = getOption("civilytics.showtext", TRUE))
registers the brand fonts and only then turns on showtext, so ragg users can
opt out of its 96 dpi text sizing. The default is unchanged, so existing
reports render as before. The help page documents the ragg path.

Closes #29

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-15 15:45:47 -04:00
jaredandClaude Sonnet 5.5 f3ec052144 fix(logo): reserve a logo band in add_logo_ga() instead of a negative margin (#28)
R-CMD-check / R CMD check (push) Successful in 4m38s
add_logo_ga() now gives the logo its own band (logo_height inches) below the
plots, as add_logo() does, and leaves plot margins alone unless margin_param
is given.

Closes #28

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-15 15:39:43 -04:00
jaredandClaude Sonnet 5.5 a2a0fce265 docs: refresh status board after branch rename and follow-up issues (#28, #29)
R-CMD-check / R CMD check (push) Successful in 4m53s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-15 15:34:35 -04:00
10 changed files with 168 additions and 42 deletions

No files matched your search

+2 -1
View File
@@ -35,7 +35,8 @@ Suggests:
flextable, flextable,
officer, officer,
patchwork, patchwork,
ragg ragg,
withr
Config/testthat/edition: 3 Config/testthat/edition: 3
Config/roxygen2/version: 8.0.0 Config/roxygen2/version: 8.0.0
RoxygenNote: 7.3.3 RoxygenNote: 7.3.3
+6
View File
@@ -3,6 +3,9 @@
## New features ## New features
- `civilytics_logo()` and `add_logo()` gain `logo_height` (inches, default `0.5`), - `civilytics_logo()` and `add_logo()` gain `logo_height` (inches, default `0.5`),
the height of a band reserved for the logo. the height of a band reserved for the logo.
- `civilytics_load_fonts()` gains `showtext` (default `getOption("civilytics.showtext", TRUE)`), so ragg
users can register the brand fonts without turning on showtext, which draws text
at a third of its size on a 300 dpi ragg device. The default is unchanged (#29).
- `patchwork` is now a suggested package, used when a patchwork composition is - `patchwork` is now a suggested package, used when a patchwork composition is
passed to `civilytics_logo()`. passed to `civilytics_logo()`.
- Added comprehensive test coverage for the `prop_conf` module, including - Added comprehensive test coverage for the `prop_conf` module, including
@@ -16,6 +19,9 @@
- The logo now sits in its own reserved band instead of pulling the plot down with - The logo now sits in its own reserved band instead of pulling the plot down with
negative margins, so captions are no longer clipped at the bottom edge and the negative margins, so captions are no longer clipped at the bottom edge and the
layout no longer depends on whether showtext is active (#20). layout no longer depends on whether showtext is active (#20).
- `add_logo_ga()` gets the same reserved logo band (`logo_height`) and no longer
pulls the plots down with a negative margin. `margin_param` still overrides the
bottom margin when given (#28).
- The logo keeps its own aspect ratio on any canvas. `make_logo_grob()` used to - The logo keeps its own aspect ratio on any canvas. `make_logo_grob()` used to
stretch it to a fixed fraction of the plot width, so its shape changed with stretch it to a fixed fraction of the plot width, so its shape changed with
the canvas and it was already about 1.5 times too wide at 11 by 7 inches (#20). the canvas and it was already about 1.5 times too wide at 11 by 7 inches (#20).
+24 -7
View File
@@ -14,16 +14,26 @@ CV_FONT_MONO <- "JetBrains Mono" # code, data tables, numeric callouts
#' Load Civilytics brand fonts #' Load Civilytics brand fonts
#' #'
#' Downloads Inter, Libre Franklin, Source Serif 4 and JetBrains Mono from #' Downloads Inter, Libre Franklin, Source Serif 4 and JetBrains Mono from
#' Google Fonts via [sysfonts::font_add_google()], then calls #' Google Fonts via [sysfonts::font_add_google()], then, unless
#' [showtext::showtext_auto()] so that all graphics devices render text with #' `showtext = FALSE`, calls [showtext::showtext_auto()] so that all graphics
#' those fonts. This is called automatically when the package loads; use this #' devices render text with those fonts. This is called automatically when the
#' function to retry if the initial load failed (e.g., the machine was offline #' package loads; use this function to retry if the initial load failed (e.g.,
#' at load time). #' the machine was offline at load time).
#' #'
#' Subsequent calls within the same session are no-ops unless `force = TRUE`. #' Subsequent calls within the same session are no-ops unless `force = TRUE`.
#' #'
#' **Using ragg.** [showtext::showtext_auto()] draws text at 96 dpi whatever the
#' device resolution, so on a `ragg::agg_png(res = 300)` device text comes out
#' at about a third of its requested size. For ragg, set
#' `options(civilytics.showtext = FALSE)` before loading the package, or call
#' `showtext::showtext_auto(FALSE)` afterwards. The brand fonts must then be
#' installed on the system, because ragg reads system fonts rather than the
#' ones registered through sysfonts.
#'
#' @param force Logical. If `TRUE`, reload fonts even if they were already #' @param force Logical. If `TRUE`, reload fonts even if they were already
#' loaded in this session. Default `FALSE`. #' loaded in this session. Default `FALSE`.
#' @param showtext Logical. Turn on [showtext::showtext_auto()] after
#' registering the fonts. Default is `getOption("civilytics.showtext", TRUE)`.
#' #'
#' @return Invisibly returns `TRUE` if fonts were loaded, `FALSE` if skipped #' @return Invisibly returns `TRUE` if fonts were loaded, `FALSE` if skipped
#' (already loaded and `force = FALSE`). #' (already loaded and `force = FALSE`).
@@ -32,15 +42,22 @@ CV_FONT_MONO <- "JetBrains Mono" # code, data tables, numeric callouts
#' @examples #' @examples
#' \dontrun{ #' \dontrun{
#' civilytics_load_fonts() #' civilytics_load_fonts()
#'
#' # For ragg devices: register the fonts but leave showtext off
#' civilytics_load_fonts(force = TRUE, showtext = FALSE)
#' } #' }
civilytics_load_fonts <- function(force = FALSE) { civilytics_load_fonts <- function(force = FALSE,
showtext = getOption("civilytics.showtext", TRUE)) {
if (!is.logical(showtext) || length(showtext) != 1L || is.na(showtext)) {
stop("`showtext` must be a single TRUE or FALSE.", call. = FALSE)
}
if (.cv_state$fonts_loaded && !force) return(invisible(FALSE)) if (.cv_state$fonts_loaded && !force) return(invisible(FALSE))
sysfonts::font_add_google("Inter", family = "Inter") sysfonts::font_add_google("Inter", family = "Inter")
sysfonts::font_add_google("Libre Franklin", family = "Libre Franklin") sysfonts::font_add_google("Libre Franklin", family = "Libre Franklin")
sysfonts::font_add_google("Source Serif 4", family = "Source Serif 4") sysfonts::font_add_google("Source Serif 4", family = "Source Serif 4")
sysfonts::font_add_google("JetBrains Mono", family = "JetBrains Mono") sysfonts::font_add_google("JetBrains Mono", family = "JetBrains Mono")
showtext::showtext_auto() if (showtext) showtext::showtext_auto()
.cv_state$fonts_loaded <- TRUE .cv_state$fonts_loaded <- TRUE
invisible(TRUE) invisible(TRUE)
+13 -11
View File
@@ -160,9 +160,12 @@ has_caption <- function(gg) {
#' @param logo a grob containing the logo created with `make_logo_grob` #' @param logo a grob containing the logo created with `make_logo_grob`
#' @param nrow an integer, default = 1, for the number of rows to align the plots in #' @param nrow an integer, default = 1, for the number of rows to align the plots in
#' @param widths an optional vector the same length as plot_list with the widths for each plot #' @param widths an optional vector the same length as plot_list with the widths for each plot
#' @param margin_param a number giving the adjustment up or down to help manually align logo and captions #' @param margin_param Optional number. Replaces the bottom plot margin (in points).
#' `NULL` (default) leaves plot margins alone.
#' @param font_scale Numeric. Multiplicative scaling factor applied to text #' @param font_scale Numeric. Multiplicative scaling factor applied to text
#' sizes before composing. Default `1`. See [add_logo()] for details. #' sizes before composing. Default `1`. See [add_logo()] for details.
#' @param logo_height Numeric. Height in inches of the band reserved for the
#' logo below the plots. Default `0.5`.
#' #'
#' @return a grid object #' @return a grid object
#' @note The resulting object needs to be drawn to the screen using grid.draw() #' @note The resulting object needs to be drawn to the screen using grid.draw()
@@ -181,11 +184,11 @@ has_caption <- function(gg) {
#' dev.off() #' dev.off()
#' } #' }
add_logo_ga <- function(plot_list, logo, nrow = 1, widths = NULL, add_logo_ga <- function(plot_list, logo, nrow = 1, widths = NULL,
margin_param = NULL, font_scale = 1) { margin_param = NULL, font_scale = 1,
logo_height = 0.5) {
# Capture the background color from the first plot # Capture the background color from the first plot
bg_fill <- plot_list[[1]]$theme$plot.background$fill bg_fill <- plot_list[[1]]$theme$plot.background$fill
# Inflate text sizes to compensate for viewport shrinkage
if (!is.null(font_scale) && font_scale != 1) { if (!is.null(font_scale) && font_scale != 1) {
plot_list <- lapply(plot_list, function(p) { plot_list <- lapply(plot_list, function(p) {
base_size <- p$theme$text$size %||% 14 base_size <- p$theme$text$size %||% 14
@@ -195,21 +198,17 @@ add_logo_ga <- function(plot_list, logo, nrow = 1, widths = NULL,
}) })
} }
# Change position of logo depending on if plot has a caption # The logo has its own band below the plots, so no margin adjustment is
# needed. `margin_param` still replaces the bottom margin when given.
if (!is.null(margin_param)) { if (!is.null(margin_param)) {
margin <- theme(plot.margin = unit(c(7, 7, margin_param, 7), "pt")) margin <- theme(plot.margin = unit(c(7, 7, margin_param, 7), "pt"))
} else if (any(unlist(lapply(plot_list, has_caption)))) {
cap_lines <- max(sapply(plot_list, measure_caption))
margin <- theme(plot.margin = unit(c(7, 7, -7 * sqrt(cap_lines), 7), "pt"))
} else {
margin <- theme(plot.margin = unit(c(7, 7, 7, 7), "pt"))
}
if (nrow > 1) { if (nrow > 1) {
len <- length(plot_list) len <- length(plot_list)
plot_list[[len]] <- plot_list[[len]] + margin plot_list[[len]] <- plot_list[[len]] + margin
} else { } else {
plot_list <- lapply(plot_list, "+", margin) plot_list <- lapply(plot_list, "+", margin)
} }
}
if (nrow != 1) { if (nrow != 1) {
if (!is.null(widths)) warning("`widths` is ignored when `nrow > 1`") if (!is.null(widths)) warning("`widths` is ignored when `nrow > 1`")
@@ -218,7 +217,10 @@ add_logo_ga <- function(plot_list, logo, nrow = 1, widths = NULL,
hold <- arrangeGrob(grobs = plot_list, nrow = 1, ncol = length(plot_list), widths = widths) hold <- arrangeGrob(grobs = plot_list, nrow = 1, ncol = length(plot_list), widths = widths)
} }
composed <- arrangeGrob(hold, logo, heights = c(0.93, .07)) composed <- arrangeGrob(
hold, logo,
heights = grid::unit.c(grid::unit(1, "null"), grid::unit(logo_height, "in"))
)
if (!is.null(bg_fill) && !is.na(bg_fill)) { if (!is.null(bg_fill) && !is.na(bg_fill)) {
bg_rect <- grid::rectGrob(gp = grid::gpar(fill = bg_fill, col = NA)) bg_rect <- grid::rectGrob(gp = grid::gpar(fill = bg_fill, col = NA))
+7 -2
View File
@@ -10,7 +10,8 @@ add_logo_ga(
nrow = 1, nrow = 1,
widths = NULL, widths = NULL,
margin_param = NULL, margin_param = NULL,
font_scale = 1 font_scale = 1,
logo_height = 0.5
) )
} }
\arguments{ \arguments{
@@ -22,10 +23,14 @@ add_logo_ga(
\item{widths}{an optional vector the same length as plot_list with the widths for each plot} \item{widths}{an optional vector the same length as plot_list with the widths for each plot}
\item{margin_param}{a number giving the adjustment up or down to help manually align logo and captions} \item{margin_param}{Optional number. Replaces the bottom plot margin (in points).
`NULL` (default) leaves plot margins alone.}
\item{font_scale}{Numeric. Multiplicative scaling factor applied to text \item{font_scale}{Numeric. Multiplicative scaling factor applied to text
sizes before composing. Default `1`. See [add_logo()] for details.} sizes before composing. Default `1`. See [add_logo()] for details.}
\item{logo_height}{Numeric. Height in inches of the band reserved for the
logo below the plots. Default `0.5`.}
} }
\value{ \value{
a grid object a grid object
+25 -7
View File
@@ -4,11 +4,17 @@
\alias{civilytics_load_fonts} \alias{civilytics_load_fonts}
\title{Load Civilytics brand fonts} \title{Load Civilytics brand fonts}
\usage{ \usage{
civilytics_load_fonts(force = FALSE) civilytics_load_fonts(
force = FALSE,
showtext = getOption("civilytics.showtext", TRUE)
)
} }
\arguments{ \arguments{
\item{force}{Logical. If \code{TRUE}, reload fonts even if they were already \item{force}{Logical. If \code{TRUE}, reload fonts even if they were already
loaded in this session. Default \code{FALSE}.} loaded in this session. Default \code{FALSE}.}
\item{showtext}{Logical. Turn on \code{showtext::showtext_auto()} after
registering the fonts. Default is \code{getOption("civilytics.showtext", TRUE)}.}
} }
\value{ \value{
Invisibly returns \code{TRUE} if fonts were loaded, \code{FALSE} if skipped Invisibly returns \code{TRUE} if fonts were loaded, \code{FALSE} if skipped
@@ -16,16 +22,28 @@ Invisibly returns \code{TRUE} if fonts were loaded, \code{FALSE} if skipped
} }
\description{ \description{
Downloads Inter, Libre Franklin, Source Serif 4 and JetBrains Mono from Downloads Inter, Libre Franklin, Source Serif 4 and JetBrains Mono from
Google Fonts via \code{sysfonts::font_add_google()}, then calls Google Fonts via \code{sysfonts::font_add_google()}, then, unless
\code{showtext::showtext_auto()} so that all graphics devices render text with \code{showtext = FALSE}, calls \code{showtext::showtext_auto()} so that all graphics
those fonts. This is called automatically when the package loads; use this devices render text with those fonts. This is called automatically when the
function to retry if the initial load failed (e.g., the machine was offline package loads; use this function to retry if the initial load failed (e.g.,
at load time). the machine was offline at load time).
}
\details{
Subsequent calls within the same session are no-ops unless \code{force = TRUE}. Subsequent calls within the same session are no-ops unless \code{force = TRUE}.
\strong{Using ragg.} \code{showtext::showtext_auto()} draws text at 96 dpi whatever the
device resolution, so on a \code{ragg::agg_png(res = 300)} device text comes out
at about a third of its requested size. For ragg, set
\code{options(civilytics.showtext = FALSE)} before loading the package, or call
\code{showtext::showtext_auto(FALSE)} afterwards. The brand fonts must then be
installed on the system, because ragg reads system fonts rather than the
ones registered through sysfonts.
} }
\examples{ \examples{
\dontrun{ \dontrun{
civilytics_load_fonts() civilytics_load_fonts()
# For ragg devices: register the fonts but leave showtext off
civilytics_load_fonts(force = TRUE, showtext = FALSE)
} }
} }
+6
View File
@@ -13,6 +13,12 @@ file carries the reasoning and the pointers.
--- ---
## 2026-10-15 · packaging · default branch renamed to main; add_logo_ga band and showtext switch
**Why:** `Closes` keywords only fire on the default branch, so the rename came first; #28 and #29 finished the logo work, and #29 took the opt-out switch because changing the showtext default would alter published reports we cannot see from here.
**Obligates:** none; turning showtext off by default is a future decision if consumers allow it
**Refs:** #28, #29, f3ec052, 119aa7a, 7bc547a
## 2026-10-15 · logo · logo band, patchwork panels, brand table colors, reveal print fixes ## 2026-10-15 · logo · logo band, patchwork panels, brand table colors, reveal print fixes
**Why:** figures with captions were shipping clipped and patchwork figures lost panels (#20); the table default and reveal print/column bugs were off-brand or broken in published decks. Default changes (font_scale 1, brand table colors) alter existing output, so this is 0.3.2. **Why:** figures with captions were shipping clipped and patchwork figures lost panels (#20); the table default and reveal print/column bugs were off-brand or broken in published decks. Default changes (font_scale 1, brand table colors) alter existing output, so this is 0.3.2.
+10 -14
View File
@@ -7,38 +7,34 @@
## Where this stands ## Where this stands
Five open defects are fixed in 0.3.2: the logo no longer clips captions or drops patchwork panels and keeps its shape, flextable defaults use brand colors, and the reveal theme honors column widths, slide margins and list numbers in print. The reveal print fixes have not been checked in a rendered PDF; another project will do that. The `kodor` label duplication was settled in favor of the org labels. Reviews for the three fix commits are queued. Nothing is left in the ready queue except pushing so the issues close. Every issue that was open is closed, and the default branch is `main`. The 0.3.2 changes are all pushed: the logo and `add_logo_ga()` reserve their own band so captions are not clipped, patchwork figures keep every panel, flextable defaults use brand colors, and `civilytics_load_fonts()` has a switch for ragg users who do not want showtext. The showtext default is unchanged, so turning it off by default is a separate decision that depends on which reports rely on it. The reveal print fixes still need a look in a rendered PDF, which another project will do.
## Ready to work on next ## Ready to work on next
- **#20** civilytics_logo(): drops patchwork panels, clips captions, and silently rescales fonts · `ws/logo` — nothing is blocking it; something is currently wrong _Nothing is open and unblocked._
- **#25** civilytics-reveal: PDF output has no slide margins (print-pdf overrides section padding) · `ws/quarto` — nothing is blocking it; something is currently wrong
- **#26** civilytics-reveal: .column { flex: 1 } ignores Quarto column widths · `ws/quarto` — nothing is blocking it; something is currently wrong
- **#27** civilytics-reveal: ordered-list numbers clip at the left edge in PDF output · `ws/quarto` — nothing is blocking it; something is currently wrong
- **#21** style_flextable_civilytics() defaults to Bootstrap colors, not Civilytics brand · `ws/logo` — nothing is blocking it; owed work from an earlier change
## Workstreams ## Workstreams
| Stream | Commits since | Open | Debt | Owes docs | | Stream | Commits since | Open | Debt | Owes docs |
|---|---|---|---|---| |---|---|---|---|---|
| Themes, palettes, and fonts | 0 | 0 | 0 | no | | Themes, palettes, and fonts | 1 | 0 | 0 | no |
| Logo and branded output composition | 2 | 2 | 1 | no | | Logo and branded output composition | 1 | 0 | 0 | no |
| Quarto themes and publishing templates | 1 | 3 | 0 | **yes** | | Quarto themes and publishing templates | 0 | 0 | 0 | no |
| Analysis and workflow helpers | 0 | 0 | 0 | no | | Analysis and workflow helpers | 0 | 0 | 0 | no |
| Package infrastructure and release | 3 | 0 | 0 | no | | Package infrastructure and release | 2 | 0 | 0 | no |
## CI ## CI
![R-CMD-check](https://gitea.civilytics.org/Civilytics/civilyticsR/actions/workflows/check.yaml/badge.svg?branch=master) ![R-CMD-check](https://gitea.civilytics.org/Civilytics/civilyticsR/actions/workflows/check.yaml/badge.svg?branch=main)
<details> <details>
<summary>Dependency graph and detail</summary> <summary>Dependency graph and detail</summary>
_Nothing blocks anything else, so there is no graph to draw._ _Nothing blocks anything else, so there is no graph to draw._
- Marker: `04a5ee95` (2026-08-24) - Marker: `c16e6cec` (2026-10-15)
- Commits since: 7 - Commits since: 4
- Open issues: 5 - Open issues: 0
</details> </details>
+50
View File
@@ -0,0 +1,50 @@
# civilytics_load_fonts() must not touch the network or global devices in tests:
# both sysfonts::font_add_google() and showtext::showtext_auto() are mocked.
with_font_mocks <- function(code, env = parent.frame()) {
calls <- new.env()
calls$showtext <- 0L
calls$google <- character()
old <- .cv_state$fonts_loaded
.cv_state$fonts_loaded <- FALSE
withr::defer(.cv_state$fonts_loaded <- old, envir = env)
testthat::local_mocked_bindings(
font_add_google = function(name, family = name, ...) {
calls$google <- c(calls$google, family)
},
.package = "sysfonts", .env = env
)
testthat::local_mocked_bindings(
showtext_auto = function(enable = TRUE) calls$showtext <- calls$showtext + 1L,
.package = "showtext", .env = env
)
calls
}
test_that("civilytics_load_fonts turns showtext on by default (#29)", {
skip_if_not_installed("withr")
calls <- with_font_mocks()
expect_true(civilytics_load_fonts())
expect_length(calls$google, 4)
expect_equal(calls$showtext, 1L)
})
test_that("showtext = FALSE registers fonts but leaves showtext off (#29)", {
skip_if_not_installed("withr")
calls <- with_font_mocks()
expect_true(civilytics_load_fonts(showtext = FALSE))
expect_length(calls$google, 4)
expect_equal(calls$showtext, 0L)
})
test_that("options(civilytics.showtext = FALSE) sets the default (#29)", {
skip_if_not_installed("withr")
calls <- with_font_mocks()
withr::local_options(civilytics.showtext = FALSE)
civilytics_load_fonts()
expect_equal(calls$showtext, 0L)
})
test_that("showtext must be a single TRUE or FALSE", {
expect_error(civilytics_load_fonts(showtext = NA), "showtext")
expect_error(civilytics_load_fonts(showtext = c(TRUE, FALSE)), "showtext")
})
+25
View File
@@ -111,3 +111,28 @@ test_that("the logo keeps its aspect ratio at any canvas width (#20)", {
expect_lt(diff(range(aspects)) / mean(aspects), 0.03, label = type) expect_lt(diff(range(aspects)) / mean(aspects), 0.03, label = type)
} }
}) })
# --- add_logo_ga() layout (#28) ----------------------------------------------
test_that("add_logo_ga reserves a logo band instead of using negative margins", {
logo <- make_logo_grob()
composed <- add_logo_ga(list(caption_plot(), caption_plot()), logo, logo_height = 0.6)
heights <- composed_table(composed)$heights
expect_equal(length(heights), 2)
expect_true(any(grepl("null", as.character(heights))))
expect_true(any(grepl("0.6", as.character(heights))))
})
test_that("add_logo_ga does not clip captions at several canvas sizes", {
skip_on_cran()
logo <- make_logo_grob()
for (nrow in c(1, 2)) {
for (w in c(8, 11, 16, 24)) {
composed <- suppressWarnings(
add_logo_ga(list(caption_plot(), caption_plot()), logo, nrow = nrow)
)
ink <- bottom_ink(composed, w, w * 0.64)
expect_equal(ink, 0, info = paste("nrow", nrow, "width", w))
}
}
})