Sprint 9-10 - Figure Factory Pattern for Reusable Charts
Date: 2026-01-17
Tags: plotly, dash, design-patterns, python, visualization, reusability, code-organization
Context
Creating multiple chart types across 5 dashboard tabs, with consistent styling and behavior needed across all visualizations.
Problem
Without a standardized approach, each callback would create figures inline with:
- Duplicated styling code (colors, fonts, backgrounds)
- Inconsistent hover templates
- Hard-to-maintain figure creation logic
- No reuse between tabs
Solution
Created a figures/ module with factory functions:
Factory pattern benefits:
- Consistent styling - dark theme applied once
- Type-safe interfaces - clear parameters for each chart type
- Easy testing - factories can be unit tested with sample data
- Reusability - same factory used across multiple tabs
Example factory signature:
Prevention
- Create factories early - before implementing callbacks
- Design generic interfaces - factories should work with any data matching the schema
- Apply styling in one place - use constants for colors, fonts
- Test factories independently - with synthetic data before integration