13 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
jaredandClaude Sonnet 5.5 7bc547a995 ci(packaging): run check on main after renaming the default branch from master
R-CMD-check / R CMD check (push) Successful in 4m58s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-15 15:33:49 -04:00
jaredandClaude Sonnet 5.5 c16e6cec19 docs: record session (#20, #21, #22, #24, #25, #26, #27)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-15 15:31:25 -04:00
jaredandClaude Sonnet 5.5 dab960aaf1 docs(packaging): drop the flextable hex-default debt note now that #21 is fixed
AGENTS.md and the roborev project guideline in pm/compass.toml both said
R/flextable.R carries off-brand defaults. It no longer does.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-15 15:31:15 -04:00
jaredandClaude Sonnet 5.5 dfcad3d0b8 chore(packaging): bump version to 0.3.2 and record fixes in NEWS
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-15 15:27:55 -04:00
jaredandClaude Sonnet 5.5 0561df4221 fix(logo): reserve a logo band, keep patchwork panels, and preserve logo aspect (#20)
The logo gets its own band (logo_height inches) instead of negative
margins, so captions are no longer clipped. Patchwork compositions go
through patchworkGrob() so every panel survives. font_scale defaults to 1.
make_logo_grob() sizes by height so the logo keeps its shape on any canvas.

Closes #20

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-15 15:27:55 -04:00
jaredandClaude Sonnet 5.5 d6e3ba2fb4 fix(logo): take style_flextable_civilytics() defaults from civilytics_colors (#21)
Header, zebra, borders, and footer text now use navy_700, paper_2,
rule_strong, rule, and ink_3 instead of Bootstrap hex values. Tables built
with the defaults change appearance.

Closes #21

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-15 15:27:54 -04:00
jaredandClaude Sonnet 5.5 4f697e2d52 fix(quarto): keep slide margins, list numbers, and column widths in civilytics-reveal
Print-to-PDF restores a 32px 56px section padding (full-bleed slides are
left alone), ordered lists get room for two-digit markers, and columns
with a Quarto width keep it while unsized columns stay equal. The default
column gap drops from 3em to 1.5em.

Closes #25
Closes #26
Closes #27

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-15 15:27:54 -04:00
jared 76aebe2b49 chore: add CLAUDE.md that imports AGENTS.md
R-CMD-check / R CMD check (push) Successful in 4m46s
Claude Code loads a project's AGENTS.md only when the project has no CLAUDE.md, and then
also loads every AGENTS.md and .claude/AGENTS.md above it, including ~/AGENTS.md and
~/.claude/AGENTS.md. This one-line import keeps the project's instructions to its own
AGENTS.md, matching the other Civilytics repos.
2026-10-11 16:57:02 -04:00
jared 446843bc86 docs: refresh status board for #24
R-CMD-check / R CMD check (push) Successful in 4m11s
2026-08-24 00:24:01 -04:00
21 changed files with 434 additions and 159 deletions

No files matched your search

+2 -2
View File
@@ -2,9 +2,9 @@ name: R-CMD-check
on: on:
push: push:
branches: [master] branches: [main]
pull_request: pull_request:
branches: [master] branches: [main]
jobs: jobs:
check: check:
+1 -1
View File
@@ -51,7 +51,7 @@ review_guidelines = '''
- Tests use testthat edition 3. Each test is self-sufficient -- no reliance on state - Tests use testthat edition 3. Each test is self-sufficient -- no reliance on state
left by an earlier test or on a fixture built elsewhere in the file. left by an earlier test or on a fixture built elsewhere in the file.
- Prefer duplication in tests over a helper that hides what is being asserted. - Prefer duplication in tests over a helper that hides what is being asserted.
- Brand colors come from `civilytics_colors`; never write a hex literal in theme, scale, logo, or table code. `R/flextable.R` still carries off-brand Bootstrap defaults (#2c3e50, #f0f0eb, #888888, #cccccc, #555555) -- do not add more. - Brand colors come from `civilytics_colors`; never write a hex literal in theme, scale, logo, or table code.
- No tidyverse dependency. Imports is base R plus ggplot2, grid/gridExtra, png/jpeg, stringr, stringdist, showtext/sysfonts, jsonlite. Reject dplyr, purrr, magrittr, tibble, and data.table; use base R idioms. - No tidyverse dependency. Imports is base R plus ggplot2, grid/gridExtra, png/jpeg, stringr, stringdist, showtext/sysfonts, jsonlite. Reject dplyr, purrr, magrittr, tibble, and data.table; use base R idioms.
- NAMESPACE is roxygen-generated. Declare imports with `@importFrom` in the roxygen block and re-run roxygen; never hand-edit NAMESPACE. - NAMESPACE is roxygen-generated. Declare imports with `@importFrom` in the roxygen block and re-run roxygen; never hand-edit NAMESPACE.
- Themes default to a transparent background (`paper_bg = FALSE`) so plots composite onto any Quarto, Reveal, or Typst background. Making an opaque background the default is a regression, not a preference. - Themes default to a transparent background (`paper_bg = FALSE`) so plots composite onto any Quarto, Reveal, or Typst background. Making an opaque background the default is a regression, not a preference.
+2 -3
View File
@@ -47,8 +47,7 @@ tibble, or data.table. Prefer an existing dependency or base R over adding one
this package is installed into other people's environments. this package is installed into other people's environments.
**Brand colors** live in `civilytics_colors` and nowhere else. Never write a hex **Brand colors** live in `civilytics_colors` and nowhere else. Never write a hex
literal in theme, scale, logo, or table code. (`R/flextable.R` still carries literal in theme, scale, logo, or table code.
off-brand Bootstrap defaults; that is known debt, not a pattern to copy.)
**Themes** default to a transparent background (`paper_bg = FALSE`) so plots **Themes** default to a transparent background (`paper_bg = FALSE`) so plots
composite onto any Quarto, Reveal, or Typst background. Thread `ink`, `paper`, and composite onto any Quarto, Reveal, or Typst background. Thread `ink`, `paper`, and
@@ -84,7 +83,7 @@ Rscript -e 'devtools::test()'
``` ```
CI runs `R CMD check` on `rocker/r-ver:4.6` via `.gitea/workflows/check.yaml` for CI runs `R CMD check` on `rocker/r-ver:4.6` via `.gitea/workflows/check.yaml` for
every push and PR to `master`. every push and PR to `main`.
## Release ## Release
+1
View File
@@ -0,0 +1 @@
@AGENTS.md
+4 -2
View File
@@ -1,7 +1,7 @@
Package: civilytics Package: civilytics
Type: Package Type: Package
Title: Brand Themes, Color Palettes, and Utility Functions for Civilytics Title: Brand Themes, Color Palettes, and Utility Functions for Civilytics
Version: 0.3.1 Version: 0.3.2
Authors@R: Authors@R:
person("Jared", "E. Knowles", email = "jared@civilytics.com", person("Jared", "E. Knowles", email = "jared@civilytics.com",
role = c("aut", "cre")) role = c("aut", "cre"))
@@ -34,7 +34,9 @@ Suggests:
quarto, quarto,
flextable, flextable,
officer, officer,
ragg patchwork,
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
+30
View File
@@ -1,11 +1,41 @@
# civilytics 0.3.2 # civilytics 0.3.2
## New features ## New features
- `civilytics_logo()` and `add_logo()` gain `logo_height` (inches, default `0.5`),
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
passed to `civilytics_logo()`.
- Added comprehensive test coverage for the `prop_conf` module, including - Added comprehensive test coverage for the `prop_conf` module, including
correctness checks against `binom.test()` for Clopper-Pearson intervals and correctness checks against `binom.test()` for Clopper-Pearson intervals and
formula-based verification for Wald and Agresti-Coull intervals. formula-based verification for Wald and Agresti-Coull intervals.
## Bug fixes ## Bug fixes
- `civilytics_logo()` / `add_logo()` now render every panel and the
`plot_annotation()` of a patchwork composition. They previously drew only the
last panel (#20).
- 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
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
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).
- `font_scale` now defaults to `1` in `civilytics_logo()`, `add_logo()` and
`add_logo_ga()`. The old default of `1.1` enlarged the base text by 10% whenever
a logo was added. Pass `font_scale = 1.1` to keep the old sizes (#20).
- `style_flextable_civilytics()` defaults now come from `civilytics_colors`
instead of Bootstrap hex values: header `navy_700`, zebra `paper_2`, outer
border `rule_strong`, inner border `rule`, footer text `ink_3`. Tables built
with the defaults change appearance (#21).
- `civilytics-reveal`: PDF output keeps slide margins, ordered-list numbers no
longer clip at the left edge, and Quarto column widths (`.column width="60%"`)
are honored. Columns without a width stay equal, and the default gap is now
`1.5em` (#25, #26, #27).
- Removed vendored headshot images (`Knowles_Headshot_2019_good.jpg`, - Removed vendored headshot images (`Knowles_Headshot_2019_good.jpg`,
`Knowles_Headshot_2019_prisma.jpg`) from `inst/img/` to prevent personal `Knowles_Headshot_2019_prisma.jpg`) from `inst/img/` to prevent personal
photos from being distributed with the package. The `plot_jpeg()` example photos from being distributed with the package. The `plot_jpeg()` example
+12 -10
View File
@@ -15,7 +15,8 @@
#' `flextable` is unavailable. #' `flextable` is unavailable.
#' #'
#' @param ft A [flextable::flextable()] object. #' @param ft A [flextable::flextable()] object.
#' @param header_bg Character. Header background fill. Default `"#2c3e50"`. #' @param header_bg Character. Header background fill. Default
#' `civilytics_colors[["navy_700"]]`.
#' @param header_color Character. Header text color. Default `"white"`. #' @param header_color Character. Header text color. Default `"white"`.
#' @param title_fontsize Numeric. Font size for the first header line (the #' @param title_fontsize Numeric. Font size for the first header line (the
#' title row, `i = 1`). Default `14`. #' title row, `i = 1`). Default `14`.
@@ -25,17 +26,18 @@
#' @param zebra Logical. Apply alternating-row striping to even body rows. #' @param zebra Logical. Apply alternating-row striping to even body rows.
#' Default `TRUE`. Safely skipped for tables with fewer than two body rows. #' Default `TRUE`. Safely skipped for tables with fewer than two body rows.
#' @param zebra_bg Character. Fill color for striped (even) body rows. #' @param zebra_bg Character. Fill color for striped (even) body rows.
#' Default `"#f0f0eb"`. #' Default `civilytics_colors[["paper_2"]]`.
#' @param outer_border_color Character. Outer border color. Default #' @param outer_border_color Character. Outer border color. Default
#' `"#888888"`. #' `civilytics_colors[["rule_strong"]]`.
#' @param outer_border_width Numeric. Outer border width. Default `1`. #' @param outer_border_width Numeric. Outer border width. Default `1`.
#' @param inner_border_color Character. Inner horizontal border color (body). #' @param inner_border_color Character. Inner horizontal border color (body).
#' Default `"#cccccc"`. #' Default `civilytics_colors[["rule"]]`.
#' @param inner_border_width Numeric. Inner horizontal border width. Default #' @param inner_border_width Numeric. Inner horizontal border width. Default
#' `0.5`. #' `0.5`.
#' @param footer_fontsize Numeric. Footer font size (applied only if a footer #' @param footer_fontsize Numeric. Footer font size (applied only if a footer
#' part exists). Default `9`. #' part exists). Default `9`.
#' @param footer_color Character. Footer text color. Default `"#555555"`. #' @param footer_color Character. Footer text color. Default
#' `civilytics_colors[["ink_3"]]`.
#' #'
#' @return The styled [flextable::flextable()] object. #' @return The styled [flextable::flextable()] object.
#' @export #' @export
@@ -50,19 +52,19 @@
#' style_flextable_civilytics() #' style_flextable_civilytics()
#' } #' }
style_flextable_civilytics <- function(ft, style_flextable_civilytics <- function(ft,
header_bg = "#2c3e50", header_bg = civilytics_colors[["navy_700"]],
header_color = "white", header_color = "white",
title_fontsize = 14, title_fontsize = 14,
body_fontsize = 11, body_fontsize = 11,
font_name = "Arial", font_name = "Arial",
zebra = TRUE, zebra = TRUE,
zebra_bg = "#f0f0eb", zebra_bg = civilytics_colors[["paper_2"]],
outer_border_color = "#888888", outer_border_color = civilytics_colors[["rule_strong"]],
outer_border_width = 1, outer_border_width = 1,
inner_border_color = "#cccccc", inner_border_color = civilytics_colors[["rule"]],
inner_border_width = 0.5, inner_border_width = 0.5,
footer_fontsize = 9, footer_fontsize = 9,
footer_color = "#555555") { footer_color = civilytics_colors[["ink_3"]]) {
if (!requireNamespace("flextable", quietly = TRUE)) { if (!requireNamespace("flextable", quietly = TRUE)) {
stop("Install 'flextable' to use this function.", call. = FALSE) stop("Install 'flextable' to use this function.", call. = FALSE)
} }
+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)
+71 -65
View File
@@ -44,65 +44,67 @@ get_png <- function(filename) {
#' Add a logo to a ggplot2 object #' Add a logo to a ggplot2 object
#' #'
#' @param plot a ggplot2 grob #' The logo gets its own band of reserved height (`logo_height`, in inches)
#' below or above the plot, so it cannot overlap the plot's caption or push
#' anything off the canvas. Patchwork compositions are converted with
#' [patchwork::patchworkGrob()] so every panel and the
#' [patchwork::plot_annotation()] survive.
#'
#' @param plot a ggplot2 object, or a patchwork composition
#' @param logo a logo grob created by make_logo_grob() #' @param logo a logo grob created by make_logo_grob()
#' @param margin_param a numeric specifying what margin to add or subtract to align the logo #' @param margin_param Optional numeric. Replaces the plot margin (in points)
#' @param font_scale Numeric. Multiplicative scaling factor applied to text #' on the side next to the logo. `NULL` (default) leaves the plot's margins
#' sizes before composing the plot with the logo. Default `1.1` inflates #' alone.
#' text by ~10 \% to compensate for the viewport shrinkage caused by #' @param font_scale Numeric. Multiplicative scaling factor applied to the
#' [gridExtra::arrangeGrob()]. Set to `1` to disable. #' base text size before composing. Default `1` leaves typography unchanged.
#' @param position Character. Corner placement for the logo: `"bottom-right"` #' @param position Character. Corner placement for the logo: `"bottom-right"`
#' (default), `"bottom-left"`, `"top-right"`, or `"top-left"`. Controls #' (default), `"bottom-left"`, `"top-right"`, or `"top-left"`. Controls
#' whether the logo is placed above or below the plot. #' whether the logo is placed above or below the plot.
#' @param logo_height Numeric. Height in inches of the band reserved for the
#' logo. Default `0.5`.
#' #'
#' @return a grob with a logo attached to it ready to plot #' @return a grob with a logo attached to it ready to plot
#' @importFrom ggplot2 theme #' @importFrom ggplot2 theme
#' @importFrom gridExtra arrangeGrob #' @importFrom gridExtra arrangeGrob
#' @export #' @export
add_logo <- function(plot, logo, margin_param = NULL, font_scale = 1.1, add_logo <- function(plot, logo, margin_param = NULL, font_scale = 1,
position = c("bottom-right", "bottom-left", position = c("bottom-right", "bottom-left",
"top-right", "top-left")) { "top-right", "top-left"),
logo_height = 0.5) {
position <- match.arg(position) position <- match.arg(position)
at_top <- grepl("top", position) at_top <- grepl("top", position)
is_patchwork <- inherits(plot, "patchwork")
# Capture the plot's background color so we can fill the entire composed # Capture the plot's background color so we can fill the entire composed
# grob with it. The logo grob must stay transparent (theme_void) so that # grob with it. The logo grob stays transparent (theme_void).
# caption/axis text overlapping via negative margins remains visible.
bg_fill <- plot$theme$plot.background$fill bg_fill <- plot$theme$plot.background$fill
# Inflate text sizes to compensate for arrangeGrob viewport shrinkage.
# All theme text elements use rel() sizing, so scaling the root 'text'
# element cascades to titles, axis labels, legends, captions, and strips.
if (!is.null(font_scale) && font_scale != 1) { if (!is.null(font_scale) && font_scale != 1) {
base_size <- plot$theme$text$size %||% 14 base_size <- plot$theme$text$size
plot <- plot + theme( if (is.null(base_size)) base_size <- 14
text = element_text(size = base_size * font_scale) scaled <- theme(text = ggplot2::element_text(size = base_size * font_scale))
) plot <- if (is_patchwork) plot & scaled else plot + scaled
} }
if (at_top) {
# For top placement, tighten the top margin of the plot
if (!is.null(margin_param)) { if (!is.null(margin_param)) {
plot <- plot + theme(plot.margin = unit(c(margin_param, 7, 7, 7), "pt")) side <- if (at_top) c(margin_param, 7, 7, 7) else c(7, 7, margin_param, 7)
} else { margin <- theme(plot.margin = grid::unit(side, "pt"))
plot <- plot + theme(plot.margin = unit(c(-14, 7, 7, 7), "pt")) plot <- if (is_patchwork) plot & margin else plot + margin
} }
composed <- arrangeGrob(logo, plot, heights = c(0.1, 0.93),
padding = unit(0.1, "line")) # ggplot_build() on a patchwork builds only its last panel, so convert it
# explicitly before handing it to arrangeGrob().
plot_grob <- if (is_patchwork) patchwork::patchworkGrob(plot) else plot
plot_height <- grid::unit(1, "null")
band_height <- grid::unit(logo_height, "in")
composed <- if (at_top) {
arrangeGrob(logo, plot_grob, heights = grid::unit.c(band_height, plot_height),
padding = grid::unit(0.1, "line"))
} else { } else {
# Bottom placement (original behaviour) arrangeGrob(plot_grob, logo,
if(has_caption(plot)) { heights = grid::unit.c(plot_height, band_height),
cap_lines <- measure_caption(plot) padding = grid::unit(0.1, "line"))
if (!is.null(margin_param)) {
plot <- plot + theme(plot.margin = unit(c(7, 7, margin_param, 7), "pt"))
} else {
plot <- plot + theme(plot.margin = unit(c(7, 7, cap_lines * -52, 7), "pt"))
}
} else {
plot <- plot + theme(plot.margin = unit(c(7, 7, -14, 7), "pt"))
}
composed <- arrangeGrob(plot, logo, heights = c(0.93, 0.1),
padding = unit(0.1, "line"))
} }
# Wrap with a full-bleed background rect so any transparent areas (the # Wrap with a full-bleed background rect so any transparent areas (the
@@ -158,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.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()
@@ -179,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.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
@@ -193,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`")
@@ -216,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))
@@ -268,20 +272,20 @@ make_logo_grob <- function(type = c("wordmark", "mark"),
align_left <- grepl("left", position) align_left <- grepl("left", position)
if (align_left) { # Give the raster a height only, so grid derives its width from the image's
xmin <- 0 # own aspect ratio, then pin it to the corner. The logo is the same shape on
xmax <- if (type == "mark") 0.07 else 0.35 # any canvas width.
} else { logo <- grid::rasterGrob(
xmin <- if (type == "mark") 0.93 else 0.65 png::readPNG(system.file("img", img_file, package = "civilytics")),
xmax <- 1 x = if (align_left) grid::unit(7, "pt") else grid::unit(1, "npc") - grid::unit(7, "pt"),
} just = if (align_left) "left" else "right",
height = grid::unit(1, "npc"),
interpolate = TRUE
)
ggplot() + ggplot() +
theme_void() + theme_void() +
annotation_custom( annotation_custom(logo, xmin = -Inf, xmax = Inf, ymin = -Inf, ymax = Inf)
get_png(system.file("img", img_file, package = "civilytics")),
xmin = xmin, xmax = xmax
)
} }
#' Add a Civilytics logo to a ggplot (pipe-friendly) #' Add a Civilytics logo to a ggplot (pipe-friendly)
@@ -308,9 +312,10 @@ make_logo_grob <- function(type = c("wordmark", "mark"),
#' (default), `"bottom-left"`, `"top-right"`, or `"top-left"`. #' (default), `"bottom-left"`, `"top-right"`, or `"top-left"`.
#' @param margin_param Numeric or `NULL`. Manual margin adjustment passed to #' @param margin_param Numeric or `NULL`. Manual margin adjustment passed to
#' [add_logo()]. #' [add_logo()].
#' @param font_scale Numeric. Inflate text sizes by this factor to compensate #' @param font_scale Numeric. Multiplies the plot's base text size before
#' for viewport shrinkage when composing with [gridExtra::arrangeGrob()]. #' composing. Default `1` leaves typography unchanged.
#' Default `1.1` (~10 \% inflation). Set to `1` to disable. #' @param logo_height Numeric. Height in inches of the band reserved for the
#' logo. Default `0.5`.
#' #'
#' @return A grob (from [gridExtra::arrangeGrob()]) ready to draw with #' @return A grob (from [gridExtra::arrangeGrob()]) ready to draw with
#' [grid::grid.draw()]. #' [grid::grid.draw()].
@@ -355,11 +360,12 @@ civilytics_logo <- function(plot,
position = c("bottom-right", "bottom-left", position = c("bottom-right", "bottom-left",
"top-right", "top-left"), "top-right", "top-left"),
margin_param = NULL, margin_param = NULL,
font_scale = 1.1) { font_scale = 1,
logo_height = 0.5) {
position <- match.arg(position) position <- match.arg(position)
logo <- make_logo_grob(type = type, variant = variant, position = position) logo <- make_logo_grob(type = type, variant = variant, position = position)
add_logo(plot, logo, margin_param = margin_param, font_scale = font_scale, add_logo(plot, logo, margin_param = margin_param, font_scale = font_scale,
position = position) position = position, logo_height = logo_height)
} }
@@ -209,7 +209,11 @@ $code-color: #923D00 !default;
height: 2px; height: 2px;
background: var(--accent-600); background: var(--accent-600);
} }
.reveal ol { list-style: decimal; } .reveal ol {
list-style: decimal;
/* Room for two-digit markers in the bold mono face (#27) */
padding-left: 1.6em;
}
.reveal ol > li::marker { .reveal ol > li::marker {
color: var(--accent-600); color: var(--accent-600);
font-family: var(--font-mono); font-family: var(--font-mono);
@@ -747,7 +751,7 @@ img.civilytics-wordmark,
----------------------------------------------------------- */ ----------------------------------------------------------- */
.reveal .columns { .reveal .columns {
display: flex; display: flex;
gap: 3em; gap: 1.5em;
align-items: flex-start; align-items: flex-start;
margin: 0.25em 0; margin: 0.25em 0;
} }
@@ -755,6 +759,11 @@ img.civilytics-wordmark,
flex: 1; flex: 1;
min-width: 0; min-width: 0;
} }
/* Quarto writes width="60%" as an inline style; honor it (#26). Columns
without a width stay equal. */
.reveal .column[style*="width"] {
flex: 0 1 auto;
}
.reveal .column > :first-child { margin-top: 0; } .reveal .column > :first-child { margin-top: 0; }
/* Hand-rolled two-col for pandoc (non-Quarto) users */ /* Hand-rolled two-col for pandoc (non-Quarto) users */
@@ -1040,6 +1049,15 @@ body.civilytics-hide-chrome .slide-number {
.reveal section { break-inside: avoid; } .reveal section { break-inside: avoid; }
} }
/* reveal.js print-pdf zeroes section padding with !important, so the screen
padding is lost. Restore a smaller print value; 48px 72px pushed dense
slides onto extra pages (#25). */
html.print-pdf .reveal .slides section:not(.full-bleed):not(.stack),
html.reveal-print .reveal .slides section:not(.full-bleed):not(.stack) {
padding: 32px 56px !important;
box-sizing: border-box !important;
}
/* ----------------------------------------------------------- /* -----------------------------------------------------------
SMALL-SCREEN GUARDRAILS SMALL-SCREEN GUARDRAILS
Reveal scales slides, but the narrowest keep-legible margins. Reveal scales slides, but the narrowest keep-legible margins.
+17 -9
View File
@@ -8,29 +8,37 @@ add_logo(
plot, plot,
logo, logo,
margin_param = NULL, margin_param = NULL,
font_scale = 1.1, font_scale = 1,
position = c("bottom-right", "bottom-left", "top-right", "top-left") position = c("bottom-right", "bottom-left", "top-right", "top-left"),
logo_height = 0.5
) )
} }
\arguments{ \arguments{
\item{plot}{a ggplot2 grob} \item{plot}{a ggplot2 object, or a patchwork composition}
\item{logo}{a logo grob created by make_logo_grob()} \item{logo}{a logo grob created by make_logo_grob()}
\item{margin_param}{a numeric specifying what margin to add or subtract to align the logo} \item{margin_param}{Optional numeric. Replaces the plot margin (in points)
on the side next to the logo. `NULL` (default) leaves the plot's margins
alone.}
\item{font_scale}{Numeric. Multiplicative scaling factor applied to text \item{font_scale}{Numeric. Multiplicative scaling factor applied to the
sizes before composing the plot with the logo. Default `1.1` inflates base text size before composing. Default `1` leaves typography unchanged.}
text by ~10 \% to compensate for the viewport shrinkage caused by
[gridExtra::arrangeGrob()]. Set to `1` to disable.}
\item{position}{Character. Corner placement for the logo: `"bottom-right"` \item{position}{Character. Corner placement for the logo: `"bottom-right"`
(default), `"bottom-left"`, `"top-right"`, or `"top-left"`. Controls (default), `"bottom-left"`, `"top-right"`, or `"top-left"`. Controls
whether the logo is placed above or below the plot.} whether the logo is placed above or below the plot.}
\item{logo_height}{Numeric. Height in inches of the band reserved for the
logo. Default `0.5`.}
} }
\value{ \value{
a grob with a logo attached to it ready to plot a grob with a logo attached to it ready to plot
} }
\description{ \description{
Add a logo to a ggplot2 object The logo gets its own band of reserved height (`logo_height`, in inches)
below or above the plot, so it cannot overlap the plot's caption or push
anything off the canvas. Patchwork compositions are converted with
[patchwork::patchworkGrob()] so every panel and the
[patchwork::plot_annotation()] survive.
} }
+8 -3
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.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.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)
} }
} }
+7 -4
View File
@@ -10,7 +10,8 @@ civilytics_logo(
variant = c("light", "dark"), variant = c("light", "dark"),
position = c("bottom-right", "bottom-left", "top-right", "top-left"), position = c("bottom-right", "bottom-left", "top-right", "top-left"),
margin_param = NULL, margin_param = NULL,
font_scale = 1.1 font_scale = 1,
logo_height = 0.5
) )
} }
\arguments{ \arguments{
@@ -28,9 +29,11 @@ civilytics_logo(
\item{margin_param}{Numeric or `NULL`. Manual margin adjustment passed to \item{margin_param}{Numeric or `NULL`. Manual margin adjustment passed to
[add_logo()].} [add_logo()].}
\item{font_scale}{Numeric. Inflate text sizes by this factor to compensate \item{font_scale}{Numeric. Multiplies the plot's base text size before
for viewport shrinkage when composing with [gridExtra::arrangeGrob()]. composing. Default `1` leaves typography unchanged.}
Default `1.1` (~10 \% inflation). Set to `1` to disable.}
\item{logo_height}{Numeric. Height in inches of the band reserved for the
logo. Default `0.5`.}
} }
\value{ \value{
A grob (from [gridExtra::arrangeGrob()]) ready to draw with A grob (from [gridExtra::arrangeGrob()]) ready to draw with
+12 -10
View File
@@ -6,25 +6,26 @@
\usage{ \usage{
style_flextable_civilytics( style_flextable_civilytics(
ft, ft,
header_bg = "#2c3e50", header_bg = civilytics_colors[["navy_700"]],
header_color = "white", header_color = "white",
title_fontsize = 14, title_fontsize = 14,
body_fontsize = 11, body_fontsize = 11,
font_name = "Arial", font_name = "Arial",
zebra = TRUE, zebra = TRUE,
zebra_bg = "#f0f0eb", zebra_bg = civilytics_colors[["paper_2"]],
outer_border_color = "#888888", outer_border_color = civilytics_colors[["rule_strong"]],
outer_border_width = 1, outer_border_width = 1,
inner_border_color = "#cccccc", inner_border_color = civilytics_colors[["rule"]],
inner_border_width = 0.5, inner_border_width = 0.5,
footer_fontsize = 9, footer_fontsize = 9,
footer_color = "#555555" footer_color = civilytics_colors[["ink_3"]]
) )
} }
\arguments{ \arguments{
\item{ft}{A [flextable::flextable()] object.} \item{ft}{A [flextable::flextable()] object.}
\item{header_bg}{Character. Header background fill. Default `"#2c3e50"`.} \item{header_bg}{Character. Header background fill. Default
`civilytics_colors[["navy_700"]]`.}
\item{header_color}{Character. Header text color. Default `"white"`.} \item{header_color}{Character. Header text color. Default `"white"`.}
@@ -40,15 +41,15 @@ title row, `i = 1`). Default `14`.}
Default `TRUE`. Safely skipped for tables with fewer than two body rows.} Default `TRUE`. Safely skipped for tables with fewer than two body rows.}
\item{zebra_bg}{Character. Fill color for striped (even) body rows. \item{zebra_bg}{Character. Fill color for striped (even) body rows.
Default `"#f0f0eb"`.} Default `civilytics_colors[["paper_2"]]`.}
\item{outer_border_color}{Character. Outer border color. Default \item{outer_border_color}{Character. Outer border color. Default
`"#888888"`.} `civilytics_colors[["rule_strong"]]`.}
\item{outer_border_width}{Numeric. Outer border width. Default `1`.} \item{outer_border_width}{Numeric. Outer border width. Default `1`.}
\item{inner_border_color}{Character. Inner horizontal border color (body). \item{inner_border_color}{Character. Inner horizontal border color (body).
Default `"#cccccc"`.} Default `civilytics_colors[["rule"]]`.}
\item{inner_border_width}{Numeric. Inner horizontal border width. Default \item{inner_border_width}{Numeric. Inner horizontal border width. Default
`0.5`.} `0.5`.}
@@ -56,7 +57,8 @@ Default `"#cccccc"`.}
\item{footer_fontsize}{Numeric. Footer font size (applied only if a footer \item{footer_fontsize}{Numeric. Footer font size (applied only if a footer
part exists). Default `9`.} part exists). Default `9`.}
\item{footer_color}{Character. Footer text color. Default `"#555555"`.} \item{footer_color}{Character. Footer text color. Default
`civilytics_colors[["ink_3"]]`.}
} }
\value{ \value{
The styled [flextable::flextable()] object. The styled [flextable::flextable()] object.
+12
View File
@@ -13,6 +13,18 @@ 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
**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.
**Obligates:** PDF check of #25/#27 in another project (never rendered here)
**Refs:** #20, #21, #22, #24, #25, #26, #27, 4f697e2, d6e3ba2, 0561df4, dfcad3d
## 2026-08-24 · packaging · roborev exclusion patterns fixed; init review triaged ## 2026-08-24 · packaging · roborev exclusion patterns fixed; init review triaged
**Why:** roborev reviewed the init commit because `excluded_commit_patterns` are **Why:** roborev reviewed the init commit because `excluded_commit_patterns` are
+9 -33
View File
@@ -7,58 +7,34 @@
## Where this stands ## Where this stands
`civilytics` is the house R package behind every Civilytics chart, table, and report — 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.
ggplot2 themes, brand palettes, logo composition, and Quarto templates, plus the
data-wrangling helpers the analysis work leans on. It is at version 0.3.1 and already
depended on by live projects, so changes here surface in reports that are published.
Project tracking went in on 23 August. Five workstreams divide the package by how it
actually goes stale rather than by directory: themes and palettes, logo and branded
output, Quarto templates, analysis helpers, and packaging. Documentation debt is caught
automatically — if code moves and its roxygen pages do not, an issue gets filed.
Automated review is now working correctly. The first review ran on a config-only commit,
which turned out to be the useful part: the exclusion patterns match plain text, so
`chore:` never matched the `chore(packaging):` form this project's own commit convention
requires. Both forms are now listed, and `pm/compass.toml` is named as the one place
review rules are edited.
Three things are open, none blocked. A logo defect (#20) drops patchwork panels and clips
captions, which is the one that bites users. The flextable styling helper (#21) ships
Bootstrap's palette as its default instead of the brand's, so tables built with the
defaults are quietly off-brand. The third (#22) is forge housekeeping: the `kodor/*`
labels are defined twice, at repo and org scope, which makes filtering by name unreliable.
The next substantive work is #20.
## 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._
- **#21** style_flextable_civilytics() defaults to Bootstrap colors, not Civilytics brand · `ws/logo` — nothing is blocking it; owed work from an earlier change
- **#22** kodor/* labels are defined at both repo and org scope · `ws/packaging` — nothing is blocking it
## 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 | 0 | 2 | 1 | no | | Logo and branded output composition | 1 | 0 | 0 | no |
| Quarto themes and publishing templates | 0 | 0 | 0 | no | | 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 | 1 | 1 | 0 | **yes** | | 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: `496b9ed9` (2026-08-23) - Marker: `c16e6cec` (2026-10-15)
- Commits since: 1 - Commits since: 4
- Open issues: 3 - Open issues: 0
</details> </details>
+1 -1
View File
@@ -95,7 +95,7 @@ docs = [
[roborev] [roborev]
project_guidelines = [ project_guidelines = [
"Brand colors come from `civilytics_colors`; never write a hex literal in theme, scale, logo, or table code. `R/flextable.R` still carries off-brand Bootstrap defaults (#2c3e50, #f0f0eb, #888888, #cccccc, #555555) -- do not add more.", "Brand colors come from `civilytics_colors`; never write a hex literal in theme, scale, logo, or table code.",
"No tidyverse dependency. Imports is base R plus ggplot2, grid/gridExtra, png/jpeg, stringr, stringdist, showtext/sysfonts, jsonlite. Reject dplyr, purrr, magrittr, tibble, and data.table; use base R idioms.", "No tidyverse dependency. Imports is base R plus ggplot2, grid/gridExtra, png/jpeg, stringr, stringdist, showtext/sysfonts, jsonlite. Reject dplyr, purrr, magrittr, tibble, and data.table; use base R idioms.",
"NAMESPACE is roxygen-generated. Declare imports with `@importFrom` in the roxygen block and re-run roxygen; never hand-edit NAMESPACE.", "NAMESPACE is roxygen-generated. Declare imports with `@importFrom` in the roxygen block and re-run roxygen; never hand-edit NAMESPACE.",
"Themes default to a transparent background (`paper_bg = FALSE`) so plots composite onto any Quarto, Reveal, or Typst background. Making an opaque background the default is a regression, not a preference.", "Themes default to a transparent background (`paper_bg = FALSE`) so plots composite onto any Quarto, Reveal, or Typst background. Making an opaque background the default is a regression, not a preference.",
+18
View File
@@ -87,3 +87,21 @@ test_that("extra_height increases the exported PNG height", {
expect_gt(dim(png::readPNG(path_big))[1], dim(png::readPNG(path_small))[1]) expect_gt(dim(png::readPNG(path_big))[1], dim(png::readPNG(path_small))[1])
}) })
test_that("style_flextable_civilytics defaults come from civilytics_colors (#21)", {
defaults <- formals(style_flextable_civilytics)
expect_identical(eval(defaults$header_bg), civilytics_colors[["navy_700"]])
expect_identical(eval(defaults$zebra_bg), civilytics_colors[["paper_2"]])
expect_identical(eval(defaults$outer_border_color), civilytics_colors[["rule_strong"]])
expect_identical(eval(defaults$inner_border_color), civilytics_colors[["rule"]])
expect_identical(eval(defaults$footer_color), civilytics_colors[["ink_3"]])
})
test_that("style_flextable_civilytics paints the header with brand navy", {
skip_if_not_installed("flextable")
skip_if_not_installed("officer")
styled <- style_flextable_civilytics(flextable::flextable(head(mtcars, 3)))
header_fill <- unique(as.vector(styled$header$styles$cells$background.color$data))
expect_identical(toupper(header_fill), toupper(civilytics_colors[["navy_700"]]))
})
+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")
})
+108
View File
@@ -28,3 +28,111 @@ test_that("stamp_logo_png validates its inputs", {
# invalid type is rejected by match.arg() before the file is touched # invalid type is rejected by match.arg() before the file is touched
expect_error(stamp_logo_png(tempfile(fileext = ".png"), type = "banner")) expect_error(stamp_logo_png(tempfile(fileext = ".png"), type = "banner"))
}) })
# --- civilytics_logo() layout (#20) ------------------------------------------
caption_plot <- function() {
ggplot2::ggplot(mtcars, ggplot2::aes(mpg, wt)) +
ggplot2::geom_point() +
ggplot2::labs(title = "Title",
caption = "Source: a reasonably long attribution line, 2021-22\nSecond line") +
theme_civilytics()
}
# The composed grob is a gtable, wrapped in a grobTree when the plot has a
# background fill.
composed_table <- function(composed) {
if (inherits(composed, "gtable")) composed else composed$children[[2]]
}
bottom_ink <- function(grob, width, height, rows = 2) {
path <- tempfile(fileext = ".png")
grDevices::png(path, width = width, height = height, units = "in", res = 100)
grid::grid.newpage()
grid::grid.draw(grob)
grDevices::dev.off()
img <- png::readPNG(path)
n <- dim(img)[1]
edge <- img[(n - rows + 1):n, , 1:3, drop = FALSE]
sum(edge < 0.5)
}
test_that("font_scale defaults to 1 everywhere", {
expect_identical(formals(add_logo)$font_scale, 1)
expect_identical(formals(add_logo_ga)$font_scale, 1)
expect_identical(formals(civilytics_logo)$font_scale, 1)
})
test_that("the logo band is reserved space that sums to the canvas", {
p <- caption_plot()
for (pos in c("bottom-right", "top-left")) {
composed <- suppressWarnings(civilytics_logo(p, position = pos, 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("a caption is not clipped at the bottom edge at several canvas sizes", {
skip_on_cran()
p <- caption_plot()
for (w in c(8, 11, 16, 24)) {
h <- w * 0.64
ink <- bottom_ink(suppressWarnings(civilytics_logo(p, position = "top-right")), w, h)
expect_equal(ink, 0, info = paste("width", w))
}
})
test_that("patchwork compositions keep every panel", {
skip_if_not_installed("patchwork")
p1 <- ggplot2::ggplot(mtcars, ggplot2::aes(mpg, wt)) + ggplot2::geom_point()
p2 <- ggplot2::ggplot(mtcars, ggplot2::aes(hp, wt)) + ggplot2::geom_point()
pw <- p1 + p2 + patchwork::plot_annotation(title = "Both panels")
composed <- suppressWarnings(civilytics_logo(pw))
panel_grob <- composed_table(composed)$grobs[[1]]
n_panels <- sum(grepl("^panel", panel_grob$layout$name))
expect_gte(n_panels, 2)
})
test_that("the logo keeps its aspect ratio at any canvas width (#20)", {
skip_if_not_installed("ragg")
ink_aspect <- function(width, type) {
path <- tempfile(fileext = ".png")
ragg::agg_png(path, width = width, height = 0.5, units = "in", res = 200,
background = "transparent")
grid::grid.draw(ggplot2::ggplotGrob(make_logo_grob(type = type)))
grDevices::dev.off()
ink <- which(png::readPNG(path)[, , 4] > 0.05, arr.ind = TRUE)
diff(range(ink[, 2])) / diff(range(ink[, 1]))
}
for (type in c("wordmark", "mark")) {
aspects <- vapply(c(6, 11, 24), ink_aspect, numeric(1), type = 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))
}
}
})