Skip to content

Commit

Permalink
Lint some moreLint
Browse files Browse the repository at this point in the history
  • Loading branch information
huong-li-nguyen committed Jul 17, 2024
1 parent 9733b79 commit 2eaf143
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
7 changes: 2 additions & 5 deletions vizro-core/examples/_chart-gallery/utils/_page_utils.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
"""Contains re-usable data sets and constants."""
"""Contains reusable data sets and constants."""

import json
from urllib.request import urlopen

import pandas as pd
import vizro.plotly.express as px

# DATA --------------------------------------------------------------
with urlopen("https://raw.githubusercontent.com/plotly/datasets/master/geojson-counties-fips.json") as response:
counties = json.load(response)

counties = json.load("https://raw.githubusercontent.com/plotly/datasets/master/geojson-counties-fips.json")
gapminder = px.data.gapminder()
gapminder_2007 = gapminder.query("year == 2007")
iris = px.data.iris()
Expand Down
10 changes: 8 additions & 2 deletions vizro-core/examples/_chart-gallery/utils/chart_factory.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Contains re-usable page functions to create identical content with a different `id`.
"""Contains reusable page functions to create identical content with a different `id`.
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.
Expand All @@ -12,6 +12,7 @@


def line_factory(id: str, title: str):
"""Reusable function to create the page content for the line chart with a unique ID."""
return vm.Page(
id=id,
title=title,
Expand Down Expand Up @@ -66,6 +67,7 @@ def line_factory(id: str, title: str):


def scatter_factory(id: str, title: str):
"""Reusable function to create the page content for the scatter chart with a unique ID."""
return vm.Page(
id=id,
title=title,
Expand Down Expand Up @@ -123,6 +125,7 @@ def scatter_factory(id: str, title: str):


def bar_factory(id: str, title: str):
"""Reusable function to create the page content for the bar chart with a unique ID."""
return vm.Page(
id=id,
title=title,
Expand Down Expand Up @@ -196,6 +199,7 @@ def bar_factory(id: str, title: str):


def column_factory(id: str, title: str):
"""Reusable function to create the page content for the column chart with a unique ID."""
return vm.Page(
id=id,
title=title,
Expand Down Expand Up @@ -265,6 +269,7 @@ def column_factory(id: str, title: str):


def treemap_factory(id: str, title: str):
"""Reusable function to create the page content for the treemap chart with a unique ID."""
return vm.Page(
id=id,
title=title,
Expand Down Expand Up @@ -331,6 +336,7 @@ def treemap_factory(id: str, title: str):


def butterfly_factory(id: str, title: str):
"""Reusable function to create the page content for the butterfly chart with a unique ID."""
return vm.Page(
id=id,
title=title,
Expand All @@ -354,7 +360,7 @@ def butterfly_factory(id: str, title: str):
categories.
"""
),
vm.Graph(figure=butterfly(ages, x1="Male", x2="Female", y="Age")),
vm.Graph(figure=butterfly(DATA_DICT["ages"], x1="Male", x2="Female", y="Age")),
CodeClipboard(
text="""
```python
Expand Down
13 changes: 9 additions & 4 deletions vizro-core/examples/_chart-gallery/utils/custom_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class CodeClipboard(vm.VizroBaseModel):
text: str

def build(self):
"""Returns the code clipboard component inside an accordion."""
return dbc.Accordion(
[
dbc.AccordionItem(
Expand Down Expand Up @@ -50,6 +51,7 @@ class Markdown(vm.VizroBaseModel):
classname: str = ""

def build(self):
"""Returns a markdown component with an optional classname."""
return dcc.Markdown(id=self.id, children=self.text, dangerously_allow_html=False, className=self.classname)


Expand All @@ -59,13 +61,15 @@ class FlexContainer(vm.Container):
type: Literal["flex_container"] = "flex_container"

def build(self):
"""Returns a flex container."""
return html.Div(
id=self.id, children=[component.build() for component in self.components], className="flex-container"
)


@capture("graph")
def butterfly(data_frame: pd.DataFrame, x1: str, x2: str, y: str):
def butterfly(data_frame: pd.DataFrame, x1: str, x2: str, y: str) -> go.Figure:
"""Creates a custom butterfly chart based on a go.Figure."""
fig = go.Figure()
fig.add_trace(
go.Bar(
Expand All @@ -88,16 +92,17 @@ def butterfly(data_frame: pd.DataFrame, x1: str, x2: str, y: str):


@capture("graph")
def sankey(data_frame: pd.DataFrame, source: str, target: str, value: str, labels: List[str]):
def sankey(data_frame: pd.DataFrame, source: str, target: str, value: str, labels: List[str]) -> go.Figure:
"""Creates a custom sankey chart based on a go.Figure."""
fig = go.Figure(
data=[
go.Sankey(
node=dict(
node=dict( # noqa: C408
pad=16,
thickness=16,
label=labels,
),
link=dict(
link=dict( # noqa: C408
source=data_frame[source],
target=data_frame[target],
value=data_frame[value],
Expand Down
7 changes: 4 additions & 3 deletions vizro-core/examples/scratch_dev/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@ def sankey(
target: str,
value: str,
labels: List[str],
):
) -> go.Figure:
"""Creates a sankey diagram based on a go.Figure."""
fig = go.Figure(
data=[
go.Sankey(
node=dict(
node=dict( # noqa: C408
pad=16,
thickness=16,
label=labels,
),
link=dict(
link=dict( # noqa: C408
source=data_frame[source],
target=data_frame[target],
value=data_frame[value],
Expand Down

0 comments on commit 2eaf143

Please sign in to comment.