diff --git a/DESCRIPTION b/DESCRIPTION index e462eebcd4..b1f9c1db81 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: plotly Type: Package Title: Interactive, publication-quality graphs online. -Version: 0.5.19 +Version: 0.5.20 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 3ec054e9c8..4a5c9c3b12 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,8 @@ +0.5.20 -- 9 February 2015. + +Add alpha transparency to fill conversion. +Let geom_area support colour and fill aesthetics. + 0.5.19 -- 23 January 2015. Support class conversion such as as.Date() within ggplot code. diff --git a/R/colour_conversion.R b/R/colour_conversion.R index 7a7ab318ff..1f520c15fd 100644 --- a/R/colour_conversion.R +++ b/R/colour_conversion.R @@ -1,6 +1,6 @@ #' Convert R colours to RGBA hexadecimal colour values #' @param x character for colour, for example: "white" -#' @param alpha alpha +#' @param alpha transparency alpha #' @return hexadecimal colour value (if is.na(x), return "transparent" for compatibility with Plotly) #' @export toRGB <- function(x, alpha=1) { @@ -20,7 +20,8 @@ toRGB <- function(x, alpha=1) { #' Use default ggplot colour for fill (gray20) if not declared #' @param x character for colour +#' @param alpha transparency alpha #' @return hexadecimal colour value -toFill <- function(x) { - ifelse(!is.null(x), toRGB(x), toRGB("gray20")) +toFill <- function(x, alpha=1) { + ifelse(!is.null(x), toRGB(x, alpha), toRGB("gray20", alpha)) } diff --git a/R/ggplotly.R b/R/ggplotly.R index 49c4b4a872..868122718f 100644 --- a/R/ggplotly.R +++ b/R/ggplotly.R @@ -52,6 +52,7 @@ markLegends <- path=c("linetype", "size", "colour", "shape"), polygon=c("colour", "fill", "linetype", "size", "group"), bar=c("colour", "fill"), + area=c("colour", "fill"), step=c("linetype", "size", "colour"), boxplot=c("x"), text=c("colour")) diff --git a/R/plotly-package.r b/R/plotly-package.r index a39c58d874..96ec60eb3f 100644 --- a/R/plotly-package.r +++ b/R/plotly-package.r @@ -7,7 +7,7 @@ #' \itemize{ #' \item Package: plotly #' \item Type: Package -#' \item Version: 0.5.19 +#' \item Version: 0.5.20 #' \item Date: 2014-03-07 #' \item License: MIT #' } diff --git a/R/plotly.R b/R/plotly.R index 7fb269893e..7e86ed3db3 100644 --- a/R/plotly.R +++ b/R/plotly.R @@ -82,7 +82,7 @@ For more help, see https://plot.ly/R or contact .") # public attributes/methods that the user has access to pub <- list(username=username, key=key, filename="from api", fileopt=NULL, - version="0.5.19") + version="0.5.20") priv <- list() pub$makecall <- function(args, kwargs, origin) { diff --git a/R/trace_generation.R b/R/trace_generation.R index 5477972f5d..3457c78b40 100644 --- a/R/trace_generation.R +++ b/R/trace_generation.R @@ -556,7 +556,8 @@ geom2trace <- list( type="scatter", line=paramORdefault(params, aes2line, ribbon.line.defaults), fill="tozeroy", - fillcolor=toFill(params$fill)) + fillcolor=toFill(params$fill, ifelse(is.null(params$alpha), 1, + params$alpha))) }, ribbon=function(data, params) { list(x=c(data$x[1], data$x, rev(data$x)), diff --git a/tests/testthat/test-ggplot-area.R b/tests/testthat/test-ggplot-area.R index 3fef99ad47..49ec966aec 100644 --- a/tests/testthat/test-ggplot-area.R +++ b/tests/testthat/test-ggplot-area.R @@ -15,3 +15,14 @@ test_that("sanity check for geom_area", { }) save_outputs(ar, "area") + +# Test alpha transparency in fill color +gg <- ggplot(huron) + geom_area(aes(x=year, y=level), alpha=0.4) +L <- gg2list(gg) + +test_that("transparency alpha in geom_area is converted", { + expect_identical(L[[1]]$line$color, "transparent") + expect_identical(L[[1]]$fillcolor, "rgba(51,51,51,0.4)") +}) + +save_outputs(gg, "area-fillcolor")