Skip to content

Commit

Permalink
rename to anno_textbox()
Browse files Browse the repository at this point in the history
  • Loading branch information
jokergoo committed Jun 15, 2022
1 parent 2bb14c9 commit 5cefa67
Show file tree
Hide file tree
Showing 160 changed files with 179 additions and 298 deletions.
17 changes: 8 additions & 9 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ S3method("heightDetails", "legend_body")
export("heightDetails.legend_body")
S3method("heightDetails", "packed_legends")
export("heightDetails.packed_legends")
S3method("heightDetails", "text_box")
export("heightDetails.text_box")
S3method("heightDetails", "textbox")
export("heightDetails.textbox")
S3method("length", "HeatmapAnnotation")
export("length.HeatmapAnnotation")
S3method("length", "HeatmapList")
Expand Down Expand Up @@ -124,8 +124,8 @@ S3method("widthDetails", "legend_body")
export("widthDetails.legend_body")
S3method("widthDetails", "packed_legends")
export("widthDetails.packed_legends")
S3method("widthDetails", "text_box")
export("widthDetails.text_box")
S3method("widthDetails", "textbox")
export("widthDetails.textbox")
export("%v%")
export("AdditiveUnit")
export("AnnotationFunction")
Expand Down Expand Up @@ -159,7 +159,7 @@ export("anno_points")
export("anno_simple")
export("anno_summary")
export("anno_text")
export("anno_text_box")
export("anno_textbox")
export("anno_zoom")
export("annotation_axis_grob")
export("bar3D")
Expand Down Expand Up @@ -199,7 +199,7 @@ export("getXY_in_parent_vp")
export("grid.annotation_axis")
export("grid.boxplot")
export("grid.dendrogram")
export("grid.text_box")
export("grid.textbox")
export("gt_render")
export("ht_global_opt")
export("ht_opt")
Expand Down Expand Up @@ -235,7 +235,7 @@ export("subset_matrix_by_row")
export("subset_no")
export("subset_vector")
export("test_alter_fun")
export("text_box_grob")
export("textbox_grob")
export("unify_mat_list")
export("upset_left_annotation")
export("upset_right_annotation")
Expand Down Expand Up @@ -290,14 +290,14 @@ exportMethods("set_component_height")
exportMethods("set_component_width")

import(digest)
import(parallel)
import(doParallel)
import(foreach)
import(grDevices)
import(graphics)
import(grid)
import(matrixStats)
import(methods)
import(parallel)
import(png)
import(stats)
importFrom("GetoptLong", qq)
Expand All @@ -324,5 +324,4 @@ importFrom("utils", "combn")
importFrom("utils", "getFromNamespace")
importFrom("utils", "packageDescription")
importFrom("utils", "str")
importFrom("utils", "sessionInfo")

