Skip to content
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

Customizing the Tooltip / Adding to the Data object #4

Open
elbamos opened this issue Oct 29, 2018 · 1 comment
Open

Customizing the Tooltip / Adding to the Data object #4

elbamos opened this issue Oct 29, 2018 · 1 comment

Comments

@elbamos
Copy link

elbamos commented Oct 29, 2018

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.

@pvictor
Copy link
Member

pvictor commented Oct 31, 2018

That's complicated... the additional data are not kept, it is not possible to refer to label. A solution will be to pass a custom JSON in the contents function and retrieve data by index and group. I'll investigate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants