PRD: Charting Refactor Checklist
Status: Completed (2026-01-31)
Goals
- Simplify the charting surface area so common workflows read clearly and predictably.
- Reduce conditional branching for time axis behavior (REAL_TIME vs BAR_INDEX).
- Separate dataset creation, axis configuration, renderer styling, and overlay composition.
- Keep public APIs stable while making internal responsibilities easier to test.
Guiding principles
- Tests first: add or expand unit tests before behavior-heavy refactors.
- Prefer small, isolated refactors over sweeping changes.
- Preserve current chart defaults and rendering behavior.
- Use existing ta4j style conventions (immutability, explicit imports, no reflection in tests).
Current focus area
- ChartWorkflow, ChartBuilder, TradingChartFactory (charting pipeline and time axis behavior).
Prioritized refactor opportunities
- P0 - TradingChartFactory is a god class (dataset creation, axis config, renderer styling, overlays, tooltips). Minimal path: extract focused helpers (AxisFactory, DatasetFactory, OverlayRenderer) without changing behavior.
- P0 - Repeated REAL_TIME vs BAR_INDEX branching across dataset creation, tooltips, and axis labels. Minimal path: introduce a TimeAxisModeStrategy interface that supplies axis, x-values, and tooltip formatting.
- P1 - ChartWorkflow has many overloads with repeated validation. Minimal path: shared validation + chart creation helpers, keep current overloads delegating.
- P1 - ChartBuilder stores timeAxisMode on builder but does not expose it in a dedicated config object. Minimal path: introduce ChartDefinitionMetadata or ChartContext that carries timeAxisMode + domain series.
- P2 - Chart styling (background, anti-alias, title paint) is duplicated across factory methods. Minimal path: private applyChartStyling(JFreeChart chart) helper.
Implementation status
- Delivered TimeAxisMode (REAL_TIME/BAR_INDEX) and BAR_INDEX support across chart workflows.
- Extracted AxisFactory, DatasetFactory, and OverlayRendererFactory to reduce branching in TradingChartFactory.
- Centralized chart styling defaults to keep title/background/anti-aliasing consistent across chart types.
- Introduced ChartDefinitionMetadata and ChartContext to encapsulate domain series and time axis configuration.
- Added BAR_INDEX-focused tests for tooltips, analysis criterion overlays, and composite charts.
- Updated charting documentation to reference metadata inspection before rendering.
Test coverage gaps
- None noted after latest pass.
Step-by-step checklist
- Initial refactor scout completed (2026-01-31).
- Add BAR_INDEX dual-axis tooltip/date label tests.
- Add BAR_INDEX analysis criterion overlay test.
- Add BAR_INDEX overlay tooltip generator test.
- Extract TimeAxisModeStrategy and migrate one call site.
- Extract AxisFactory and replace in TradingChartFactory.
- Extract DatasetFactory (TimeSeries vs XYSeries) and update overlays.
- Extract OverlayRendererFactory for overlay renderers and tooltips.
- Route domain value selection through TimeAxisModeStrategy.
- Centralize ChartWorkflow validation/chart creation into helper methods.
- Centralize chart styling in TradingChartFactory.
- Introduce ChartDefinitionMetadata for time axis mode and domain series.
- Route ChartPlan/compose title handling through ChartDefinitionMetadata.
- Introduce ChartContext and use it across chart planning/rendering.
- Document chart metadata/consistent title styling in README.
- Verify full build after each refactor step (latest: 2026-01-31).
Open questions
- None.