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.
- package/.github/copilot-instructions.md +40 -40
- package/.github/workflows/release.yml +61 -61
- package/.github/workflows/tests.yml +26 -26
- package/.prettierrc +5 -5
- package/CLAUDE.md +44 -44
- package/GEMINI.md +40 -40
- package/LICENSE +21 -21
- package/MIGRATION.md +126 -0
- package/README.md +166 -149
- package/babel.config.js +3 -3
- package/changelog.md +39 -39
- package/dist/chartjs-plugin-trendline.cjs +885 -0
- package/dist/chartjs-plugin-trendline.esm.js +883 -0
- package/dist/chartjs-plugin-trendline.js +891 -0
- package/dist/chartjs-plugin-trendline.min.js +8 -1
- package/dist/chartjs-plugin-trendline.min.js.map +1 -0
- package/example/barChart.html +165 -165
- package/example/barChartWithNullValues.html +168 -168
- package/example/barChart_label.html +174 -174
- package/example/exponentialChart.html +244 -244
- package/example/lineChart.html +210 -210
- package/example/lineChartProjection.html +261 -261
- package/example/lineChartTypeTime.html +190 -190
- package/example/scatterChart.html +136 -136
- package/example/scatterProjection.html +141 -141
- package/example/test-null-handling.html +59 -59
- package/index.html +215 -215
- package/jest.config.js +4 -4
- package/package.json +40 -30
- package/rollup.config.js +54 -0
- package/src/components/label.js +56 -56
- package/src/components/label.test.js +129 -129
- package/src/components/trendline.js +375 -375
- package/src/components/trendline.test.js +789 -789
- package/src/core/plugin.js +79 -79
- package/src/index.js +12 -12
- package/src/utils/drawing.js +125 -125
- package/src/utils/drawing.test.js +308 -308
- package/src/utils/exponentialFitter.js +146 -146
- package/src/utils/exponentialFitter.test.js +362 -362
- package/src/utils/lineFitter.js +86 -86
- package/src/utils/lineFitter.test.js +340 -340
- package/dist/chartjs-plugin-trendline.min.js.LICENSE.txt +0 -11
- 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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
// optional
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
{
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
##
|
|
148
|
-
|
|
149
|
-
|
|
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
|
+
[](https://star-history.com/#Makanz/chartjs-plugin-trendline&Date)
|
package/babel.config.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
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
|