chartjs-plugin-trendline 3.1.1 → 3.2.0

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.
Files changed (44) hide show
  1. package/.github/copilot-instructions.md +40 -40
  2. package/.github/workflows/release.yml +61 -61
  3. package/.github/workflows/tests.yml +26 -26
  4. package/.prettierrc +5 -5
  5. package/CLAUDE.md +44 -44
  6. package/GEMINI.md +40 -40
  7. package/LICENSE +21 -21
  8. package/MIGRATION.md +126 -0
  9. package/README.md +166 -149
  10. package/babel.config.js +3 -3
  11. package/changelog.md +39 -39
  12. package/dist/chartjs-plugin-trendline.cjs +885 -0
  13. package/dist/chartjs-plugin-trendline.esm.js +883 -0
  14. package/dist/chartjs-plugin-trendline.js +891 -0
  15. package/dist/chartjs-plugin-trendline.min.js +8 -1
  16. package/dist/chartjs-plugin-trendline.min.js.map +1 -0
  17. package/example/barChart.html +165 -165
  18. package/example/barChartWithNullValues.html +168 -168
  19. package/example/barChart_label.html +174 -174
  20. package/example/exponentialChart.html +244 -244
  21. package/example/lineChart.html +210 -210
  22. package/example/lineChartProjection.html +261 -261
  23. package/example/lineChartTypeTime.html +190 -190
  24. package/example/scatterChart.html +136 -136
  25. package/example/scatterProjection.html +141 -141
  26. package/example/test-null-handling.html +59 -59
  27. package/index.html +215 -215
  28. package/jest.config.js +4 -4
  29. package/package.json +40 -30
  30. package/rollup.config.js +54 -0
  31. package/src/components/label.js +56 -56
  32. package/src/components/label.test.js +129 -129
  33. package/src/components/trendline.js +375 -375
  34. package/src/components/trendline.test.js +789 -789
  35. package/src/core/plugin.js +79 -79
  36. package/src/index.js +12 -12
  37. package/src/utils/drawing.js +125 -125
  38. package/src/utils/drawing.test.js +308 -308
  39. package/src/utils/exponentialFitter.js +146 -146
  40. package/src/utils/exponentialFitter.test.js +362 -362
  41. package/src/utils/lineFitter.js +86 -86
  42. package/src/utils/lineFitter.test.js +340 -340
  43. package/dist/chartjs-plugin-trendline.min.js.LICENSE.txt +0 -11
  44. package/webpack.config.js +0 -9
