Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c5f2860

Browse filesBrowse files
Merge pull request plotly#2524 from plotly/path_hover_fixes
fixing hover_data and hover_name bugs in path API
2 parents 1a61d9a + 2f401e0 commit c5f2860
Copy full SHA for c5f2860

File tree

Expand file treeCollapse file tree

2 files changed

+23
-17
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+23
-17
lines changed

‎packages/python/plotly/plotly/express/_core.py

Copy file name to clipboardExpand all lines: packages/python/plotly/plotly/express/_core.py
+6-17Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,23 +1432,12 @@ def process_dataframe_hierarchy(args):
14321432
_check_dataframe_all_leaves(df[path[::-1]])
14331433
discrete_color = False
14341434

1435-
if args["color"] and args["color"] in path:
1436-
series_to_copy = df[args["color"]]
1437-
new_col_name = args["color"] + "additional_col_for_color"
1438-
path = [new_col_name if x == args["color"] else x for x in path]
1439-
df[new_col_name] = series_to_copy
1440-
if args["hover_data"]:
1441-
for col_name in args["hover_data"]:
1442-
if col_name == args["color"]:
1443-
series_to_copy = df[col_name]
1444-
new_col_name = str(args["color"]) + "additional_col_for_hover"
1445-
df[new_col_name] = series_to_copy
1446-
args["color"] = new_col_name
1447-
elif col_name in path:
1448-
series_to_copy = df[col_name]
1449-
new_col_name = col_name + "additional_col_for_hover"
1450-
path = [new_col_name if x == col_name else x for x in path]
1451-
df[new_col_name] = series_to_copy
1435+
new_path = []
1436+
for col_name in path:
1437+
new_col_name = col_name + "_path_copy"
1438+
new_path.append(new_col_name)
1439+
df[new_col_name] = df[col_name]
1440+
path = new_path
14521441
# ------------ Define aggregation functions --------------------------------
14531442

14541443
def aggfunc_discrete(x):

‎packages/python/plotly/plotly/tests/test_core/test_px/test_px_functions.py

Copy file name to clipboardExpand all lines: packages/python/plotly/plotly/tests/test_core/test_px/test_px_functions.py
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,23 @@ def test_sunburst_treemap_with_path_and_hover():
171171
)
172172
assert "smoker" in fig.data[0].hovertemplate
173173

174+
df = px.data.gapminder().query("year == 2007")
175+
fig = px.sunburst(
176+
df, path=["continent", "country"], color="lifeExp", hover_data=df.columns
177+
)
178+
assert fig.layout.coloraxis.colorbar.title.text == "lifeExp"
179+
180+
df = px.data.tips()
181+
fig = px.sunburst(df, path=["sex", "day", "time", "smoker"], hover_name="smoker")
182+
assert "smoker" not in fig.data[0].hovertemplate # represented as '%{hovertext}'
183+
assert "%{hovertext}" in fig.data[0].hovertemplate # represented as '%{hovertext}'
184+
185+
df = px.data.tips()
186+
fig = px.sunburst(df, path=["sex", "day", "time", "smoker"], custom_data=["smoker"])
187+
assert fig.data[0].customdata[0][0] in ["Yes", "No"]
188+
assert "smoker" not in fig.data[0].hovertemplate
189+
assert "%{hovertext}" not in fig.data[0].hovertemplate
190+
174191

175192
def test_sunburst_treemap_with_path_color():
176193
vendors = ["A", "B", "C", "D", "E", "F", "G", "H"]

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.