Thank you for your interest in contributing to Chart2CSV! This document provides guidelines and instructions for contributing.
- Code of Conduct
- Getting Started
- Development Setup
- Making Changes
- Testing
- Code Style
- Submitting Changes
- Reporting Bugs
- Suggesting Enhancements
This project follows a standard open-source code of conduct:
- Be respectful and inclusive
- Welcome newcomers
- Focus on what is best for the community
- Show empathy towards other community members
- Python 3.8 or higher
- Git
- Tesseract OCR (for CV pipeline)
- A Mistral API key (for LLM features)
- Fork the repository on GitHub
- Clone your fork locally:
git clone https://github.com/YOUR_USERNAME/Chart2CSV.git cd Chart2CSV - Add upstream remote:
git remote add upstream https://github.com/KikuAI-Lab/Chart2CSV.git
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate# Install package in editable mode with dev dependencies
pip install -e .
pip install -r requirements.txtpip install pre-commit
pre-commit installThis will automatically run linters (black, ruff, mypy) before each commit.
cp .env.example .env
# Edit .env and add your MISTRAL_API_KEY# Run tests
pytest
# Start API server
cd api
python main.py
# Visit http://localhost:8000/docs-
Create a feature branch from
main:git checkout -b feature/your-feature-name
-
Use descriptive branch names:
feature/add-pie-chart-supportfix/ocr-crash-on-rotated-imagesdocs/improve-api-examplesrefactor/extract-common-logic
Follow Conventional Commits:
<type>(<scope>): <description>
[optional body]
[optional footer]
Types:
feat: New featurefix: Bug fixdocs: Documentation changesstyle: Code style changes (formatting)refactor: Code refactoringtest: Adding/updating testschore: Maintenance tasks
Examples:
feat(api): add support for pie charts
fix(ocr): handle rotated images correctly
docs(readme): add installation instructions for Windows
refactor(api): extract common extraction logic to helper function
# Run all tests
pytest
# Run with coverage
pytest --cov=chart2csv --cov-report=html
# Run specific test file
pytest chart2csv/tests/test_mistral.py
# Run tests matching pattern
pytest -k "test_extract"- Place tests in
chart2csv/tests/ - Name test files
test_*.py - Use descriptive test names:
test_extract_handles_rotated_images - Include unit tests for new functions
- Include integration tests for new features
Example Test:
import pytest
from chart2csv.core.pipeline import extract_chart
def test_extract_scatter_chart():
result = extract_chart("fixtures/scatter_simple.png")
assert result.chart_type.value == "scatter"
assert len(result.data) > 0
assert result.confidence.overall() > 0.5- Aim for 70%+ coverage for new code
- Critical paths should have 100% coverage
- Check coverage report:
open htmlcov/index.html
Pre-commit hooks will automatically format code, but you can run manually:
# Format with Black
black .
# Sort imports
isort .
# Lint with Ruff
ruff check . --fix
# Type check with mypy
mypy chart2csv-
Line Length: 100 characters (configured in pyproject.toml)
-
Type Hints: Use type hints for all function signatures
def extract_chart( image_path: Union[str, Path], chart_type: Optional[ChartType] = None ) -> ChartResult: ...
-
Docstrings: Use Google-style docstrings
def extract_scatter_points(image: np.ndarray) -> tuple[np.ndarray, float]: """ Extract scatter plot data points from image. Args: image: Input image array (BGR format) Returns: Tuple of (points, confidence) where: - points: Nx2 array of (x, y) pixel coordinates - confidence: Detection confidence (0.0-1.0) Raises: ValueError: If image is empty or invalid format """ ...
-
Naming Conventions:
- Functions/variables:
snake_case - Classes:
PascalCase - Constants:
UPPER_CASE - Private members:
_leading_underscore
- Functions/variables:
-
Imports: Group in order:
- Standard library
- Third-party packages
- Local imports
-
Error Handling:
- Raise specific exceptions
- Include helpful error messages
- Log errors with context
-
Update from upstream:
git fetch upstream git rebase upstream/main
-
Run tests:
pytest
-
Run linters:
pre-commit run --all-files
-
Update documentation if needed
-
Push to your fork:
git push origin feature/your-feature-name
-
Go to GitHub and create a Pull Request
-
PR Description Should Include:
- Summary: What does this PR do?
- Motivation: Why is this change needed?
- Testing: How was it tested?
- Screenshots: If UI/output changes
- Breaking Changes: If any
Example PR Template:
## Summary
Add support for pie chart extraction
## Motivation
Users frequently request pie chart support (#123)
## Changes
- Added `PieChartExtractor` class
- Updated `detect_chart_type()` to recognize pie charts
- Added 15 unit tests for pie chart edge cases
## Testing
- [x] All tests pass
- [x] Added new tests for pie charts
- [x] Tested manually with 20 sample images
- [x] Coverage increased from 65% to 72%
## Breaking Changes
None
## Screenshots
- Maintainers will review your PR
- Address feedback by pushing new commits
- Once approved, PR will be merged
- Check if the bug is already reported in Issues
- Test with the latest
mainbranch - Gather reproduction steps
**Describe the bug**
Clear description of what the bug is.
**To Reproduce**
Steps to reproduce:
1. Run command '...'
2. Upload image '...'
3. See error
**Expected behavior**
What you expected to happen.
**Actual behavior**
What actually happened.
**Environment:**
- OS: [e.g., Ubuntu 22.04]
- Python version: [e.g., 3.10.5]
- Chart2CSV version: [e.g., 0.1.0]
**Sample image:**
Attach the chart image that triggers the bug
**Error message:**Paste full error traceback here
**Additional context**
Any other relevant information.
We welcome feature suggestions! Please:
- Check existing issues for similar requests
- Open a new issue with the
enhancementlabel - Describe the feature:
- What problem does it solve?
- Who would benefit?
- Proposed implementation (if you have ideas)
- Examples from other tools
Example Enhancement Request:
**Feature:** Add support for heatmap extraction
**Problem:** Users with scientific papers often need to extract data from heatmaps
**Proposed Solution:**
- Detect colorbar to map colors → values
- Segment grid cells
- Extract value for each cell
- Return as 2D array
**Alternatives Considered:**
- Manual calibration per cell (too tedious)
- OCR on colorbar (unreliable)
**Priority:** Medium
**Willing to contribute:** YesUnderstanding the codebase:
chart2csv/
├── core/ # Core extraction logic
│ ├── pipeline.py # Main extraction orchestrator
│ ├── llm_extraction.py # LLM-based extraction
│ ├── detection.py # Axis/tick detection
│ ├── ocr.py # OCR for tick labels
│ ├── extraction.py # Point extraction
│ ├── transform.py # Pixel → value mapping
│ ├── types.py # Data structures
│ └── ...
├── cli/ # Command-line interface
└── tests/ # Unit tests
api/ # FastAPI REST API
└── main.py # API endpoints
scripts/ # Development utilities
deploy/ # Deployment configs
Image → Preprocess → Detect → OCR → Transform → Extract → Result
- Preprocess: Resize, enhance contrast, denoise
- Detect: Find axes and tick marks
- OCR: Read tick labels (Tesseract or Mistral)
- Transform: Build pixel→value mapping
- Extract: Detect and extract data points
- Result: Package with confidence scores
Every decision includes a confidence score (0.0-1.0):
- Crop detection confidence
- Axis detection confidence
- OCR success rate
- Point extraction confidence
Overall confidence is a weighted average.
- LLM Mode: Mistral Pixtral directly extracts data (fast, 90%+ accuracy)
- CV Mode: Traditional computer vision pipeline (fallback, works offline)
- Documentation: Check the Wiki
- Issues: Search existing issues
- Discussions: Use GitHub Discussions for questions
By contributing, you agree that your contributions will be licensed under the AGPL-3.0 License.
Thank you for contributing to Chart2CSV! 🎉