Skip to content

Commit 306b4ef

Browse files
committed
Ensure marker.sizemode is always respected, closes #1133, closes #1198
1 parent 677a52c commit 306b4ef

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

R/utils.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,13 @@ verify_attr <- function(proposed, schema) {
496496
proposed$name <- uniq(proposed$name)
497497
}
498498

499+
# if marker.sizemode='area', make sure marker.size is boxed up
500+
# (otherwise, when marker.size is a constant, it always sets the diameter!)
501+
# https://codepen.io/cpsievert/pen/zazXgw
502+
if ("area" %in% proposed$marker$sizemode) {
503+
proposed$marker[["size"]] <- i(proposed$marker[["size"]])
504+
}
505+
499506
# do the same for "sub-attributes"
500507
if (identical(role, "object")) {
501508
proposed[[attr]] <- verify_attr(proposed[[attr]], schema[[attr]])

tests/testthat/test-plotly-size.R

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
context("size")
2+
3+
test_that("sizemode is always respected", {
4+
5+
# https://github.com/ropensci/plotly/issues/1133
6+
p <- plot_ly(mtcars, x = ~wt, y = ~wt, size = ~wt, color = ~as.factor(carb))
7+
d <- plotly_build(p)$x$data
8+
expect_length(d, length(unique(mtcars$carb)))
9+
10+
for (i in seq_along(d)) {
11+
expect_true(d[[i]]$type == "scatter")
12+
expect_true(d[[i]]$mode == "markers")
13+
expect_true(d[[i]]$marker$sizemode == "area")
14+
# Make sure size is always translated as an array in this case, because plotly.js
15+
# https://github.com/plotly/plotly.js/issues/2735
16+
s <- d[[i]]$marker$size
17+
if (length(s) == 1) expect_is(s, "AsIs")
18+
}
19+
20+
})

0 commit comments

Comments
 (0)