@@ -36,9 +36,10 @@ layers2traces <- function(data, prestats_data, layout, p) {
36
36
d <- datz [[i ]]
37
37
# always split on discrete scales, and other geom specific aesthetics that
38
38
# 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" )
40
41
# 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 )
42
43
# split "this layers" data into a list of data frames
43
44
idx <- names(d ) %in% split_by
44
45
# ensure the factor level orders (which determies traces order)
@@ -55,16 +56,20 @@ layers2traces <- function(data, prestats_data, layout, p) {
55
56
trs <- Map(geom2trace , dl , paramz [i ], list (p ))
56
57
# are we splitting by a discrete scale on this layer?
57
58
# 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() )
59
60
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 ))
66
64
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
+ }
68
73
}, character (1 ))
69
74
trs <- Map(function (x , y ) {
70
75
x $ name <- y
0 commit comments