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

xarray DataArray and Dataset HTML representation #164

Open
blaylockbk opened this issue Aug 30, 2023 · 4 comments
Open

xarray DataArray and Dataset HTML representation #164

blaylockbk opened this issue Aug 30, 2023 · 4 comments

Comments

@blaylockbk
Copy link

Hi mkdocs-jupyter, Thanks for providing this support. It's been great to work with.

One thing I've run into is the Xarray DataArray and Dataset HTML representations are not rendered the same as they are in a Jupyter Notebook.

In Jupyter

import xarray as xr
import numpy as np

data = xr.DataArray(np.random.randn(2, 3), dims=("x", "y"), coords={"x": [10, 20]})
data
image

Rendered in MkDocs (light and dark theme in mkdocs material)

image image

Some of the elements are there, but it doesn't look quite right.


I was expecting it to render similar to how mkdocs-jupyter nicely handles a Pandas DataFrame

import pandas as pd
pd.DataFrame({"A": [1, 2, 3, 4]})
image image

Thanks for your consideration on this issue.

@giswqs
Copy link
Contributor

giswqs commented Sep 4, 2023

I am interested in this as well.

@danielfrg
Copy link
Owner

It should be a matter of adding some CSS styles. We do that for pandas so they look good.

@brynpickering
Copy link
Contributor

Based on damianavila/RISE#594, I added this to my CSS to at least remove the repetition of the dataset contents in pretty and simple HTML:

.md-typeset pre.xr-text-repr-fallback {
    display: none;
}

Ideally the dropdowns would all be closed by default but it seems that it only closes them when there are >=10 items in the dropdown.

@brynpickering
Copy link
Contributor

I've gone into the CSS and made more tweaks that now lead to what I think is the correct formatting for the xarray dataset HTML representation:

.md-typeset pre.xr-text-repr-fallback {
    display: none;
}

.md-typeset ul.xr-sections, .jupyter-wrapper .jp-OutputArea-output dl.xr-attrs {
    display: grid;
}

.md-typeset li.xr-var-item, .md-typeset ul.xr-var-list {
    display: contents;
}

.md-typeset .xr-section-details {
    display: none;
}

.md-typeset ul.xr-dim-list li {
    margin-bottom: 0;
    margin-left: 0;
}

.md-typeset ul.xr-dim-list {
    margin-bottom: 0;
    margin-top: 0;
}

.jupyter-wrapper .jp-OutputArea-output .xr-attrs dt {
    padding: 0;
    margin: 0;
    float: left;
    padding-right: 10px;
    width: auto;
    font-weight: normal;
    grid-column: 1;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants