Compare commits
7
Commits
76aebe2b49
...
7bc547a995
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7bc547a995
|
||
|
|
c16e6cec19
|
||
|
|
dab960aaf1
|
||
|
|
dfcad3d0b8
|
||
|
|
0561df4221
|
||
|
|
d6e3ba2fb4
|
||
|
|
4f697e2d52
|
No files matched your search
@@ -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
@@ -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.
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -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,6 +34,7 @@ Suggests:
|
|||||||
quarto,
|
quarto,
|
||||||
flextable,
|
flextable,
|
||||||
officer,
|
officer,
|
||||||
|
patchwork,
|
||||||
ragg
|
ragg
|
||||||
Config/testthat/edition: 3
|
Config/testthat/edition: 3
|
||||||
Config/roxygen2/version: 8.0.0
|
Config/roxygen2/version: 8.0.0
|
||||||
|
|||||||
@@ -1,11 +1,35 @@
|
|||||||
# 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.
|
||||||
|
- `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).
|
||||||
|
- 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
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -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 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 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
|
#' @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
|
#' @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,7 +181,7 @@ 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) {
|
||||||
# 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
|
||||||
|
|
||||||
@@ -268,20 +270,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 +310,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 +358,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
@@ -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.
|
||||||
}
|
}
|
||||||
+2
-2
@@ -10,7 +10,7 @@ add_logo_ga(
|
|||||||
nrow = 1,
|
nrow = 1,
|
||||||
widths = NULL,
|
widths = NULL,
|
||||||
margin_param = NULL,
|
margin_param = NULL,
|
||||||
font_scale = 1.1
|
font_scale = 1
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
\arguments{
|
\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{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
|
\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{
|
\value{
|
||||||
a grid object
|
a grid object
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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.
|
||||||
|
|||||||
@@ -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
|
## 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
-30
@@ -7,46 +7,25 @@
|
|||||||
|
|
||||||
## Where this stands
|
## Where this stands
|
||||||
|
|
||||||
`civilytics` is the house R package behind every Civilytics chart, table, and report —
|
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.
|
||||||
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.
|
|
||||||
|
|
||||||
## 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
|
- **#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
|
- **#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
|
## 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 | 0 | 0 | 0 | no |
|
||||||
| Logo and branded output composition | 0 | 2 | 1 | no |
|
| Logo and branded output composition | 2 | 2 | 1 | no |
|
||||||
| Quarto themes and publishing templates | 0 | 0 | 0 | no |
|
| Quarto themes and publishing templates | 1 | 3 | 0 | **yes** |
|
||||||
| Analysis and workflow helpers | 0 | 0 | 0 | no |
|
| 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
|
## 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._
|
_Nothing blocks anything else, so there is no graph to draw._
|
||||||
|
|
||||||
- Marker: `04a5ee95` (2026-08-24)
|
- Marker: `04a5ee95` (2026-08-24)
|
||||||
- Commits since: 0
|
- Commits since: 7
|
||||||
- Open issues: 4
|
- Open issues: 5
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -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.",
|
||||||
|
|||||||
@@ -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"]]))
|
||||||
|
})
|
||||||
@@ -28,3 +28,86 @@ 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)
|
||||||
|
}
|
||||||
|
})
|
||||||
Reference in new issue
Block a user