R/heat_tree--resizing_text.R

Defines functions text_grob_length

Documented in text_grob_length

#' Estimate text grob length
#' 
#' Estimate the printed length of `resizingTextGrob` text
#' 
#' @param text \code{character} The text to be printed
#' @param rot The rotation in radians 
#' 
#' @return The estimated length of the printed text as a multiple of its text size (height)
#' 
#' @keywords internal 
text_grob_length <- function(text, rot = 0) {
  do_one <- function(text) {
    as.numeric(grid::widthDetails(grid::textGrob(text, rot = rot * 180 / pi))) / as.numeric(grid::heightDetails(grid::textGrob(text))) * .8
  }
  vapply(text, do_one, numeric(1))
 }

Try the metacoder package in your browser

Any scripts or data that you put into this service are public.

metacoder documentation built on April 4, 2023, 9:08 a.m.