From 42f0d106c8c5f94777c81e988e326e633686c51b Mon Sep 17 00:00:00 2001 From: Carson Sievert Date: Thu, 7 Mar 2019 17:48:15 -0600 Subject: [PATCH 1/3] Be more careful about searching for default aesthetics, closes #1457 --- R/layers2traces.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/layers2traces.R b/R/layers2traces.R index 563b8174cf..d854e8b841 100644 --- a/R/layers2traces.R +++ b/R/layers2traces.R @@ -999,7 +999,7 @@ aes2plotly <- function(data, params, aes = "size") { defaults <- if (inherits(data, "GeomSf")) { type <- if (any(grepl("point", class(data)))) "point" else if (any(grepl("line", class(data)))) "line" else "" ggfun("default_aesthetics")(type) - } else { + } else if ("default_aes" %in% names(ggfun(geom))) { ggfun(geom)$default_aes } From 18e66d20e90f9a800b387e0ffb724bb08b705ccb Mon Sep 17 00:00:00 2001 From: Carson Sievert Date: Mon, 11 Mar 2019 14:51:47 -0500 Subject: [PATCH 2/3] stylistic changes --- R/layers2traces.R | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/R/layers2traces.R b/R/layers2traces.R index d854e8b841..fba34f75c9 100644 --- a/R/layers2traces.R +++ b/R/layers2traces.R @@ -999,8 +999,13 @@ aes2plotly <- function(data, params, aes = "size") { defaults <- if (inherits(data, "GeomSf")) { type <- if (any(grepl("point", class(data)))) "point" else if (any(grepl("line", class(data)))) "line" else "" ggfun("default_aesthetics")(type) - } else if ("default_aes" %in% names(ggfun(geom))) { - ggfun(geom)$default_aes + } else { + geom_obj <- ggfun(geom) + # If the first class of `data` is a data.frame, + # ggfun() returns a function because ggplot2 now + # defines data.frame in it's namespace + # https://github.com/ropensci/plotly/pull/1481 + if ("default_aes" %in% names(geom_obj)) geom_obj$default_aes else NULL } vals <- uniq(data[[aes]]) %||% params[[aes]] %||% defaults[[aes]] %||% NA From 37b79e935f1eec70e3e68b07504b885e64b0b117 Mon Sep 17 00:00:00 2001 From: Carson Sievert Date: Mon, 11 Mar 2019 14:53:26 -0500 Subject: [PATCH 3/3] support the new Layer method setup_layer() --- R/ggplotly.R | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/R/ggplotly.R b/R/ggplotly.R index e3d2097e64..6e0c2d9009 100644 --- a/R/ggplotly.R +++ b/R/ggplotly.R @@ -236,10 +236,18 @@ gg2list <- function(p, width = NULL, height = NULL, out } + # ggplot2 3.1.0.9000 introduced a Layer method named setup_layer() + # currently, LayerSf is the only core-ggplot2 Layer that makes use + # of it https://github.com/tidyverse/ggplot2/pull/2875 + data <- layer_data + if (packageVersion("ggplot2") > "3.1.0") { + data <- by_layer(function(l, d) l$setup_layer(d, plot)) + } + # Initialise panels, add extra data for margins & missing facetting # variables, and add on a PANEL variable to data layout <- ggfun("create_layout")(plot$facet, plot$coordinates) - data <- layout$setup(layer_data, plot$data, plot$plot_env) + data <- layout$setup(data, plot$data, plot$plot_env) # save the domain of the group for display in tooltips groupDomains <- Map(function(x, y) {