Skip to content

Commit 46c39fe

Browse files
author
Matt Summersgill
committed
Merge branch 'master' into data.table
2 parents 6b31528 + b905e6d commit 46c39fe

File tree

5 files changed

+33
-6
lines changed

5 files changed

+33
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Rapp.history
44
*.RData
55
*.Rproj.user
66
*.DS_Store
7+
node_modules/
78
build_site.R
89
todo.R
910
inst/examples/*.html

R/ggplotly.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ gg2list <- function(p, width = NULL, height = NULL,
632632
# convert the special *degree expression in plotmath to HTML entity
633633
# TODO: can this be done more generally for all ?
634634
rng[[paste0(xy, ".labels")]] <- sub(
635-
"\\*\\s+degree\\s+\\*", "&#176;", rng[[paste0(xy, ".labels")]]
635+
"\\*\\s+degree[ ]?[\\*]?", "&#176;", rng[[paste0(xy, ".labels")]]
636636
)
637637
}
638638

R/plotly_build.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,10 +450,12 @@ registerFrames <- function(p, frameMapping = NULL) {
450450
invisible <- modify_list(p$x$data[[idx]], list(visible = FALSE))
451451
d <- c(d, list(invisible))
452452
}
453-
454453
p$x$frames[[i]] <- list(
455454
name = as.character(format(nm)),
456-
data = d
455+
data = lapply(d, function(tr) {
456+
spec <- Schema$traces[[tr$type %||% "scatter"]]$attributes
457+
verify_attr(tr, spec)
458+
})
457459
)
458460
}
459461

R/toRGB.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@
2222
toRGB <- function(x, alpha = 1) {
2323
if (length(x) == 0) return(x)
2424
if (any(x %in% "transparent")) return(x)
25+
# allow x/alpha vector(s), but only sensible cases...
26+
if (length(x) != length(alpha)) {
27+
# try to reduce alpha to length 1 (in case x is of length 1)
28+
alpha <- uniq(alpha)
29+
if (length(x) != length(alpha) && length(alpha) != 1) {
30+
stop(
31+
"alpha must be of length 1 or the same length as x",
32+
call. = FALSE
33+
)
34+
}
35+
}
2536
# add alpha to already converted "rgb(x,y,z)" codes
2637
idx <- grepl("^rgba\\(", x) & alpha <= 1 & 0 <= alpha
2738
if (any(idx)) {

tests/testthat/test-animate-highlight.R

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,6 @@ test_that("simple animation targeting works", {
287287
}
288288
}
289289

290-
291-
292-
293290
# since all trace types are scatter, redraw = FALSE
294291
buttonArgs <- l$layout$updatemenus[[1]]$buttons[[1]]$args
295292
expect_false(buttonArgs[[2]]$frame$redraw)
@@ -298,7 +295,23 @@ test_that("simple animation targeting works", {
298295
res <- lapply(steps, function(s) {
299296
expect_false(s$args[[2]]$frame$redraw)
300297
})
298+
})
299+
300+
test_that("animation frames are boxed up correctly", {
301+
dallas <- subset(txhousing, city == "Dallas" & month == 1)
302+
p <- ggplot(dallas) +
303+
geom_point(aes(x = volume, y = sales, frame = year))
304+
l <- plotly_build(p)$x
301305

306+
for (i in seq_along(l$frames)) {
307+
traces <- l$frames[[i]]$data
308+
for (j in seq_along(traces)) {
309+
x <- traces[[j]]$x
310+
y <- traces[[j]]$y
311+
expect_true(length(x) > 1 || inherits(x, "AsIs"))
312+
expect_true(length(y) > 1 || inherits(y, "AsIs"))
313+
}
314+
}
302315

303316
})
304317

0 commit comments

Comments
 (0)