Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix annotation bug in plotly_build.R
Fixed a bug in which, if the plot only has one annotation but the 'font' attribute has multiple elements (such as color and size), the annotation becomes duplicated. This was due to the fact that plotly_build, when counting annotations, also counted the length of the 'font' attribute list, so if there's only one annotation but 'font' is of length 2, it created a list of 2 identical annotations. 

Now, when counting the length of annotation attributes, any attribute of class 'list' (which I believe should only apply to 'font'), is removed and not counted.
  • Loading branch information
ellenbouchard authored Dec 12, 2024
commit d6b648228fcd392e90817d38a5458428775ee56d
7 changes: 6 additions & 1 deletion R/plotly_build.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ plotly_build.plotly <- function(p, registerFrames = TRUE) {
x <- rapply(x, eval_attr, data = d, how = "list")

# if an annotation attribute is an array, expand into multiple annotations
nAnnotations <- max(lengths(x$annotations) %||% 0)

# Remove any elements from x$annotations that are of class 'list'
# this will remove the 'font' attribute list while retaining relevent attributes
x_annotations_subset <- Filter(function(x) !inherits(x, "list"), x$annotations)
nAnnotations <- max(lengths(x_annotations_subset) %||% 0)

if (!is.null(names(x$annotations))) {
# font is the only list object, so store it, and attach after transposing
font <- x$annotations[["font"]]
Expand Down