Skip to content

Commit 8ae278b

Browse files
committed
transpose annotations only when necessary
1 parent 3b374ad commit 8ae278b

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

R/plotly_build.R

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,15 @@ plotly_build.plotly <- function(p) {
4343

4444
# if an annotation attribute is an array, expand into multiple annotations
4545
nAnnotations <- max(lengths(x$annotations) %||% 0)
46-
# font is the only list object, so store it, and attach after transposing
47-
font <- x$annotations[["font"]]
48-
x$annotations <- purrr::transpose(lapply(x$annotations, function(x) {
49-
as.list(rep(x, length.out = nAnnotations))
50-
}))
51-
for (i in seq_len(nAnnotations)) {
52-
x$annotations[[i]][["font"]] <- font
46+
if (nAnnotations > 1 && !is.null(names(x$annotations))) {
47+
# font is the only list object, so store it, and attach after transposing
48+
font <- x$annotations[["font"]]
49+
x$annotations <- purrr::transpose(lapply(x$annotations, function(x) {
50+
as.list(rep(x, length.out = nAnnotations))
51+
}))
52+
for (i in seq_len(nAnnotations)) {
53+
x$annotations[[i]][["font"]] <- font
54+
}
5355
}
5456

5557
x[lengths(x) > 0]

0 commit comments

Comments
 (0)