chartjs-plugin-trendline 3.0.1 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/copilot-instructions.md +1 -1
- package/CLAUDE.md +45 -0
- package/GEMINI.md +40 -0
- package/package.json +1 -1
package/CLAUDE.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Project Overview
|
|
6
|
+
|
|
7
|
+
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.
|
|
8
|
+
|
|
9
|
+
## Development Commands
|
|
10
|
+
|
|
11
|
+
- `pnpm run build` - Build the minified plugin using webpack
|
|
12
|
+
- `pnpm test` - Run Jest tests for all components
|
|
13
|
+
|
|
14
|
+
## Architecture
|
|
15
|
+
|
|
16
|
+
The plugin follows a modular structure:
|
|
17
|
+
|
|
18
|
+
- **Entry Point**: `src/index.js` - Auto-registers plugin globally and exports for manual registration
|
|
19
|
+
- **Core**: `src/core/plugin.js` - Main plugin lifecycle integration with Chart.js hooks (`afterDatasetsDraw`, `beforeInit`)
|
|
20
|
+
- **Components**: `src/components/` - Rendering logic for trendlines and labels
|
|
21
|
+
- **Utilities**: `src/utils/` - Math calculations (`lineFitter.js`) and drawing helpers (`drawing.js`)
|
|
22
|
+
|
|
23
|
+
## Key Implementation Details
|
|
24
|
+
|
|
25
|
+
- Plugin integrates with Chart.js v4+ lifecycle using `afterDatasetsDraw` hook
|
|
26
|
+
- Trendlines are drawn after datasets to appear on top
|
|
27
|
+
- Dataset ordering is handled via `order` property (0-order datasets draw last)
|
|
28
|
+
- Configuration is added to datasets via `trendlineLinear` property
|
|
29
|
+
- Supports projection mode, custom styling, and labels with legends
|
|
30
|
+
|
|
31
|
+
## Testing
|
|
32
|
+
|
|
33
|
+
All components have corresponding `.test.js` files using Jest. Uses `jest-canvas-mock` for Canvas API mocking.
|
|
34
|
+
|
|
35
|
+
## Coding Standards
|
|
36
|
+
|
|
37
|
+
- Use modern JavaScript (ES6+)
|
|
38
|
+
- 2-space indentation
|
|
39
|
+
- JSDoc for public methods (Google style)
|
|
40
|
+
- Descriptive naming without abbreviations
|
|
41
|
+
- Ensure Chart.js v4+ compatibility
|
|
42
|
+
|
|
43
|
+
## Chart Type Support
|
|
44
|
+
|
|
45
|
+
Currently supports: bar, line, scatter charts
|
package/GEMINI.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Chart.js Plugin Trendline — Agent Instructions
|
|
2
|
+
|
|
3
|
+
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.
|
|
4
|
+
|
|
5
|
+
## Project Structure
|
|
6
|
+
|
|
7
|
+
- Root:
|
|
8
|
+
- `package.json`, `webpack.config.js`, `example/*.html`
|
|
9
|
+
- Source (`src/`):
|
|
10
|
+
- `index.js` — Entry point
|
|
11
|
+
- `components/` — Rendering logic (`label.js`, `trendline.js`)
|
|
12
|
+
- `core/` — Plugin definition (`plugin.js`)
|
|
13
|
+
- `utils/` — Math and drawing helpers (`drawing.js`, `lineFitter.js`)
|
|
14
|
+
|
|
15
|
+
## Coding Guidelines
|
|
16
|
+
|
|
17
|
+
1. Use modern JavaScript (ES6+)
|
|
18
|
+
2. Indent with 2 spaces
|
|
19
|
+
3. Use JSDoc for public methods (Google style)
|
|
20
|
+
4. Ensure compatibility with Chart.js v4+
|
|
21
|
+
5. Name files/functions descriptively (no abbreviations)
|
|
22
|
+
|
|
23
|
+
## File Notes
|
|
24
|
+
|
|
25
|
+
- `plugin.js`: Main plugin lifecycle integration
|
|
26
|
+
- `trendline.js`: Handles drawing trendlines
|
|
27
|
+
- `lineFitter.js`: Performs regression math
|
|
28
|
+
- `example/*.html`: Demo charts — manually verify after changes
|
|
29
|
+
|
|
30
|
+
## Workflow Tips
|
|
31
|
+
|
|
32
|
+
1. Changes to `plugin.js` should align with Chart.js plugin lifecycle (e.g., `afterDatasetsDraw`)
|
|
33
|
+
2. If editing `trendline.js`, test with multiple chart types
|
|
34
|
+
3. Validate rendering via example HTMLs after code updates
|
|
35
|
+
4. Run linter and formatter before commit (see `.eslintrc.js` if present)
|
|
36
|
+
|
|
37
|
+
## Restrictions
|
|
38
|
+
|
|
39
|
+
- Do not modify build config unless changing build behavior
|
|
40
|
+
- Do not auto-generate example files
|