Skip to content

Commit adcc2ba

Browse files
committed
test different colors
1 parent baa31e8 commit adcc2ba

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

R/print.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
print.trace <- function(x, ...){
2+
str(x)
3+
invisible(x)
4+
}

R/trace_generation.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ layer2traces <- function(l, d, misc) {
198198
data.params <- data.list[[data.i]]
199199
data.params$params$stat.type <- l$stat$objname
200200
tr <- do.call(getTrace, data.params)
201+
class(tr) <- "trace"
201202
for (v.name in c("x", "y")) {
202203
vals <- tr[[v.name]]
203204
if (length(vals) > 0 && is.na(vals[length(vals)])) {

tests/testthat/test-mean-error-bars.R

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ one.line.df <-
88
y = c(2, 1, 3, 4),
99
array = c(0.1, 0.2, 0.1, 0.1),
1010
arrayminus = c(0.2, 0.4, 1, 0.2))
11+
1112
one.line.json <- list(
1213
list(
1314
x = c(1, 2, 3, 4),
@@ -28,9 +29,15 @@ test_that("asymmetric error bars, geom_errorbar last", {
2829
geom_point()+
2930
geom_errorbar(aes(ymin=y-arrayminus, ymax=y+array))
3031
generated.json <- gg2list(one.line.gg)
32+
## BUG: lines do not appear in plotly.
33+
generated.json[[2]]$mode <- "lines+markers"
34+
## when there is 1 trace with error bars, lines, and markers, plotly
35+
## shows error bars in the background, lines in the middle and
36+
## markers in front.
3137
is.trace <- names(generated.json) == ""
3238
traces <- generated.json[is.trace]
3339
expect_identical(length(traces), 1L)
40+
## TODO: check that data agrees in one.line.json and generated.json.
3441
})
3542

3643
test_that("asymmetric error bars, geom_errorbar first", {
@@ -44,7 +51,36 @@ test_that("asymmetric error bars, geom_errorbar first", {
4451
expect_identical(length(traces), 1L)
4552
})
4653

54+
colors.json <- list(
55+
list(
56+
x = c(1, 2, 3, 4),
57+
y = c(2, 1, 3, 4),
58+
error_y = list(
59+
type = "data",
60+
symmetric = FALSE,
61+
array = c(0.1, 0.2, 0.1, 0.1),
62+
arrayminus = c(0.2, 0.4, 1, 0.2),
63+
color="red"
64+
),
65+
type = "scatter",
66+
marker=list(color="blue", size=14),
67+
line=list(color="black")
68+
)
69+
)
4770

71+
test_that("different colors for error bars, points, and lines", {
72+
one.line.gg <- ggplot(one.line.df, aes(x, y))+
73+
geom_errorbar(aes(ymin=y-arrayminus, ymax=y+array), color="red")+
74+
geom_line(color="black")+
75+
geom_point(color="blue", size=14)
76+
generated.json <- gg2list(one.line.gg)
77+
is.trace <- names(generated.json) == ""
78+
traces <- generated.json[is.trace]
79+
expect_identical(length(traces), 1L)
80+
## TODO: check that colors agree in colors.json and generated.json.
81+
})
82+
83+
if(FALSE){
4884
## from https://github.com/chriddyp/ggplot2-plotly-cookbook/blob/a45f2c70b7adf484e0b0eb8810a1e59e018adbb8/means_and_error_bars.R#L162-L191
4985
df <- ToothGrowth
5086

@@ -107,3 +143,4 @@ good.json[[1]]$error_y <-
107143
visible=TRUE,
108144
type="data")
109145

146+
}

0 commit comments

Comments
 (0)