Skip to content

Commit

Permalink
Merge pull request #66 from poissonconsulting/upkeep
Browse files Browse the repository at this point in the history
Upkeep
  • Loading branch information
evanamiesgalonski authored Jan 22, 2025
2 parents 728f64e + f799585 commit 7a2bc06
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 47 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Depends:
R (>= 3.4)
Imports:
chk,
ggplot2,
ggplot2 (>= 3.5.0),
grDevices,
colorscale
Remotes:
Expand All @@ -27,4 +27,4 @@ LazyData: true
RoxygenNote: 7.2.2.9000
Language: en-US
Roxygen: list(markdown = TRUE)
Config/Needs/website: poissonconsulting/poissontemplate
Config/Needs/website: poissonconsulting/poissontemplate
4 changes: 2 additions & 2 deletions R/scales.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ scale_colour_disc_poisson <- function(
pal <- pois_pal_custom(palette = palette, reverse = reverse)
}

ggplot2::discrete_scale("colour", paste0("pois_", palette), palette = pal, na.value = "#7F7F7F", ...)
ggplot2::discrete_scale(aesthetics = "colour", palette = pal, na.value = "#7F7F7F", ...)
}

#' discrete fill scale constructor for poisson colours
Expand All @@ -42,7 +42,7 @@ scale_fill_disc_poisson <- function(
pal <- pois_pal_custom(palette = palette, reverse = reverse)
}

ggplot2::discrete_scale("fill", paste0("pois_", palette), palette = pal, na.value = "#7F7F7F", ...)
ggplot2::discrete_scale(aesthetics = "fill", palette = pal, na.value = "#7F7F7F", ...)
}

#' gradient colour scale constructor for poisson colours
Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ knitr::opts_chunk$set(
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[![R-CMD-check](https://github.com/poissonconsulting/poispalette/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/poissonconsulting/poispalette/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/poissonconsulting/poispalette/branch/master/graph/badge.svg)](https://codecov.io/gh/poissonconsulting/poispalette?branch=master)
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/license/mit/)
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
<!-- badges: end -->

## Introduction
Expand Down
1 change: 1 addition & 0 deletions poispalette.Rproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Version: 1.0
ProjectId: 1ec9aa15-174b-4512-b955-8a356bc9e87b

RestoreWorkspace: Default
SaveWorkspace: Default
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed tests/testthat/_snaps/scales/discrete_colours.png
Binary file not shown.
Binary file removed tests/testthat/_snaps/scales/gradient_colours.png
Binary file not shown.
42 changes: 42 additions & 0 deletions tests/testthat/test-scales-snapshot.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
test_that("scale functions work with plots", {
gp <- ggplot2::ggplot(poispalette::points, ggplot2::aes(x = RandomX, y = RandomY)) +
ggplot2::geom_point(ggplot2::aes(colour = ID), size = 2) +
scale_colour_disc_poisson()

local_edition(3)
expect_snapshot_plot(gp, "discrete_colours")

gp <- ggplot2::ggplot(poispalette::points, ggplot2::aes(x = X, y = Y)) +
ggplot2::geom_point(ggplot2::aes(colour = RandomX), size = 2) +
scale_colour_grad_poisson(palette = c("#FF0000", "#00FF00"))

expect_snapshot_plot(gp, "gradient_colours")
})

test_that("scale functions correctly display NA data values", {
points_with_na_id <- poispalette::points[1:5, ]
points_with_na_id$ID[5] <- NA

gp <- ggplot2::ggplot(points_with_na_id, ggplot2::aes(x = RandomX, y = RandomY)) +
ggplot2::geom_col(ggplot2::aes(colour = ID, fill = ID)) +
scale_colour_disc_poisson() +
scale_fill_disc_poisson()

local_edition(3)
expect_snapshot_plot(gp, "disc_pals_with_na")

points_with_na_randx <- poispalette::points[1:5, ]
points_with_na_randx$RandomX[5] <- NA

gp <- ggplot2::ggplot(points_with_na_randx, ggplot2::aes(x = X, y = Y)) +
ggplot2::geom_col(ggplot2::aes(colour = RandomX, fill = RandomX)) +
scale_colour_grad_poisson() +
scale_fill_grad_poisson()

expect_snapshot_plot(gp, "grad_pals_with_na")
})

if(FALSE) {
testthat::test_file(file.path(getwd(),"tests/testthat/test-scales-snapshot.R"))
testthat::snapshot_review('scales-snapshot/')
}
42 changes: 0 additions & 42 deletions tests/testthat/test-scales.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,45 +24,3 @@ test_that("scale functions produce objects", {
scale <- scale_fill_grad_poisson(palette = c("#000000", "#000000"))
expect_identical(class(scale), c("ScaleContinuous", "Scale", "ggproto", "gg"))
})


test_that("scale functions work with plots", {
gp <- ggplot2::ggplot(poispalette::points, ggplot2::aes(x = RandomX, y = RandomY)) +
ggplot2::geom_point(ggplot2::aes(colour = ID), size = 2) +
scale_colour_disc_poisson()

local_edition(3)
expect_snapshot_plot(gp, "discrete_colours")

gp <- ggplot2::ggplot(poispalette::points, ggplot2::aes(x = X, y = Y)) +
ggplot2::geom_point(ggplot2::aes(colour = RandomX), size = 2) +
scale_colour_grad_poisson(palette = c("#FF0000", "#00FF00"))

expect_snapshot_plot(gp, "gradient_colours")
})

test_that("scale functions accomodate NAs", {
expect_identical(scale_colour_disc_poisson()$call$na.value, .na_colour)
expect_identical(scale_fill_disc_poisson()$call$na.value, .na_colour)
expect_identical(scale_colour_grad_poisson()$na.value, .na_colour)
expect_identical(scale_fill_grad_poisson()$na.value, .na_colour)
})


test_that("scale naming works", {
scale <- scale_colour_disc_poisson("new_name")
expect_identical(scale$name, "new_name")

scale <- scale_fill_disc_poisson("new_name")
expect_identical(scale$name, "new_name")

scale <- scale_colour_grad_poisson("new_name")
expect_identical(scale$name, "new_name")

scale <- scale_fill_grad_poisson("new_name")
expect_identical(scale$name, "new_name")

scale <- scale_colour_disc_poisson()
expect_identical(scale$name, structure(list(), class = "waiver"))

})

0 comments on commit 7a2bc06

Please sign in to comment.