Skip to content

Commit c5c8c7d

Browse files
committed
new helper
1 parent e807aa9 commit c5c8c7d

1 file changed

Lines changed: 70 additions & 1 deletion

File tree

R/aaa.R

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,13 +980,17 @@ NULL
980980
# final cli message.
981981
# @param union_keys Character vector of meta keys to union across
982982
# calls. Defaults to `character()`.
983+
# @param sum_keys Character vector of numeric meta keys to sum across
984+
# calls (e.g. a count of dropped rows aggregated over
985+
# layers / panels). Defaults to `character()`.
983986
#' @noRd
984987
#' @keywords internal
985988
.queue_or_emit <- function(id,
986989
geom_name,
987990
meta = list(),
988991
emit_fn,
989-
union_keys = character()) {
992+
union_keys = character(),
993+
sum_keys = character()) {
990994
target_frame <- .find_render_frame()
991995
if (is.null(target_frame)) {
992996
emit_fn(geom_name, meta)
@@ -1001,6 +1005,9 @@ NULL
10011005
for (key in union_keys) {
10021006
state$meta[[key]] <- unique(c(state$meta[[key]], meta[[key]]))
10031007
}
1008+
for (key in sum_keys) {
1009+
state$meta[[key]] <- (state$meta[[key]] %||% 0) + (meta[[key]] %||% 0)
1010+
}
10041011
}
10051012
state$geoms <- unique(c(state$geoms, geom_name))
10061013
.ggpointless_state$pending[[id]] <- state
@@ -1261,6 +1268,68 @@ NULL
12611268
}
12621269

12631270

1271+
# `geom_rect_fade()` drops rectangles whose bounds are non-finite after the
1272+
# coord transform (e.g. `-Inf`/`Inf` under `scale_y_log10()`). The drop fires
1273+
# once per layer and per panel, so a plot with several rect-fade layers (or
1274+
# facets) would emit the same warning many times. Consolidate into one
1275+
# warning naming the affected geom(s) with the total count summed across
1276+
# layers and panels.
1277+
#' @noRd
1278+
#' @keywords internal
1279+
.queue_rect_fade_nonfinite <- function(geom_name, n) {
1280+
.queue_or_emit(
1281+
id = "rect_fade_nonfinite",
1282+
geom_name = geom_name,
1283+
meta = list(n = n),
1284+
emit_fn = .emit_rect_fade_nonfinite,
1285+
sum_keys = "n"
1286+
)
1287+
}
1288+
1289+
#' @noRd
1290+
#' @keywords internal
1291+
.emit_rect_fade_nonfinite <- function(geoms, meta) {
1292+
n <- meta$n
1293+
cli::cli_warn(
1294+
c(
1295+
"!" = "{.fn {geoms}}: removed {n} rect{?s} with non-finite bounds.",
1296+
"i" = "This usually means {.code -Inf} or {.code Inf} was used together \\
1297+
with a transformed scale (e.g. {.fn scale_y_log10}) that has no \\
1298+
representation for those values. Use finite \\
1299+
{.field xmin}/{.field xmax}/{.field ymin}/{.field ymax} values \\
1300+
instead."
1301+
)
1302+
)
1303+
}
1304+
1305+
1306+
# Pattern + fade compositing fallback for geom_rect_fade() (and future
1307+
# geoms) when the device does not support Porter-Duff dest.in.
1308+
#' @noRd
1309+
#' @keywords internal
1310+
.queue_rect_fade_pattern_no_composite <- function(geom_name) {
1311+
.queue_or_emit(
1312+
id = "rect_fade_pattern_no_composite",
1313+
geom_name = geom_name,
1314+
emit_fn = .emit_rect_fade_pattern_no_composite
1315+
)
1316+
}
1317+
1318+
#' @noRd
1319+
#' @keywords internal
1320+
.emit_rect_fade_pattern_no_composite <- function(geoms, meta) {
1321+
cli::cli_inform(
1322+
c(
1323+
"!" = "{.fn {geoms}}: {.arg pattern} fill with alpha fade requires \\
1324+
Porter-Duff compositing.",
1325+
"i" = "Falling back to a flat semi-transparent fill. Switch to a \\
1326+
device that supports compositing (e.g. {.code ragg::agg_png()}, \\
1327+
{.code svg()}) for the full effect."
1328+
)
1329+
)
1330+
}
1331+
1332+
12641333
# `geom_curve_fade()` compositing fallback (pdf, cairo_pdf, postscript,
12651334
# or any device without Porter-Duff dest.in). One grob per panel.
12661335
#' @noRd

0 commit comments

Comments
 (0)