Skip to content

Fixes #516

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 17, 2016
Merged

Fixes #516

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: plotly
Title: Create Interactive Web Graphics via 'plotly.js'
Version: 3.4.3
Version: 3.4.4
Authors@R: c(person("Carson", "Sievert", role = c("aut", "cre"),
email = "cpsievert1@gmail.com"),
person("Chris", "Parmer", role = c("aut", "cph"),
Expand Down
6 changes: 6 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
3.4.4 -- 17 Mar 2016

BUGFIX:

Show discrete positional values in tooltip (see #515); better GeomTile conversion; pass plot object into layers2traces.

3.4.3 -- 14 Mar 2016

BUGFIX:
Expand Down
29 changes: 17 additions & 12 deletions R/ggplotly.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ gg2list <- function(p, width = NULL, height = NULL, tooltip = "all", source = "A
scale_x <- function() scales$get_scales("x")
scale_y <- function() scales$get_scales("y")
panel <- ggfun("train_position")(panel, data, scale_x(), scale_y())
# Before mapping x/y position, save the domain (for discrete scales)
# to display in tooltip.
data <- lapply(data, function(d) {
if (!is.null(scale_x()) && scale_x()$is_discrete()) d$x_plotlyDomain <- d$x
if (!is.null(scale_y()) && scale_y()$is_discrete()) d$y_plotlyDomain <- d$y
d
})
data <- ggfun("map_position")(panel, data, scale_x(), scale_y())
# for some geoms (e.g. boxplots) plotly.js needs the "pre-statistics" data
prestats_data <- data
Expand Down Expand Up @@ -187,21 +194,18 @@ gg2list <- function(p, width = NULL, height = NULL, tooltip = "all", source = "A
# stat specific mappings
grep("^\\.\\.", as.character(x$stat$default_aes), value = TRUE)
)
# remove leading/trailing dots in "hidden" stat aes
map <- sub("^\\.\\.", "", sub("\\.\\.$", "", map))
# "hidden" names should be taken verbatim
idx <- grepl("^\\.\\.", map) & grepl("\\.\\.$", map)
hiddenMap <- sub("^\\.\\.", "", sub("\\.\\.$", "", map))
map[idx] <- hiddenMap[idx]
names(map)[idx] <- hiddenMap[idx]
if (!identical(tooltip, "all")) {
map <- map[tooltip]
}
# tooltips for discrete positional scales are misleading
if (scales$get_scales("x")$is_discrete()) {
map <- map[!names(map) %in% "x"]
}
if (scales$get_scales("y")$is_discrete()) {
map <- map[!names(map) %in% "y"]
}
map
})


# attach a new column (hovertext) to each layer of data that should get mapped
# to the text trace property
data <- Map(function(x, y) {
Expand Down Expand Up @@ -234,10 +238,11 @@ gg2list <- function(p, width = NULL, height = NULL, tooltip = "all", source = "A
x
}, data, aesMap)



# layers -> plotly.js traces
traces <- layers2traces(
data, prestats_data, layers, panel$layout, scales, p$labels
)
traces <- layers2traces(data, prestats_data, panel$layout, p)

# default to just the text in hover info, mainly because of this
# https://github.com/plotly/plotly.js/issues/320
traces <- lapply(traces, function(tr) {
Expand Down
Loading