diff --git a/DESCRIPTION b/DESCRIPTION index ca5fe573b0..f9b782d37a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: plotly Title: Create Interactive Web Graphics via Plotly's JavaScript Graphing Library -Version: 2.0.13 +Version: 2.0.14 Authors@R: c(person("Carson", "Sievert", role = c("aut", "cre"), email = "cpsievert1@gmail.com"), person("Chris", "Parmer", role = c("aut", "cph"), diff --git a/NEWS b/NEWS index 313c4139a6..8a4232d3b8 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,7 @@ +2.0.14 -- 13 Dec 2015 + +Fix #212 + 2.0.13 -- 12 Dec 2015 Fix #286 diff --git a/R/ggplotly.R b/R/ggplotly.R index b0d31db54f..17017686be 100644 --- a/R/ggplotly.R +++ b/R/ggplotly.R @@ -106,6 +106,8 @@ markLegends <- ## characteristics and could be drawn using just 1 trace! polygon=c("colour", "fill", "linetype", "size"), bar=c("colour", "fill"), + density=c("colour", "fill", "linetype"), + boxplot=c("colour", "fill", "size"), errorbar=c("colour", "linetype"), errorbarh=c("colour", "linetype"), area=c("colour", "fill"), @@ -114,7 +116,8 @@ markLegends <- markUnique <- as.character(unique(unlist(markLegends))) -markSplit <- c(markLegends,list(boxplot=c("x"))) +markSplit <- markLegends +markSplit$boxplot <- "x" guide_names <- function(p, aes = c("shape", "fill", "alpha", "area", "color", "colour", "size", "linetype")) { diff --git a/tests/testthat/test-ggplot-boxplot.R b/tests/testthat/test-ggplot-boxplot.R index 17a69a9122..c51097eace 100644 --- a/tests/testthat/test-ggplot-boxplot.R +++ b/tests/testthat/test-ggplot-boxplot.R @@ -1,5 +1,19 @@ context("Boxplot") +expect_traces <- function(gg, n.traces, name) { + stopifnot(is.ggplot(gg)) + stopifnot(is.numeric(n.traces)) + save_outputs(gg, paste0("boxplot-", name)) + L <- gg2list(gg) + all.traces <- L$data + 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, layout=L$layout) +} + test_that("geom_boxplot gives a boxplot", { gg <- ggplot(mtcars, aes(factor(cyl), mpg)) + geom_boxplot() @@ -43,6 +57,34 @@ test_that("you can make a boxplot for a distribution of datetimes", { expect_identical(L$data[[1]]$y, as.character(df$y)) }) +# check legend shows up when each box-and-whiskers has a fill +# make ggplot2 +m <- ggplot(mtcars, aes(factor(cyl), mpg)) +p <- m + geom_boxplot(aes(fill = factor(cyl))) +# tests +test_that("legends for boxplot", { + info <- expect_traces(p, 3, "legends_for_fill") + tr <- info$traces + la <- info$layout + expect_identical(tr[[1]]$type, "box") + # check legend exists + expect_identical(la$showlegend, TRUE) + # check legend for each fill exists + for (i in 1:3) { + expect_identical(tr[[i]]$showlegend, TRUE) + } + # check the fill colors are correct + g <- ggplot_build(p) + fill.colors <- unique(g$data[[1]]["fill"])[,1] + for (i in 1:3) { + plotly.color <- as.integer(strsplit(gsub("[\\(\\)]|rgb", "", + tr[[i]]$fillcolor), split = ",")[[1]]) + names(plotly.color) <- c("red", "green", "blue") + expect_equal(plotly.color, col2rgb(fill.colors[i])[,1], + tolerance = 1) + } +}) + dat <- data.frame( cond = factor(rep(c("A", "B", "C", "D"), each = 200)), col = factor(rep(c("C1", "C2"), each = 400)), @@ -58,4 +100,3 @@ test_that("correct # of unique fillcolors", { fills <- sapply(L$data, "[[", "fillcolor") expect_equal(length(unique(fills)), length(unique(dat$col))) }) - diff --git a/tests/testthat/test-ggplot-density.R b/tests/testthat/test-ggplot-density.R index 459e7f0e06..d6396424c6 100644 --- a/tests/testthat/test-ggplot-density.R +++ b/tests/testthat/test-ggplot-density.R @@ -32,6 +32,10 @@ test_that("geom_density() respects fill aesthetic", { fill <- unique(sapply(trs, "[[", "fill")) expect_identical(type, "scatter") expect_identical(fill, "tozeroy") + # check legend exists + expect_true(info$layout$showlegend, TRUE) + # check legend for each fill exists + expect_true(all(sapply(trs, "[[", "showlegend"))) }) test_that("geom_density() respects colour aesthetic", { diff --git a/tests/testthat/test-ggplot-trace-order.R b/tests/testthat/test-ggplot-trace-order.R new file mode 100644 index 0000000000..e69de29bb2