Skip to content

Commit e80e167

Browse files
authored
Merge pull request #651 from ropensci/fix/symbol
Bug fixes
2 parents 715e036 + 679f33f commit e80e167

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

R/plotly_build.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ map_symbol <- function(traces) {
533533
palette <- setNames(symbols[seq_len(N)], unique(symbol))
534534
for (i in which(nSymbols > 0)) {
535535
s <- symbolList[[i]]
536-
symbols <- pch2symbol(if (inherits(s, "AsIs")) s else as.character(palette[s]))
536+
symbols <- pch2symbol(if (inherits(s, "AsIs")) s else as.character(palette[as.character(s)]))
537537
illegalSymbols <- setdiff(symbols, validSymbols)
538538
if (length(illegalSymbols)) {
539539
warning(
@@ -581,7 +581,7 @@ map_linetype <- function(traces) {
581581
palette <- setNames(linetypes[seq_len(N)], unique(linetype))
582582
for (i in which(nLinetypes > 0)) {
583583
l <- linetypeList[[i]]
584-
dashes <- lty2dash(if (inherits(l, "AsIs")) l else as.character(palette[l]))
584+
dashes <- lty2dash(if (inherits(l, "AsIs")) l else as.character(palette[as.character(l)]))
585585
illegalLinetypes <- setdiff(dashes, validLinetypes)
586586
if (length(illegalLinetypes)) {
587587
warning(

tests/testthat/test-plotly-symbol.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,12 @@ test_that("Warn about invalid symbol codes", {
3737
p <- plot_ly(iris, x = ~Sepal.Length, y = ~Petal.Length, symbol = I("DNE"))
3838
expect_warning(plotly_build(p), "DNE")
3939
})
40+
41+
test_that("Formula resulting in logical vector works", {
42+
s <- c("triangle-up", "circle-open")
43+
p <- plot_ly(x = 1:10, y = 1:10, symbol = ~1:10 > 5, symbols = s)
44+
l <- expect_traces(p, 2, "logical")
45+
markers <- lapply(l$data, "[[", "marker")
46+
syms <- unlist(lapply(markers, "[[", "symbol"))
47+
expect_identical(syms, s)
48+
})

0 commit comments

Comments
 (0)