Skip to content

Hovertemplate should allow nil values from arrays #7317

Closed
@alexcjohnson

Description

@alexcjohnson

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugsomething broken

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions