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

Hovertemplate should allow nil values from arrays #7317

Open
alexcjohnson opened this issue Dec 16, 2024 · 0 comments
Open

Hovertemplate should allow nil values from arrays #7317

alexcjohnson opened this issue Dec 16, 2024 · 0 comments
Labels
bug something broken

Comments

@alexcjohnson
Copy link
Collaborator

There can be good reasons to include nil values (null, Number("NaN"), etc) in your data, but if these are displayed via hovertemplate we act like that field of the template was invalid:

https://codepen.io/alexcjohnson/pen/ogvBpNB?editors=0010

var data = [{
  x: [1,2,3,4],
  y: [1,3,2,3],
  customdata: [[1,2],[3,4],[5,6],[7,null]],
  hovertemplate: "%{customdata[0]} - %{customdata[1]}"
}];

var layout = {
  width: 400, height: 400,
};

Plotly.newPlot(gd, data, layout);
Image

This is confusing to the end viewer, and ugly. Instead, if the data array we pulled the value from explicitly had such an entry we should stringify it (the above would be "null" and "NaN" respectively) and display that. We should only display the un-templated value if you ask for an unrecognized item (%{typo}), or an index that the array doesn't have (%{customdata[2]} when the array only has 2 items for each point))

I'll be glad to make a PR for this.

@alexcjohnson alexcjohnson added the bug something broken label Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken
Projects
None yet
Development

No branches or pull requests

1 participant