Components#
Reusable dashboard components (cards, tables, headers).
- create_header_with_logo(logo_src: str | None, portfolio_name: str, start_date: str, end_date: str) list[source]#
Build the dashboard header, optionally including a logo.
- Parameters:
logo_src (str or None) – Image source for the logo (e.g. a base64 data URI). If None, the header is rendered without a logo section.
portfolio_name (str) – Portfolio name displayed as the header’s subtitle.
start_date (str) – Start date of the analysis period, displayed as-is (e.g.
"2023-01-01").end_date (str) – End date of the analysis period, displayed as-is.
- Returns:
A list of Dash HTML components making up the header content, suitable for passing directly as children to a container component.
- Return type:
list
- create_metric_card(title: str, value: str, card_type: str = 'primary') Div[source]#
Build a single metric card (title + value) for the dashboard’s KPI row.
- Parameters:
title (str) – Metric label displayed above the value (e.g.
"Sharpe Ratio").value (str) – Pre-formatted metric value to display (e.g.
"1.234").card_type (str, default "primary") – Style variant appended as a CSS class to the value element (e.g.
"success","warning","danger"), used to color-code the card.
- Returns:
A
Divcontaining the title (H4) and value (H2) elements, styled with themetric-cardclass.- Return type:
dash.html.Div
- create_statistics_table(stats_data: list[dict], portfolio_name: str) Div[source]#
Build a sortable Dash DataTable of performance statistics.
- Parameters:
stats_data (list of dict) – Row data for the table, where each dict has
"Metric"and"Value"keys.portfolio_name (str) – Portfolio name used as the header label for the value column.
- Returns:
A
Divwrapping adash_table.DataTablewith columnsMetricand portfolio_name, sortable natively and paginated at 25 rows per page.- Return type:
dash.html.Div
- format_metric_value(metric_name: str, value: object) str[source]#
Format a metric value for display based on its name and type.
The formatting rule is inferred from keywords found in metric_name: currency (
$#,##0.00), percentage (0.00%), ratio (4 decimal places), or date (YYYY-MM-DD). Falls back to 4 decimal places for other numeric values, orstr(value)otherwise.- Parameters:
metric_name (str) – Name of the metric, matched case-insensitively against CURRENCY_KEYWORDS, PERCENTAGE_KEYWORDS, RATIO_KEYWORDS, and DATE_KEYWORDS to select the formatting rule.
value (object) – The value to format. Typically an
int,float, date-like object (with astrftimemethod), or None.
- Returns:
The formatted value, or
"N/A"if value is None or NaN.- Return type:
str