Skip to content

Commit

Permalink
re-factor print function
Browse files Browse the repository at this point in the history
  • Loading branch information
ernestguevarra committed Feb 29, 2024
1 parent 67cfbc0 commit 0b9d583
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ License: GPL (>= 3)
Depends:
R (>= 2.10)
Imports:
stringr
stringr,
withr
Suggests:
covr,
sf
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ importFrom(graphics,par)
importFrom(graphics,rect)
importFrom(graphics,text)
importFrom(stringr,str_pad)
importFrom(withr,with_par)
1 change: 1 addition & 0 deletions R/oxfordtheme.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
#' @importFrom stringr str_pad
#' @importFrom grDevices col2rgb rgb colorRampPalette
#' @importFrom graphics rect par image text
#' @importFrom withr with_par
#'
"_PACKAGE"
17 changes: 11 additions & 6 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,17 @@ cmyk2rgb <- function(C, M, Y, K) {
#'
print.palette <- function(x, ...) {
n <- length(x)
old <- par(mar = c(0.5, 0.5, 0.5, 0.5))
on.exit(par(old))
# old <- par(mar = c(0.5, 0.5, 0.5, 0.5))
# on.exit(par(old))

image(1:n, 1, as.matrix(1:n), col = x,
ylab = "", xaxt = "n", yaxt = "n", bty = "n")
withr::with_par(
new = list(mar = c(0.5, 0.5, 0.5, 0.5)),
code = {
image(1:n, 1, as.matrix(1:n), col = x,
ylab = "", xaxt = "n", yaxt = "n", bty = "n")

Check warning on line 53 in R/utils.R

View check run for this annotation

Codecov / codecov/patch

R/utils.R#L49-L53

Added lines #L49 - L53 were not covered by tests

rect(0, 0.9, n + 1, 1.1, col = rgb(1, 1, 1, 0.8), border = NA)
text((n + 1) / 2, 1, labels = attr(x, "name"), cex = 1, family = "serif")
rect(0, 0.9, n + 1, 1.1, col = rgb(1, 1, 1, 0.8), border = NA)
text((n + 1) / 2, 1, labels = attr(x, "name"), cex = 1, family = "serif")

Check warning on line 56 in R/utils.R

View check run for this annotation

Codecov / codecov/patch

R/utils.R#L55-L56

Added lines #L55 - L56 were not covered by tests
}
)
}

0 comments on commit 0b9d583

Please sign in to comment.