package/README.md CHANGED
@@ -1,149 +1,166 @@
1
- # chartjs-plugin-trendline
2
-
3
- This plugin draws linear and exponential trendlines in your Chart.
4
- It has been tested with Chart.js version 4.4.9.
5
-
6
- ## 📊 [View Live Examples](https://makanz.github.io/chartjs-plugin-trendline/)
7
-
8
- See the plugin in action with interactive examples for different chart types.
9
-
10
- ## Installation
11
-
12
- #### Load directly in the browser
13
-
14
- Load Chart.js first, then the plugin which will automatically register itself with Chart.js
15
-
16
- ```html
17
- <script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.9/dist/chart.min.js"></script>
18
- <script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-trendline/dist/chartjs-plugin-trendline.min.js"></script>
19
- ```
20
-
21
- #### As a Chart.JS plugin
22
-
23
- Install & import the plugin via npm:
24
-
25
- `npm i chart.js chartjs-plugin-trendline`
26
-
27
- ```js
28
- import ChartJS from 'chart.js';
29
- import chartTrendline from 'chartjs-plugin-trendline';
30
-
31
- ChartJS.plugins.register(chartTrendline);
32
- ```
33
-
34
- ## Configuration
35
-
36
- To configure the trendline plugin you simply add a new config options to your dataset in your chart config.
37
-
38
- ### Linear Trendlines
39
-
40
- For linear trendlines (straight lines), use the `trendlineLinear` configuration:
41
-
42
- ```javascript
43
- {
44
- trendlineLinear: {
45
- colorMin: Color,
46
- colorMax: Color,
47
- lineStyle: string, // "dotted" | "solid" | "dashed" | "dashdot"
48
- width: number,
49
- xAxisKey: string, // optional
50
- yAxisKey: string, // optional
51
- projection: boolean, // optional
52
- trendoffset: number, // optional, if > 0 skips first n elements, if < 0 uses last n elements
53
- // optional
54
- label: {
55
- color: Color,
56
- text: string,
57
- display: boolean,
58
- displayValue: boolean, // shows slope value
59
- offset: number,
60
- percentage: boolean,
61
- font: {
62
- family: string,
63
- size: number,
64
- }
65
- },
66
- // optional
67
- legend: {
68
- text: string,
69
- strokeStyle: Color,
70
- fillStyle: Color,
71
- lineCap: string,
72
- lineDash: number[],
73
- lineWidth: number,
74
- }
75
- }
76
- }
77
- ```
78
-
79
- ### Exponential Trendlines
80
-
81
- For exponential trendlines (curves of the form y = a × e^(b×x)), use the `trendlineExponential` configuration:
82
-
83
- ```javascript
84
- {
85
- trendlineExponential: {
86
- colorMin: Color,
87
- colorMax: Color,
88
- lineStyle: string, // "dotted" | "solid" | "dashed" | "dashdot"
89
- width: number,
90
- xAxisKey: string, // optional
91
- yAxisKey: string, // optional
92
- projection: boolean, // optional
93
- trendoffset: number, // optional, if > 0 skips first n elements, if < 0 uses last n elements
94
- // optional
95
- label: {
96
- color: Color,
97
- text: string,
98
- display: boolean,
99
- displayValue: boolean, // shows exponential parameters (a, b)
100
- offset: number,
101
- font: {
102
- family: string,
103
- size: number,
104
- }
105
- },
106
- // optional
107
- legend: {
108
- text: string,
109
- strokeStyle: Color,
110
- fillStyle: Color,
111
- lineCap: string,
112
- lineDash: number[],
113
- lineWidth: number,
114
- }
115
- }
116
- }
117
- ```
118
-
119
- **Note:** Exponential trendlines work best with positive y-values. The equation fitted is y = a × e^(b×x), where:
120
- - `a` is the coefficient (scaling factor)
121
- - `b` is the growth rate (positive for growth, negative for decay)
122
-
123
- ## Examples
124
-
125
- - [Linear Trendline Example](./example/lineChart.html)
126
- - [Exponential Trendline Example](./example/exponentialChart.html)
127
- - [Bar Chart with Trendline](./example/barChart.html)
128
- - [Scatter Chart with Trendline](./example/scatterChart.html)
129
-
130
- ## Supported chart types
131
-
132
- - bar
133
- - line
134
- - scatter
135
-
136
- Both linear and exponential trendlines are supported for all chart types.
137
-
138
- ## Contributing
139
-
140
- Pull requests and issues are always welcome.
141
- For bugs and feature requests, [please create an issue](https://github.com/Makanz/chartjs-plugin-trendline/issues).
142
-
143
- ## License
144
-
145
- chartjs-plugin-trendline.js is available under the [MIT license](http://opensource.org/licenses/MIT).
146
-
147
- ## Star History
148
-
149
- [![Star History Chart](https://api.star-history.com/svg?repos=Makanz/chartjs-plugin-trendline&type=Date)](https://star-history.com/#Makanz/chartjs-plugin-trendline&Date)
1
+ # chartjs-plugin-trendline
2
+
3
+ This plugin draws linear and exponential trendlines in your Chart.
4
+ It has been tested with Chart.js version 4.4.9.
5
+
6
+ ## 📊 [View Live Examples](https://makanz.github.io/chartjs-plugin-trendline/)
7
+
8
+ See the plugin in action with interactive examples for different chart types.
9
+
10
+ ## Installation
11
+
12
+ > **Note:** Version 3.2.0+ supports ES modules (ESM) for modern bundlers like Vite, SvelteKit, and Next.js. See [MIGRATION.md](./MIGRATION.md) for upgrade details.
13
+
14
+ ### Modern Bundlers (Vite, SvelteKit, Next.js, webpack 5+)
15
+
16
+ Install via npm:
17
+
18
+ ```bash
19
+ npm i chart.js chartjs-plugin-trendline
20
+ ```
21
+
22
+ Import and register with Chart.js:
23
+
24
+ ```js
25
+ import { Chart } from 'chart.js';
26
+ import ChartJSTrendline from 'chartjs-plugin-trendline';
27
+
28
+ Chart.register(ChartJSTrendline);
29
+ ```
30
+
31
+ ### Node.js (CommonJS)
32
+
33
+ ```js
34
+ const { Chart } = require('chart.js');
35
+ const ChartJSTrendline = require('chartjs-plugin-trendline');
36
+
37
+ Chart.register(ChartJSTrendline);
38
+ ```
39
+
40
+ ### Browser (CDN)
41
+
42
+ Load Chart.js first, then the plugin which will automatically register itself:
43
+
44
+ ```html
45
+ <script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.9/dist/chart.min.js"></script>
46
+ <script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-trendline/dist/chartjs-plugin-trendline.min.js"></script>
47
+ ```
48
+
49
+ The plugin is now available globally as `ChartJSTrendline` and auto-registers with Chart.js.
50
+
51
+ ## Configuration
52
+
53
+ To configure the trendline plugin you simply add a new config options to your dataset in your chart config.
54
+
55
+ ### Linear Trendlines
56
+
57
+ For linear trendlines (straight lines), use the `trendlineLinear` configuration:
58
+
59
+ ```javascript
60
+ {
61
+ trendlineLinear: {
62
+ colorMin: Color,
63
+ colorMax: Color,
64
+ lineStyle: string, // "dotted" | "solid" | "dashed" | "dashdot"
65
+ width: number,
66
+ xAxisKey: string, // optional
67
+ yAxisKey: string, // optional
68
+ projection: boolean, // optional
69
+ trendoffset: number, // optional, if > 0 skips first n elements, if < 0 uses last n elements
70
+ // optional
71
+ label: {
72
+ color: Color,
73
+ text: string,
74
+ display: boolean,
75
+ displayValue: boolean, // shows slope value
76
+ offset: number,
77
+ percentage: boolean,
78
+ font: {
79
+ family: string,
80
+ size: number,
81
+ }
82
+ },
83
+ // optional
84
+ legend: {
85
+ text: string,
86
+ strokeStyle: Color,
87
+ fillStyle: Color,
88
+ lineCap: string,
89
+ lineDash: number[],
90
+ lineWidth: number,
91
+ }
92
+ }
93
+ }
94
+ ```
95
+
96
+ ### Exponential Trendlines
97
+
98
+ For exponential trendlines (curves of the form y = a × e^(b×x)), use the `trendlineExponential` configuration:
99
+
100
+ ```javascript
101
+ {
102
+ trendlineExponential: {
103
+ colorMin: Color,
104
+ colorMax: Color,
105
+ lineStyle: string, // "dotted" | "solid" | "dashed" | "dashdot"
106
+ width: number,
107
+ xAxisKey: string, // optional
108
+ yAxisKey: string, // optional
109
+ projection: boolean, // optional
110
+ trendoffset: number, // optional, if > 0 skips first n elements, if < 0 uses last n elements
111
+ // optional
112
+ label: {
113
+ color: Color,
114
+ text: string,
115
+ display: boolean,
116
+ displayValue: boolean, // shows exponential parameters (a, b)
117
+ offset: number,
118
+ font: {
119
+ family: string,
120
+ size: number,
121
+ }
122
+ },
123
+ // optional
124
+ legend: {
125
+ text: string,
126
+ strokeStyle: Color,
127
+ fillStyle: Color,
128
+ lineCap: string,
129
+ lineDash: number[],
130
+ lineWidth: number,
131
+ }
132
+ }
133
+ }
134
+ ```
135
+
136
+ **Note:** Exponential trendlines work best with positive y-values. The equation fitted is y = a × e^(b×x), where:
137
+ - `a` is the coefficient (scaling factor)
138
+ - `b` is the growth rate (positive for growth, negative for decay)
139
+
140
+ ## Examples
141
+
142
+ - [Linear Trendline Example](./example/lineChart.html)
143
+ - [Exponential Trendline Example](./example/exponentialChart.html)
144
+ - [Bar Chart with Trendline](./example/barChart.html)
145
+ - [Scatter Chart with Trendline](./example/scatterChart.html)
146
+
147
+ ## Supported chart types
148
+
149
+ - bar
150
+ - line
151
+ - scatter
152
+
153
+ Both linear and exponential trendlines are supported for all chart types.
154
+
155
+ ## Contributing
156
+
157
+ Pull requests and issues are always welcome.
158
+ For bugs and feature requests, [please create an issue](https://github.com/Makanz/chartjs-plugin-trendline/issues).
159
+
160
+ ## License
161
+
162
+ chartjs-plugin-trendline.js is available under the [MIT license](http://opensource.org/licenses/MIT).
163
+
164
+ ## Star History
165
+
166
+ [![Star History Chart](https://api.star-history.com/svg?repos=Makanz/chartjs-plugin-trendline&type=Date)](https://star-history.com/#Makanz/chartjs-plugin-trendline&Date)
package/babel.config.js CHANGED
@@ -1,3 +1,3 @@
1
- module.exports = {
2
- presets: [['@babel/preset-env', {targets: {node: 'current'}}]],
3
- };
1
+ export default {
2
+ presets: [['@babel/preset-env', {targets: {node: 'current'}}]],
3
+ };
package/changelog.md CHANGED
@@ -1,40 +1,40 @@
1
- # Changelog 3.1.0
2
-
3
- ### New Features
4
- - Added exponential trendline support with `trendlineExponential` configuration
5
- - Exponential trendlines fit curves of the form y = a × e^(b×x)
6
- - All existing styling options (colors, width, lineStyle, projection, etc.) work with exponential trendlines
7
- - Added comprehensive test coverage for exponential functionality
8
- - Added exponential trendline example (exponentialChart.html)
9
-
10
- ### Improvements
11
- - Updated README with exponential trendline documentation
12
- - Enhanced package description to mention exponential support
13
-
14
- # Changelog 3.0.0
15
-
16
- ### Breaking Changes
17
- - Updated to version 3.0.0-beta.1 with modular code structure
18
-
19
- ### New Features
20
- - Added trendline offset setting (`trendoffset`)
21
- - Added two new example files (barChartWithNullValues.html, scatterProjection.html)
22
-
23
- ### Bug Fixes
24
- - Fixed trendline accuracy and boundary calculations
25
- - Corrected trendline rendering, projection, and data accuracy
26
- - Fixed trendline data processing issues
27
-
28
- ### Testing & CI
29
- - Added comprehensive unit tests for all components (trendline, label, drawing utils, lineFitter)
30
- - Added GitHub Actions workflow for automated testing on PRs and main branch
31
- - Updated Node.js version to 22 in CI
32
-
33
- ### Code Quality
34
- - Split code into modular structure with separate components
35
- - Added Copilot instructions for development
36
- - Updated Chart.js dependency to version 4.4.9
37
-
38
- ### Documentation
39
- - Updated README with new features
1
+ # Changelog 3.1.0
2
+
3
+ ### New Features
4
+ - Added exponential trendline support with `trendlineExponential` configuration
5
+ - Exponential trendlines fit curves of the form y = a × e^(b×x)
6
+ - All existing styling options (colors, width, lineStyle, projection, etc.) work with exponential trendlines
7
+ - Added comprehensive test coverage for exponential functionality
8
+ - Added exponential trendline example (exponentialChart.html)
9
+
10
+ ### Improvements
11
+ - Updated README with exponential trendline documentation
12
+ - Enhanced package description to mention exponential support
13
+
14
+ # Changelog 3.0.0
15
+
16
+ ### Breaking Changes
17
+ - Updated to version 3.0.0-beta.1 with modular code structure
18
+
19
+ ### New Features
20
+ - Added trendline offset setting (`trendoffset`)
21
+ - Added two new example files (barChartWithNullValues.html, scatterProjection.html)
22
+
23
+ ### Bug Fixes
24
+ - Fixed trendline accuracy and boundary calculations
25
+ - Corrected trendline rendering, projection, and data accuracy
26
+ - Fixed trendline data processing issues
27
+
28
+ ### Testing & CI
29
+ - Added comprehensive unit tests for all components (trendline, label, drawing utils, lineFitter)
30
+ - Added GitHub Actions workflow for automated testing on PRs and main branch
31
+ - Updated Node.js version to 22 in CI
32
+
33
+ ### Code Quality
34
+ - Split code into modular structure with separate components
35
+ - Added Copilot instructions for development
36
+ - Updated Chart.js dependency to version 4.4.9
37
+
38
+ ### Documentation
39
+ - Updated README with new features
40
40
  - Added agent instructions for development workflow