Skip to content

Commit

Permalink
Fix justification for add_phylopic_base and fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
willgearty committed Jan 31, 2024
1 parent b2a5dd2 commit 21908b8
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 78 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Encoding: UTF-8
LazyData: true
biocViews:
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Depends:
R (>= 4.0)
Imports:
Expand Down
24 changes: 10 additions & 14 deletions R/add_phylopic_base.r
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,9 @@
#' @param angle \code{numeric}. The number of degrees to rotate the silhouette
#' clockwise. The default is no rotation.
#' @param hjust \code{numeric}. A numeric vector between 0 and 1 specifying
#' horizontal justification (left = 0, center = 0.5, right = 1). Note that,
#' due to the enforcement of the silhouette's aspect ratio, there may be
#' unexpected behavior due to interactions between the aspect ratio of the
#' plot and the aspect ratio of the silhouette.
#' horizontal justification (left = 0, center = 0.5, right = 1).
#' @param vjust \code{numeric}. A numeric vector between 0 and 1 specifying
#' vertical justification (top = 1, middle = 0.5, bottom = 0). Note that, due
#' to the enforcement of the silhouette's aspect ratio, there may be
#' unexpected behavior due to interactions between the aspect ratio of the
#' plot and the aspect ratio of the silhouette.
#' vertical justification (top = 1, middle = 0.5, bottom = 0).
#' @param remove_background \code{logical}. Should any white background be
#' removed from the silhouette(s)? See [recolor_phylopic()] for details.
#' @param verbose \code{logical}. Should the attribution information for the
Expand Down Expand Up @@ -122,10 +116,10 @@ add_phylopic_base <- function(img = NULL, name = NULL, uuid = NULL,
if (any(alpha > 1 | alpha < 0)) {
stop("`alpha` must be between 0 and 1.")
}
if (any(data$hjust > 1 | data$hjust < 0)) {
if (any(hjust > 1 | hjust < 0)) {
stop("`hjust` must be between 0 and 1.")

Check warning on line 120 in R/add_phylopic_base.r

View check run for this annotation

Codecov / codecov/patch

R/add_phylopic_base.r#L120

Added line #L120 was not covered by tests
}
if (any(data$vjust > 1 | data$vjust < 0)) {
if (any(vjust > 1 | vjust < 0)) {
stop("`vjust` must be between 0 and 1.")

Check warning on line 123 in R/add_phylopic_base.r

View check run for this annotation

Codecov / codecov/patch

R/add_phylopic_base.r#L123

Added line #L123 was not covered by tests
}
if (!is.logical(verbose)) {
Expand Down Expand Up @@ -226,14 +220,16 @@ add_phylopic_base <- function(img = NULL, name = NULL, uuid = NULL,
all(is.finite(img@summary@xscale)) && diff(img@summary@xscale) != 0 &&
is.numeric(img@summary@yscale) && length(img@summary@yscale) == 2 &&
all(is.finite(img@summary@yscale)) && diff(img@summary@yscale) != 0) {
grid.picture(img, x = x, y = y, height = ysize, expansion = 0,
just = c(hjust, vjust))
xsize <- grconvertX(
grconvertY(ysize, from = "ndc", to = "inches") * aspect_ratio(img),

Check warning on line 224 in R/add_phylopic_base.r

View workflow job for this annotation

GitHub Actions / lint

file=R/add_phylopic_base.r,line=224,col=10,[indentation_linter] Hanging indent should be 28 spaces but is 10 spaces.
from = "inches", to = "ndc")
grid.picture(img, x = x, y = y, height = ysize, width = xsize,
expansion = 0, just = c(hjust, vjust))
} else {
return(NULL)
}
} else { # png
grid.raster(img, x = x, y = y, height = ysize,
just = c(hjust, vjust))
grid.raster(img, x = x, y = y, height = ysize, just = c(hjust, vjust))
}
},
img = imgs, x = x, y = y, ysize = ysize, alpha = alpha, color = color,
Expand Down
1 change: 0 additions & 1 deletion R/geom_phylopic.R
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,6 @@ phylopicGrob <- function(img, x, y, height, color, fill, alpha,
}
} else { # png
img_grob <- rasterGrob(img, x = x, y = y, height = height,
width = height * aspect_ratio(img),
default.units = "native",
just = c(hjust, vjust))
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 10 additions & 11 deletions tests/testthat/_snaps/geom_phylopic/phylopic-key-glyph-with-img.svg
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.
32 changes: 15 additions & 17 deletions tests/testthat/_snaps/geom_phylopic/phylopic-key-glyph.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 21908b8

Please sign in to comment.