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

[Feat] Enable header and footer inside Graph, Table and AgGrid #669

Merged
merged 45 commits into from
Sep 4, 2024

Conversation

huong-li-nguyen
Copy link
Contributor

@huong-li-nguyen huong-li-nguyen commented Sep 2, 2024

Description

  • Add warning if figure.title is used instead of graph.title
  • Enable header and footer in Graph, Table and AgGrid
  • Enable title in Graph
  • Some quick design updates to dash_data_table to look more similar to dash_ag_grid
  • Update margin_b in dashboard overwrites

TO DO:

  • Update existing unit tests
  • Unit test for warning
  • Unit tests for header / footer / title
  • Update dev example
  • Docs

@l0uden

Screenshot

Notice

  • I acknowledge and agree that, by checking this box and clicking "Submit Pull Request":

    • I submit this contribution under the Apache 2.0 license and represent that I am entitled to do so on behalf of myself, my employer, or relevant third parties, as applicable.
    • I certify that (a) this contribution is my original creation and / or (b) to the extent it is not my original creation, I am authorized to submit this contribution on behalf of the original creator(s) or their licensees.
    • I certify that the use of this contribution as authorized by the Apache 2.0 license does not violate the intellectual property rights of anyone else.
    • I have not referenced individuals, products or companies in any commits, directly or indirectly.
    • I have not added data or restricted code in any commits, directly or indirectly.

@huong-li-nguyen huong-li-nguyen changed the title Feat/enable header footer [Feat] Enable header and footer inside Graph, Table and AgGrid Sep 2, 2024
@huong-li-nguyen huong-li-nguyen mentioned this pull request Sep 2, 2024
1 task
@huong-li-nguyen huong-li-nguyen self-assigned this Sep 2, 2024
@huong-li-nguyen
Copy link
Contributor Author

@l0uden - could you create new screenshot tests based on this branch? :) You can take this config:

import vizro.models as vm
import vizro.plotly.express as px
from vizro import Vizro

df = px.data.iris()

HEADER = """
Each point in the scatter plot represents one of the 150 iris flowers, with colors indicating their types. The Setosa
type is easily identifiable by its short and wide sepals.

However, there is still overlap between the Versicolor and Virginica types when considering only sepal width and length.
"""

FOOTER = """SOURCE: **Plotly Iris, 2024**"""

page = vm.Page(
    title="Styling Header/Footer - Graph",
    components=[
        vm.Graph(
            figure=px.scatter(df, x="sepal_width", y="sepal_length", color="species"),
            title="Relationships between Sepal Width and Sepal Length",
            header=HEADER,
            footer=FOOTER,
        ),
    ],
)


dashboard = vm.Dashboard(pages=[page])

if __name__ == "__main__":
    Vizro().build(dashboard).run(debug=True)

Copy link
Contributor

@maxschulz-COL maxschulz-COL left a comment

Choose a reason for hiding this comment

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

Love this change, really nice to look at! Have a few comments, but approving pending the implementation of those :)

Comment on lines 147 to 152
warnings.warn(
"Using `fig.layout.title` in your Plotly chart may cause misalignment with other "
"component titles on the screen. To ensure consistent alignment, consider using "
"`Graph.title` instead."
)

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
warnings.warn(
"Using `fig.layout.title` in your Plotly chart may cause misalignment with other "
"component titles on the screen. To ensure consistent alignment, consider using "
"`Graph.title` instead."
)
warnings.warn(
"""Using the `title` argument in your Plotly chart function may cause misalignment with other component titles on the screen. To ensure consistent alignment, consider using add a title via the `vm.Graph` model
instead: `vm.Graph(title=<foo>, ...).""")

I would align the warning with the actual pre-condition, not only because that is safer to use, but also because it is probably easier to understand.

Would further use triple quotes to make this easier to read.

Lastly, why did we opt for the argument check vs the actual fig.layout.title check? It was not to build the figure right? I think that was a good choice!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like that!

For context:

Screenshot 2024-09-04 at 12 44 31

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using the triple quotes actually makes it a bit more difficult to read (as an output), because the formatting seems off then 🤔

Triple quotes
Screenshot 2024-09-04 at 14 18 48

