# WARNING - Generated by {fusen} from /dev/flat_figma_ggplot_correspondance.Rmd: do not edit by hand
#' Determine the ggplot2 theme elements.
#'
#' @param .data Tibble. An object returned by \code{architekter::\link{add_ggplot_theme_type}()}
#'
#' @importFrom dplyr mutate case_when select rename
#' @importFrom cli cli_alert_success
#'
#' @return A tibble with the values of the ggplot2 theme elements.
#' @export
#' @examples
#' data(toy_raw_file_content)
#'
#' toy_raw_file_content %>%
#' raw_to_design_tibble() %>%
#' add_ggplot_theme_type() %>%
#' determine_ggplot_theme_elements()
determine_ggplot_theme_elements <- function(.data) {
data_ggplot_theme_elements <- .data %>%
# _family
mutate(
family = case_when(
!is.na(fontPostScriptName) ~ fontPostScriptName,
!is.na(fontFamily) ~ fontFamily,
TRUE ~ NA_character_
)
) %>%
select(-fontFamily, -fontPostScriptName, -fontWeight) %>%
# _size (depending if it is a text or not)
mutate(
size = case_when(
element_type == "text" ~ fontSize,
TRUE ~ strokeWeight
)
) %>%
select(-fontSize, -strokeWeight, -textAutoResize) %>%
# _letter_spacing
rename(letter_spacing = letterSpacing) %>%
# _lineheight
rename(lineheight = lineHeightPx) %>%
select(-lineHeightPercent, -lineHeightUnit) %>%
# _hjust & vjust
mutate(
hjust = case_when(
textAlignHorizontal == "LEFT" ~ 0,
textAlignHorizontal == "CENTER" ~ 0.5,
textAlignHorizontal == "RIGHT" ~ 1,
TRUE ~ NA_real_
)
) %>%
select(-textAlignHorizontal) %>%
mutate(
hjust = case_when(
textAlignVertical == "BOTTOM" ~ 0,
textAlignVertical == "CENTER" ~ 0.5,
textAlignVertical == "TOP" ~ 1,
TRUE ~ NA_real_
)
) %>%
select(-textAlignVertical) %>%
# _color
mutate(
color = case_when(
element_type %in% c("rect", "line") ~ strokes_color,
TRUE ~ fills_color
)
) %>%
mutate(
fill = case_when(
element_type == "rect" ~ fills_color,
TRUE ~ NA_character_
)
) %>%
select(-fills_color, -strokes_color, -fills_blendMode, -strokes_blendMode)
# _linetype
if ("strokeDashes" %in% colnames(data_ggplot_theme_elements)) {
data_ggplot_theme_elements <- data_ggplot_theme_elements %>%
mutate(
linetype = case_when(
element_type %in% c("rect", "line") & strokeDashes == TRUE ~ "dashed",
element_type %in% c("rect", "line") & is.na(strokeDashes) ~ "solid",
TRUE ~ NA_character_
)
) %>%
select(-strokeDashes, -strokes_type, -fills_type)
} else {
data_ggplot_theme_elements <- data_ggplot_theme_elements %>%
mutate(
linetype = case_when(
element_type %in% c("rect", "line") == TRUE ~ "solid",
TRUE ~ NA_character_
)
) %>%
select(-strokes_type, -fills_type)
}
cli_alert_success("The ggplot2 theme elements have been extracted.")
return(data_ggplot_theme_elements)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.