diff --git a/R/ggplotly.R b/R/ggplotly.R index e29dd2b907..6db8b6547b 100644 --- a/R/ggplotly.R +++ b/R/ggplotly.R @@ -88,6 +88,7 @@ ggplotly.ggmatrix <- function(p = ggplot2::last_plot(), width = NULL, height = NULL, tooltip = "all", dynamicTicks = FALSE, layerData = 1, originalData = TRUE, source = "A", ...) { dots <- list(...) + # provide a sensible crosstalk if none is already provided (makes ggnostic() work at least) if (!crosstalk_key() %in% names(p$data)) { p$data[[crosstalk_key()]] <- p$data[[".rownames"]] %||% seq_len(nrow(p$data)) diff --git a/R/layers2traces.R b/R/layers2traces.R index 0387d34c5c..7e1ab5e640 100644 --- a/R/layers2traces.R +++ b/R/layers2traces.R @@ -23,8 +23,11 @@ layers2traces <- function(data, prestats_data, layout, p) { # turn symbol (e.g., ..count..) & call (e.g. calc(count)) mappings into text labels map <- ggfun("make_labels")(map) + # filter tooltip aesthetics down to those specified in `tooltip` arg if (!identical(p$tooltip, "all")) { + # rectify tooltips, ggplot automatically convert `color` => `colour` + p$tooltip[p$tooltip == "color"] <- "colour" map <- map[names(map) %in% p$tooltip | map %in% p$tooltip] } diff --git a/tests/testthat/_snaps/ggplot-theme/theme-marker-default.svg b/tests/testthat/_snaps/ggplot-theme/theme-marker-default.svg index fe353c297e..85424aa0cd 100644 --- a/tests/testthat/_snaps/ggplot-theme/theme-marker-default.svg +++ b/tests/testthat/_snaps/ggplot-theme/theme-marker-default.svg @@ -1 +1 @@ -2340.40.81.21.6countrypopulationParaguayPeruPhilippineseduilln +2340.40.81.21.6countrypopulationParaguayPeruPhilippineseduilln diff --git a/tests/testthat/_snaps/plotly-area/add-area.svg b/tests/testthat/_snaps/plotly-area/add-area.svg new file mode 100644 index 0000000000..467003cc86 --- /dev/null +++ b/tests/testthat/_snaps/plotly-area/add-area.svg @@ -0,0 +1 @@ +NorthN-EEastS-ESouthS-WWestN-W0%50%100%150%200%11-14 m/s8-11 m/s5-8 m/sless than m/s diff --git a/tests/testthat/test-ggplot-color.R b/tests/testthat/test-ggplot-color.R new file mode 100644 index 0000000000..012b888977 --- /dev/null +++ b/tests/testthat/test-ggplot-color.R @@ -0,0 +1,10 @@ +df = data.frame(width = 1:3, height = 1:3, col = letters[1:3]) +test_that("ggplotly automatically converts `color` aes to `colour`", { + p <- qplot(width, height, + data = df, color = col) + # color variable is not shown + color <- plotly_build(ggplotly(p, tooltip = c("color"))) + # colour (with u!) variable is shown + expect_identical(color$x$data, plotly_build(ggplotly(p, tooltip = c("colour")))$x$data) +}) +