Skip to content

Commit

Permalink
Fix sidebar logo display (#729)
Browse files Browse the repository at this point in the history
* Fix sidebar logo display

* Do not lint notebooks twice

* Fix mypy
  • Loading branch information
stefsmeets authored Sep 23, 2024
1 parent 4b0286e commit f249f5c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ repos:
rev: v0.6.7
hooks:
- id: ruff
args: [--fix]
args: [--fix, '--extend-exclude', '*.ipynb']
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.2
hooks:
Expand Down
19 changes: 12 additions & 7 deletions src/duqtools/dashboard/_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,25 @@ def get_base64_of_bin_file(png_file):


def build_markup_for_logo(
png_file,
background_position='50% 10%',
margin_top='10%',
image_width='60%',
image_height='',
png_file,
background_position='50% 10%',
margin_top='10%',
image_width='53%',
image_height='100%',
nav=True, # page has navigation
):
binary_string = get_base64_of_bin_file(png_file)

loc = 'stSidebarHeader' if nav else 'stSidebarUserContent'

return f"""
<style>
[data-testid="stSidebarNav"] {{
[data-testid="{loc}"] {{
background-image: url("data:image/png;base64,{binary_string}");
background-repeat: no-repeat;
background-position: {background_position};
margin-top: {margin_top};
margin-bottom: {margin_top};
background-size: {image_width} {image_height};
}}
</style>
Expand All @@ -129,7 +134,7 @@ def build_markup_for_logo(
def add_sidebar_logo():
"""Based on: https://stackoverflow.com/a/73278825."""
png_file = data_directory / 'logo.png'
logo_markup = build_markup_for_logo(png_file)
logo_markup = build_markup_for_logo(png_file, nav=True)
st.markdown(
logo_markup,
unsafe_allow_html=True,
Expand Down
3 changes: 2 additions & 1 deletion src/duqtools/schema/_dimensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def check_custom(cls, values):
return values

def _custom_function(self,
data: np.ndarray,
data: np.ndarray | float,
value,
*,
out: Optional[np.ndarray] = None,
Expand All @@ -125,6 +125,7 @@ def npfunc(self,
out: Optional[np.ndarray] = None,
var: Optional[Any] = None) -> Any:
if self.operator == 'custom':
assert self.custom_code
npfunc = partial(self._custom_function,
code=self.custom_code,
var=var)
Expand Down

0 comments on commit f249f5c

Please sign in to comment.