gcubed.reporting.chartpacks

Load G-Cubed chartpacks into a format-neutral reporting model.

class ChartpackError(builtins.ValueError):

Raised when a chartpack violates its serialization or data contract.

@dataclass(frozen=True)
class ChartpackSeries:

One exact series in a normalized chartpack.

ChartpackSeries( variable: str, label: str | None = None, color: str | None = None, line: str = 'solid')
variable: str
label: str | None = None
color: str | None = None
line: str = 'solid'
@dataclass(frozen=True)
class ChartpackChart:

One chart with its normalized exact series.

ChartpackChart( series: tuple[ChartpackSeries, ...], title: str | None = None, start_year: int | None = None, end_year: int | None = None, min_value: int | float | None = None, max_value: int | float | None = None, section_label: str | None = None)
series: tuple[ChartpackSeries, ...]
title: str | None = None
start_year: int | None = None
end_year: int | None = None
min_value: int | float | None = None
max_value: int | float | None = None
section_label: str | None = None
@dataclass(frozen=True)
class ChartpackDocument:

A validated chartpack ready for projection extraction and rendering.

ChartpackDocument( title: str, charts: tuple[ChartpackChart, ...], source_format: str, source_text: str)
title: str
charts: tuple[ChartpackChart, ...]
source_format: str
source_text: str
variables: tuple[str, ...]

Return unique exact variables in first-authored order.

semantic_manifest: tuple[str, tuple[ChartpackChart, ...]]

Return serialization-independent normalized chartpack semantics.

def load_chartpack( chartpack_path: pathlib.Path, projections: pandas.DataFrame) -> ChartpackDocument:

Load a CSV or YAML chartpack and validate its exact variables.

def prepare_setup_charts( chartpack_config: dict, projections: pandas.DataFrame | None = None, *, context_path: pathlib.Path | None = None) -> list[dict]:

Resolve and implicitly split portable setup chart declarations.

def render_chartpack_yaml( chartpack_config: dict, *, projections: pandas.DataFrame | None = None, context_path: pathlib.Path | None = None) -> str:

Render and validate a model-aware setup chartpack without writing it.

def write_chartpack_yaml( chartpack_path: pathlib.Path, chartpack_config: dict, *, projections: pandas.DataFrame | None = None, overwrite: bool = False) -> None:

Write a model-aware setup chartpack configuration as canonical YAML.

def convert_csv_chartpack_to_yaml( csv_path: pathlib.Path, yaml_path: pathlib.Path, projections: pandas.DataFrame, *, overwrite: bool = False) -> ChartpackDocument:

Convert legacy CSV to validated exact YAML without partial writes.