Skip to content

Commit

Permalink
Merge branch 'main' into demo/chart-gallery
Browse files Browse the repository at this point in the history
  • Loading branch information
huong-li-nguyen committed Jul 3, 2024
2 parents b6a8af7 + b5e8245 commit 4cf8721
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 24 deletions.
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ repos:
args: [--autofix]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.7
rev: v0.5.0
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand All @@ -60,14 +60,14 @@ repos:
- id: black

- repo: https://github.com/PyCQA/bandit
rev: 1.7.8
rev: 1.7.9
hooks:
- id: bandit
args: [-c, pyproject.toml, -ll]
additional_dependencies: ["bandit[toml]"]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.0
rev: v1.10.1
hooks:
- id: mypy
files: ^vizro-core/src/
Expand All @@ -79,7 +79,7 @@ repos:
- pydantic==1.10.14

- repo: https://github.com/gitleaks/gitleaks
rev: v8.18.3
rev: v8.18.4
hooks:
- id: gitleaks
name: gitleaks (protect)
Expand All @@ -103,7 +103,7 @@ repos:
args: ["--fix"]

- repo: https://github.com/errata-ai/vale
rev: v3.4.2
rev: v3.6.0
hooks:
- id: vale
args: [--config=.vale/.vale.ini]
Expand Down
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 ✨
- 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
- 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))
-->
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 ✨
- 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
- 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))
-->
Binary file modified vizro-core/docs/assets/user_guides/figure/custom_kpi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified vizro-core/docs/assets/user_guides/figure/figure.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified vizro-core/docs/assets/user_guides/figure/kpi_cards.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions vizro-core/docs/pages/user-guides/custom-figures.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ adjust the return statement of the function.
title: Optional[str] = None,
icon: Optional[str] = None,
) -> dbc.Card: # (2)!
"""Creates a custom KPI Card."""
"""Creates a custom KPI card."""
title = title or f"{agg_func} {value_column}".title()
value = data_frame[value_column].agg(agg_func)

Expand All @@ -78,7 +78,7 @@ adjust the return statement of the function.


page = vm.Page(
title="Create your own KPI Card",
title="Create your own KPI card",
layout=vm.Layout(grid=[[0, 1, -1, -1]] + [[-1, -1, -1, -1]] * 3), # (4)!
components=[
vm.Figure(
Expand All @@ -87,7 +87,7 @@ adjust the return statement of the function.
value_column="tip",
value_format="${value:.2f}",
icon="shopping_cart",
title="Default KPI Card",
title="Default KPI card",
)
),
vm.Figure(
Expand All @@ -96,7 +96,7 @@ adjust the return statement of the function.
value_column="tip",
value_format="${value:.2f}",
icon="payment",
title="Custom KPI Card",
title="Custom KPI card",
)
),
],
Expand Down
24 changes: 12 additions & 12 deletions vizro-core/docs/pages/user-guides/figure.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ If these more specific models already achieve what you need then they should be
the more generic `Figure`. Remember that it is possible to supply [custom charts](custom-charts.md) to `Graph`
and [custom tables](custom-tables.md) to `Table`.

