Skip to content

Commit

Permalink
add geom_rect3d
Browse files Browse the repository at this point in the history
  • Loading branch information
Yunuuuu committed Dec 4, 2024
1 parent 4471dde commit ffdad26
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 12 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ export(free_space)
export(free_vp)
export(geom_draw)
export(geom_pie)
export(geom_rect3d)
export(geom_subrect)
export(geom_subtile)
export(geom_tile3d)
Expand Down
67 changes: 56 additions & 11 deletions R/geom-tile3d.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
#' @inheritParams ggplot2::layer
#' @inheritParams ggplot2::geom_polygon
#' @inheritParams ggplot2::geom_path
#' @eval rd_gg_aesthetics("geom", "tile3d")
#' @eval rd_gg_aesthetics("geom", "rect3d")
#' @export
geom_tile3d <- function(mapping = NULL, data = NULL, stat = "identity",
geom_rect3d <- function(mapping = NULL, data = NULL, stat = "identity",
position = "identity", ...,
lineend = "butt", linejoin = "round", linemitre = 10,
na.rm = FALSE, show.legend = NA, inherit.aes = TRUE) {
ggplot2::layer(
data = data,
mapping = mapping,
stat = stat,
geom = GeomTile3d,
geom = GeomRect3d,
position = position,
show.legend = show.legend,
inherit.aes = inherit.aes,
Expand All @@ -30,22 +30,23 @@ geom_tile3d <- function(mapping = NULL, data = NULL, stat = "identity",
}

#' @importFrom ggplot2 ggproto
GeomTile3d <- ggproto(
"GeomTile3d",
ggplot2::GeomTile,
default_aes = ggplot2::GeomTile$default_aes,
required_aes = c(ggplot2::GeomTile$required_aes, "z"),
non_missing_aes = c(ggplot2::GeomTile$non_missing_aes, "z", "theta"),
GeomRect3d <- ggproto(
"GeomRect3d",
ggplot2::GeomRect,
required_aes = c(ggplot2::GeomRect$required_aes, "z"),
non_missing_aes = c(ggplot2::GeomRect$non_missing_aes, "z", "theta"),
setup_data = function(self, data, params) {
if (any(data$z %||% .subset2(params, "z") < 0)) {
cli_abort("value mapped to {.field z} aesthetic must >= 0")
}
theta <- data$theta %||% .subset2(params, "theta") %||% 60
if (!is.null(theta) && any(theta <= 0 || theta >= 90)) {
cli_abort("value mapped to {.field theta} aesthetic must > 0 and < 90.")
cli_abort(
"value mapped to {.field theta} aesthetic must > 0 and < 90."
)
}
data$theta <- theta
data <- ggproto_parent(ggplot2::GeomTile, self)$setup_data(
data <- ggproto_parent(ggplot2::GeomRect, self)$setup_data(
data, params
)
data <- vec_slice(data, order(
Expand Down Expand Up @@ -130,3 +131,47 @@ GeomTile3d <- ggproto(
)
}
)

#' @eval rd_gg_aesthetics("geom", "tile3d")
#' @importFrom rlang list2
#' @export
#' @rdname geom_rect3d
geom_tile3d <- function(mapping = NULL, data = NULL, stat = "identity",
position = "identity", ...,
lineend = "butt", linejoin = "round", linemitre = 10,
na.rm = FALSE, show.legend = NA, inherit.aes = TRUE) {
ggplot2::layer(
data = data,
mapping = mapping,
stat = stat,
geom = GeomTile3d,
position = position,
show.legend = show.legend,
inherit.aes = inherit.aes,
params = list(
lineend = lineend,
linejoin = linejoin,
linemitre = linemitre,
na.rm = na.rm, ...
)
)
}

#' @importFrom ggplot2 ggproto ggproto_parent
GeomTile3d <- ggproto(
"GeomTile3d",
ggplot2::GeomTile,
required_aes = c(ggplot2::GeomTile$required_aes, "z"),
non_missing_aes = c(ggplot2::GeomTile$non_missing_aes, "z", "theta"),
setup_data = function(self, data, params) {
data <- ggproto_parent(ggplot2::GeomTile, self)$setup_data(data, params)
ggproto_parent(GeomRect3d, self)$setup_data(data, params)
},
draw_panel = function(self, data, panel_params, coord, lineend = "butt",
linejoin = "round", linemitre = 10) {
GeomRect3d$draw_panel(
data = data, panel_params = panel_params, coord = coord,
lineend = lineend, linejoin = linejoin, linemitre = linemitre
)
}
)
34 changes: 33 additions & 1 deletion man/geom_tile3d.Rd → man/geom_rect3d.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ffdad26

Please sign in to comment.