From 9733b799206ea500c8ef41a9d7427e266227601a Mon Sep 17 00:00:00 2001 From: huong-li-nguyen Date: Wed, 17 Jul 2024 11:09:53 +0200 Subject: [PATCH] Lint --- .../assets/{images => }/app.svg | 0 .../utils/{helper.py => _page_utils.py} | 14 +++++++++++-- .../_chart-gallery/utils/chart_factory.py | 20 +++++++++---------- .../_chart-gallery/utils/chart_pages.py | 20 +++++++++---------- ...om_charts_comp.py => custom_extensions.py} | 2 +- .../_chart-gallery/utils/tab_containers.py | 4 ++-- 6 files changed, 35 insertions(+), 25 deletions(-) rename vizro-core/examples/_chart-gallery/assets/{images => }/app.svg (100%) rename vizro-core/examples/_chart-gallery/utils/{helper.py => _page_utils.py} (80%) rename vizro-core/examples/_chart-gallery/utils/{custom_charts_comp.py => custom_extensions.py} (98%) diff --git a/vizro-core/examples/_chart-gallery/assets/images/app.svg b/vizro-core/examples/_chart-gallery/assets/app.svg similarity index 100% rename from vizro-core/examples/_chart-gallery/assets/images/app.svg rename to vizro-core/examples/_chart-gallery/assets/app.svg diff --git a/vizro-core/examples/_chart-gallery/utils/helper.py b/vizro-core/examples/_chart-gallery/utils/_page_utils.py similarity index 80% rename from vizro-core/examples/_chart-gallery/utils/helper.py rename to vizro-core/examples/_chart-gallery/utils/_page_utils.py index 0308842bc..4adaa626d 100644 --- a/vizro-core/examples/_chart-gallery/utils/helper.py +++ b/vizro-core/examples/_chart-gallery/utils/_page_utils.py @@ -1,4 +1,4 @@ -"""Contains re-usable constants, data sets and custom charts.""" +"""Contains re-usable data sets and constants.""" import json from urllib.request import urlopen @@ -36,5 +36,15 @@ } ) -# CONSTANTS --------------------------------------------------------- +DATA_DICT = { + "gapminder": gapminder, + "gapminder_2007": gapminder_2007, + "iris": iris, + "stocks": stocks, + "tips": tips, + "tips_agg": tips_agg, + "ages": ages, + "fips_unemp": fips_unemp, + "sankey_data": sankey_data, +} PAGE_GRID = [[0, 0, 0, 0, 0]] * 2 + [[1, 1, 1, 2, 2]] * 5 diff --git a/vizro-core/examples/_chart-gallery/utils/chart_factory.py b/vizro-core/examples/_chart-gallery/utils/chart_factory.py index 76919b9dd..415f08a06 100644 --- a/vizro-core/examples/_chart-gallery/utils/chart_factory.py +++ b/vizro-core/examples/_chart-gallery/utils/chart_factory.py @@ -1,14 +1,14 @@ -"""Contains re-usable page functions. +"""Contains re-usable page functions to create identical content with a different `id`. -Note: Given the restriction that one page can only be mapped to one navigation group, -we have to create a new page with a new ID for each chart type being re-used per navigation group. +Note: Since each page can only belong to one navigation group, we need a new page with a unique ID for +each chart type used in different groups. """ import vizro.models as vm import vizro.plotly.express as px -from .custom_charts_comp import CodeClipboard, butterfly -from .helper import PAGE_GRID, ages, gapminder_2007, iris, stocks, tips_agg +from ._page_utils import DATA_DICT, PAGE_GRID +from .custom_extensions import CodeClipboard, butterfly def line_factory(id: str, title: str): @@ -35,7 +35,7 @@ def line_factory(id: str, title: str): same chart, try to limit yourself to 3-4 to avoid cluttering up your chart. """ ), - vm.Graph(figure=px.line(stocks, x="date", y="GOOG")), + vm.Graph(figure=px.line(DATA_DICT["stocks"], x="date", y="GOOG")), CodeClipboard( text=""" ```python @@ -89,7 +89,7 @@ def scatter_factory(id: str, title: str): that correlation is not causation. Make sure your audience does not draw the wrong conclusions. """ ), - vm.Graph(figure=px.scatter(iris, x="sepal_width", y="sepal_length", color="species")), + vm.Graph(figure=px.scatter(DATA_DICT["iris"], x="sepal_width", y="sepal_length", color="species")), CodeClipboard( text=""" ```python @@ -151,7 +151,7 @@ def bar_factory(id: str, title: str): ), vm.Graph( figure=px.bar( - data_frame=tips_agg, + data_frame=DATA_DICT["tips_agg"], x="total_bill", y="day", orientation="h", @@ -222,7 +222,7 @@ def column_factory(id: str, title: str): ), vm.Graph( figure=px.bar( - data_frame=tips_agg, + data_frame=DATA_DICT["tips_agg"], y="total_bill", x="day", ) @@ -291,7 +291,7 @@ def treemap_factory(id: str, title: str): ), vm.Graph( figure=px.treemap( - gapminder_2007, + DATA_DICT["gapminder_2007"], path=[px.Constant("world"), "continent", "country"], values="pop", color="lifeExp", diff --git a/vizro-core/examples/_chart-gallery/utils/chart_pages.py b/vizro-core/examples/_chart-gallery/utils/chart_pages.py index fdcc2709b..d1690fbe9 100644 --- a/vizro-core/examples/_chart-gallery/utils/chart_pages.py +++ b/vizro-core/examples/_chart-gallery/utils/chart_pages.py @@ -1,8 +1,9 @@ -"""Contains custom components and charts used inside the dashboard.""" +"""Contains variables that store each chart page.""" import vizro.models as vm import vizro.plotly.express as px +from ._page_utils import DATA_DICT, PAGE_GRID from .chart_factory import ( bar_factory, butterfly_factory, @@ -11,8 +12,7 @@ scatter_factory, treemap_factory, ) -from .custom_charts_comp import CodeClipboard, FlexContainer, Markdown, sankey -from .helper import PAGE_GRID, counties, fips_unemp, sankey_data, tips +from .custom_extensions import CodeClipboard, FlexContainer, Markdown, sankey # COMPONENTS -------------------------------------------------------- vm.Page.add_type("components", CodeClipboard) @@ -62,7 +62,7 @@ ), vm.Graph( figure=px.pie( - data_frame=tips, + data_frame=DATA_DICT["tips"], values="tip", names="day", ) @@ -121,7 +121,7 @@ ), vm.Graph( figure=px.pie( - data_frame=tips, + data_frame=DATA_DICT["tips"], values="tip", names="day", hole=0.4, @@ -185,7 +185,7 @@ ), vm.Graph( figure=px.box( - data_frame=tips, + data_frame=DATA_DICT["tips"], y="total_bill", x="day", color="day", @@ -245,7 +245,7 @@ ), vm.Graph( figure=px.violin( - data_frame=tips, + data_frame=DATA_DICT["tips"], y="total_bill", x="day", color="day", @@ -308,8 +308,8 @@ ), vm.Graph( figure=px.choropleth( - fips_unemp, - geojson=counties, + DATA_DICT["fips_unemp"], + geojson=DATA_DICT["counties"], locations="fips", color="unemp", range_color=(0, 12), @@ -390,7 +390,7 @@ ), vm.Graph( figure=sankey( - data_frame=sankey_data, + data_frame=DATA_DICT["sankey_data"], labels=["A1", "A2", "B1", "B2", "C1", "C2", "D1"], source="Origin", target="Destination", diff --git a/vizro-core/examples/_chart-gallery/utils/custom_charts_comp.py b/vizro-core/examples/_chart-gallery/utils/custom_extensions.py similarity index 98% rename from vizro-core/examples/_chart-gallery/utils/custom_charts_comp.py rename to vizro-core/examples/_chart-gallery/utils/custom_extensions.py index 0e36a2077..0de0f2602 100644 --- a/vizro-core/examples/_chart-gallery/utils/custom_charts_comp.py +++ b/vizro-core/examples/_chart-gallery/utils/custom_extensions.py @@ -1,6 +1,6 @@ """Contains custom components and charts used inside the dashboard.""" -from typing import Literal, List +from typing import List, Literal import dash_bootstrap_components as dbc import pandas as pd diff --git a/vizro-core/examples/_chart-gallery/utils/tab_containers.py b/vizro-core/examples/_chart-gallery/utils/tab_containers.py index 080c86d2d..15e7364a1 100644 --- a/vizro-core/examples/_chart-gallery/utils/tab_containers.py +++ b/vizro-core/examples/_chart-gallery/utils/tab_containers.py @@ -1,10 +1,10 @@ -"""Contains custom components and charts used inside the dashboard.""" +"""Contains code for the containers used inside the tabs (homepage).""" import re import vizro.models as vm -from .custom_charts_comp import FlexContainer, Markdown +from .custom_extensions import FlexContainer, Markdown vm.Container.add_type("components", Markdown) vm.Container.add_type("components", FlexContainer)