There are already a few figure functions you can reuse, see the section on [KPI Cards](#key-performance-indicator-kpi-cards)
There are already a few figure functions you can reuse, see the section on [KPI cards](#key-performance-indicator-kpi-cards)
for more details:

- [`kpi_card`][vizro.figures.kpi_card]
Expand Down Expand Up @@ -58,7 +58,7 @@ To add a `Figure` to your page:
tips = px.data.tips

page = vm.Page(
title="KPI Indicators",
title="KPI card",
layout=vm.Layout(grid=[[0, -1, -1, -1]] + [[-1, -1, -1, -1]] * 4), # (1)!
components=[
vm.Figure(
Expand All @@ -67,7 +67,7 @@ To add a `Figure` to your page:
value_column="tip",
value_format="${value:.2f}",
icon="shopping_cart",
title="KPI Card I",
title="KPI card I",
)
)
],
Expand All @@ -93,7 +93,7 @@ To add a `Figure` to your page:
value_column: tip
value_format: ${value:.2f}
icon: shopping_cart
title: KPI Card I
title: KPI card I
type: figure
controls:
- column: day
Expand All @@ -109,7 +109,7 @@ To add a `Figure` to your page:
[-1, -1, -1, -1],
[-1, -1, -1, -1],
]
title: KPI Indicators
title: KPI card
```
=== "Result"
[![Figure]][Figure]
Expand All @@ -133,7 +133,7 @@ As described in the [API reference](../API-reference/figure-callables.md) and il
functions have several arguments to customize your KPI cards. If you require a level of customization that is not
possible with the built-in functions then you can create a [custom figure](custom-figures.md).

!!! example "KPI Card Variations"
!!! example "KPI card variations"

=== "app.py"
```py
Expand Down Expand Up @@ -180,8 +180,8 @@ possible with the built-in functions then you can create a [custom figure](custo
value_column="Actual",
reference_column="Reference",
title="KPI reference with formatting",
value_format="{value:.2f}$",
reference_format="{delta:.2f}$ vs. last year ({reference:.2f}$)",
value_format="{value:.2f}",
reference_format="{delta:+.2f} vs. last year ({reference:.2f})",
),
kpi_card_reference(
data_frame=df_kpi,
Expand All @@ -193,7 +193,7 @@ possible with the built-in functions then you can create a [custom figure](custo
]

page = vm.Page(
title="KPI Indicators",
title="KPI cards",
layout=vm.Layout(grid=[[0, 1, 2, 3], [4, 5, 6, 7], [-1, -1, -1, -1], [-1, -1, -1, -1]]), # (3)!
components=[vm.Figure(figure=figure) for figure in example_cards + example_reference_cards],
controls=[vm.Filter(column="Category")],
Expand Down Expand Up @@ -261,8 +261,8 @@ possible with the built-in functions then you can create a [custom figure](custo
value_column: Actual
reference_column: Reference
title: KPI reference with formatting
value_format: "{value:.2f}$"
reference_format: "{delta:.2f}$ vs. last year ({reference:.2f}$)"
value_format: "{value:.2f}"
reference_format: "{delta:+.2f} vs. last year ({reference:.2f})"
type: figure
- figure:
_target_: kpi_card_reference
Expand All @@ -277,7 +277,7 @@ possible with the built-in functions then you can create a [custom figure](custo
type: filter
layout:
grid: [[0, 1, 2, 3], [4, 5, 6, 7], [-1, -1, -1, -1], [-1, -1, -1, -1]]
title: KPI Indicators
title: KPI cards
```
=== "Result"
[![KPICards]][KPICards]
Expand Down
2 changes: 1 addition & 1 deletion vizro-core/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ filterwarnings = [
"ignore:(?s).*Pyarrow will become a required dependency of pandas:DeprecationWarning",
# Ignore until plotly fixes so the warning is no longer raised:
"ignore:When grouping with a length-1 list-like, you will need to pass a length-1 tuple to get_group:FutureWarning",
# Ignore warning when providing a custom format string to the KPI Cards:
# Ignore warning when providing a custom format string to the KPI cards:
"ignore:Custom format string detected."
]
norecursedirs = ["tests/tests_utils", "tests/js"]
Expand Down
2 changes: 1 addition & 1 deletion vizro-core/src/vizro/figures/kpi_cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def kpi_card_reference( # noqa: PLR0913
- "{value:,}": Formats the value with comma as a thousands separator.
reference_format: Format string to be applied to the reference. For more details on possible placeholders, see
docstring on `value_format`. Defaults to "{delta_relative:.1%} vs. reference ({reference})".
docstring on `value_format`. Defaults to "{delta_relative:+.1%} vs. reference ({reference})".
agg_func: String function name to be used for aggregating the data. Common options include
"sum", "mean" or "median". Default is "sum". For more information on possible functions, see
https://stackoverflow.com/questions/65877567/passing-function-names-as-strings-to-pandas-groupby-aggregrate.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ def set_default_marks(cls, marks, values):


def validate_date_picker_range(cls, range, values):
#
if range and values.get("value") and (isinstance(values["value"], (date, str)) or len(values["value"]) == 1):
raise ValueError("Please set range=False if providing single date value.")

Expand Down

0 comments on commit 4cf8721

Please sign in to comment.