diff --git a/DESCRIPTION b/DESCRIPTION index 53f7fb6af7..18e50e1b92 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: plotly Type: Package Title: Interactive, publication-quality graphs online. -Version: 0.5.25 +Version: 0.5.26 Authors@R: c(person("Chris", "Parmer", role = c("aut", "cre"), email = "chris@plot.ly"), person("Scott", "Chamberlain", role = "aut", diff --git a/NEWS b/NEWS index d6834f7932..d1d6bdca77 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,7 @@ +0.5.26 -- 18 Mar 2015 + +Implemented geom_rect #178 + 0.5.25 -- 10 March 2015 Implemented geom_smooth() #183 diff --git a/R/ggplotly.R b/R/ggplotly.R index fee32a633c..08bf4af08f 100644 --- a/R/ggplotly.R +++ b/R/ggplotly.R @@ -52,7 +52,11 @@ markLegends <- # list(point=c("colour", "fill", "shape", "size"), list(point=c("colour", "fill", "shape"), path=c("linetype", "size", "colour", "shape"), - polygon=c("colour", "fill", "linetype", "size", "group"), + ## NOTE: typically "group" should not be present here, since + ## that would mean creating a separate plotly legend for each + ## group, even when they have the exact same visual + ## characteristics and could be drawn using just 1 trace! + polygon=c("colour", "fill", "linetype", "size"), bar=c("colour", "fill"), errorbar=c("colour", "linetype"), errorbarh=c("colour", "linetype"), diff --git a/R/trace_generation.R b/R/trace_generation.R index 13939c4504..2181e0e3c4 100644 --- a/R/trace_generation.R +++ b/R/trace_generation.R @@ -322,14 +322,18 @@ toBasic <- list( }) group2NA(g, "path") }, - polygon=function(g){ - if(is.null(g$params$fill)){ - g - }else if(is.na(g$params$fill)){ - group2NA(g, "path") - }else{ - g - } + rect=function(g){ + g$data$group <- 1:nrow(g$data) + used <- c("xmin", "ymin", "xmax", "ymax") + others <- g$data[!names(g$data) %in% used] + g$data <- with(g$data, { + rbind(cbind(x=xmin, y=ymin, others), + cbind(x=xmin, y=ymax, others), + cbind(x=xmax, y=ymax, others), + cbind(x=xmax, y=ymin, others)) + }) + g$geom <- "polygon" + g }, path=function(g) { group2NA(g, "path") @@ -411,7 +415,6 @@ toBasic <- list( } ) - #' Drawing ggplot2 geoms with a group aesthetic is most efficient in #' plotly when we convert groups of things that look the same to #' vectors with NA. @@ -421,16 +424,41 @@ toBasic <- list( #' @return list of geom info. #' @author Toby Dylan Hocking group2NA <- function(g, geom) { - poly.list <- split(g$data, g$data$group) + poly.list <- split(g$data, g$data$group, drop=TRUE) is.group <- names(g$data) == "group" - poly.na.df <- data.frame() - for (i in seq_along(poly.list)) { + poly.na.list <- list() + forward.i <- seq_along(poly.list) + ## When group2NA is called on geom_polygon (or geom_rect, which is + ## treated as a basic polygon), we need to retrace the first points + ## of each group, see https://github.com/ropensci/plotly/pull/178 + retrace.first.points <- g$geom == "polygon" + for (i in forward.i) { no.group <- poly.list[[i]][, !is.group, drop=FALSE] na.row <- no.group[1, ] na.row[, c("x", "y")] <- NA - poly.na.df <- rbind(poly.na.df, no.group, na.row) + retrace.first <- if(retrace.first.points){ + no.group[1,] + } + poly.na.list[[paste(i, "forward")]] <- + rbind(no.group, retrace.first, na.row) + } + if(retrace.first.points){ + backward.i <- rev(forward.i[-1])[-1] + for(i in backward.i){ + no.group <- poly.list[[i]][1, !is.group, drop=FALSE] + na.row <- no.group[1, ] + na.row[, c("x", "y")] <- NA + poly.na.list[[paste(i, "backward")]] <- rbind(no.group, na.row) + } + if(length(poly.list) > 1){ + first.group <- poly.list[[1]][1, !is.group, drop=FALSE] + poly.na.list[["last"]] <- rbind(first.group, first.group) + } + } + g$data <- do.call(rbind, poly.na.list) + if(is.na(g$data$x[nrow(g$data)])){ + g$data <- g$data[-nrow(g$data), ] } - g$data <- poly.na.df g$geom <- geom g } @@ -477,10 +505,12 @@ geom2trace <- list( line=paramORdefault(params, aes2line, line.defaults)) }, polygon=function(data, params){ - list(x=c(data$x, data$x[1]), - y=c(data$y, data$y[1]), + g <- list(data=data, geom="polygon") + g <- group2NA(g, "polygon") + list(x=g$data$x, + y=g$data$y, name=params$name, - text=data$text, + text=g$data$text, type="scatter", mode="lines", line=paramORdefault(params, aes2line, polygon.line.defaults), diff --git a/tests/testthat/test-ggplot-polygons.R b/tests/testthat/test-ggplot-polygons.R index b159e2d10a..097d9588ee 100644 --- a/tests/testthat/test-ggplot-polygons.R +++ b/tests/testthat/test-ggplot-polygons.R @@ -1,115 +1,141 @@ context("polygon") -test_that("filled polygons become several traces", { - poly.df <- data.frame(x=c(0, 1, 1, 0, 2, 3, 3, 2)+10, - y=c(0, 0, 1, 1, 0, 0, 1, 1)+10, - g=c(1, 1, 1, 1, 2, 2, 2, 2)) - poly.df$lab <- paste0("name", poly.df$g) +expect_traces <- function(gg, n.traces, name){ + stopifnot(is.ggplot(gg)) + stopifnot(is.numeric(n.traces)) + save_outputs(gg, paste0("polygon-", name)) + L <- gg2list(gg) + is.trace <- names(L) == "" + all.traces <- L[is.trace] + no.data <- sapply(all.traces, function(tr) { + is.null(tr[["x"]]) && is.null(tr[["y"]]) + }) + has.data <- all.traces[!no.data] + expect_equal(length(has.data), n.traces) + list(traces=has.data, kwargs=L$kwargs) +} + +poly.df <- data.frame(x=c(0, 1, 1, 0, 2, 3, 3, 2)+10, + y=c(0, 0, 1, 1, 0, 0, 1, 1), + g=c(1, 1, 1, 1, 2, 2, 2, 2), + lab=rep(c("left", "right"), each=4)) + +test_that("polygons filled with the same color become one trace", { gg <- ggplot(poly.df)+ geom_polygon(aes(x, y, group=g)) - info <- gg2list(gg) - expect_equal(length(info), 3) - expect_equal(info[[1]]$x, c(10, 11, 11, 10, 10)) - expect_equal(info[[1]]$y, c(10, 10, 11, 11, 10)) - expect_equal(info[[2]]$x, c(12, 13, 13, 12, 12)) - expect_equal(info[[2]]$y, c(10, 10, 11, 11, 10)) - expect_identical(info[[1]]$line$color, "transparent") - expect_identical(info[[2]]$line$color, "transparent") - - expect_identical(info[[1]]$showlegend, FALSE) - expect_identical(info[[2]]$showlegend, FALSE) - - save_outputs(gg, "polygons-filled-polygons") - - first.color <- rgb(0.23, 0.45, 0.67) - gg <- ggplot(poly.df)+ - geom_polygon(aes(x, y, color=lab), fill="grey")+ - scale_color_manual(values=c(name1=first.color, name2="springgreen3")) - info <- gg2list(gg) - expect_equal(length(info), 3) - expect_equal(info[[1]]$x, c(10, 11, 11, 10, 10)) - expect_equal(info[[1]]$y, c(10, 10, 11, 11, 10)) - expect_equal(info[[1]]$fillcolor, toRGB("grey")) - expect_equal(info[[1]]$line$color, toRGB(first.color)) - expect_equal(info[[1]]$name, "name1") - expect_equal(info[[2]]$x, c(12, 13, 13, 12, 12)) - expect_equal(info[[2]]$y, c(10, 10, 11, 11, 10)) - expect_equal(info[[2]]$fillcolor, toRGB("grey")) - expect_equal(info[[2]]$line$color, toRGB("springgreen3")) - expect_equal(info[[2]]$name, "name2") - - expect_identical(info[[1]]$showlegend, TRUE) - expect_identical(info[[2]]$showlegend, TRUE) + info <- expect_traces(gg, 1, "black") + tr <- info$traces[[1]] + expected.x <- + c(10, 11, 11, 10, 10, NA, + 12, 13, 13, 12, 12, NA, + 10, 10) + expect_equal(tr$x, expected.x) + expect_equal(tr$fill, "tozerox") + expected.y <- + c(0, 0, 1, 1, 0, NA, + 0, 0, 1, 1, 0, NA, + 0, 0) + expect_equal(tr$y, expected.y) + expect_identical(tr$line$color, "transparent") + expect_identical(tr$line$color, "transparent") +}) - save_outputs(gg, "polygons-springgreen3") +blue.color <- rgb(0.23, 0.45, 0.67) +test_that("polygons with different color become separate traces", { + gg <- ggplot(poly.df)+ + geom_polygon(aes(x, y, color=lab), fill="grey")+ + scale_color_manual(values=c(left=blue.color, right="springgreen3")) + info <- expect_traces(gg, 2, "aes-color") + traces.by.name <- list() + for(tr in info$traces){ + expect_equal(tr$fillcolor, toRGB("grey")) + expect_equal(tr$fill, "tozerox") + traces.by.name[[tr$name]] <- tr + } + expect_equal(traces.by.name$left$x, c(10, 11, 11, 10, 10)) + expect_equal(traces.by.name$left$y, c(0, 0, 1, 1, 0)) + expect_equal(traces.by.name$right$x, c(12, 13, 13, 12, 12)) + expect_equal(traces.by.name$right$y, c(0, 0, 1, 1, 0)) + expect_equal(traces.by.name$left$line$color, toRGB(blue.color)) + expect_equal(traces.by.name$right$line$color, toRGB("springgreen3")) +}) - first.color <- rgb(0.23, 0.45, 0.67) +test_that("geom_polygon(aes(fill)) -> fillcolor + line$color transparent", { gg <- ggplot(poly.df)+ geom_polygon(aes(x, y, fill=lab))+ - scale_fill_manual(values=c(name1=first.color, name2="springgreen3")) - info <- gg2list(gg) - expect_equal(length(info), 3) - expect_equal(info[[1]]$x, c(10, 11, 11, 10, 10)) - expect_equal(info[[1]]$y, c(10, 10, 11, 11, 10)) - expect_equal(info[[1]]$fillcolor, toRGB(first.color)) - expect_equal(info[[1]]$name, "name1") - expect_equal(info[[2]]$x, c(12, 13, 13, 12, 12)) - expect_equal(info[[2]]$y, c(10, 10, 11, 11, 10)) - expect_equal(info[[2]]$fillcolor, toRGB("springgreen3")) - expect_equal(info[[2]]$name, "name2") - - expect_identical(info[[1]]$showlegend, TRUE) - expect_identical(info[[2]]$showlegend, TRUE) - - save_outputs(gg, "polygons-springgreen3-lab") + scale_fill_manual(values=c(left=blue.color, right="springgreen3")) + info <- expect_traces(gg, 2, "aes-fill") + traces.by.name <- list() + for(tr in info$traces){ + expect_equal(tr$line$color, "transparent") + traces.by.name[[tr$name]] <- tr + } + expect_equal(traces.by.name$left$x, c(10, 11, 11, 10, 10)) + expect_equal(traces.by.name$left$y, c(0, 0, 1, 1, 0)) + expect_equal(traces.by.name$right$x, c(12, 13, 13, 12, 12)) + expect_equal(traces.by.name$right$y, c(0, 0, 1, 1, 0)) + expect_equal(traces.by.name$left$fillcolor, toRGB(blue.color)) + expect_equal(traces.by.name$right$fillcolor, toRGB("springgreen3")) +}) +test_that("geom_polygon(aes(fill), color) -> line$color", { + gg <- ggplot(poly.df)+ + geom_polygon(aes(x, y, fill=lab), color="black")+ + scale_fill_manual(values=c(left=blue.color, right="springgreen3")) + info <- expect_traces(gg, 2, "color-aes-fill") + traces.by.name <- list() + for(tr in info$traces){ + expect_equal(tr$line$color, toRGB("black")) + expect_equal(tr$fill, "tozerox") + traces.by.name[[tr$name]] <- tr + } + expect_equal(traces.by.name$left$x, c(10, 11, 11, 10, 10)) + expect_equal(traces.by.name$left$y, c(0, 0, 1, 1, 0)) + expect_equal(traces.by.name$right$x, c(12, 13, 13, 12, 12)) + expect_equal(traces.by.name$right$y, c(0, 0, 1, 1, 0)) + expect_equal(traces.by.name$left$fillcolor, toRGB(blue.color)) + expect_equal(traces.by.name$right$fillcolor, toRGB("springgreen3")) +}) +test_that("geom_polygon(aes(linetype), fill, color)", { gg <- ggplot(poly.df)+ geom_polygon(aes(x, y, linetype=lab), fill="red", colour="blue")+ - scale_linetype_manual(values=c(name1="dotted", name2="dashed")) - info <- gg2list(gg) - expect_equal(length(info), 3) - expect_equal(info[[1]]$x, c(10, 11, 11, 10, 10)) - expect_equal(info[[1]]$y, c(10, 10, 11, 11, 10)) - expect_equal(info[[1]]$fillcolor, toRGB("red")) - expect_equal(info[[1]]$line$color, toRGB("blue")) - expect_equal(info[[1]]$line$dash, "dot") - expect_equal(info[[1]]$name, "name1") - expect_equal(info[[2]]$x, c(12, 13, 13, 12, 12)) - expect_equal(info[[2]]$y, c(10, 10, 11, 11, 10)) - expect_equal(info[[2]]$fillcolor, toRGB("red")) - expect_equal(info[[2]]$line$color, toRGB("blue")) - expect_equal(info[[2]]$line$dash, "dash") - expect_equal(info[[2]]$name, "name2") - - expect_identical(info[[1]]$showlegend, TRUE) - expect_identical(info[[2]]$showlegend, TRUE) - - save_outputs(gg, "polygons-dashed") - + scale_linetype_manual(values=c(left="dotted", right="dashed")) + info <- expect_traces(gg, 2, "color-fill-aes-linetype") + traces.by.name <- list() + for(tr in info$traces){ + expect_equal(tr$fillcolor, toRGB("red")) + expect_equal(tr$line$color, toRGB("blue")) + expect_equal(tr$fill, "tozerox") + traces.by.name[[tr$name]] <- tr + } + expect_equal(traces.by.name$left$x, c(10, 11, 11, 10, 10)) + expect_equal(traces.by.name$left$y, c(0, 0, 1, 1, 0)) + expect_equal(traces.by.name$left$line$dash, "dot") + expect_equal(traces.by.name$right$x, c(12, 13, 13, 12, 12)) + expect_equal(traces.by.name$right$y, c(0, 0, 1, 1, 0)) + expect_equal(traces.by.name$right$line$dash, "dash") +}) +test_that("geom_polygon(aes(size), fill, colour)", { gg <- ggplot(poly.df)+ geom_polygon(aes(x, y, size=lab), fill="orange", colour="black")+ - scale_size_manual(values=c(name1=2, name2=3)) - info <- gg2list(gg) - expect_equal(length(info), 3) - expect_equal(info[[1]]$x, c(10, 11, 11, 10, 10)) - expect_equal(info[[1]]$y, c(10, 10, 11, 11, 10)) - expect_equal(info[[1]]$fillcolor, toRGB("orange")) - expect_equal(info[[1]]$line$width, 4) - expect_equal(info[[1]]$name, "name1") - expect_equal(info[[2]]$x, c(12, 13, 13, 12, 12)) - expect_equal(info[[2]]$y, c(10, 10, 11, 11, 10)) - expect_equal(info[[2]]$fillcolor, toRGB("orange")) - expect_equal(info[[2]]$line$width, 6) - expect_equal(info[[2]]$name, "name2") - - expect_identical(info[[1]]$showlegend, TRUE) - expect_identical(info[[2]]$showlegend, TRUE) - - save_outputs(gg, "polygons-halloween") - + scale_size_manual(values=c(left=2, right=3)) + info <- expect_traces(gg, 2, "color-fill-aes-linetype") + traces.by.name <- list() + for(tr in info$traces){ + expect_equal(tr$fillcolor, toRGB("orange")) + expect_equal(tr$line$color, toRGB("black")) + expect_equal(tr$fill, "tozerox") + traces.by.name[[tr$name]] <- tr + } + expect_equal(traces.by.name$left$x, c(10, 11, 11, 10, 10)) + expect_equal(traces.by.name$left$y, c(0, 0, 1, 1, 0)) + expect_equal(traces.by.name$right$x, c(12, 13, 13, 12, 12)) + expect_equal(traces.by.name$right$y, c(0, 0, 1, 1, 0)) + expect_false(traces.by.name$left$line$width == + traces.by.name$right$line$width) }) test_that("borders become one trace with NA", { @@ -122,5 +148,62 @@ test_that("borders become one trace with NA", { tr <- info[[1]] expect_true(any(is.na(tr$x))) - save_outputs(gg, "polygons-borders") + save_outputs(gg, "polygons-canada-borders") +}) + +x <- c(0, -1, 2, -2, 1) +y <- c(2, 0, 1, 1, 0) +stars <- + rbind(data.frame(x, y, group="left"), + data.frame(x=x+10, y, group="right")) +star.group <- ggplot(stars)+ + geom_polygon(aes(x, y, group=group)) + +test_that("geom_polygon(aes(group)) -> 1 trace", { + info <- expect_traces(star.group, 1, "star-group") + tr <- info$traces[[1]] + expect_equal(tr$fill, "tozerox") + expect_equal(tr$x, + c(0, -1, 2, -2, 1, 0, NA, + 10, 9, 12, 8, 11, 10, NA, + 0, 0)) + expect_equal(tr$y, + c(2, 0, 1, 1, 0, 2, NA, + 2, 0, 1, 1, 0, 2, NA, + 2, 2)) +}) + +star.group.color <- ggplot(stars)+ + geom_polygon(aes(x, y, group=group), color="red") + +test_that("geom_polygon(aes(group), color) -> 1 trace", { + info <- expect_traces(star.group.color, 1, "star-group-color") + tr <- info$traces[[1]] + expect_equal(tr$fill, "tozerox") + expect_equal(tr$line$color, toRGB("red")) + expect_equal(tr$x, + c(0, -1, 2, -2, 1, 0, NA, + 10, 9, 12, 8, 11, 10, NA, + 0, 0)) + expect_equal(tr$y, + c(2, 0, 1, 1, 0, 2, NA, + 2, 0, 1, 1, 0, 2, NA, + 2, 2)) +}) + +star.fill.color <- ggplot(stars)+ + geom_polygon(aes(x, y, group=group, fill=group), color="black") + +test_that("geom_polygon(aes(group, fill), color) -> 2 trace", { + info <- expect_traces(star.fill.color, 2, "star-fill-color") + tr <- info$traces[[1]] + traces.by.name <- list() + for(tr in info$traces){ + expect_equal(tr$line$color, toRGB("black")) + expect_equal(tr$fill, "tozerox") + expect_equal(tr$y, c(2, 0, 1, 1, 0, 2)) + traces.by.name[[tr$name]] <- tr + } + expect_equal(traces.by.name$left$x, c(0, -1, 2, -2, 1, 0)) + expect_equal(traces.by.name$right$x, c(10, 9, 12, 8, 11, 10)) }) diff --git a/tests/testthat/test-ggplot-rect.R b/tests/testthat/test-ggplot-rect.R new file mode 100644 index 0000000000..964698a8a3 --- /dev/null +++ b/tests/testthat/test-ggplot-rect.R @@ -0,0 +1,147 @@ +context("geom_rect") + +expect_traces <- function(gg, n.traces, name){ + stopifnot(is.ggplot(gg)) + stopifnot(is.numeric(n.traces)) + save_outputs(gg, paste0("rect-", name)) + L <- gg2list(gg) + is.trace <- names(L) == "" + all.traces <- L[is.trace] + no.data <- sapply(all.traces, function(tr) { + is.null(tr[["x"]]) && is.null(tr[["y"]]) + }) + has.data <- all.traces[!no.data] + expect_equal(length(has.data), n.traces) + list(traces=has.data, kwargs=L$kwargs) +} + +set.seed(1) +df <- data.frame( + x = sample(10, 20, replace = TRUE), + y = sample(10, 20, replace = TRUE) +) + +gg <- ggplot(df, aes(xmin = x, xmax = x + 1, ymin = y, ymax = y + 2)) + + geom_rect() + +test_that('geom_rect becomes 1 trace with mode="lines" fill="tozerox"', { + info <- expect_traces(gg, 1, "black") + tr <- info$traces[[1]] + expect_identical(tr$fill, "tozerox") + expect_identical(tr$type, "scatter") + expect_identical(tr$mode, "lines") + for(xy in c("x", "y")){ + expect_true(anyNA(tr[[xy]])) + } +}) + +df4 <- data.frame(x=1:4, status=c("cool", "not", "not", "cool")) + +gg4 <- ggplot(df4, aes(xmin = x, xmax = x + 0.5, ymin = 0, ymax = 1)) + + geom_rect() + +test_that('trace contains NA back to 1st rect', { + info <- expect_traces(gg4, 1, "black4") + tr <- info$traces[[1]] + expect_identical(tr$fill, "tozerox") + expect_identical(tr$type, "scatter") + expect_identical(tr$mode, "lines") + expected.x <- c(1, 1, 1.5, 1.5, 1, NA, + 2, 2, 2.5, 2.5, 2, NA, + 3, 3, 3.5, 3.5, 3, NA, + 4, 4, 4.5, 4.5, 4, NA, + 3, NA, + 2, NA, + 1, 1) + expect_equal(tr$x, expected.x) + expected.y <- c(0, 1, 1, 0, 0, NA, + 0, 1, 1, 0, 0, NA, + 0, 1, 1, 0, 0, NA, + 0, 1, 1, 0, 0, NA, + 0, NA, + 0, NA, + 0, 0) + expect_equal(tr$y, expected.y) +}) + +rect.color <- ggplot(df4, aes(xmin = x, xmax = x + 0.5, ymin = 0, ymax = 1)) + + geom_rect(aes(color=status), fill="grey") + +test_that('rect color', { + info <- expect_traces(rect.color, 2, "color") + traces.by.name <- list() + for(tr in info$traces){ + expect_equal(tr$fillcolor, toRGB("grey")) + expect_equal(tr$fill, "tozerox") + expect_equal(tr$y, + c(0, 1, 1, 0, 0, NA, + 0, 1, 1, 0, 0, NA, + 0, 0)) + traces.by.name[[tr$name]] <- tr + } + expect_equal(traces.by.name$cool$x, + c(1, 1, 1.5, 1.5, 1, NA, + 4, 4, 4.5, 4.5, 4, NA, + 1, 1)) + expect_equal(traces.by.name$not$x, + c(2, 2, 2.5, 2.5, 2, NA, + 3, 3, 3.5, 3.5, 3, NA, + 2, 2)) + expect_false(traces.by.name$not$line$color == + traces.by.name$cool$line$color) +}) + +rect.fill <- ggplot(df4, aes(xmin = x, xmax = x + 0.5, ymin = 0, ymax = 1)) + + geom_rect(aes(fill=status)) + +test_that('rect color', { + info <- expect_traces(rect.fill, 2, "fill") + traces.by.name <- list() + for(tr in info$traces){ + expect_equal(tr$line$color, "transparent") + expect_equal(tr$fill, "tozerox") + expect_equal(tr$y, + c(0, 1, 1, 0, 0, NA, + 0, 1, 1, 0, 0, NA, + 0, 0)) + traces.by.name[[tr$name]] <- tr + } + expect_equal(traces.by.name$cool$x, + c(1, 1, 1.5, 1.5, 1, NA, + 4, 4, 4.5, 4.5, 4, NA, + 1, 1)) + expect_equal(traces.by.name$not$x, + c(2, 2, 2.5, 2.5, 2, NA, + 3, 3, 3.5, 3.5, 3, NA, + 2, 2)) + expect_false(traces.by.name$not$fillcolor == + traces.by.name$cool$fillcolor) +}) + +rect.fill.color <- + ggplot(df4, aes(xmin = x, xmax = x + 0.5, ymin = 0, ymax = 1)) + + geom_rect(aes(fill=status), color="black") + +test_that('rect aes(fill) with constant color', { + info <- expect_traces(rect.fill.color, 2, "fill-color") + traces.by.name <- list() + for(tr in info$traces){ + expect_equal(tr$line$color, toRGB("black")) + expect_equal(tr$fill, "tozerox") + expect_equal(tr$y, + c(0, 1, 1, 0, 0, NA, + 0, 1, 1, 0, 0, NA, + 0, 0)) + traces.by.name[[tr$name]] <- tr + } + expect_equal(traces.by.name$cool$x, + c(1, 1, 1.5, 1.5, 1, NA, + 4, 4, 4.5, 4.5, 4, NA, + 1, 1)) + expect_equal(traces.by.name$not$x, + c(2, 2, 2.5, 2.5, 2, NA, + 3, 3, 3.5, 3.5, 3, NA, + 2, 2)) + expect_false(traces.by.name$not$fillcolor == + traces.by.name$cool$fillcolor) +})