Skip to content

html repr: improve style for dropdown sections #10354

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

Merged
merged 6 commits into from
May 30, 2025
Merged
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
4 changes: 4 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ Bug fixes
calculating mean in rolling for correct operations (preserve float dtypes,
correct mean of bool arrays) (:issue:`10340`, :pull:`10341`).
By `Kai Mühlbauer <https://github.com/kmuehlbauer>`_.
- Improve the html ``repr`` of Xarray objects (dark mode, icons and variable attribute / data
dropdown sections).
(:pull:`10353`, :pull:`10354`)
By `Benoit Bovy <https://github.com/benbovy>`_.
- Raise an error when attempting to encode :py:class:`numpy.datetime64` values
prior to the Gregorian calendar reform date of 1582-10-15 with a
``"standard"`` or ``"gregorian"`` calendar. Previously we would warn and
Expand Down
31 changes: 28 additions & 3 deletions xarray/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ body.vscode-dark {

.xr-section-item input + label {
color: var(--xr-disabled-color);
border: 2px solid transparent !important;
}

.xr-section-item input:enabled + label {
Expand All @@ -136,7 +137,7 @@ body.vscode-dark {
}

.xr-section-item input:focus + label {
border: 2px solid var(--xr-font-color0);
border: 2px solid var(--xr-font-color0) !important;
}

.xr-section-item input:enabled + label:hover {
Expand Down Expand Up @@ -268,7 +269,9 @@ body.vscode-dark {
.xr-var-item label,
.xr-var-item > .xr-var-name span {
background-color: var(--xr-background-color-row-even);
border-color: var(--xr-background-color-row-odd);
margin-bottom: 0;
padding-top: 2px;
}

.xr-var-item > .xr-var-name:hover span {
Expand All @@ -279,6 +282,7 @@ body.vscode-dark {
.xr-var-list > li:nth-child(odd) > label,
.xr-var-list > li:nth-child(odd) > .xr-var-name span {
background-color: var(--xr-background-color-row-odd);
border-color: var(--xr-background-color-row-even);
}

.xr-var-name {
Expand Down Expand Up @@ -328,8 +332,15 @@ body.vscode-dark {
.xr-var-data,
.xr-index-data {
display: none;
background-color: var(--xr-background-color) !important;
padding-bottom: 5px !important;
border-top: 2px dotted var(--xr-background-color);
padding-bottom: 20px !important;
padding-top: 10px !important;
}

.xr-var-attrs-in + label,
.xr-var-data-in + label,
.xr-index-data-in + label {
padding: 0 1px;
}

.xr-var-attrs-in:checked ~ .xr-var-attrs,
Expand All @@ -342,6 +353,12 @@ body.vscode-dark {
float: right;
}

.xr-var-data > pre,
.xr-index-data > pre,
.xr-var-data > table > tbody > tr {
background-color: transparent !important;
Comment on lines +358 to +359
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a special case for dask's array repr so that it looks like this:

Screenshot 2025-05-28 at 10 27 33

instead of this:

Screenshot 2025-05-28 at 10 30 26

This trick may not work well for other wrapped arrays that have an html repr, though.

}

.xr-var-name span,
.xr-var-data,
.xr-index-name div,
Expand Down Expand Up @@ -401,3 +418,11 @@ dl.xr-attrs {
stroke: currentColor;
fill: currentColor;
}

.xr-var-attrs-in:checked + label > .xr-icon-file-text2,
.xr-var-data-in:checked + label > .xr-icon-database,
.xr-index-data-in:checked + label > .xr-icon-database {
color: var(--xr-font-color0);
filter: drop-shadow(1px 1px 5px var(--xr-font-color2));
stroke-width: 0.8px;
}
Loading