-
Notifications
You must be signed in to change notification settings - Fork 151
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] Add Figure
model and introduce KPI card functions
#493
Merged
Merged
Changes from all commits
Commits
Show all changes
79 commits
Select commit
Hold shift + click to select a range
fb37101
Add KPI Card based on Plotly indicator
huong-li-nguyen 9428969
Add KPI Card based on custom component
huong-li-nguyen c2c3710
Refine and leave some comments
huong-li-nguyen dbba0dd
Get dynamic Card working quickly
huong-li-nguyen a3ca6f6
Add logic to enable `text_card` and `nav_card`
huong-li-nguyen 521954a
Tidy
huong-li-nguyen 1081cd2
Lint
huong-li-nguyen 4ceeed8
Add partially styled KPI
huong-li-nguyen 1ca2be2
Simplify dynamic styled card
huong-li-nguyen bba9e01
Tidy
huong-li-nguyen e1a2858
Add styling to mkd card
huong-li-nguyen 8309d9f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 7edfec2
Add another KPI style
huong-li-nguyen c65678e
Merge branch 'feat/create_kpi_cards' of https://github.com/mckinsey/v…
huong-li-nguyen 798d8ef
Lint
huong-li-nguyen c01a3db
Add comments
huong-li-nguyen 6062063
Tidy CSS
huong-li-nguyen 67d41aa
Make sample page with 3 pre-selected designs
huong-li-nguyen 6eedfe7
Move `dbc.Card` to `build` and remove id provision
huong-li-nguyen f3b1d6a
Refactor classNames for `kpi_card_icon`
huong-li-nguyen feaf493
Refactor simple and icon KPI card to one
huong-li-nguyen 466b252
Refactor classNames for `kpi_card_ref`
huong-li-nguyen 35f64aa
Refactor and tidy some more
huong-li-nguyen 284f2ba
Add formatting arguments to function for discussion
huong-li-nguyen eb2c9c6
Enable coloring of higher-level card
huong-li-nguyen 456eb29
Improve naming
huong-li-nguyen 3f87ac9
Remove remaining `kpi-card-icon` reference
huong-li-nguyen 67321aa
Tidy app
huong-li-nguyen 3aab16b
Merge branch 'main' into feat/create_kpi_cards
huong-li-nguyen 289ada3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 9f37512
Merge branch 'main' into feat/create_kpi_cards
huong-li-nguyen 1c7eb6e
Update docstrings
huong-li-nguyen 1554541
Return `dbc.Card` inside `CapturedCallable`
huong-li-nguyen 98b8c1e
Replace `kpi_card` with suggested improvement
huong-li-nguyen 26ce1be
Replace `kpi_card_ref` with suggested
huong-li-nguyen 3ef65f2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] a1b1228
Remove redundant code from previous iterations
huong-li-nguyen 4309315
Lint
huong-li-nguyen 90dfcb3
Merge branch 'feat/create_kpi_cards' of https://github.com/mckinsey/v…
huong-li-nguyen faabc46
Commit this
huong-li-nguyen 6bf46d5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] b005f51
Revert changes in card
huong-li-nguyen e964bb6
Create higher-level `Figure` model
huong-li-nguyen 5c31faf
Merge branch 'feat/create_kpi_cards' of https://github.com/mckinsey/v…
huong-li-nguyen 7161d15
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 2a92af6
Revert unwanted changes
huong-li-nguyen ae3e57b
Tidy
huong-li-nguyen d0bce82
Fix renaming
huong-li-nguyen ac56dba
Merge branch 'main' into feat/create_kpi_cards
huong-li-nguyen b6515ff
Tidy CSS
huong-li-nguyen bed23b4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 4c6969f
Merge branch 'main' into feat/create_kpi_cards
huong-li-nguyen acccea1
Add docstrings to kpi card functions
huong-li-nguyen a344db5
Merge branch 'main' into feat/create_kpi_cards
huong-li-nguyen 72343be
Implement reverse-color coding via CSS
huong-li-nguyen c5c7368
Update schema
huong-li-nguyen 8062991
Add changelog
huong-li-nguyen fda4a5e
Add ignore for custom format warning
huong-li-nguyen de649ee
Tidy redundant TODOs
huong-li-nguyen ec4a45b
Add unit tests for `Figure`
huong-li-nguyen 95ebf91
Add empty doc file for now
huong-li-nguyen 6f5b33d
Revert changes in `vizro-ai`
huong-li-nguyen 4c71bdc
Add relevant updates in docs
huong-li-nguyen 104b99c
Fix doc warning for now
huong-li-nguyen 9d53cbb
Update schema
huong-li-nguyen f0d0304
Update components.md
stichbury 8883285
Change icon and apply lowercase
huong-li-nguyen 0e5fa7d
Merge branch 'feat/create_kpi_cards' of https://github.com/mckinsey/v…
huong-li-nguyen f07e7d1
Incorporate PR comments
huong-li-nguyen 09ceea1
Fix height due to added container
huong-li-nguyen 5fbfe84
Replace output with function call
huong-li-nguyen db8ac58
Add constants for defaults and tidy html divs
huong-li-nguyen 41c4ca5
Handle ZeroDivisonError
huong-li-nguyen 782127c
Simplify docstrings for `getitem` and remove TODO
huong-li-nguyen cea7a61
Add more context to docstrings of kpi card functions
huong-li-nguyen 36c6a4f
Merge branch 'main' into feat/create_kpi_cards
huong-li-nguyen 68cf51e
Change container className
huong-li-nguyen 769a314
Merge branch 'main' into feat/create_kpi_cards
huong-li-nguyen ee606f8
Incorporate last PR comments
huong-li-nguyen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
vizro-core/changelog.d/20240607_125345_huong_li_nguyen_create_kpi_cards.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<!-- | ||
A new scriv changelog fragment. | ||
|
||
Uncomment the section that is right (remove the HTML comment wrapper). | ||
--> | ||
|
||
### Highlights ✨ | ||
|
||
- Introduce `Figure` as a new `Page` component, enabling all dash components to be reactive in | ||
`Vizro`. See the [user guide on figure](XXXX) for more information. ([#493](https://github.com/mckinsey/vizro/pull/493)) | ||
- Introduce styled KPI cards to be used inside `Figure`. See the [user guide on KPI cards](XXXX) for more information. ([#493](https://github.com/mckinsey/vizro/pull/493)) | ||
|
||
<!-- | ||
### 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 | ||
|
||
- A bullet item for the Added 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)) | ||
|
||
--> | ||
<!-- | ||
### 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)) | ||
|
||
--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# How to use figures | ||
huong-li-nguyen marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,100 @@ | ||
"""Example to show dashboard configuration.""" | ||
"""Dev app to try things out.""" | ||
|
||
petar-qb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import pandas as pd | ||
import vizro.models as vm | ||
import vizro.plotly.express as px | ||
from vizro import Vizro | ||
from vizro.actions import export_data | ||
from vizro.models.types import capture | ||
from vizro.tables import dash_ag_grid | ||
from vizro.figures import kpi_card, kpi_card_reference | ||
|
||
df = px.data.gapminder() | ||
df = pd.DataFrame([[67434, 65553, "A"], [6434, 6553, "B"], [34, 53, "C"]], columns=["Actual", "Reference", "Category"]) | ||
|
||
# Vizro filter exporting Page -------------------------------------------- | ||
# Solution based on https://vizro.readthedocs.io/en/stable/pages/user-guides/actions/#export-data | ||
|
||
page_one = vm.Page( | ||
title="Vizro filters exporting", | ||
layout=vm.Layout(grid=[[0]] * 5 + [[1]]), | ||
page = vm.Page( | ||
title="KPI Indicators", | ||
layout=vm.Layout(grid=[[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10, -1]]), | ||
components=[ | ||
vm.AgGrid(id="ag_grid_1", title="Equal Title One", figure=dash_ag_grid(data_frame=df)), | ||
vm.Button(text="Export data", actions=[vm.Action(function=export_data())]), | ||
], | ||
controls=[vm.Filter(column="continent"), vm.Filter(column="year")], | ||
) | ||
|
||
# AgGrid filter exporting Page ------------------------------------------- | ||
# Solution based on https://dash.plotly.com/dash-ag-grid/export-data-csv | ||
|
||
|
||
# More about Vizro Custom Actions -> https://vizro.readthedocs.io/en/stable/pages/user-guides/custom-actions/ | ||
@capture("action") | ||
def ag_grid_data_exporting(): | ||
"""Custom Action.""" | ||
return True | ||
|
||
|
||
page_two = vm.Page( | ||
title="AgGrid filters exporting", | ||
layout=vm.Layout(grid=[[0]] * 5 + [[1]]), # grid = [[0], [0], [0], [0], [0], [1]] | ||
components=[ | ||
vm.AgGrid( | ||
id="ag_grid_2", | ||
title="Equal Title One", | ||
figure=dash_ag_grid( | ||
# underlying_ag_grid_2 is the id of the AgGrid component on the client-side. It is used to reference | ||
# it's `exportDataAsCsv` property with the custom action below | ||
id="underlying_ag_grid_2", | ||
# Style 1: Value Only | ||
vm.Figure(figure=kpi_card(data_frame=df, value_column="Actual", title="Value I", agg_func="sum")), | ||
vm.Figure(figure=kpi_card(data_frame=df, value_column="Actual", title="Value II", agg_func="mean")), | ||
vm.Figure(figure=kpi_card(data_frame=df, value_column="Actual", title="Value III", agg_func="median")), | ||
# Style 2: Value and reference value | ||
vm.Figure( | ||
figure=kpi_card_reference( | ||
data_frame=df, | ||
value_column="Reference", | ||
reference_column="Actual", | ||
title="Ref. Value II", | ||
agg_func="sum", | ||
) | ||
), | ||
vm.Figure( | ||
figure=kpi_card_reference( | ||
data_frame=df, | ||
csvExportParams={ | ||
"fileName": "ag_grid_2.csv", | ||
}, | ||
value_column="Actual", | ||
reference_column="Reference", | ||
title="Ref. Value I", | ||
agg_func="sum", | ||
) | ||
), | ||
vm.Figure( | ||
id="kpi-card-reverse-coloring", | ||
figure=kpi_card_reference( | ||
data_frame=df, | ||
value_column="Actual", | ||
reference_column="Reference", | ||
title="Ref. Value III", | ||
agg_func="median", | ||
icon="shopping_cart", | ||
), | ||
), | ||
vm.Button( | ||
id="button_2", | ||
text="Export data", | ||
actions=[vm.Action(function=ag_grid_data_exporting(), outputs=["underlying_ag_grid_2.exportDataAsCsv"])], | ||
# Style 3: Value and icon | ||
vm.Figure( | ||
figure=kpi_card( | ||
data_frame=df, | ||
value_column="Actual", | ||
icon="shopping_cart", | ||
title="Icon I", | ||
agg_func="sum", | ||
value_format="${value:.2f}", | ||
) | ||
), | ||
vm.Figure( | ||
figure=kpi_card( | ||
data_frame=df, | ||
value_column="Actual", | ||
icon="payment", | ||
title="Icon II", | ||
agg_func="mean", | ||
value_format="{value:.0f}€", | ||
) | ||
), | ||
vm.Figure( | ||
figure=kpi_card( | ||
data_frame=df, | ||
value_column="Actual", | ||
icon="monitoring", | ||
title="Icon III", | ||
agg_func="median", | ||
) | ||
), | ||
# This should still work without a figure argument | ||
vm.Card( | ||
text=""" | ||
# Text Card | ||
Hello, this is a text card. | ||
""" | ||
), | ||
vm.Card( | ||
text=""" | ||
# Nav Card | ||
Hello, this is a nav card. | ||
""", | ||
href="https://www.google.com", | ||
), | ||
], | ||
controls=[vm.Filter(column="continent"), vm.Filter(column="year")], | ||
controls=[vm.Filter(column="Category")], | ||
) | ||
|
||
dashboard = vm.Dashboard(pages=[page_one, page_two]) | ||
|
||
dashboard = vm.Dashboard(pages=[page]) | ||
|
||
if __name__ == "__main__": | ||
Vizro().build(dashboard).run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,4 @@ | ||
#logo { | ||
height: 40px; | ||
margin-left: -8px; | ||
} | ||
|
||
/* Apply styling to parent */ | ||
.card:has(#my-card) { | ||
background-color: white; | ||
} | ||
|
||
/* Apply styling to children */ | ||
#my-card p { | ||
color: black; | ||
/* Apply reverse color logic via CSS */ | ||
#kpi-card-reverse-coloring .card-kpi:has(.color-neg) { | ||
border-left: 4px solid #1a85ff; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Example of how we can color code in reverse, see comment here: #505 (comment) |
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from vizro.figures.kpi_cards import kpi_card, kpi_card_reference | ||
|
||
# Please keep alphabetically ordered | ||
__all__ = ["kpi_card", "kpi_card_reference"] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reminder for myself to update this with the relevant links when docs are ready