refactor: update app code for domain-scoped schema migration
Some checks failed
CI / lint-and-test (pull_request) Has been cancelled
Some checks failed
CI / lint-and-test (pull_request) Has been cancelled
- Update dbt model references to use new schema naming (stg_toronto, int_toronto, mart_toronto) - Refactor figure factories to use consistent column naming from new schema - Update callbacks to work with refactored data structures - Add centralized design tokens module for consistent styling - Streamline CLAUDE.md documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,14 @@ import pandas as pd
|
||||
import plotly.graph_objects as go
|
||||
from dash import Input, Output, callback
|
||||
|
||||
from portfolio_app.design import (
|
||||
CHART_PALETTE,
|
||||
GRID_COLOR,
|
||||
PAPER_BG,
|
||||
PLOT_BG,
|
||||
TEXT_PRIMARY,
|
||||
TEXT_SECONDARY,
|
||||
)
|
||||
from portfolio_app.figures.toronto import (
|
||||
create_donut_chart,
|
||||
create_horizontal_bar,
|
||||
@@ -109,18 +117,18 @@ def update_housing_trend(year: str, neighbourhood_id: int | None) -> go.Figure:
|
||||
x=[d["year"] for d in data],
|
||||
y=[d["avg_rent"] for d in data],
|
||||
mode="lines+markers",
|
||||
line={"color": "#2196F3", "width": 2},
|
||||
line={"color": CHART_PALETTE[0], "width": 2},
|
||||
marker={"size": 8},
|
||||
name="City Average",
|
||||
)
|
||||
)
|
||||
|
||||
fig.update_layout(
|
||||
paper_bgcolor="rgba(0,0,0,0)",
|
||||
plot_bgcolor="rgba(0,0,0,0)",
|
||||
font_color="#c9c9c9",
|
||||
xaxis={"gridcolor": "rgba(128,128,128,0.2)"},
|
||||
yaxis={"gridcolor": "rgba(128,128,128,0.2)", "title": "Avg Rent (2BR)"},
|
||||
paper_bgcolor=PAPER_BG,
|
||||
plot_bgcolor=PLOT_BG,
|
||||
font_color=TEXT_PRIMARY,
|
||||
xaxis={"gridcolor": GRID_COLOR},
|
||||
yaxis={"gridcolor": GRID_COLOR, "title": "Avg Rent (2BR)"},
|
||||
showlegend=False,
|
||||
margin={"l": 40, "r": 10, "t": 10, "b": 30},
|
||||
)
|
||||
@@ -153,7 +161,7 @@ def update_housing_types(year: str) -> go.Figure:
|
||||
data=data,
|
||||
name_column="type",
|
||||
value_column="percentage",
|
||||
colors=["#4CAF50", "#2196F3"],
|
||||
colors=[CHART_PALETTE[3], CHART_PALETTE[0]], # Teal for owner, blue for renter
|
||||
)
|
||||
|
||||
|
||||
@@ -178,19 +186,19 @@ def update_safety_trend(year: str) -> go.Figure:
|
||||
x=[d["year"] for d in data],
|
||||
y=[d["crime_rate"] for d in data],
|
||||
mode="lines+markers",
|
||||
line={"color": "#FF5722", "width": 2},
|
||||
line={"color": CHART_PALETTE[5], "width": 2}, # Vermillion
|
||||
marker={"size": 8},
|
||||
fill="tozeroy",
|
||||
fillcolor="rgba(255,87,34,0.1)",
|
||||
fillcolor="rgba(213, 94, 0, 0.1)", # Vermillion with opacity
|
||||
)
|
||||
)
|
||||
|
||||
fig.update_layout(
|
||||
paper_bgcolor="rgba(0,0,0,0)",
|
||||
plot_bgcolor="rgba(0,0,0,0)",
|
||||
font_color="#c9c9c9",
|
||||
xaxis={"gridcolor": "rgba(128,128,128,0.2)"},
|
||||
yaxis={"gridcolor": "rgba(128,128,128,0.2)", "title": "Crime Rate per 100K"},
|
||||
paper_bgcolor=PAPER_BG,
|
||||
plot_bgcolor=PLOT_BG,
|
||||
font_color=TEXT_PRIMARY,
|
||||
xaxis={"gridcolor": GRID_COLOR},
|
||||
yaxis={"gridcolor": GRID_COLOR, "title": "Crime Rate per 100K"},
|
||||
showlegend=False,
|
||||
margin={"l": 40, "r": 10, "t": 10, "b": 30},
|
||||
)
|
||||
@@ -233,7 +241,7 @@ def update_safety_types(year: str) -> go.Figure:
|
||||
data=data,
|
||||
name_column="category",
|
||||
value_column="count",
|
||||
color="#FF5722",
|
||||
color=CHART_PALETTE[5], # Vermillion for crime
|
||||
)
|
||||
|
||||
|
||||
@@ -264,7 +272,11 @@ def update_demographics_age(year: str) -> go.Figure:
|
||||
data=data,
|
||||
name_column="age_group",
|
||||
value_column="percentage",
|
||||
colors=["#9C27B0", "#673AB7", "#3F51B5"],
|
||||
colors=[
|
||||
CHART_PALETTE[2],
|
||||
CHART_PALETTE[0],
|
||||
CHART_PALETTE[4],
|
||||
], # Sky, Blue, Yellow
|
||||
)
|
||||
|
||||
|
||||
@@ -301,7 +313,7 @@ def update_demographics_income(year: str) -> go.Figure:
|
||||
data=data,
|
||||
name_column="bracket",
|
||||
value_column="count",
|
||||
color="#4CAF50",
|
||||
color=CHART_PALETTE[3], # Teal
|
||||
sort=False,
|
||||
)
|
||||
|
||||
@@ -333,7 +345,7 @@ def update_amenities_breakdown(year: str) -> go.Figure:
|
||||
data=data,
|
||||
name_column="type",
|
||||
value_column="count",
|
||||
color="#4CAF50",
|
||||
color=CHART_PALETTE[3], # Teal
|
||||
)
|
||||
|
||||
|
||||
@@ -387,9 +399,9 @@ def _empty_chart(message: str) -> go.Figure:
|
||||
"""Create an empty chart with a message."""
|
||||
fig = go.Figure()
|
||||
fig.update_layout(
|
||||
paper_bgcolor="rgba(0,0,0,0)",
|
||||
plot_bgcolor="rgba(0,0,0,0)",
|
||||
font_color="#c9c9c9",
|
||||
paper_bgcolor=PAPER_BG,
|
||||
plot_bgcolor=PLOT_BG,
|
||||
font_color=TEXT_PRIMARY,
|
||||
xaxis={"visible": False},
|
||||
yaxis={"visible": False},
|
||||
)
|
||||
@@ -400,6 +412,6 @@ def _empty_chart(message: str) -> go.Figure:
|
||||
x=0.5,
|
||||
y=0.5,
|
||||
showarrow=False,
|
||||
font={"size": 14, "color": "#888888"},
|
||||
font={"size": 14, "color": TEXT_SECONDARY},
|
||||
)
|
||||
return fig
|
||||
|
||||
@@ -4,6 +4,12 @@
|
||||
import plotly.graph_objects as go
|
||||
from dash import Input, Output, State, callback, no_update
|
||||
|
||||
from portfolio_app.design import (
|
||||
PAPER_BG,
|
||||
PLOT_BG,
|
||||
TEXT_PRIMARY,
|
||||
TEXT_SECONDARY,
|
||||
)
|
||||
from portfolio_app.figures.toronto import create_choropleth_figure, create_ranking_bar
|
||||
from portfolio_app.toronto.services import (
|
||||
get_amenities_data,
|
||||
@@ -267,8 +273,8 @@ def _empty_map(message: str) -> go.Figure:
|
||||
"zoom": 9.5,
|
||||
},
|
||||
margin={"l": 0, "r": 0, "t": 0, "b": 0},
|
||||
paper_bgcolor="rgba(0,0,0,0)",
|
||||
font_color="#c9c9c9",
|
||||
paper_bgcolor=PAPER_BG,
|
||||
font_color=TEXT_PRIMARY,
|
||||
)
|
||||
fig.add_annotation(
|
||||
text=message,
|
||||
@@ -277,7 +283,7 @@ def _empty_map(message: str) -> go.Figure:
|
||||
x=0.5,
|
||||
y=0.5,
|
||||
showarrow=False,
|
||||
font={"size": 14, "color": "#888888"},
|
||||
font={"size": 14, "color": TEXT_SECONDARY},
|
||||
)
|
||||
return fig
|
||||
|
||||
@@ -286,9 +292,9 @@ def _empty_chart(message: str) -> go.Figure:
|
||||
"""Create an empty chart with a message."""
|
||||
fig = go.Figure()
|
||||
fig.update_layout(
|
||||
paper_bgcolor="rgba(0,0,0,0)",
|
||||
plot_bgcolor="rgba(0,0,0,0)",
|
||||
font_color="#c9c9c9",
|
||||
paper_bgcolor=PAPER_BG,
|
||||
plot_bgcolor=PLOT_BG,
|
||||
font_color=TEXT_PRIMARY,
|
||||
xaxis={"visible": False},
|
||||
yaxis={"visible": False},
|
||||
)
|
||||
@@ -299,6 +305,6 @@ def _empty_chart(message: str) -> go.Figure:
|
||||
x=0.5,
|
||||
y=0.5,
|
||||
showarrow=False,
|
||||
font={"size": 14, "color": "#888888"},
|
||||
font={"size": 14, "color": TEXT_SECONDARY},
|
||||
)
|
||||
return fig
|
||||
|
||||
Reference in New Issue
Block a user