Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8341a47

Browse filesBrowse files
authored
fix traceNames with frames (#1932)
* * fix traceNames * update NEWS * update tests figs from docker image * remove type = "scatter" and update tests SVGs
1 parent 9abcba9 commit 8341a47
Copy full SHA for 8341a47

14 files changed

+62
-18
lines changed

‎NEWS.md

Copy file name to clipboardExpand all lines: NEWS.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## BUG FIXES
44

55
* `group_by.plotly()` now properly retains crosstalk information across `{dplyr}` versions (#1920).
6+
* Fixes some issues with `name` and `frames` when both attributes are specified. (#1903 and #1618).
67

78
# 4.9.3
89

‎R/plotly_build.R

Copy file name to clipboardExpand all lines: R/plotly_build.R
+6-4Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -484,12 +484,14 @@ registerFrames <- function(p, frameMapping = NULL) {
484484
d <- lapply(d, function(tr) { tr$visible <- tr$visible %||% TRUE; tr })
485485

486486
# if this frame is missing a trace name, supply an invisible one
487-
traceNamesMissing <- setdiff(frameTraceNames, sapply(d, "[[", "name"))
487+
traceNamesMissing <- setdiff(frameTraceNames, unlist(lapply(d, "[[", "name")))
488488
for (j in traceNamesMissing) {
489489
idx <- vapply(p$x$data, function(tr) isTRUE(tr[["name"]] == j), logical(1))
490-
idx <- which(idx)[[1]]
491-
invisible <- modify_list(p$x$data[[idx]], list(visible = FALSE))
492-
d <- c(d, list(invisible))
490+
if (any(idx)){
491+
idx <- which(idx)[[1]]
492+
invisible <- modify_list(p$x$data[[idx]], list(visible = FALSE))
493+
d <- c(d, list(invisible))
494+
}
493495
}
494496
p$x$frames[[i]] <- list(
495497
name = as.character(format(nm)),

‎tests/figs/density2d/density2d.svg

Copy file name to clipboardExpand all lines: tests/figs/density2d/density2d.svg
+1-1Lines changed: 1 addition & 1 deletion
Loading

‎tests/figs/deps.txt

Copy file name to clipboard
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
- vdiffr-svg-engine: 1.0
22
- vdiffr: 0.3.3.9000
3-
- freetypeharfbuzz: 0.2.5
3+
- freetypeharfbuzz: 0.2.6

‎tests/figs/geom-sf/sf-aspect.svg

Copy file name to clipboardExpand all lines: tests/figs/geom-sf/sf-aspect.svg
+1-1Lines changed: 1 addition & 1 deletion
Loading

‎tests/figs/geom-sf/sf-axis-ticks.svg

Copy file name to clipboardExpand all lines: tests/figs/geom-sf/sf-axis-ticks.svg
+1-1Lines changed: 1 addition & 1 deletion
Loading

‎tests/figs/geom-sf/sf-fill-text.svg

Copy file name to clipboardExpand all lines: tests/figs/geom-sf/sf-fill-text.svg
+1-1Lines changed: 1 addition & 1 deletion
Loading

‎tests/figs/geom-sf/sf-points.svg

Copy file name to clipboardExpand all lines: tests/figs/geom-sf/sf-points.svg
+1-1Lines changed: 1 addition & 1 deletion
Loading

‎tests/figs/geom-sf/sf.svg

Copy file name to clipboardExpand all lines: tests/figs/geom-sf/sf.svg
+1-1Lines changed: 1 addition & 1 deletion
Loading

‎tests/figs/plotly-linetype/plotly-linetype-alphabetical.svg

Copy file name to clipboardExpand all lines: tests/figs/plotly-linetype/plotly-linetype-alphabetical.svg
+1-1Lines changed: 1 addition & 1 deletion
Loading

‎tests/figs/plotly-symbol/plotly-symbol-alphabetical.svg

Copy file name to clipboardExpand all lines: tests/figs/plotly-symbol/plotly-symbol-alphabetical.svg
+1-1Lines changed: 1 addition & 1 deletion
Loading

‎tests/figs/plotly-symbol/plotly-symbol-pch.svg

Copy file name to clipboardExpand all lines: tests/figs/plotly-symbol/plotly-symbol-pch.svg
+1-1Lines changed: 1 addition & 1 deletion
Loading

‎tests/testthat/test-plotly-name.R

Copy file name to clipboardExpand all lines: tests/testthat/test-plotly-name.R
+41Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,44 @@ test_that("adding trace name with frame does not throw frameOrder warning", {
7979

8080

8181
})
82+
83+
test_that("adding trace name does not throw error", {
84+
85+
#From ropensci/plotly/issues/1618
86+
df <- data.frame(category=c('a', 'b', 'c', 'd', 'a', 'b', 'c', 'd'),
87+
year=c(2000, 2000, 2000, 2000, 2001, 2001, 2001, 2001),
88+
val_a=c(1,2,2,1,2,5,6,8),
89+
val_b=c(3,5,4,7,1,9,2,12))
90+
91+
92+
p1 <- plot_ly(data = df, frame = ~year) %>%
93+
add_markers(x = ~val_a, y = ~category, name = "Val_A", color = I("red")) %>%
94+
add_markers(x = ~val_b, y = ~category, name = "Val_B", color = I("blue")) %>%
95+
add_segments(x = ~val_a, xend = ~val_b, y = ~category, yend = ~category, showlegend=F) %>%
96+
layout(
97+
title = "Val A v Val B",
98+
xaxis = list(title = "Value"),
99+
yaxis = list(title = ""),
100+
margin = list(l = 65)
101+
)
102+
103+
104+
expect_error(l <- plotly_build(p1), NA)
105+
106+
expect_equal(l$x$data[[1]]$name, "Val_A")
107+
expect_equal(l$x$data[[2]]$name, "Val_B")
108+
109+
110+
#From ropensci/plotly/issues/1903
111+
df1 <- data.frame(frame = 1:10, x = 1:10, y = 0)
112+
df2 <- data.frame(frame = rep(1:10, 1:10),
113+
x = unlist(lapply(1:10, function(x) 1:x)),
114+
y = 1)
115+
116+
p2 <- plot_ly() %>%
117+
add_trace(data = df1, type = "scatter", mode = "markers", x = ~x, y = ~y, frame = ~frame, name= "A") %>%
118+
add_trace(data = df2, type = "scatter", mode = "lines", x = ~x, y = ~y, frame = ~frame, name = "B")
119+
120+
expect_error(l1 <- plotly_build(p2), NA)
121+
122+
})

‎tests/testthat/test-plotly-subplot.R

Copy file name to clipboardExpand all lines: tests/testthat/test-plotly-subplot.R
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,9 @@ test_that("image paper repositioning", {
302302

303303
test_that("annotation xref/yref bumping", {
304304

305-
p1 <- plot_ly(mtcars, type = "scatter") %>%
305+
p1 <- plot_ly(mtcars) %>%
306306
add_annotations(text = ~cyl, x = ~wt, y = ~mpg)
307-
p2 <- plot_ly(mtcars, type = "scatter") %>%
307+
p2 <- plot_ly(mtcars) %>%
308308
add_annotations(text = ~am, x = ~wt, y = ~mpg)
309309
s <- subplot(p1, p2)
310310
ann <- expect_doppelganger_built(s, "subplot-bump-axis-annotation")$layout$annotations
@@ -328,11 +328,11 @@ test_that("annotation xref/yref bumping", {
328328

329329
# now, with more traces than annotations
330330
# https://github.com/ropensci/plotly/issues/1444
331-
p1 <- plot_ly(type = "scatter") %>%
331+
p1 <- plot_ly() %>%
332332
add_markers(x = 1, y = 1) %>%
333333
add_markers(x = 2, y = 2) %>%
334334
add_annotations(text = "foo", x = 1.5, y = 1.5)
335-
p2 <- plot_ly(type = "scatter") %>%
335+
p2 <- plot_ly() %>%
336336
add_markers(x = 1, y = 1) %>%
337337
add_markers(x = 2, y = 2) %>%
338338
add_annotations(text = "bar", x = 1.5, y = 1.5)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.