Skip to content

Commit 3d9a6b7

Browse files
committed
Merge pull request #235 from ropensci/baobao-fix_exists
Fix exists in ggplotly
2 parents dd3b1da + 7fddc01 commit 3d9a6b7

File tree

4 files changed

+69
-2
lines changed

4 files changed

+69
-2
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: plotly
22
Title: Create Interactive Web Graphics via Plotly's JavaScript Graphing Library
3-
Version: 2.0.6
3+
Version: 2.0.7
44
Authors@R: c(person("Carson", "Sievert", role = c("aut", "cre"),
55
email = "[email protected]"),
66
person("Chris", "Parmer", role = c("aut", "cph"),

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2.0.7 -- 10 Dec 2015
2+
3+
Fix #233
4+
15
2.0.6 -- 2 Dec 2015
26

37
Upgrade to plotlyjs 1.1.1. Fixes #319.

R/trace_generation.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ layer2traces <- function(l, d, misc) {
252252

253253
# special handling for bars
254254
if (g$geom == "bar") {
255-
tr$bargap <- if (exists("bargap")) bargap else "default"
255+
tr$bargap <- if (exists("bargap", where = environment())) bargap else "default"
256256
pos <- l$position$.super$objname
257257
tr$barmode <-
258258
if (pos %in% "identity" && tr$bargap == 0) {
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
context("Objects and Environments")
2+
3+
# Expect trace function
4+
expect_traces <- function(gg, n_traces, name) {
5+
stopifnot(is.ggplot(gg))
6+
stopifnot(is.numeric(n_traces))
7+
save_outputs(gg, paste0("object_environments-", name))
8+
L <- gg2list(gg)
9+
all_traces <- L$data
10+
no_data <- sapply(all_traces, function(tr) {
11+
is.null(tr[["x"]]) && is.null(tr[["y"]])
12+
})
13+
has_data <- all_traces[!no_data]
14+
expect_equal(length(has_data), n_traces)
15+
list(traces = has_data, layout = L$layout)
16+
}
17+
18+
# make data
19+
set.seed(955)
20+
dat <- data.frame(cond = rep(c("A", "B"), each=10),
21+
xvar = 1:20 + rnorm(20,sd=3),
22+
yvar = 1:20 + rnorm(20,sd=3))
23+
24+
# make ggplot
25+
p <- ggplot(dat, aes(x = xvar, y = yvar, color = cond)) +
26+
geom_point() + xlab("X") + ylab("Y")
27+
28+
# Test 1: annotation
29+
test_that("object annotations in environment outside plotly", {
30+
annotations <- "outside of the plotly environment"
31+
info <- expect_traces(p, 2, "annotations")
32+
tr <- info$traces[[1]]
33+
la <- info$layout
34+
expect_identical(tr$type, "scatter")
35+
expect_identical(la$xaxis$title, "X")
36+
expect_identical(la$yaxis$title, "Y")
37+
expect_true(grepl("cond", la$annotations[[1]]$text))
38+
})
39+
40+
# Test 2: increase_margin_r
41+
test_that("object increase_margin_r in environment outside plotly", {
42+
increase_margin_r <- "outside of the plotly environment"
43+
info <- expect_traces(p, 2, "increase_margin_r")
44+
tr <- info$traces[[1]]
45+
la <- info$layout
46+
expect_identical(la$xaxis$title, "X")
47+
expect_identical(la$yaxis$title, "Y")
48+
expect_identical(tr$type, "scatter")
49+
expect_true(grepl("cond", la$annotations[[1]]$text))
50+
})
51+
52+
# Test 3: bargap
53+
test_that("object bargap in environment outside plotly", {
54+
bargap <- "outside of the plotly environment"
55+
info <- expect_traces(p, 2, "bargap")
56+
tr <- info$traces[[1]]
57+
la <- info$layout
58+
expect_identical(la$xaxis$title, "X")
59+
expect_identical(la$yaxis$title, "Y")
60+
expect_identical(tr$type, "scatter")
61+
expect_true(grepl("cond", la$annotations[[1]]$text))
62+
})
63+

0 commit comments

Comments
 (0)