Skip to content

Customizing the Tooltip / Adding to the Data object #4

@elbamos

Description

@elbamos

I'd like to customize the tooltip shown when a user hovers over a scatterplot point. To do this, I need to pull data out of the data object passed to format.contents. However, not all of the fields from my data.frame are getting into data. How can I add fields to data, or otherwise get the other columns from the data.frame into the right place?

Here is an example that should illustrate what I mean:

data.frame(
  x = rnorm(200), 
  y = rnorm(200), 
  group = sample(letters[1:3], size=200, replace=T), 
  label = sample(letters[4:26], size=200, replace=T) 
) %>%
  billboarder(data=.) %>%
  bb_aes(x = x, y = y, group=group, label=label) %>%
  bb_scatterplot() %>%
  bb_tooltip(grouped=FALSE, 
             contents = htmlwidgets::JS(
               "function(data, titleFormat, valueFormat, color) {console.log(data);return `<table><tr><td>${data[0].label}</td></tr><tr><td>${data[0].x}</td></tr><tr><td>${data[0].value}</td></tr></table>`;}"
             ))

As of now, the labels are all undefined, because data has group for both the id and name fields.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions