Skip to content

Commit f5852ce

Browse files
committed
fix trace processing if number of subplots >= 10
Also fix the split-by/discrete scales logic uncovered by the "@%&" fix
1 parent ae6b073 commit f5852ce

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

R/layers2traces.R

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ layers2traces <- function(data, prestats_data, layout, p) {
3636
d <- datz[[i]]
3737
# always split on discrete scales, and other geom specific aesthetics that
3838
# can't translate to a single trace
39-
split_by <- c(split_on(d), names(discreteScales))
39+
split_by <- unique(c(split_on(d), names(discreteScales)))
40+
if (length(split_by)>0) split_by <- paste0(split_by, "_plotlyDomain")
4041
# always split on PANEL and domain values (for trace ordering)
41-
split_by <- c("PANEL", paste0(split_by, "_plotlyDomain"))
42+
split_by <- c("PANEL", split_by)
4243
# split "this layers" data into a list of data frames
4344
idx <- names(d) %in% split_by
4445
# ensure the factor level orders (which determies traces order)
@@ -55,16 +56,20 @@ layers2traces <- function(data, prestats_data, layout, p) {
5556
trs <- Map(geom2trace, dl, paramz[i], list(p))
5657
# are we splitting by a discrete scale on this layer?
5758
# if so, set name/legendgroup/showlegend
58-
isDiscrete <- names(d) %in% paste0(names(discreteScales), "_plotlyDomain")
59+
isDiscrete <- names(d) %in% (if (length(discreteScales) > 0) { paste0(names(discreteScales), "_plotlyDomain") } else as.character())
5960
if (length(trs) > 1 && sum(isDiscrete) >= 1) {
60-
nms <- names(trs)
61-
# ignore "non-discrete" scales that we've split on
62-
for (w in seq_len(sum(names(d) %in% c("PANEL", split_on(d))))) {
63-
nms <- sub("^[^@%&]@%&", "", nms)
64-
}
65-
nms <- strsplit(nms, "@%&")
61+
nms <- strsplit(names(trs), "@%&", fixed = TRUE)
62+
# ignore "non-discrete" scales that we've split by
63+
n_ignore <- sum(!isDiscrete & (names(d) %in% split_by))
6664
nms <- vapply(nms, function(x) {
67-
if (length(x) > 1) paste0("(", paste0(x, collapse = ","), ")") else x
65+
n_x <- length(x)
66+
if (n_x > n_ignore + 1) {
67+
paste0("(", paste0(x[(n_ignore+1):n_x], collapse = ","), ")")
68+
} else if (n_x > n_ignore) {
69+
x[[n_ignore+1]]
70+
} else {
71+
NA_character_
72+
}
6873
}, character(1))
6974
trs <- Map(function(x, y) {
7075
x$name <- y

0 commit comments

Comments
 (0)