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

Enable automatic logo insertion #248

Merged
merged 46 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
68fe28f
Move dashboard title up
huong-li-nguyen Dec 22, 2023
8db7334
Update CSS
huong-li-nguyen Dec 22, 2023
ae1a689
Move settings container conditionally
huong-li-nguyen Dec 22, 2023
93e6e56
Fix CSS
huong-li-nguyen Dec 22, 2023
d52db40
Add dashboar title
huong-li-nguyen Dec 22, 2023
811bc1f
Add POC for logo
huong-li-nguyen Dec 22, 2023
0ced94d
Revert "Add POC for logo"
huong-li-nguyen Dec 22, 2023
3926b9b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 22, 2023
7057eff
Move dashboard title up
huong-li-nguyen Dec 22, 2023
0e3881f
Update CSS
huong-li-nguyen Dec 22, 2023
76a07c7
Move settings container conditionally
huong-li-nguyen Dec 22, 2023
89cee6d
Fix CSS
huong-li-nguyen Dec 22, 2023
6791f0f
Add dashboar title
huong-li-nguyen Dec 22, 2023
ac696cf
Add POC for logo
huong-li-nguyen Dec 22, 2023
6611754
Revert "Add POC for logo"
huong-li-nguyen Dec 22, 2023
aaebcee
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 22, 2023
22cdf15
Merge branch 'dev/dashboard_title_position' of https://github.com/mck…
huong-li-nguyen Jan 2, 2024
f916f9a
Fix misalignment between icons and title
huong-li-nguyen Jan 2, 2024
77e3bb5
Revert scrolling bug
huong-li-nguyen Jan 2, 2024
6bf2741
Fix scrolling on right-side
huong-li-nguyen Jan 2, 2024
cff0243
Fix scroll for left-main
huong-li-nguyen Jan 2, 2024
78e744f
Fix unnecessary scrolling on screens with cards
huong-li-nguyen Jan 2, 2024
1c8079d
Merge branch 'main' into dev/dashboard_title_position
huong-li-nguyen Jan 2, 2024
fc0f448
Use short-cut CSS
huong-li-nguyen Jan 2, 2024
d95dada
Add changelog
huong-li-nguyen Jan 3, 2024
a9f80a9
Merge branch 'main' into dev/dashboard_title_position
huong-li-nguyen Jan 3, 2024
e37d83e
Fix typo
huong-li-nguyen Jan 4, 2024
b52b956
Enable logo
huong-li-nguyen Jan 4, 2024
df8bf95
Fix CSS for no logo / no title
huong-li-nguyen Jan 4, 2024
4002197
Find a middle-ground for logo size
huong-li-nguyen Jan 4, 2024
d71f101
Test out rectangular logo
huong-li-nguyen Jan 4, 2024
b09e35c
Revert "Test out rectangular logo"
huong-li-nguyen Jan 4, 2024
4b37b93
Add changelog
huong-li-nguyen Jan 4, 2024
cb82fd9
Merge branch 'main' into dev/dashboard_title_position
huong-li-nguyen Jan 4, 2024
af87572
Enable logo
huong-li-nguyen Jan 4, 2024
c3dc66c
Fix CSS for no logo / no title
huong-li-nguyen Jan 4, 2024
2401e1a
Find a middle-ground for logo size
huong-li-nguyen Jan 4, 2024
605e5cf
Test out rectangular logo
huong-li-nguyen Jan 4, 2024
b7188f6
Revert "Test out rectangular logo"
huong-li-nguyen Jan 4, 2024
5503f7e
Add changelog
huong-li-nguyen Jan 4, 2024
cf36cf0
Merge branch 'feat/enable_logo' of https://github.com/mckinsey/vizro …
huong-li-nguyen Jan 16, 2024
06ba512
Merge branch 'main' into feat/enable_logo
huong-li-nguyen Jan 16, 2024
136cdd1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 16, 2024
d4ad0e7
Increase margin
huong-li-nguyen Jan 16, 2024
568c69e
PR comments
huong-li-nguyen Jan 16, 2024
f48437a
Fix scroll-bar
huong-li-nguyen Jan 16, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!--
A new scriv changelog fragment.

Uncomment the section that is right (remove the HTML comment wrapper).
-->

<!--
### Highlights ✨

- A bullet item for the Highlights ✨ category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
<!--
### Removed

- A bullet item for the Removed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))

-->

### Added

- Enable automatic logo insertion into `page-header` container ([#248](https://github.com/mckinsey/vizro/pull/248))

<!--
### Changed

- A bullet item for the Changed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
<!--
### Deprecated

- A bullet item for the Deprecated category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
<!--
### Fixed

- A bullet item for the Fixed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
<!--
### Security

- A bullet item for the Security category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ img[src*="#my-image"] {
float: left;
margin: 10px 25px;
}

#logo {
margin-left: -8px;
height: 40px;
}
27 changes: 16 additions & 11 deletions vizro-core/src/vizro/models/_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import dash
import dash_bootstrap_components as dbc
import dash_mantine_components as dmc
from dash import ClientsideFunction, Input, Output, clientside_callback, get_relative_path, html
from dash import ClientsideFunction, Input, Output, clientside_callback, get_asset_url, get_relative_path, html

try:
from pydantic.v1 import Field, validator
Expand Down Expand Up @@ -49,7 +49,8 @@ def _all_hidden(components: List[Component]):
"nav-bar": html.Div,
"nav-panel": html.Div,
"control-panel": html.Div,
"components": html.Div,
"page-components": html.Div,
"logo": html.Div,
},
)

