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

HTML __repr__ for Sorting objects #2747

Merged
merged 5 commits into from
May 13, 2024
Merged
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
26 changes: 26 additions & 0 deletions src/spikeinterface/core/basesorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,32 @@ def __repr__(self):
txt += "\n file_path: {}".format(self._kwargs["file_path"])
return txt

def _repr_html_(self):
common_style = "margin-left: 10px;"
border_style = "border:1px solid #ddd; padding:10px;"

html_header = f"<div style='{border_style}'><strong>{self.__repr__()}</strong></div>"

html_unit_ids = f"<details style='{common_style}'> <summary><strong>Unit IDs</strong></summary><ul>"
html_unit_ids += f"{self.unit_ids} </details>"

html_annotations = f"<details style='{common_style}'> <summary><strong>Annotations</strong></summary><ul>"
for key, value in self._annotations.items():
html_annotations += f"<li> <strong> {key} </strong>: {value}</li>"
html_annotations += f"</details>"

html_unit_properties = (
f"<details style='{common_style}'><summary><strong>Unit Properties</strong></summary><ul>"
)
for key, value in self._properties.items():
# Add a further indent for each property
value_formatted = np.asarray(value)
html_unit_properties += f"<details><summary><strong>{key}</strong></summary>{value_formatted}</details>"
html_unit_properties += "</ul></details>"

html_repr = html_header + html_unit_ids + html_annotations + html_unit_properties
return html_repr

@property
def unit_ids(self):
return self._main_ids
Expand Down
Loading