Skip to content

Commit

Permalink
Better handling of extra_point_data
Browse files Browse the repository at this point in the history
  • Loading branch information
lmcinnes committed Feb 16, 2024
1 parent 33a8615 commit 08085e9
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions datamapplot/interactive_rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,9 +761,7 @@ def render_html(
point_data = point_dataframe[["x", "y", "r", "g", "b", "a"]]

if "hover_text" in point_dataframe.columns:
if extra_point_data is not None and (
hover_text_html_template is not None or on_click is not None
):
if extra_point_data is not None:
hover_data = pd.concat(
[point_dataframe[["hover_text"]], extra_point_data],
axis=1,
Expand Down Expand Up @@ -798,6 +796,22 @@ def render_html(

if on_click is not None:
on_click = '({index}, event) => ' + on_click.format_map(replacements)
elif extra_point_data is not None:
hover_data = extra_point_data
replacements = FormattingDict(
**{
str(name): f"${{hoverData.data.{name}[index]}}"
for name in hover_data.columns
}
)
if hover_text_html_template is not None:
get_tooltip = (
'({index, picked}) => picked ? {"html": `'
+ hover_text_html_template.format_map(replacements)
+ "`} : null"
)
else:
get_tooltip = "null"
else:
hover_data = pd.DataFrame(columns=("hover_text",))
get_tooltip = "null"
Expand Down

0 comments on commit 08085e9

Please sign in to comment.