Bar Chart Strategy¶
bar_chart_strategy ¶
Bar Chart Strategy.
This module implements the BarChartStrategy class following the Strategy Pattern, providing specific logic for generating bar chart visualizations with flexible configuration.
Classes:
| Name | Description |
|---|---|
BarChartStrategy | Concrete strategy for bar chart generation |
Notes
This strategy supports: - Horizontal and vertical bar orientations - Data filtering before aggregation - Flexible grouping and counting operations - Custom styling from YAML configuration
For supported use cases, refer to the official documentation.
Classes¶
BarChartStrategy ¶
Bases: BasePlotStrategy
Bar chart strategy for ranking and comparison visualizations.
This strategy supports both horizontal and vertical bar charts with flexible data processing including filtering, grouping, counting, and sorting operations.
Attributes:
| Name | Type | Description |
|---|---|---|
data_config | Dict[str, Any] | Data processing configuration |
plotly_config | Dict[str, Any] | Plotly-specific configuration |
Notes
Refer to the official documentation for supported use cases and detailed configuration examples.
Initialize bar chart strategy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config | Dict[str, Any] | Complete configuration from YAML file | required |
Source code in src/domain/plot_strategies/charts/bar_chart_strategy.py
Functions¶
validate_data ¶
Validate input data for bar chart requirements.
Validation rules applied (from YAML config): - DataFrame not empty - Required columns exist ('sample', 'KO') - No null values in critical columns - Minimum number of samples
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df | DataFrame | Input data to validate | required |
Raises:
| Type | Description |
|---|---|
ValueError | If any validation rule fails |
Source code in src/domain/plot_strategies/charts/bar_chart_strategy.py
process_data ¶
Process data for bar chart: filter, group, count, sort.
Processing pipeline (from YAML config): 1. Validate structure (handled by validate_data) 2. Filter data (optional - remove unwanted rows) 3. Group by specified column 4. Count/aggregate values per group 5. Rename result column 6. Sort by count (ascending or descending)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df | DataFrame | Input data with required columns | required |
Returns:
| Type | Description |
|---|---|
DataFrame | Processed data ready for visualization (sorted by aggregated values) |
Source code in src/domain/plot_strategies/charts/bar_chart_strategy.py
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 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | |
create_figure ¶
Create bar chart figure from processed data.
Uses Plotly Express for initial figure creation, then applies additional layout customizations from YAML configuration.
Configuration applied: - Chart type (bar) with horizontal/vertical orientation - Colors (color_discrete_sequence) - Text labels on bars (optional) - Title (text, font, position) - Axis labels and styling - Layout (height, width, template, margins) - Hover behavior
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
processed_df | DataFrame | Processed data with configured columns | required |
Returns:
| Type | Description |
|---|---|
Figure | Configured Plotly bar chart |
Source code in src/domain/plot_strategies/charts/bar_chart_strategy.py
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 | |
apply_filters ¶
Apply filters to data.
This is a common implementation that can be overridden by subclasses if needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df | DataFrame | Data to filter. | required |
filters | Optional[Dict[str, Any]] | Filter specifications. | None |
Returns:
| Type | Description |
|---|---|
DataFrame | Filtered data. |
Source code in src/domain/plot_strategies/base/base_plot_strategy.py
apply_customizations ¶
Apply custom styling to figure.
This is a hook for future customization features (FLEXIVEL and FLEXIVEL2).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fig | Figure | Base figure. | required |
customizations | Optional[Any] | Customization specifications. | None |
Returns:
| Type | Description |
|---|---|
Figure | Customized figure. |
Source code in src/domain/plot_strategies/base/base_plot_strategy.py
generate_plot ¶
generate_plot(data: DataFrame, filters: Optional[Dict[str, Any]] = None, customizations: Optional[Any] = None) -> go.Figure
Generate complete plot (Template Method).
This method orchestrates the entire plot generation process: 1. Validate input data 2. Process data 3. Apply filters 4. Create figure 5. Apply customizations
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data | DataFrame | Input data. | required |
filters | Optional[Dict[str, Any]] | Filters to apply. | None |
customizations | Optional[Any] | Customizations to apply. | None |
Returns:
| Type | Description |
|---|---|
Figure | Complete Plotly figure. |
Raises:
| Type | Description |
|---|---|
ValueError | If validation fails. |