# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Project Overview

FL Chart is a highly customizable Flutter chart library supporting 6 chart types: Line, Bar, Pie, Scatter, Radar, and Candlestick. Single-package Flutter library (not a monorepo).

## Common Commands

```bash
make sure              # Run tests + checkstyle (use before pushing)
make runTests          # flutter test
make analyze           # flutter analyze
make checkFormat       # Verify formatting (dry run)
make format            # Auto-format code
make checkstyle        # analyze + format check
make codeGen           # Generate mock files: dart run build_runner build --delete-conflicting-outputs
flutter test test/chart/line_chart/line_chart_painter_test.dart  # Run a single test file
```

## Architecture

### Per-Chart Pattern

Every chart type in `lib/src/chart/` follows a consistent structure:
- `{type}_chart.dart` — Widget (extends `ImplicitlyAnimatedWidget` for built-in animations)
- `{type}_chart_data.dart` — Data classes (extend `BaseChartData` or `AxisChartData`)
- `{type}_chart_painter.dart` — Canvas drawing logic (extends `BaseChartPainter`)
- `{type}_chart_renderer.dart` — Rendering widget that builds the custom painter
- `{type}_chart_helper.dart` — Chart-specific utility functions

### Class Hierarchy

```
BaseChartData
├── AxisChartData (charts with X/Y axes)
│   ├── LineChartData
│   ├── BarChartData
│   ├── ScatterChartData
│   └── RadarChartData
├── PieChartData
└── CandlestickChartData
```

Painters follow the same hierarchy: `BaseChartPainter` → `AxisChartPainter` → specific painters.

### Key Design Decisions

- **CanvasWrapper** (`lib/src/utils/canvas_wrapper.dart`): All drawing goes through this proxy instead of `Canvas` directly, enabling unit testing of paint logic with Mockito.
- **PaintHolder**: Holds current data, target data, text scaler, and virtual rect — passed to painters for rendering and animation interpolation.
- **Implicit animations**: Charts use `ImplicitlyAnimatedWidget` with `*DataTween` classes. Default: 150ms linear.
- **Equatable**: All data classes use `equatable` for value equality.
- **Lerp**: Data models must implement a `lerp()` method to enable smooth implicit animations between states. See `lib/src/utils/lerp.dart` for helpers.
- **Theme-aware text styles**: When rendering text in painters, always use `Utils().getThemeAwareTextStyle(context, style)` instead of hardcoded fallback `TextStyle` values. This merges user-provided styles with the app's theme.

### Touch System

Each chart type defines `*TouchData` and uses `FlTouchEvent` base class. Touch callbacks are configured in the chart data classes.

## Testing

Tests mirror the `lib/` structure under `test/`. Each chart has tests for data, painter, renderer, and helper. Painter tests mock `CanvasWrapper` to verify drawing calls.

Key test utilities:
- `test/helper_methods.dart` — Path/RRect equality helpers
- `test/chart/data_pool.dart` — Shared mock data
- `*.mocks.dart` files are generated by Mockito (run `make codeGen` to regenerate)

## Code Style

- Uses `very_good_analysis` linter (strict, with some relaxed rules in `analysis_options.yaml`)
- `public_member_api_docs` is disabled — public API docs are not enforced
- `lines_longer_than_80_chars` is disabled
- Generated `*.mocks.dart` files are excluded from analysis

## PR Conventions

PR titles must follow Conventional Commits: `<type>: <Subject>` (e.g., `feat: Add tooltip support`). Types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert. Breaking changes use `!` (e.g., `feat!: Change API`). Subject starts with a capital letter.
