R/s3-ggplot2-CoordTransform.R

Defines functions .cstr_construct.CoordTransform.coord_transform is_corrupted_CoordTransform .cstr_construct.CoordTransform opts_CoordTransform

Documented in opts_CoordTransform

#' Constructive options for class 'CoordTransform'
#'
#' These options will be used on objects of class 'CoordTransform'.
#'
#' Depending on `constructor`, we construct the object as follows:
#' * `"coord_transform"` (default): We build the object using `ggplot2::coord_transform()`.
#' * `"next"` : Use the constructor for the next supported class.
#'
#' @param constructor String. Name of the function used to construct the object.
#' @param ... Additional options used by user defined constructors through the `opts` object
#' @return An object of class <constructive_options/constructive_options_CoordTransform>
#' @export
opts_CoordTransform <- function(constructor = c("coord_transform", "next"), ...) {
  constructive::.cstr_options("CoordTransform", constructor = constructor[[1]], ...)
}

#' @exportS3Method constructive::.cstr_construct
.cstr_construct.CoordTransform <- function(x, ...) {
  opts <- list(...)$opts$CoordTransform %||% opts_CoordTransform()
  if (is_corrupted_CoordTransform(x) || opts$constructor == "next") return(NextMethod())
  UseMethod(".cstr_construct.CoordTransform", structure(NA, class = opts$constructor))
}

is_corrupted_CoordTransform <- function(x) {
  FALSE
}

#' @export
.cstr_construct.CoordTransform.coord_transform <- function(x, ...) {
  # opts <- list(...)$opts$CoordTransform %||% opts_CoordTransform()
  args <- list(
    x = x$trans$x$name,
    y = x$trans$y$name,
    xlim = x$limits$x,
    ylim = x$limits$y,
    clip = x$clip,
    expand = x$expand,
    reverse = x$reverse
  )

  args <- keep_only_non_defaults(args, getFromNamespace("coord_transform", "ggplot2"))
  code <- .cstr_apply(args, "ggplot2::coord_transform", ...)
  constructive::.cstr_repair_attributes(
    x, code, ...,
    idiomatic_class = c("CoordTransform", "Coord", "ggproto", "gg")
  )
}

Try the constructive package in your browser

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

constructive documentation built on Nov. 5, 2025, 7:14 p.m.