Styling Context
Central configuration for fonts, colors, and styling options with proper bundled font management.
FontConfig
dataclass
Configuration for fonts used in plots.
Source code in pyretailscience/plots/styles/styling_context.py
StylingContext
Central styling context that maintains bundled fonts as defaults but enables customization.
Source code in pyretailscience/plots/styles/styling_context.py
__init__()
Initialize the styling context with default fonts and cache.
Source code in pyretailscience/plots/styles/styling_context.py
get_color_generators()
Get color generators for plots.
Returns:
Type | Description |
---|---|
dict[str, Generator[str, None, None]] | None
|
Dictionary with 'single' and 'multi' color generators if custom colors are set, |
dict[str, Generator[str, None, None]] | None
|
or None to fall back to default tailwind colors. |
dict[str, Generator[str, None, None]] | None
|
Enterprise plugins override this method to provide custom color generators. |
Source code in pyretailscience/plots/styles/styling_context.py
get_font_properties(font_name)
Get matplotlib FontProperties with flexible font resolution.
This method resolves fonts in the following priority order: 1. Check cache for previously loaded font 2. Try to load from bundled fonts if font_name matches a built-in font 3. Try to load as a system font family name
Parameters:
Name | Type | Description | Default |
---|---|---|---|
font_name |
str
|
The name of the font to load. Can be: - A built-in font name (e.g., 'poppins_regular') - A system font family name (e.g., 'Arial', 'Times New Roman') |
required |
Returns:
Type | Description |
---|---|
FontProperties
|
fm.FontProperties: A matplotlib FontProperties object that can be used for text rendering. |
Source code in pyretailscience/plots/styles/styling_context.py
get_styling_context()
update_styling_context(context)
Update the global styling context (used by enterprise plugins).