Plot Services¶
Application Layer - Plot Services Package.
This package provides services for managing plot generation, configuration loading, and factory pattern implementation for chart creation across all use cases.
Modules¶
- Plot Service: Main service orchestrating plot generation
- Plot Factory: Factory for creating plot strategies
- Plot Config Loader: Loads plot configurations from YAML
- Singleton: Singleton pattern implementation for plot service
Architecture¶
The plot services follow the Strategy Pattern and Factory Pattern to provide flexible and extensible chart generation capabilities.
Package Overview¶
Application Layer - Plot Services.
Provides services for plot generation, configuration loading, and strategy creation with multi-layer caching support.
Classes:
| Name | Description |
|---|---|
PlotService | Orchestrates plot generation pipeline with caching |
PlotFactory | Factory for creating plot strategies |
PlotConfigLoader | Loads and caches YAML configurations |
PlotService¶
PlotService ¶
Central service for plot generation with caching.
This service implements the Facade pattern, providing a simple interface for plot generation while managing complex operations behind the scenes: - Load YAML configuration - Create strategy via factory - Check multi-layer cache - Generate plot - Cache results
Attributes:
| Name | Type | Description |
|---|---|---|
config_loader | PlotConfigLoader | Configuration loader instance. |
factory | PlotFactory | Plot factory instance. |
cache_manager | GraphCacheManager | Cache manager instance. |
Examples:
>>> service = PlotService()
>>> fig = service.generate_plot(
... "UC-2.1",
... df,
... filters={"uc-2-1-range-slider": [10, 50]}
... )
Initialize plot service with dependencies.
Source code in src/application/plot_services/plot_service.py
Functions¶
generate_plot ¶
generate_plot(use_case_id: str, data: DataFrame, filters: Optional[Dict[str, Any]] = None, customizations: Optional[Any] = None, force_refresh: bool = False) -> go.Figure
Generate plot for given use case with caching.
Pipeline: 1. Load configuration from YAML 2. Generate cache keys 3. Check graph cache 4. If miss: Create strategy and generate plot 5. Cache result 6. Return figure
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
use_case_id | str | Use case identifier (e.g., "UC-2.1"). | required |
data | DataFrame | Input data. | required |
filters | Optional[Dict[str, Any]] | Filters to apply (e.g., {"uc-2-1-range-slider": [10, 50]}). | None |
customizations | Optional[Any] | Additional customizations (future feature). | None |
force_refresh | bool | Force cache refresh. | False |
Returns:
| Type | Description |
|---|---|
Figure | Generated Plotly figure. |
Raises:
| Type | Description |
|---|---|
ValueError | If data validation fails. |
FileNotFoundError | If configuration file not found. |
Examples:
Source code in src/application/plot_services/plot_service.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
clear_cache ¶
Clear cache for specific use case or all.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
use_case_id | Optional[str] | Use case ID to clear. If None, clears all. | None |
Source code in src/application/plot_services/plot_service.py
PlotFactory¶
PlotFactory ¶
Factory for creating plot strategies.
Maps strategy names (from YAML config) to concrete strategy classes.
Attributes:
| Name | Type | Description |
|---|---|---|
_strategy_registry | Dict[str, type] | Registry mapping strategy names to classes |
Initialize plot factory with strategy registry.
Source code in src/application/plot_services/plot_factory.py
Functions¶
create_strategy ¶
Create strategy instance from configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config | Dict[str, Any] | Complete configuration dictionary (must contain visualization.strategy: str) | required |
Returns:
| Type | Description |
|---|---|
BasePlotStrategy | Instantiated strategy |
Raises:
| Type | Description |
|---|---|
ValueError | If strategy name not found in registry |
KeyError | If configuration missing required keys |
Source code in src/application/plot_services/plot_factory.py
register_strategy ¶
Register new strategy class.
Allows dynamic registration of strategies at runtime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name | str | Strategy name (used in YAML config) | required |
strategy_class | type | Strategy class (must inherit from BasePlotStrategy) | required |
Source code in src/application/plot_services/plot_factory.py
get_available_strategies ¶
Get list of available strategy names.
Returns:
| Type | Description |
|---|---|
list | List of registered strategy names. |
PlotConfigLoader¶
PlotConfigLoader ¶
Configuration loader for plot use cases.
Loads YAML configuration files and caches them in memory for performance.
Attributes:
| Name | Type | Description |
|---|---|---|
config_dir | Path | Base directory for configurations |
_cache | Dict[str, Dict[str, Any]] | Configuration cache |
Initialize configuration loader.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_dir | str | Base directory for plot configurations. | "src/infrastructure/plot_configs" |
Source code in src/application/plot_services/plot_config_loader.py
Functions¶
load_config ¶
Load configuration for given use case.
Configuration file naming convention: - UC-2.1 -> module2/uc_2_1_config.yaml - UC-3.4 -> module3/uc_3_4_config.yaml
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
use_case_id | str | Use case identifier (e.g., "UC-2.1") | required |
force_reload | bool | Force reload from file (bypass cache) | False |
Returns:
| Type | Description |
|---|---|
Dict[str, Any] | Configuration dictionary |
Raises:
| Type | Description |
|---|---|
FileNotFoundError | If configuration file not found |
ValueError | If YAML is invalid |
Source code in src/application/plot_services/plot_config_loader.py
clear_cache ¶
get_cached_keys ¶
Get list of cached use case IDs.
Returns:
| Type | Description |
|---|---|
list | List of cached use case IDs. |