@@ -73,6 +73,13 @@ gg2list <- function(p, width = NULL, height = NULL, tooltip = "all", source = "A
73
73
scale_x <- function () scales $ get_scales(" x" )
74
74
scale_y <- function () scales $ get_scales(" y" )
75
75
panel <- ggfun(" train_position" )(panel , data , scale_x(), scale_y())
76
+ # Before mapping x/y position, save the domain (for discrete scales)
77
+ # to display in tooltip.
78
+ data <- lapply(data , function (d ) {
79
+ if (! is.null(scale_x()) && scale_x()$ is_discrete()) d $ x_plotlyDomain <- d $ x
80
+ if (! is.null(scale_y()) && scale_y()$ is_discrete()) d $ y_plotlyDomain <- d $ y
81
+ d
82
+ })
76
83
data <- ggfun(" map_position" )(panel , data , scale_x(), scale_y())
77
84
# for some geoms (e.g. boxplots) plotly.js needs the "pre-statistics" data
78
85
prestats_data <- data
@@ -245,21 +252,18 @@ gg2list <- function(p, width = NULL, height = NULL, tooltip = "all", source = "A
245
252
# stat specific mappings
246
253
grep(" ^\\ .\\ ." , as.character(x $ stat $ default_aes ), value = TRUE )
247
254
)
248
- # remove leading/trailing dots in "hidden" stat aes
249
- map <- sub(" ^\\ .\\ ." , " " , sub(" \\ .\\ .$" , " " , map ))
255
+ # "hidden" names should be taken verbatim
256
+ idx <- grepl(" ^\\ .\\ ." , map ) & grepl(" \\ .\\ .$" , map )
257
+ hiddenMap <- sub(" ^\\ .\\ ." , " " , sub(" \\ .\\ .$" , " " , map ))
258
+ map [idx ] <- hiddenMap [idx ]
259
+ names(map )[idx ] <- hiddenMap [idx ]
250
260
if (! identical(tooltip , " all" )) {
251
261
map <- map [tooltip ]
252
262
}
253
- # tooltips for discrete positional scales are misleading
254
- if (scales $ get_scales(" x" )$ is_discrete()) {
255
- map <- map [! names(map ) %in% " x" ]
256
- }
257
- if (scales $ get_scales(" y" )$ is_discrete()) {
258
- map <- map [! names(map ) %in% " y" ]
259
- }
260
263
map
261
264
})
262
265
266
+
263
267
# attach a new column (hovertext) to each layer of data that should get mapped
264
268
# to the text trace property
265
269
data <- Map(function (x , y ) {
@@ -292,10 +296,11 @@ gg2list <- function(p, width = NULL, height = NULL, tooltip = "all", source = "A
292
296
x
293
297
}, data , aesMap )
294
298
299
+
300
+
295
301
# layers -> plotly.js traces
296
- traces <- layers2traces(
297
- data , prestats_data , layers , panel $ layout , scales , p $ labels
298
- )
302
+ traces <- layers2traces(data , prestats_data , panel $ layout , p )
303
+
299
304
# default to just the text in hover info, mainly because of this
300
305
# https://github.com/plotly/plotly.js/issues/320
301
306
traces <- lapply(traces , function (tr ) {
0 commit comments