46 changes: 23 additions & 23 deletions R/00_S4_generic_methods.R
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
setGeneric('column_order', function(object, ...) standardGeneric('column_order'))
setGeneric('draw', function(object, ...) standardGeneric('draw'))
setGeneric('prepare', function(object, ...) standardGeneric('prepare'))
setGeneric('row_dend', function(object, ...) standardGeneric('row_dend'))
setGeneric('copy_all', function(object, ...) standardGeneric('copy_all'))
setGeneric('heatmap_legend_size', function(object, ...) standardGeneric('heatmap_legend_size'))
setGeneric('make_column_cluster', function(object, ...) standardGeneric('make_column_cluster'))
setGeneric('column_dend', function(object, ...) standardGeneric('column_dend'))
setGeneric('re_size', function(object, ...) standardGeneric('re_size'))
setGeneric('annotation_legend_size', function(object, ...) standardGeneric('annotation_legend_size'))
setGeneric('draw_dend', function(object, ...) standardGeneric('draw_dend'))
setGeneric('draw_annotation_legend', function(object, ...) standardGeneric('draw_annotation_legend'))
setGeneric('get_color_mapping_list', function(object, ...) standardGeneric('get_color_mapping_list'))
setGeneric('component_height', function(object, ...) standardGeneric('component_height'))
setGeneric('make_row_cluster', function(object, ...) standardGeneric('make_row_cluster'))
setGeneric('color_mapping_legend', function(object, ...) standardGeneric('color_mapping_legend'))
setGeneric('draw_annotation', function(object, ...) standardGeneric('draw_annotation'))
setGeneric('get_legend_param_list', function(object, ...) standardGeneric('get_legend_param_list'))
setGeneric('draw_title', function(object, ...) standardGeneric('draw_title'))
setGeneric('draw_heatmap_list', function(object, ...) standardGeneric('draw_heatmap_list'))
setGeneric('adjust_heatmap_list', function(object, ...) standardGeneric('adjust_heatmap_list'))
setGeneric('make_layout', function(object, ...) standardGeneric('make_layout'))
setGeneric('draw', function(object, ...) standardGeneric('draw'))
setGeneric('draw_heatmap_legend', function(object, ...) standardGeneric('draw_heatmap_legend'))
setGeneric('column_dend', function(object, ...) standardGeneric('column_dend'))
setGeneric('heatmap_legend_size', function(object, ...) standardGeneric('heatmap_legend_size'))
setGeneric('draw_heatmap_body', function(object, ...) standardGeneric('draw_heatmap_body'))
setGeneric('attach_annotation', function(object, ...) standardGeneric('attach_annotation'))
setGeneric('map_to_colors', function(object, ...) standardGeneric('map_to_colors'))
setGeneric('make_column_cluster', function(object, ...) standardGeneric('make_column_cluster'))
setGeneric('annotation_legend_size', function(object, ...) standardGeneric('annotation_legend_size'))
setGeneric('component_width', function(object, ...) standardGeneric('component_width'))
setGeneric('make_layout', function(object, ...) standardGeneric('make_layout'))
setGeneric('make_row_cluster', function(object, ...) standardGeneric('make_row_cluster'))
setGeneric('copy_all', function(object, ...) standardGeneric('copy_all'))
setGeneric('column_order', function(object, ...) standardGeneric('column_order'))
setGeneric('draw_heatmap_list', function(object, ...) standardGeneric('draw_heatmap_list'))
setGeneric('draw_dend', function(object, ...) standardGeneric('draw_dend'))
setGeneric('prepare', function(object, ...) standardGeneric('prepare'))
setGeneric('draw_dimnames', function(object, ...) standardGeneric('draw_dimnames'))
setGeneric('adjust_heatmap_list', function(object, ...) standardGeneric('adjust_heatmap_list'))
setGeneric('set_component_height', function(object, ...) standardGeneric('set_component_height'))
setGeneric('add_heatmap', function(object, ...) standardGeneric('add_heatmap'))
setGeneric('get_color_mapping_list', function(object, ...) standardGeneric('get_color_mapping_list'))
setGeneric('row_order', function(object, ...) standardGeneric('row_order'))
setGeneric('component_height', function(object, ...) standardGeneric('component_height'))
setGeneric('map_to_colors', function(object, ...) standardGeneric('map_to_colors'))
setGeneric('attach_annotation', function(object, ...) standardGeneric('attach_annotation'))
setGeneric('draw_annotation_legend', function(object, ...) standardGeneric('draw_annotation_legend'))
setGeneric('set_component_width', function(object, ...) standardGeneric('set_component_width'))
setGeneric('color_mapping_legend', function(object, ...) standardGeneric('color_mapping_legend'))
setGeneric('draw_annotation', function(object, ...) standardGeneric('draw_annotation'))
setGeneric('draw_dimnames', function(object, ...) standardGeneric('draw_dimnames'))
setGeneric('row_dend', function(object, ...) standardGeneric('row_dend'))
setGeneric('add_heatmap', function(object, ...) standardGeneric('add_heatmap'))
1 change: 1 addition & 0 deletions R/HeatmapList-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ setMethod(f = "draw",
show_parent_dend_line = NULL
) {

.ENV$IS_UNDER_JUPYTER = is_under_jupyter()

if(.ENV$IS_UNDER_JUPYTER && !.ENV$IS_UNDER_JUPYTER_IGNORE) {
.ENV$IS_UNDER_JUPYTER_IGNORE = TRUE
Expand Down
48 changes: 24 additions & 24 deletions R/anno_text_box.R → R/anno_textbox.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
# == example
# words = sapply(1:30, function(x) strrep(sample(letters, 1), sample(3:10, 1)))
# grid.newpage()
# grid.text_box(words, gp = gpar(fontsize = runif(30, min = 5, max = 30)))
# grid.textbox(words, gp = gpar(fontsize = runif(30, min = 5, max = 30)))
#
# sentenses = c("This is sentense 1", "This is a long long long long long long long sentense.")
# grid.newpage()
# grid.text_box(sentenses)
# grid.text_box(sentenses, word_wrap = TRUE)
# grid.text_box(sentenses, word_wrap = TRUE, add_new_line = TRUE)
# grid.textbox(sentenses)
# grid.textbox(sentenses, word_wrap = TRUE)
# grid.textbox(sentenses, word_wrap = TRUE, add_new_line = TRUE)
#
text_box_grob = function(text, x = unit(0.5, "npc"), y = unit(0.5, "npc"), just = "centre",
textbox_grob = function(text, x = unit(0.5, "npc"), y = unit(0.5, "npc"), just = "centre",
gp = gpar(), background_gp = gpar(col = "black", fill = "transparent"), round_corners = FALSE, r = unit(0.1, "snpc"),
line_space = unit(4, "pt"), text_space = unit(4, "pt"), max_width = unit(100, "mm"),
padding = unit(4, "pt"), first_text_from = "top", add_new_line = FALSE, word_wrap = FALSE) { # width in mm
Expand Down Expand Up @@ -203,33 +203,33 @@ text_box_grob = function(text, x = unit(0.5, "npc"), y = unit(0.5, "npc"), just
# rectGrob(x = x, y = y, width = text_width, height = text_height, default.units = "mm", just = c(0, 0))
)

gb = gTree(children = gl, cl = "text_box",
gb = gTree(children = gl, cl = "textbox",
vp = viewport(x = vp_x, y = vp_y, just = vp_just, width = unit(w, "mm"),
height = unit(h, "mm")))
return(gb)
}

# == title
# Width for text_box grob
# Width for textbox grob
#
# == param
# -x The ``text_box`` grob returned by `text_box_grob`.
# -x The ``textbox`` grob returned by `textbox_grob`.
#
# == value
# A `grid::unit` object.
widthDetails.text_box = function(x) {
widthDetails.textbox = function(x) {
x$vp$width
}

# == title
# Height for text_box grob
# Height for textbox grob
#
# == param
# -x The ``text_box`` grob returned by `text_box_grob`.
# -x The ``textbox`` grob returned by `textbox_grob`.
#
# == value
# A `grid::unit` object.
heightDetails.text_box = function(x) {
heightDetails.textbox = function(x) {
x$vp$height
}

Expand All @@ -241,13 +241,13 @@ heightDetails.text_box = function(x) {
# -x X position.
# -y Y position.
# -gp Graphics parameters of texts.
# -... Pass to `text_box_grob`.
# -... Pass to `textbox_grob`.
#
# == details
# All details can be found in the help page of `text_box_grob`.
# All details can be found in the help page of `textbox_grob`.
#
grid.text_box = function(text, x = unit(0.5, "npc"), y = unit(0.5, "npc"), gp = gpar(), ...) {
gb = text_box_grob(text, x = x, y = y, gp = gp, ...)
grid.textbox = function(text, x = unit(0.5, "npc"), y = unit(0.5, "npc"), gp = gpar(), ...) {
gb = textbox_grob(text, x = x, y = y, gp = gp, ...)
grid.draw(gb)
}

Expand All @@ -257,15 +257,15 @@ grid.text_box = function(text, x = unit(0.5, "npc"), y = unit(0.5, "npc"), gp =
#
# == param
# -align_to It controls how the text boxes are aligned to the heatmap rows. The value can be a categorical vector which have the same
# length as heatmap rows, or a list of row indices.
# length as heatmap rows, or a list of row indices. It does not necessarily include all row indices.
# -text The corresponding texts. The value should be a list of texts. To control graphics parameters of texts in the boxes, The value
# of ``text`` can also be set as a list of data frames where the first column contains the text, from the second column contains
# graphics parameters for each text. The column names should be "col", "fontsize", "fontfamily" and "fontface".
# -background_gp Graphics for the background.
# -which Only "row" is allowed.
# -by Are text boxed arranged by `anno_link` or by `anno_block`?
# -side Side of the annotation to the heatmap.
# -... Pass to `text_box_grob`.
# -... Pass to `textbox_grob`.
#
# == example
# require(circlize)
Expand All @@ -278,9 +278,9 @@ grid.text_box = function(text, x = unit(0.5, "npc"), y = unit(0.5, "npc"), gp =
# names(text) = unique(split)
#
# Heatmap(mat, cluster_rows = FALSE, row_split = split,
# right_annotation = rowAnnotation(wc = anno_text_box(split, text))
# right_annotation = rowAnnotation(wc = anno_textbox(split, text))
# )
anno_text_box = function(align_to, text, background_gp = gpar(fill = "#DDDDDD", col = "#AAAAAA"),
anno_textbox = function(align_to, text, background_gp = gpar(fill = "#DDDDDD", col = "#AAAAAA"),
which = c("row", "column"), by = "anno_link", side = c("right", "left"), ...) {

if(is.null(background_gp$fill)) background_gp$fill = "#DDDDDD"
Expand All @@ -290,7 +290,7 @@ anno_text_box = function(align_to, text, background_gp = gpar(fill = "#DDDDDD",

which = match.arg(which)[1]
if(which == "column") {
stop_wrap("`anno_text_box()` can only be used as row annotation.")
stop_wrap("`anno_textbox()` can only be used as row annotation.")
}

# 1. align_to numeric index, text: a data frame
Expand Down Expand Up @@ -328,12 +328,12 @@ anno_text_box = function(align_to, text, background_gp = gpar(fill = "#DDDDDD",
stop_wrap("Format of `align_to` or `text` is wrong.")
}

# a list of text_box grobs
# a list of textbox grobs
dev.null()

gbl = lapply(text, function(x) {
if(is.atomic(x)) {
text_box_grob(text = x, background_gp = gpar(col = NA, fill = "transparent"), ...)
textbox_grob(text = x, background_gp = gpar(col = NA, fill = "transparent"), ...)
} else if(is.data.frame(x)) {
if("col" %in% colnames(x)) {
col = x$col
Expand All @@ -358,7 +358,7 @@ anno_text_box = function(align_to, text, background_gp = gpar(fill = "#DDDDDD",
} else {
fontface = get.gpar("fontface")[[1]]
}
text_box_grob(text = x[[1]], gp = gpar(col = col, fontsize = fontsize, fontfamily = fontfamily, fontface = fontface),
textbox_grob(text = x[[1]], gp = gpar(col = col, fontsize = fontsize, fontfamily = fontfamily, fontface = fontface),
background_gp = gpar(col = NA, fill = "transparent"), ...)
}
})
Expand Down
3 changes: 1 addition & 2 deletions R/global.R
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,7 @@ GLOBAL_PADDING = unit(rep(5.5, 4), "points")


is_under_jupyter = function() {
s = sessionInfo()
"IRkernel" %in% c(names(s$otherPkgs), names(s$loadedOnly))
"IRkernel" %in% loadedNamespaces()
}

.ENV$IS_UNDER_JUPYTER = FALSE
Expand Down
3 changes: 0 additions & 3 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ This message can be suppressed by:

packageStartupMessage(msg)


.ENV$IS_UNDER_JUPYTER = is_under_jupyter()
.ENV$IS_UNDER_JUPYTER_IGNORE = FALSE
}

rv = R.Version()
Expand Down
1 change: 0 additions & 1 deletion man/AdditiveUnit-class.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ method and the \code{\%v\%v} method so that above three classes can be appended
\examples{
# There is no example
NULL

}
1 change: 0 additions & 1 deletion man/AdditiveUnit.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,4 @@ Zuguang Gu <[email protected]>
\examples{
# There is no example
NULL

}
1 change: 0 additions & 1 deletion man/AnnotationFunction-class.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ See \code{\link{AnnotationFunction}} constructor for details.
\examples{
# There is no example
NULL

}
1 change: 0 additions & 1 deletion man/ColorMapping-class.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,4 @@ Zuguang Gu <[email protected]>
\examples{
# There is no example
NULL

}
1 change: 0 additions & 1 deletion man/ComplexHeatmap-package.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,4 @@ The complete reference of ComplexHeatmap package is available at \url{http://jok
\examples{
# There is no example
NULL

}
1 change: 0 additions & 1 deletion man/Extract.gridtext.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ Internally used.
\examples{
# There is no example
NULL

}
1 change: 0 additions & 1 deletion man/Heatmap-class.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,4 @@ Zuguang Gu <[email protected]>
\examples{
# There is no example
NULL

}
5 changes: 2 additions & 3 deletions man/Heatmap.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ Heatmap(matrix, col, name,
\item{raster_quality}{A value larger than 1.}
\item{raster_device_param}{A list of further parameters for the selected graphic device. For raster image support, please check \url{https://jokergoo.github.io/ComplexHeatmap-reference/book/a-single-heatmap.html#heatmap-as-raster-image} .}
\item{raster_resize_mat}{Whether resize the matrix to let the dimension of the matrix the same as the dimension of the raster image? The value can be logical. If it is \code{TRUE}, \code{\link[base]{mean}} is used to summarize the sub matrix which corresponds to a single pixel. The value can also be a summary function, e.g. \code{\link[base:Extremes]{max}}.}
\item{raster_by_magick}{Whether to use \code{\link[magick:transform]{image_resize}} to scale the image.}
\item{raster_magick_filter}{Pass to \code{filter} argument of \code{\link[magick:transform]{image_resize}}. A character scalar and all possible values are in \code{\link[magick:options]{filter_types}}. The default is \code{"Lanczos"}.}
\item{raster_by_magick}{Whether to use \code{\link[magick]{image_resize}} to scale the image.}
\item{raster_magick_filter}{Pass to \code{filter} argument of \code{\link[magick]{image_resize}}. A character scalar and all possible values are in \code{\link[magick]{filter_types}}. The default is \code{"Lanczos"}.}
\item{post_fun}{A function which will be executed after the heatmap list is drawn.}

}
Expand Down Expand Up @@ -212,5 +212,4 @@ Zuguang Gu <[email protected]>
\examples{
# There is no example
NULL

}
1 change: 0 additions & 1 deletion man/HeatmapAnnotation-class.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@ Zuguang Gu <[email protected]>
\examples{
# There is no example
NULL

}
1 change: 0 additions & 1 deletion man/HeatmapAnnotation.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,4 @@ Zuguang Gu <[email protected]>
\examples{
# There is no example
NULL

}
1 change: 0 additions & 1 deletion man/HeatmapList-class.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@ Zuguang Gu <[email protected]>
\examples{
# There is no example
NULL

}
1 change: 0 additions & 1 deletion man/HeatmapList.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,4 @@ Zuguang Gu <[email protected]>
\examples{
# There is no example
NULL

}
1 change: 0 additions & 1 deletion man/Legends.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,4 @@ Zuguang Gu <[email protected]>
\examples{
# There is no example
NULL

}
1 change: 0 additions & 1 deletion man/SingleAnnotation-class.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@ Zuguang Gu <[email protected]>
\examples{
# There is no example
NULL

}
1 change: 0 additions & 1 deletion man/add.AdditiveUnit.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,4 @@ Zuguang Gu <[email protected]>
\examples{
# There is no example
NULL

}
Loading

0 comments on commit 5cefa67

Please sign in to comment.