Skip to content

Commit

Permalink
Update interactive docs
Browse files Browse the repository at this point in the history
  • Loading branch information
lmcinnes committed Feb 17, 2024
1 parent 08085e9 commit 2477304
Show file tree
Hide file tree
Showing 3 changed files with 836 additions and 112 deletions.
26 changes: 18 additions & 8 deletions datamapplot/interactive_rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@
max-width: 25%;
"""


class FormattingDict(dict):
def __missing__(self, key):
return f"{{{key}}}"
Expand Down Expand Up @@ -751,7 +752,9 @@ def render_html(
if enable_search:
point_dataframe["selected"] = np.ones(len(point_dataframe), dtype=np.uint8)
if point_size < 0:
point_data = point_dataframe[["x", "y", "r", "g", "b", "a", "size", "selected"]]
point_data = point_dataframe[
["x", "y", "r", "g", "b", "a", "size", "selected"]
]
else:
point_data = point_dataframe[["x", "y", "r", "g", "b", "a", "selected"]]
else:
Expand Down Expand Up @@ -782,7 +785,7 @@ def render_html(
get_tooltip = "({index}) => hoverData.data.hover_text[index]"

if on_click is not None:
on_click = '({index}, event) => ' + on_click.format_map(replacements)
on_click = "({index}, event) => " + on_click.format_map(replacements)
else:
hover_data = point_dataframe[["hover_text"]]
get_tooltip = "({index}) => hoverData.data.hover_text[index]"
Expand All @@ -795,7 +798,7 @@ def render_html(
)

if on_click is not None:
on_click = '({index}, event) => ' + on_click.format_map(replacements)
on_click = "({index}, event) => " + on_click.format_map(replacements)
elif extra_point_data is not None:
hover_data = extra_point_data
replacements = FormattingDict(
Expand All @@ -806,9 +809,9 @@ def render_html(
)
if hover_text_html_template is not None:
get_tooltip = (
'({index, picked}) => picked ? {"html": `'
+ hover_text_html_template.format_map(replacements)
+ "`} : null"
'({index, picked}) => picked ? {"html": `'
+ hover_text_html_template.format_map(replacements)
+ "`} : null"
)
else:
get_tooltip = "null"
Expand Down Expand Up @@ -836,11 +839,18 @@ def render_html(
base64_label_data = ""
point_data.to_feather("point_df.arrow", compression="uncompressed")
hover_data.to_feather("point_hover_data.arrow", compression="uncompressed")
with zipfile.ZipFile("point_hover_data.zip", "w", compression=zipfile.ZIP_DEFLATED, compresslevel=9) as f:
with zipfile.ZipFile(
"point_hover_data.zip",
"w",
compression=zipfile.ZIP_DEFLATED,
compresslevel=9,
) as f:
f.write("point_hover_data.arrow")
os.remove("point_hover_data.arrow")
label_dataframe.to_json("label_data.json", orient="records")
with zipfile.ZipFile("label_data.zip", "w", compression=zipfile.ZIP_DEFLATED, compresslevel=9) as f:
with zipfile.ZipFile(
"label_data.zip", "w", compression=zipfile.ZIP_DEFLATED, compresslevel=9
) as f:
f.write("label_data.json")
os.remove("label_data.json")

Expand Down
208 changes: 186 additions & 22 deletions doc/interactive_intro.ipynb

Large diffs are not rendered by default.

714 changes: 632 additions & 82 deletions doc/interactive_sizing_options.ipynb

Large diffs are not rendered by default.

0 comments on commit 2477304

Please sign in to comment.