7 Commits
Author SHA1 Message Date
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
17 changed files with 279 additions and 132 deletions

No files matched your search

+2 -2
View File
@@ -2,9 +2,9 @@ name: R-CMD-check
on:
push:
branches: [master]
branches: [main]
pull_request:
branches: [master]
branches: [main]
jobs:
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
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.
- 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.
- 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.
+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.
**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
off-brand Bootstrap defaults; that is known debt, not a pattern to copy.)
literal in theme, scale, logo, or table code.
**Themes** default to a transparent background (`paper_bg = FALSE`) so plots
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
every push and PR to `master`.
every push and PR to `main`.
## Release
+2 -1
View File
@@ -1,7 +1,7 @@
Package: civilytics
Type: Package
Title: Brand Themes, Color Palettes, and Utility Functions for Civilytics
Version: 0.3.1
Version: 0.3.2
Authors@R:
person("Jared", "E. Knowles", email = "jared@civilytics.com",
role = c("aut", "cre"))
@@ -34,6 +34,7 @@ Suggests:
quarto,
flextable,
officer,
patchwork,
ragg
Config/testthat/edition: 3
Config/roxygen2/version: 8.0.0
+24
View File
@@ -1,11 +1,35 @@
# civilytics 0.3.2
## New features
- `civilytics_logo()` and `add_logo()` gain `logo_height` (inches, default `0.5`),
the height of a band reserved for the logo.
- `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
correctness checks against `binom.test()` for Clopper-Pearson intervals and
formula-based verification for Wald and Agresti-Coull intervals.
## 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).
- 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`,
`Knowles_Headshot_2019_prisma.jpg`) from `inst/img/` to prevent personal
photos from being distributed with the package. The `plot_jpeg()` example
+12 -10
View File
@@ -15,7 +15,8 @@
#' `flextable` is unavailable.
#'
#' @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 title_fontsize Numeric. Font size for the first header line (the
#' title row, `i = 1`). Default `14`.
@@ -25,17 +26,18 @@
#' @param zebra Logical. Apply alternating-row striping to even 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.
#' Default `"#f0f0eb"`.
#' Default `civilytics_colors[["paper_2"]]`.
#' @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 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
#' `0.5`.
#' @param footer_fontsize Numeric. Footer font size (applied only if a footer
#' 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.
#' @export
@@ -50,19 +52,19 @@
#' style_flextable_civilytics()
#' }
style_flextable_civilytics <- function(ft,
header_bg = "#2c3e50",
header_bg = civilytics_colors[["navy_700"]],
header_color = "white",
title_fontsize = 14,
body_fontsize = 11,
font_name = "Arial",
zebra = TRUE,
zebra_bg = "#f0f0eb",
outer_border_color = "#888888",
zebra_bg = civilytics_colors[["paper_2"]],
outer_border_color = civilytics_colors[["rule_strong"]],
outer_border_width = 1,
inner_border_color = "#cccccc",
inner_border_color = civilytics_colors[["rule"]],
inner_border_width = 0.5,
footer_fontsize = 9,
footer_color = "#555555") {
footer_color = civilytics_colors[["ink_3"]]) {
if (!requireNamespace("flextable", quietly = TRUE)) {
stop("Install 'flextable' to use this function.", call. = FALSE)
}
+61 -57
View File
@@ -44,65 +44,67 @@ get_png <- function(filename) {
#' 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 margin_param a numeric specifying what margin to add or subtract to align the logo
#' @param font_scale Numeric. Multiplicative scaling factor applied to text
#' sizes before composing the plot with the logo. Default `1.1` inflates
#' text by ~10 \% to compensate for the viewport shrinkage caused by
#' [gridExtra::arrangeGrob()]. Set to `1` to disable.
#' @param 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.
#' @param font_scale Numeric. Multiplicative scaling factor applied to the
#' base text size before composing. Default `1` leaves typography unchanged.
#' @param position Character. Corner placement for the logo: `"bottom-right"`
#' (default), `"bottom-left"`, `"top-right"`, or `"top-left"`. Controls
#' 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
#' @importFrom ggplot2 theme
#' @importFrom gridExtra arrangeGrob
#' @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",
"top-right", "top-left")) {
"top-right", "top-left"),
logo_height = 0.5) {
position <- match.arg(position)
at_top <- grepl("top", position)
is_patchwork <- inherits(plot, "patchwork")
# 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
# caption/axis text overlapping via negative margins remains visible.
# grob with it. The logo grob stays transparent (theme_void).
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) {
base_size <- plot$theme$text$size %||% 14
plot <- plot + theme(
text = element_text(size = base_size * font_scale)
)
base_size <- plot$theme$text$size
if (is.null(base_size)) base_size <- 14
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)) {
plot <- plot + theme(plot.margin = unit(c(margin_param, 7, 7, 7), "pt"))
} else {
plot <- plot + theme(plot.margin = unit(c(-14, 7, 7, 7), "pt"))
}
composed <- arrangeGrob(logo, plot, heights = c(0.1, 0.93),
padding = unit(0.1, "line"))
if (!is.null(margin_param)) {
side <- if (at_top) c(margin_param, 7, 7, 7) else c(7, 7, margin_param, 7)
margin <- theme(plot.margin = grid::unit(side, "pt"))
plot <- if (is_patchwork) plot & margin else plot + margin
}
# 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 {
# Bottom placement (original behaviour)
if(has_caption(plot)) {
cap_lines <- measure_caption(plot)
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"))
arrangeGrob(plot_grob, logo,
heights = grid::unit.c(plot_height, band_height),
padding = grid::unit(0.1, "line"))
}
# Wrap with a full-bleed background rect so any transparent areas (the
@@ -160,7 +162,7 @@ has_caption <- function(gg) {
#' @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 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.
#'
#' @return a grid object
#' @note The resulting object needs to be drawn to the screen using grid.draw()
@@ -179,7 +181,7 @@ has_caption <- function(gg) {
#' dev.off()
#' }
add_logo_ga <- function(plot_list, logo, nrow = 1, widths = NULL,
margin_param = NULL, font_scale = 1.1) {
margin_param = NULL, font_scale = 1) {
# Capture the background color from the first plot
bg_fill <- plot_list[[1]]$theme$plot.background$fill
@@ -268,20 +270,20 @@ make_logo_grob <- function(type = c("wordmark", "mark"),
align_left <- grepl("left", position)
if (align_left) {
xmin <- 0
xmax <- if (type == "mark") 0.07 else 0.35
} else {
xmin <- if (type == "mark") 0.93 else 0.65
xmax <- 1
}
# Give the raster a height only, so grid derives its width from the image's
# own aspect ratio, then pin it to the corner. The logo is the same shape on
# any canvas width.
logo <- grid::rasterGrob(
png::readPNG(system.file("img", img_file, package = "civilytics")),
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() +
theme_void() +
annotation_custom(
get_png(system.file("img", img_file, package = "civilytics")),
xmin = xmin, xmax = xmax
)
annotation_custom(logo, xmin = -Inf, xmax = Inf, ymin = -Inf, ymax = Inf)
}
#' Add a Civilytics logo to a ggplot (pipe-friendly)
@@ -308,9 +310,10 @@ make_logo_grob <- function(type = c("wordmark", "mark"),
#' (default), `"bottom-left"`, `"top-right"`, or `"top-left"`.
#' @param margin_param Numeric or `NULL`. Manual margin adjustment passed to
#' [add_logo()].
#' @param font_scale Numeric. Inflate text sizes by this factor to compensate
#' for viewport shrinkage when composing with [gridExtra::arrangeGrob()].
#' Default `1.1` (~10 \% inflation). Set to `1` to disable.
#' @param font_scale Numeric. Multiplies the plot's base text size before
#' composing. Default `1` leaves typography unchanged.
#' @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
#' [grid::grid.draw()].
@@ -355,11 +358,12 @@ civilytics_logo <- function(plot,
position = c("bottom-right", "bottom-left",
"top-right", "top-left"),
margin_param = NULL,
font_scale = 1.1) {
font_scale = 1,
logo_height = 0.5) {
position <- match.arg(position)
logo <- make_logo_grob(type = type, variant = variant, position = position)
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;
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 {
color: var(--accent-600);
font-family: var(--font-mono);
@@ -747,7 +751,7 @@ img.civilytics-wordmark,
----------------------------------------------------------- */
.reveal .columns {
display: flex;
gap: 3em;
gap: 1.5em;
align-items: flex-start;
margin: 0.25em 0;
}
@@ -755,6 +759,11 @@ img.civilytics-wordmark,
flex: 1;
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; }
/* 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.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
Reveal scales slides, but the narrowest keep-legible margins.
+17 -9
View File
@@ -8,29 +8,37 @@ add_logo(
plot,
logo,
margin_param = NULL,
font_scale = 1.1,
position = c("bottom-right", "bottom-left", "top-right", "top-left")
font_scale = 1,
position = c("bottom-right", "bottom-left", "top-right", "top-left"),
logo_height = 0.5
)
}
\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{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
sizes before composing the plot with the logo. Default `1.1` inflates
text by ~10 \% to compensate for the viewport shrinkage caused by
[gridExtra::arrangeGrob()]. Set to `1` to disable.}
\item{font_scale}{Numeric. Multiplicative scaling factor applied to the
base text size before composing. Default `1` leaves typography unchanged.}
\item{position}{Character. Corner placement for the logo: `"bottom-right"`
(default), `"bottom-left"`, `"top-right"`, or `"top-left"`. Controls
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{
a grob with a logo attached to it ready to plot
}
\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.
}
+2 -2
View File
@@ -10,7 +10,7 @@ add_logo_ga(
nrow = 1,
widths = NULL,
margin_param = NULL,
font_scale = 1.1
font_scale = 1
)
}
\arguments{
@@ -25,7 +25,7 @@ add_logo_ga(
\item{margin_param}{a number giving the adjustment up or down to help manually align logo and captions}
\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.}
}
\value{
a grid object
+7 -4
View File
@@ -10,7 +10,8 @@ civilytics_logo(
variant = c("light", "dark"),
position = c("bottom-right", "bottom-left", "top-right", "top-left"),
margin_param = NULL,
font_scale = 1.1
font_scale = 1,
logo_height = 0.5
)
}
\arguments{
@@ -28,9 +29,11 @@ civilytics_logo(
\item{margin_param}{Numeric or `NULL`. Manual margin adjustment passed to
[add_logo()].}
\item{font_scale}{Numeric. Inflate text sizes by this factor to compensate
for viewport shrinkage when composing with [gridExtra::arrangeGrob()].
Default `1.1` (~10 \% inflation). Set to `1` to disable.}
\item{font_scale}{Numeric. Multiplies the plot's base text size before
composing. Default `1` leaves typography unchanged.}
\item{logo_height}{Numeric. Height in inches of the band reserved for the
logo. Default `0.5`.}
}
\value{
A grob (from [gridExtra::arrangeGrob()]) ready to draw with
+12 -10
View File
@@ -6,25 +6,26 @@
\usage{
style_flextable_civilytics(
ft,
header_bg = "#2c3e50",
header_bg = civilytics_colors[["navy_700"]],
header_color = "white",
title_fontsize = 14,
body_fontsize = 11,
font_name = "Arial",
zebra = TRUE,
zebra_bg = "#f0f0eb",
outer_border_color = "#888888",
zebra_bg = civilytics_colors[["paper_2"]],
outer_border_color = civilytics_colors[["rule_strong"]],
outer_border_width = 1,
inner_border_color = "#cccccc",
inner_border_color = civilytics_colors[["rule"]],
inner_border_width = 0.5,
footer_fontsize = 9,
footer_color = "#555555"
footer_color = civilytics_colors[["ink_3"]]
)
}
\arguments{
\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"`.}
@@ -40,15 +41,15 @@ title row, `i = 1`). Default `14`.}
Default `TRUE`. Safely skipped for tables with fewer than two 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
`"#888888"`.}
`civilytics_colors[["rule_strong"]]`.}
\item{outer_border_width}{Numeric. Outer border width. Default `1`.}
\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
`0.5`.}
@@ -56,7 +57,8 @@ Default `"#cccccc"`.}
\item{footer_fontsize}{Numeric. Footer font size (applied only if a footer
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{
The styled [flextable::flextable()] object.
+6
View File
@@ -13,6 +13,12 @@ file carries the reasoning and the pointers.
---
## 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
**Why:** roborev reviewed the init commit because `excluded_commit_patterns` are
+9 -30
View File
@@ -7,46 +7,25 @@
## Where this stands
`civilytics` is the house R package behind every Civilytics chart, table, and report —
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 running, with one sharp edge now documented. The exclusion patterns
that decide which commits get reviewed are matched against the whole commit message, not
just the subject, so a commit whose body merely mentions an excluded prefix is skipped
with no record anywhere. That is filed as #24. It is not urgent, but it is the kind of
silence that is expensive to diagnose cold.
Four 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 remaining two are housekeeping: duplicate `kodor/*`
labels at repo and org scope (#22), and the review-skip trap (#24).
CI passes on `04a5ee9`. The next substantive work is #20.
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.
## 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
- **#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
- **#22** kodor/* labels are defined at both repo and org scope · `ws/packaging` — nothing is blocking it
- **#24** roborev exclusion patterns match the whole commit message, causing silent skips · `ws/packaging` — nothing is blocking it
## Workstreams
| Stream | Commits since | Open | Debt | Owes docs |
|---|---|---|---|---|
| Themes, palettes, and fonts | 0 | 0 | 0 | no |
| Logo and branded output composition | 0 | 2 | 1 | no |
| Quarto themes and publishing templates | 0 | 0 | 0 | no |
| Logo and branded output composition | 2 | 2 | 1 | no |
| Quarto themes and publishing templates | 1 | 3 | 0 | **yes** |
| Analysis and workflow helpers | 0 | 0 | 0 | no |
| Package infrastructure and release | 0 | 2 | 0 | no |
| Package infrastructure and release | 3 | 0 | 0 | no |
## CI
@@ -58,8 +37,8 @@ CI passes on `04a5ee9`. The next substantive work is #20.
_Nothing blocks anything else, so there is no graph to draw._
- Marker: `04a5ee95` (2026-08-24)
- Commits since: 0
- Open issues: 4
- Commits since: 7
- Open issues: 5
</details>
+1 -1
View File
@@ -95,7 +95,7 @@ docs = [
[roborev]
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.",
"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.",
+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])
})
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"]]))
})
+83
View File
@@ -28,3 +28,86 @@ test_that("stamp_logo_png validates its inputs", {
# invalid type is rejected by match.arg() before the file is touched
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)
}
})