feat: add map theme variants and fix dark theme text readability
R-CMD-check / R CMD check (push) Successful in 3m48s
R-CMD-check / R CMD check (push) Successful in 3m48s
Add theme_civilytics_map(), theme_civilytics_dark_map(), and theme_civilytics_slide_map() for choropleths — suppress axes, ticks, gridlines, and axis labels while preserving titles, captions, and legends. Fix subtitle, caption, and axis text colors in theme_civilytics_dark() which were inheriting dark ink_2/ink_3 values meant for light backgrounds, making them hard to read on navy. Now uses navy_200/navy_300 instead.
This commit is contained in:
@@ -226,6 +226,21 @@ test_that("theme_civilytics_dark inherits grid parameter", {
|
||||
expect_s3_class(th$panel.grid.major.y, "element_line")
|
||||
})
|
||||
|
||||
test_that("theme_civilytics_dark uses readable subtitle and caption colors", {
|
||||
th <- theme_civilytics_dark()
|
||||
# Subtitle should use navy_200, not the dark ink_2
|
||||
expect_equal(th$plot.subtitle$colour, unname(civilytics_colors["navy_200"]))
|
||||
# Caption should use navy_300, not the dark ink_3
|
||||
expect_equal(th$plot.caption$colour, unname(civilytics_colors["navy_300"]))
|
||||
})
|
||||
|
||||
test_that("theme_civilytics_dark uses readable axis text colors", {
|
||||
th <- theme_civilytics_dark()
|
||||
expect_equal(th$axis.text$colour, unname(civilytics_colors["navy_200"]))
|
||||
expect_equal(th$axis.title.x$colour, unname(civilytics_colors["navy_300"]))
|
||||
expect_equal(th$axis.title.y$colour, unname(civilytics_colors["navy_300"]))
|
||||
})
|
||||
|
||||
# --- theme_civilytics_slide --------------------------------------------------
|
||||
|
||||
test_that("theme_civilytics_slide returns a complete ggplot2 theme", {
|
||||
@@ -253,6 +268,90 @@ test_that("theme_civilytics_slide applies to a ggplot without error", {
|
||||
expect_no_error(ggplot_build(p))
|
||||
})
|
||||
|
||||
# --- theme_civilytics_map ----------------------------------------------------
|
||||
|
||||
test_that("theme_civilytics_map returns a complete theme", {
|
||||
th <- theme_civilytics_map()
|
||||
expect_s3_class(th, "theme")
|
||||
expect_true(attr(th, "complete"))
|
||||
})
|
||||
|
||||
test_that("theme_civilytics_map suppresses axes and gridlines", {
|
||||
th <- theme_civilytics_map()
|
||||
expect_s3_class(th$axis.line.x, "element_blank")
|
||||
expect_s3_class(th$axis.text, "element_blank")
|
||||
expect_s3_class(th$axis.ticks, "element_blank")
|
||||
expect_s3_class(th$axis.title.x, "element_blank")
|
||||
expect_s3_class(th$axis.title.y, "element_blank")
|
||||
expect_s3_class(th$panel.grid.major.x, "element_blank")
|
||||
expect_s3_class(th$panel.grid.major.y, "element_blank")
|
||||
})
|
||||
|
||||
test_that("theme_civilytics_map preserves title and caption elements", {
|
||||
th <- theme_civilytics_map()
|
||||
expect_s3_class(th$plot.title, "element_text")
|
||||
expect_s3_class(th$plot.subtitle, "element_text")
|
||||
expect_s3_class(th$plot.caption, "element_text")
|
||||
})
|
||||
|
||||
test_that("theme_civilytics_map applies to a ggplot without error", {
|
||||
p <- ggplot(mpg, aes(displ, hwy)) +
|
||||
geom_point() +
|
||||
theme_civilytics_map()
|
||||
expect_no_error(ggplot_build(p))
|
||||
})
|
||||
|
||||
# --- theme_civilytics_dark_map -----------------------------------------------
|
||||
|
||||
test_that("theme_civilytics_dark_map returns a complete theme", {
|
||||
th <- theme_civilytics_dark_map()
|
||||
expect_s3_class(th, "theme")
|
||||
expect_true(attr(th, "complete"))
|
||||
})
|
||||
|
||||
test_that("theme_civilytics_dark_map suppresses axes on dark background", {
|
||||
th <- theme_civilytics_dark_map()
|
||||
expect_s3_class(th$axis.line.x, "element_blank")
|
||||
expect_s3_class(th$axis.text, "element_blank")
|
||||
expect_s3_class(th$axis.ticks, "element_blank")
|
||||
expect_equal(th$plot.background$fill, unname(civilytics_colors["navy_700"]))
|
||||
})
|
||||
|
||||
test_that("theme_civilytics_dark_map applies to a ggplot without error", {
|
||||
p <- ggplot(mpg, aes(displ, hwy)) +
|
||||
geom_point() +
|
||||
theme_civilytics_dark_map()
|
||||
expect_no_error(ggplot_build(p))
|
||||
})
|
||||
|
||||
# --- theme_civilytics_slide_map ----------------------------------------------
|
||||
|
||||
test_that("theme_civilytics_slide_map returns a complete theme", {
|
||||
th <- theme_civilytics_slide_map()
|
||||
expect_s3_class(th, "theme")
|
||||
expect_true(attr(th, "complete"))
|
||||
})
|
||||
|
||||
test_that("theme_civilytics_slide_map has larger font and suppressed axes", {
|
||||
th <- theme_civilytics_slide_map()
|
||||
th_base <- theme_civilytics_map()
|
||||
expect_gt(th$text$size, th_base$text$size)
|
||||
expect_s3_class(th$axis.line.x, "element_blank")
|
||||
expect_s3_class(th$axis.text, "element_blank")
|
||||
})
|
||||
|
||||
test_that("theme_civilytics_slide_map has transparent background by default", {
|
||||
th <- theme_civilytics_slide_map()
|
||||
expect_true(is.na(th$plot.background$fill))
|
||||
})
|
||||
|
||||
test_that("theme_civilytics_slide_map applies to a ggplot without error", {
|
||||
p <- ggplot(mpg, aes(displ, hwy)) +
|
||||
geom_point() +
|
||||
theme_civilytics_slide_map()
|
||||
expect_no_error(ggplot_build(p))
|
||||
})
|
||||
|
||||
# --- make_logo_grob ----------------------------------------------------------
|
||||
|
||||
test_that("make_logo_grob returns a gg object for all type/variant combos", {
|
||||
|
||||
Reference in New Issue
Block a user