Expand Down Expand Up @@ -133,7 +134,6 @@ def _get_page_divs(self, page: Page) -> _PageDivsType:
dashboard_title = (
html.H2(self.title, id="dashboard-title") if self.title else html.H2(hidden=True, id="dashboard-title")
)

settings = html.Div(
dmc.Switch(
id="theme_selector",
Expand All @@ -144,6 +144,9 @@ def _get_page_divs(self, page: Page) -> _PageDivsType:
),
id="settings",
)
logo_img = self._infer_image(filename="logo")
huong-li-nguyen marked this conversation as resolved.
Show resolved Hide resolved
path_to_logo = get_asset_url(logo_img) if logo_img else None
logo = html.Img(src=path_to_logo, id="logo", hidden=not path_to_logo)

# Shared across pages but slightly differ in content. These could possibly be done by a clientside
# callback instead.
Expand All @@ -155,11 +158,12 @@ def _get_page_divs(self, page: Page) -> _PageDivsType:
# Different across pages
page_content: _PageBuildType = page.build()
control_panel = page_content["control-panel"]
components = page_content["components"]
return html.Div([dashboard_title, settings, page_title, nav_bar, nav_panel, control_panel, components])
components = page_content["page-components"]
return html.Div([dashboard_title, settings, page_title, nav_bar, nav_panel, control_panel, components, logo])

def _arrange_page_divs(self, page_divs: _PageDivsType):
page_header_divs = [page_divs["dashboard-title"]]
logo_title = [page_divs["logo"], page_divs["dashboard-title"]]
page_header_divs = [html.Div(logo_title, id="logo-and-title", hidden=_all_hidden(logo_title))]
left_sidebar_divs = [page_divs["nav-bar"]]
left_main_divs = [
page_divs["nav-panel"],
Expand All @@ -168,17 +172,17 @@ def _arrange_page_divs(self, page_divs: _PageDivsType):
right_header_divs = [page_divs["page-title"]]

# Apply different container position logic based on condition
if self.title:
page_header_divs.append(page_divs["settings"])
else:
if _all_hidden(page_header_divs):
right_header_divs.append(page_divs["settings"])
else:
page_header_divs.append(page_divs["settings"])

left_sidebar = html.Div(left_sidebar_divs, id="left-sidebar", hidden=_all_hidden(left_sidebar_divs))
left_main = html.Div(left_main_divs, id="left-main", hidden=_all_hidden(left_main_divs))
left_side = html.Div([left_sidebar, left_main], id="left-side")

right_header = html.Div(right_header_divs, id="right-header")
right_main = page_divs["components"]
right_main = page_divs["page-components"]
right_side = html.Div([right_header, right_main], id="right-side")

page_header = html.Div(page_header_divs, id="page-header", hidden=_all_hidden(page_header_divs))
Expand Down Expand Up @@ -211,7 +215,8 @@ def _make_page_404_layout():
className="page_error_container",
)

def _infer_image(self, filename: str):
@staticmethod
def _infer_image(filename: str):
valid_extensions = [".apng", ".avif", ".gif", ".jpeg", ".jpg", ".png", ".svg", ".webp"]
assets_folder = Path(dash.get_app().config.assets_folder)
if assets_folder.is_dir():
Expand Down
4 changes: 2 additions & 2 deletions vizro-core/src/vizro/models/_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# (e.g. html.Div) as well as TypedDict, but that's not possible, and Dash does not have typing support anyway. When
# this type is used, the object is actually still a dash.development.base_component.Component, but this makes it easier
# to see what contract the component fulfills by making the expected keys explicit.
_PageBuildType = TypedDict("_PageBuildType", {"control-panel": html.Div, "components": html.Div})
_PageBuildType = TypedDict("_PageBuildType", {"control-panel": html.Div, "page-components": html.Div})


class Page(VizroBaseModel):
Expand Down Expand Up @@ -186,6 +186,6 @@ def _create_component_container(self, components_content):
),
dcc.Store(id=f"{ON_PAGE_LOAD_ACTION_PREFIX}_trigger_{self.id}"),
],
id="components",
id="page-components",
)
return component_container
18 changes: 16 additions & 2 deletions vizro-core/src/vizro/static/css/layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,17 @@
display: flex;
flex-direction: row;
justify-content: space-between;
min-height: 64px;
height: 64px;
padding: 0 32px;
width: 100%;
min-height: 0;
}

#page-header:not(:empty) {
border-bottom: 1px solid var(--border-subtle-alpha-01);
}

#components {
#page-components {
display: flex;
height: 100%;
overflow: auto;
Expand Down Expand Up @@ -182,10 +183,23 @@ div.dashboard_container .custom-tooltip {

#page-main {
display: flex;
flex: 1 1 0;
flex-direction: row;
height: calc(100% - 64px);
}

#dashboard-title {
margin: 0;
}

#logo {
height: 100%;
}

#logo-and-title {
align-items: center;
display: flex;
flex-direction: row;
gap: 16px;
height: 100%;
}
2 changes: 1 addition & 1 deletion vizro-core/src/vizro/static/css/scroll_bar.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
border-color: var(--surfaces-bg-card);
}

#components::-webkit-scrollbar-thumb {
#page-components::-webkit-scrollbar-thumb {
border-color: var(--main-container-bg-color);
}

Expand Down
Loading