Single quotes
Screenshot 2024-09-04 at 14 22 33

Took me forever to figure out why the unit tests were failing with this change 😄 But if you use parentheses, you have to change the syntax of match statement: pytest-dev/pytest#10595

Copy link
Contributor

@maxschulz-COL maxschulz-COL Sep 5, 2024

Choose a reason for hiding this comment

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

Ah weird, did you properly dedent? (either manually, by putting the text to the very left), or by using

from textwrap import dedent
print(dedent("""
	Text for which you want to remove
    leading whitespace when printed
    """))

Very nice tool :P

Not too important, but makes long strings in code really a lot easier to read (and edit after!)

vizro-core/src/vizro/models/_components/graph.py Outdated Show resolved Hide resolved
vizro-core/src/vizro/models/_components/ag_grid.py Outdated Show resolved Hide resolved
vizro-core/src/vizro/models/_components/table.py Outdated Show resolved Hide resolved
vizro-core/src/vizro/static/css/table.css Show resolved Hide resolved
vizro-core/mkdocs.yml Outdated Show resolved Hide resolved
vizro-core/docs/pages/user-guides/titles-header-footer.md Outdated Show resolved Hide resolved
vizro-core/docs/pages/user-guides/titles-header-footer.md Outdated Show resolved Hide resolved
vizro-core/docs/pages/user-guides/titles-header-footer.md Outdated Show resolved Hide resolved
Copy link
Contributor

@petar-qb petar-qb left a comment

Choose a reason for hiding this comment

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

I really like this initiative 😍.

This also makes initial page loading much prettier as the title is introduced for the Graph component as well (and will be even more prettier when we introduce some shinning div boxes for dynamic components - similar like it's done for dash documentation).

vizro-core/docs/pages/user-guides/titles-header-footer.md Outdated Show resolved Hide resolved
vizro-core/docs/pages/user-guides/titles-header-footer.md Outdated Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a reminder to update the requirements.txt for all py.cafe examples:
vizro==0.1.21 -> vizro==0.1.22

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also consider updating Vizro version on some other examples across the hugging face, py.cafe and similar?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is something done at release, not part of this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

I added a reminder note in the release process page for this case.

Copy link
Contributor Author

@huong-li-nguyen huong-li-nguyen Sep 10, 2024

Choose a reason for hiding this comment

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

Ah @petar-qb - I understood what you meant now. We do not need to update the requirements.txt for all py.cafe examples, because these should run fine with the previous versions, especially as they do not use any of the new features. Some of the requirements.txt in some pycafe examples we've just updated because I needed to leverage certain features from there.

What we update is our mkdocs.yml such that our pycafe examples in the docs run on the newest version. I think that's what @maxschulz-COL also referred to, there was already a step in the release process :)

vizro-core/docs/pages/user-guides/titles-header-footer.md Outdated Show resolved Hide resolved
vizro-core/docs/pages/user-guides/titles-header-footer.md Outdated Show resolved Hide resolved
@huong-li-nguyen
Copy link
Contributor Author

huong-li-nguyen commented Sep 4, 2024

@maxschulz-COL @petar-qb - do you guys want to take a final look? :)

@stichbury - If you have some time to take a look at the docs here, that would also be great! 🙇‍♀️

Copy link
Contributor

@stichbury stichbury left a comment

Choose a reason for hiding this comment

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

LGTM, only a couple of very minor comments 🌟

Copy link
Contributor

@petar-qb petar-qb left a comment

Choose a reason for hiding this comment

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

Amazing work! This looks really good to me now. 🎖️

@huong-li-nguyen huong-li-nguyen enabled auto-merge (squash) September 4, 2024 16:04
@huong-li-nguyen huong-li-nguyen merged commit fcec835 into main Sep 4, 2024
32 checks passed
@huong-li-nguyen huong-li-nguyen deleted the feat/enable-header-footer branch September 4, 2024 16:58
@maxschulz-COL
Copy link
Contributor

@maxschulz-COL @petar-qb - do you guys want to take a final look? :)

@stichbury - If you have some time to take a look at the docs here, that would also be great! 🙇‍♀️

Too late to the party, but look great 😍

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

Successfully merging this pull request may close these issues.

4 participants