Skip to content

Commit

Permalink
export eheat_prepare.ggAnno method
Browse files Browse the repository at this point in the history
  • Loading branch information
Yunuuuu committed Jun 25, 2024
1 parent 4e250ad commit c96de6a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
S3method("[",ExtendedAnnotation)
S3method(eheat_prepare,ExtendedAnnotation)
S3method(eheat_prepare,ExtendedHeatmap)
S3method(eheat_prepare,ggAnno)
S3method(eheat_prepare,ggHeatmap)
S3method(get_guides,default)
S3method(get_guides,ggplot)
Expand Down
20 changes: 11 additions & 9 deletions R/gganno.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,19 @@ methods::setClass(

#' @importFrom ggplot2 ggplot
#' @importFrom ggplot2 aes
eheat_prepare.ggAnno <- function(anno, order_list, name) {
#' @export
#' @rdname eheat_prepare
eheat_prepare.ggAnno <- function(object, order_list, name = NULL, ...) {
if (is.null(name)) {
id <- "(gganno)"
fn_id <- "{.fn ggfn}"
} else {
id <- sprintf("(gganno: %s)", name)
fn_id <- sprintf("{.fn ggfn} %s", id)
}
which <- anno@which
which <- object@which
# we always regard matrix row as the observations
matrix <- anno@matrix
matrix <- object@matrix
data <- as_tibble0(matrix, rownames = NULL) # nolint
if (length(order_list) > 1L) {
with_slice <- TRUE
Expand Down Expand Up @@ -95,7 +97,7 @@ eheat_prepare.ggAnno <- function(anno, order_list, name) {
} else {
p <- ggplot(data, aes(x = .data$.x))
}
p <- rlang::inject(anno@fun(p, !!!anno@dots))
p <- rlang::inject(object@fun(p, !!!object@dots))
if (!ggplot2::is.ggplot(p)) {
cli::cli_abort(
sprintf("%s must return a {.cls ggplot2} object.", fn_id)
Expand Down Expand Up @@ -158,7 +160,7 @@ eheat_prepare.ggAnno <- function(anno, order_list, name) {
}

gt <- ggplot2::ggplotGrob(p) # nolint
anno@fun <- function(index, k, n) {
object@fun <- function(index, k, n) {
vp <- flip_viewport(which, xscale = c(0.5, n + 0.5), yscale = c(0, 1))
if (with_slice) {
m <- NULL
Expand Down Expand Up @@ -193,8 +195,8 @@ eheat_prepare.ggAnno <- function(anno, order_list, name) {
vp = vp
)
}
anno@dots <- list()
anno@legends_panel <- get_guides(gt, margins = "i")
anno@legends_margin <- get_guides(gt)
anno
object@dots <- list()
object@legends_panel <- get_guides(gt, margins = "i")
object@legends_margin <- get_guides(gt)
object
}
5 changes: 4 additions & 1 deletion man/eheat_prepare.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c96de6a

Please sign in to comment.