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

reuse x/y/z/base in hover data #3018

Merged
merged 2 commits into from
Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).


## [4.14.3] - UNRELEASED

### Fixed

- `px.timeline()` now allows `hover_data` formatting of start and end times [3018](https://github.com/plotly/plotly.py/pull/3018)


## [4.14.2] - 2021-01-11

### Updated
Expand Down
21 changes: 15 additions & 6 deletions packages/python/plotly/plotly/express/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,10 @@ def make_trace_kwargs(args, trace_spec, trace_data, mapping_labels, sizeref):
trace_patch[error_xy] = {}
trace_patch[error_xy][arr] = trace_data[attr_value]
elif attr_name == "custom_data":
# here we store a data frame in customdata, and it's serialized
# as a list of row lists, which is what we want
trace_patch["customdata"] = trace_data[attr_value]
if len(attr_value) > 0:
# here we store a data frame in customdata, and it's serialized
# as a list of row lists, which is what we want
trace_patch["customdata"] = trace_data[attr_value]
elif attr_name == "hover_name":
if trace_spec.constructor not in [
go.Histogram,
Expand All @@ -398,6 +399,13 @@ def make_trace_kwargs(args, trace_spec, trace_data, mapping_labels, sizeref):
for col in attr_value:
if hover_is_dict and not attr_value[col]:
continue
if col in [
args.get("x", None),
args.get("y", None),
args.get("z", None),
args.get("base", None),
]:
continue
try:
position = args["custom_data"].index(col)
except (ValueError, AttributeError, KeyError):
Expand All @@ -408,9 +416,10 @@ def make_trace_kwargs(args, trace_spec, trace_data, mapping_labels, sizeref):
position
)

# here we store a data frame in customdata, and it's serialized
# as a list of row lists, which is what we want
trace_patch["customdata"] = trace_data[customdata_cols]
if len(customdata_cols) > 0:
# here we store a data frame in customdata, and it's serialized
# as a list of row lists, which is what we want
trace_patch["customdata"] = trace_data[customdata_cols]
elif attr_name == "color":
if trace_spec.constructor in [go.Choropleth, go.Choroplethmapbox]:
trace_patch["z"] = trace_data[attr_value]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ def test_pass_df_columns():
marginal="rug",
hover_data=tips.columns,
)
assert fig.data[1].hovertemplate.count("customdata") == len(tips.columns)
# the "- 2" is because we re-use x and y in the hovertemplate where possible
assert fig.data[1].hovertemplate.count("customdata") == len(tips.columns) - 2
tips_copy = px.data.tips()
assert tips_copy.columns.equals(tips.columns)

Expand Down