R/ui.R

Defines functions ui_colour_d ui_colour_c ui_fill_d ui_fill_c ui_theme ui_plot

# Console UI ----

# use rui functions

# Theme, scales and template for ggplot2 ----

ui_plot <- function(p, type = "default", class = "unknown") {
  if (getOption("RMT3DMS.theme") == "ggplot2") return(p)
  if (getOption("RMT3DMS.theme") == "RMODFLOW") {
    p <- p + ggplot2::labs(
      subtitle = paste0('RMT3DMS "', type, '" plot for "', class, '" object'),
      caption = "We strongly recommend tweaking this plot to your specific needs."
    )
    return(p)
  }
  rui::alert('Option {.arg RMT3DMS.theme} should be {.val "RMODFLOW"} or {.val "ggplot2"}.')
  rui::stop("Issue with RMT3DMS options.")
}
ui_theme <- function(...) {
  if (getOption("RMT3DMS.theme") == "RMODFLOW") {
    return(ggplot2::theme_minimal(
      base_size = 13,
      base_line_size = .8,
      base_rect_size = .8
    ) +
      ggplot2::theme(...))
  }
  if (getOption("RMT3DMS.theme") == "ggplot2") {
    return(ggplot2::theme(...))
  }
  rui::alert('Option {.arg RMT3DMS.theme} should be {.val "RMODFLOW"} or {.val "ggplot2"}.')
  rui::stop("Issue with RMT3DMS options.")
}
ui_fill_c <- function(...) {
  if (getOption("RMT3DMS.theme") == "ggplot2") return(NULL)
  if (getOption("RMT3DMS.theme") == "RMODFLOW") {
    return(spectralscale::fill_c(...))
  }
  rui::alert('Option {.arg RMT3DMS.theme} should be {.val "RMODFLOW"} or {.val "ggplot2"}.')
  rui::stop("Issue with RMT3DMS options.")
}
ui_fill_d <- function(...) {
  if (getOption("RMT3DMS.theme") == "ggplot2") return(NULL)
  if (getOption("RMT3DMS.theme") == "RMODFLOW") {
    return(spectralscale::fill_d(...))
  }
  rui::alert('Option {.arg RMT3DMS.theme} should be {.val "RMODFLOW"} or {.val "ggplot2"}.')
  rui::stop("Issue with RMT3DMS options.")
}
ui_colour_c <- function(...) {
  if (getOption("RMT3DMS.theme") == "ggplot2") return(NULL)
  if (getOption("RMT3DMS.theme") == "RMODFLOW") {
    return(spectralscale::colour_c(...))
  }
  rui::alert('Option {.arg RMT3DMS.theme} should be {.val "RMODFLOW"} or {.val "ggplot2"}.')
  rui::stop("Issue with RMT3DMS options.")
}
ui_colour_d <- function(...) {
  if (getOption("RMT3DMS.theme") == "ggplot2") return(NULL)
  if (getOption("RMT3DMS.theme") == "RMODFLOW") {
    return(spectralscale::colour_d(...))
  }
  rui::alert('Option {.arg RMT3DMS.theme} should be {.val "RMODFLOW"} or {.val "ggplot2"}.')
  rui::stop("Issue with RMT3DMS options.")
}
rogiersbart/RMT3DMS documentation built on Oct. 16, 2021, 9:45 a.m.