@@ -189,7 +189,6 @@ gg2list <- function(p, width = NULL, height = NULL, tooltip = "all", source = "A
189189 )
190190 # remove leading/trailing dots in "hidden" stat aes
191191 map <- sub(" ^\\ .\\ ." , " " , sub(" \\ .\\ .$" , " " , map ))
192- # TODO: allow users to specify a _list_ of mappings?
193192 if (! identical(tooltip , " all" )) {
194193 map <- map [tooltip ]
195194 }
@@ -217,17 +216,17 @@ gg2list <- function(p, width = NULL, height = NULL, tooltip = "all", source = "A
217216 scaleName <- scales $ get_scales(aesName )$ scale_name
218217 # convert "milliseconds from the UNIX epoch" to a date/datetime
219218 # http://stackoverflow.com/questions/13456241/convert-unix-epoch-to-date-object-in-r
220- if (" datetime" %in% scaleName ) forMat <- function (x ) as.POSIXct(x / 1000 , origin = " 1970-01-01" )
219+ if (" datetime" %in% scaleName ) forMat <- function (x ) as.POSIXct(x , origin = " 1970-01-01" )
221220 # convert "days from the UNIX epoch" to a date/datetime
222221 if (" date" %in% scaleName ) forMat <- function (x ) as.Date(as.POSIXct(x * 86400 , origin = " 1970-01-01" ))
223222 }
224223 # add a line break if hovertext already exists
225224 if (" hovertext" %in% names(x )) x $ hovertext <- paste0(x $ hovertext , " <br>" )
226- x $ hovertext <- paste0(
227- x $ hovertext ,
228- varName , " : " ,
229- forMat(x [[paste0(aesName , " _plotlyDomain" )]] %|| % x [[aesName ]])
230- )
225+ # text aestheic should be taken verbatim (for custom tooltips)
226+ prefix <- if (identical( aesName , " text " )) " " else paste0( varName , " : " )
227+ # look for the domain, if that's not found, provide the range (useful for identity scales)
228+ suffix <- forMat(x [[paste0(aesName , " _plotlyDomain" )]] %|| % x [[aesName ]])
229+ x $ hovertext <- paste0( x $ hovertext , prefix , suffix )
231230 }
232231 x
233232 }, data , aesMap )
0 commit comments