Skip to content

Commit

Permalink
rename cheat into eheat
Browse files Browse the repository at this point in the history
  • Loading branch information
Yunuuuu committed Jun 24, 2024
1 parent 96bdfd7 commit 5401dbc
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 39 deletions.
4 changes: 2 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ S3method(get_guides,ggplot)
S3method(get_guides,gtable)
export(anno_gg)
export(anno_gg2)
export(cheat_decorate)
export(cheat_grob)
export(draw)
export(eheat_decorate)
export(eheat_grob)
export(gganno)
export(ggfit)
export(ggfit2)
Expand Down
2 changes: 1 addition & 1 deletion R/anno-.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ new_anno <- function(n, draw_fn, ylim = NULL,
cli::cli_inform(msg)
}
anno <- methods::new("AnnotationFunction")
which <- cheat_which(which)
which <- eheat_which(which)
anno@which <- which
anno@fun_name <- name
anno_size <- anno_width_and_height(which, width, height, unit(1, "cm"))
Expand Down
8 changes: 4 additions & 4 deletions R/gganno.R
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ gganno_get_order_list <- function(name, axis,
nframes <- sys.nframe() - 1L # total parents
while (pos <= nframes) {
env <- parent.frame(pos)
if (is_from_cheat(env) &&
if (is_from_eheat(env) &&
exists(name, envir = env, inherits = FALSE) &&
is_call_from(pos, call_target)) {
obj <- .subset2(env, name)
Expand Down Expand Up @@ -255,7 +255,7 @@ draw_gganno <- function(anno, order_list, id) {
rows = ggplot2::vars(.data$.slice),
scales = "free_y", space = "free_y"
)
y_scale <- cheat_scales(coords[c(1L, 3:2)], labels,
y_scale <- eheat_scales(coords[c(1L, 3:2)], labels,
scale_fn = ggplot2::scale_y_continuous
)
if (!is.null(p$scales$get_scales("y"))) {
Expand All @@ -273,7 +273,7 @@ draw_gganno <- function(anno, order_list, id) {
cols = ggplot2::vars(.data$.slice),
scales = "free_x", space = "free_x"
)
x_scale <- cheat_scales(coords[c(1L, 3:2)], labels,
x_scale <- eheat_scales(coords[c(1L, 3:2)], labels,
scale_fn = ggplot2::scale_x_continuous
)
if (!is.null(p$scales$get_scales("x"))) {
Expand Down Expand Up @@ -352,7 +352,7 @@ draw_gganno <- function(anno, order_list, id) {
# } else {
# annotation_global_vp <- grid::current.viewport()$name
# }
# .cheat_decorate(annotation_global_vp, {
# .eheat_decorate(annotation_global_vp, {
# lapply(inside_guides, grid::grid.draw)
# })
if (n == 1L) {
Expand Down
8 changes: 4 additions & 4 deletions R/prepare.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ prepare_ggheat <- function(object) {
data$.column_index <- as.integer(data$.column_index)

# prepare slice panels data ------------------------
slice_list <- cheat_full_slice_index(order_list)
slice_list <- eheat_full_slice_index(order_list)

# prepare data for ggplot2 --------------------------
coords <- lapply(slice_list, function(data) {
Expand Down Expand Up @@ -132,7 +132,7 @@ prepare_ggheat <- function(object) {
}
cols <- sprintf(c(".slice_%s", ".%s", ".%s_index"), axis)
# prepapre scales for each slice panel
cheat_scales(coords[cols], labels, scale_fn = fn)
eheat_scales(coords[cols], labels, scale_fn = fn)
})
names(scales) <- c("row", "column")

Expand Down Expand Up @@ -178,7 +178,7 @@ prepare_ggheat <- function(object) {
nframes <- sys.nframe() - 1L # total parents
while (pos <= nframes) {
env <- parent.frame(pos)
if (is_from_cheat(env) &&
if (is_from_eheat(env) &&
exists("kr", envir = env, inherits = FALSE) &&
exists("kc", envir = env, inherits = FALSE) &&
# Since ComplexHeatmap function much are the S4 methods
Expand Down Expand Up @@ -209,7 +209,7 @@ prepare_ggheat <- function(object) {
}
# in the last slice, we draw inside guides
if (n == total && length(inside_guides)) {
.cheat_decorate(heatmap_body_vp_name, {
.eheat_decorate(heatmap_body_vp_name, {
lapply(inside_guides, grid::grid.draw)
})
}
Expand Down
36 changes: 18 additions & 18 deletions R/utils-complexheatmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@
#' @return A [gTree][grid::gTree] object.
#' @examples
#' h <- ggheat(matrix(rnorm(100), 10))
#' cheat_grob(h)
#' eheat_grob(h)
#' @export
cheat_grob <- function(x, ...) grid::grid.grabExpr(expr = draw(x), ...)
eheat_grob <- function(x, ...) grid::grid.grabExpr(expr = draw(x), ...)

#' Decorate ComplexHeatmap
#' @param vp_name A valid viewport name returned by
#' [list_components][ComplexHeatmap::list_components]
#' @param code Codes to draw elements in the viewport.
#' @return Decorate the viewport.
#' @examples
#' ggheat(matrix(rnorm(81), nrow = 9), column_km = 2L, name = "cheat_decorate")
#' ggheat(matrix(rnorm(81), nrow = 9), column_km = 2L, name = "eheat_decorate")
#' ComplexHeatmap::list_components()
#' cheat_decorate("cheat_decorate_heatmap_body_wrap", {
#' grid.text("I'm from cheat_decorate",
#' eheat_decorate("eheat_decorate_heatmap_body_wrap", {
#' grid.text("I'm from eheat_decorate",
#' 1.5 / 10, 2.5 / 4,
#' default.units = "npc"
#' )
#' })
#' @export
cheat_decorate <- function(vp_name, code) {
eheat_decorate <- function(vp_name, code) {
assert_string(vp_name, empty_ok = FALSE)
components <- ComplexHeatmap::list_components()
if (!length(components)) {
Expand All @@ -41,7 +41,7 @@ cheat_decorate <- function(vp_name, code) {
)
))
}
eval(substitute(.cheat_decorate(vp_name, code)))
eval(substitute(.eheat_decorate(vp_name, code)))
}

#' Make ComplexHeatmap verbose
Expand Down Expand Up @@ -84,27 +84,27 @@ with_ht_opts <- function(opts, code) {
}


.cheat_decorate <- function(vp_name, code) {
.eheat_decorate <- function(vp_name, code) {
current_vp <- grid::current.viewport()$name
if (current_vp == "ROOT") current_vp <- "global"
grid::seekViewport(vp_name)
on.exit(grid::seekViewport(current_vp))
force(code)
}

cheat_which <- function(which = NULL) {
out <- cheat_env_get("current_annotation_which")
eheat_which <- function(which = NULL) {
out <- eheat_env_get("current_annotation_which")
if (is.null(out)) {
out <- match.arg(which, c("column", "row"))
}
out
}

cheat_env_get <- function(name) .subset2(cheat_env(), name)
eheat_env_get <- function(name) .subset2(eheat_env(), name)

cheat_env <- function() utils::getFromNamespace(".ENV", ns = "ComplexHeatmap")
eheat_env <- function() utils::getFromNamespace(".ENV", ns = "ComplexHeatmap")

cheat_full_slice_index <- function(order_list) {
eheat_full_slice_index <- function(order_list) {
row_full <- unlist(order_list$row, recursive = FALSE, use.names = FALSE)
row_full <- structure(seq_along(row_full), names = row_full)
column_full <- unlist(order_list$column,
Expand Down Expand Up @@ -132,7 +132,7 @@ cheat_full_slice_index <- function(order_list) {
out
}

cheat_text_just <- function(rot, side) {
eheat_text_just <- function(rot, side) {
rot <- rot %% 180
if (side == "left") {
if (rot == 0) {
Expand Down Expand Up @@ -169,7 +169,7 @@ cheat_text_just <- function(rot, side) {
}
}

cheat_check_gp <- function(gp) {
eheat_check_gp <- function(gp) {
if (!"lineheight" %in% names(gp)) {
gp$lineheight <- 0.9
}
Expand All @@ -181,7 +181,7 @@ cheat_check_gp <- function(gp) {

#' @param data A data.frame in the order of slice, coord, index
#' @noRd
cheat_scales <- function(data, lables, scale_fn) {
eheat_scales <- function(data, lables, scale_fn) {
lapply(split(data, data[[1L]]), function(slice_data) {
slice_data <- slice_data[2:3]
slice_data <- unique(slice_data)
Expand Down Expand Up @@ -220,7 +220,7 @@ add_gg_legend_list <- function(name, gglegends, call_target = "make_layout") {
nframes <- sys.nframe() - 1L # total parents
while (pos <= nframes) {
env <- parent.frame(pos) # we locate the legend environment
if (is_from_cheat(env) &&
if (is_from_eheat(env) &&
exists(name, envir = env, inherits = FALSE) &&
# Since ComplexHeatmap function much are the S4 methods
# we identify the call name from the parent generic function
Expand All @@ -247,6 +247,6 @@ add_gg_legend_list <- function(name, gglegends, call_target = "make_layout") {
}
}

is_from_cheat <- function(env) {
is_from_eheat <- function(env) {
identical(utils::packageName(topenv(env)), "ComplexHeatmap")
}
12 changes: 6 additions & 6 deletions man/cheat_decorate.Rd → man/eheat_decorate.Rd

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

8 changes: 4 additions & 4 deletions man/cheat_grob.Rd → man/eheat_grob.Rd

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

0 comments on commit 5401dbc

Please sign in to comment.