Skip to content
Draft
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
22 changes: 18 additions & 4 deletions xarray/core/formatting_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,24 @@ def format_dims(dim_sizes, dims_with_index) -> str:


def summarize_attrs(attrs) -> str:
attrs_dl = "".join(
f"<dt><span>{escape(str(k))} :</span></dt><dd>{escape(str(v))}</dd>"
for k, v in attrs.items()
)
attrs_dl = ""
for k, v in attrs.items():
if isinstance(v, dict):
attr_id = "attrs-" + str(uuid.uuid4())

attrs_dl += "<div class='xr-attr-item'>"
attrs_dl += f"<input id='{attr_id}' class='xr-attr-in' type='checkbox'>"
attrs_dl += (
f"<label class='xr-attr-nested' for='{attr_id}'>{escape(str(k))} : "
)
attrs_dl += f"<span>({len(v)})</span></label>"
attrs_dl += "<span class='xr-attr-nested-inner'>"
attrs_dl += summarize_attrs(v)
attrs_dl += "</span></div>"
else:
attrs_dl += (
f"<dt><span>{escape(str(k))} :</span></dt><dd>{escape(str(v))}</dd>"
)

return f"<dl class='xr-attrs'>{attrs_dl}</dl>"

Expand Down
47 changes: 47 additions & 0 deletions xarray/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,53 @@ dl.xr-attrs {
word-break: break-all;
}

.xr-attr-item {
grid-column: 1/-1;
}

.xr-attr-item input {
display: none;
}

.xr-attr-item label.xr-attr-nested {
border: 0 !important;
}

.xr-attr label > span {
display: inline-block;
padding-left: 0.5em;
}

.xr-attr-item input + label.xr-attr-nested {
color: var(--xr-font-color0);
}

.xr-attr-in + label::before {
display: inline-block;
content: "►";
font-size: 11px;
width: 15px;
margin-left: -15px;
text-align: center;
}

.xr-attr-in:checked + label:before {
content: "▼";
}

.xr-attr-in:checked + label > span {
display: none;
}

.xr-attr-nested-inner {
display: none;
padding-left: 1em;
}

.xr-attr-in:checked ~ .xr-attr-nested-inner {
display: block;
}

.xr-icon-database,
.xr-icon-file-text2,
.xr-no-icon {
Expand Down
Loading