Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/copilot-instructions.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Chart.js Plugin Trendline — Copilot Instructions
# Chart.js Plugin Trendline — Agent Instructions

This plugin adds trendline support to Chart.js charts. It fits a linear regression model to datasets and draws trendlines over bar or line charts.

Expand Down
45 changes: 45 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# CLAUDE.md

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

## Project Overview

This is a Chart.js plugin that adds linear trendline support to charts. It fits regression models to datasets and draws trendlines over bar, line, and scatter charts.

## Development Commands

- `pnpm run build` - Build the minified plugin using webpack
- `pnpm test` - Run Jest tests for all components

## Architecture

The plugin follows a modular structure:

- **Entry Point**: `src/index.js` - Auto-registers plugin globally and exports for manual registration
- **Core**: `src/core/plugin.js` - Main plugin lifecycle integration with Chart.js hooks (`afterDatasetsDraw`, `beforeInit`)
- **Components**: `src/components/` - Rendering logic for trendlines and labels
- **Utilities**: `src/utils/` - Math calculations (`lineFitter.js`) and drawing helpers (`drawing.js`)

## Key Implementation Details

- Plugin integrates with Chart.js v4+ lifecycle using `afterDatasetsDraw` hook
- Trendlines are drawn after datasets to appear on top
- Dataset ordering is handled via `order` property (0-order datasets draw last)
- Configuration is added to datasets via `trendlineLinear` property
- Supports projection mode, custom styling, and labels with legends

## Testing

All components have corresponding `.test.js` files using Jest. Uses `jest-canvas-mock` for Canvas API mocking.

## Coding Standards

- Use modern JavaScript (ES6+)
- 2-space indentation
- JSDoc for public methods (Google style)
- Descriptive naming without abbreviations
- Ensure Chart.js v4+ compatibility

## Chart Type Support

Currently supports: bar, line, scatter charts
40 changes: 40 additions & 0 deletions GEMINI.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Chart.js Plugin Trendline — Agent Instructions

This plugin adds trendline support to Chart.js charts. It fits a linear regression model to datasets and draws trendlines over bar or line charts.

## Project Structure

- Root:
- `package.json`, `webpack.config.js`, `example/*.html`
- Source (`src/`):
- `index.js` — Entry point
- `components/` — Rendering logic (`label.js`, `trendline.js`)
- `core/` — Plugin definition (`plugin.js`)
- `utils/` — Math and drawing helpers (`drawing.js`, `lineFitter.js`)

## Coding Guidelines

1. Use modern JavaScript (ES6+)
2. Indent with 2 spaces
3. Use JSDoc for public methods (Google style)
4. Ensure compatibility with Chart.js v4+
5. Name files/functions descriptively (no abbreviations)

## File Notes

- `plugin.js`: Main plugin lifecycle integration
- `trendline.js`: Handles drawing trendlines
- `lineFitter.js`: Performs regression math
- `example/*.html`: Demo charts — manually verify after changes

## Workflow Tips

1. Changes to `plugin.js` should align with Chart.js plugin lifecycle (e.g., `afterDatasetsDraw`)
2. If editing `trendline.js`, test with multiple chart types
3. Validate rendering via example HTMLs after code updates
4. Run linter and formatter before commit (see `.eslintrc.js` if present)

## Restrictions

- Do not modify build config unless changing build behavior
- Do not auto-generate example files
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chartjs-plugin-trendline",
"version": "3.0.1",
"version": "3.0.2",
"description": "Trendline for Chart.js",
"main": "src/index.js",
"scripts": {
Expand Down