chartjs-plugin-trendline 3.2.0 → 3.2.3
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 +64 -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 -126
- package/README.md +166 -166
- package/babel.config.js +3 -3
- package/changelog.md +39 -39
- package/dist/chartjs-plugin-trendline.cjs +884 -885
- package/dist/chartjs-plugin-trendline.esm.js +882 -883
- package/dist/chartjs-plugin-trendline.js +890 -891
- package/dist/chartjs-plugin-trendline.min.js +8 -8
- package/dist/chartjs-plugin-trendline.min.js.map +1 -1
- 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 +45 -40
- package/rollup.config.js +54 -54
- 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 +78 -79
- package/src/core/plugin.test.js +307 -0
- 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
|
@@ -1,141 +1,141 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8">
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
-
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
|
7
|
-
<title>Scatter Chart Projection - Chart.js Trendline Plugin</title>
|
|
8
|
-
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.5.0/dist/chart.umd.js"></script>
|
|
9
|
-
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-trendline/dist/chartjs-plugin-trendline.min.js"></script>
|
|
10
|
-
<style>
|
|
11
|
-
body {
|
|
12
|
-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
13
|
-
margin: 0;
|
|
14
|
-
padding: 40px 20px;
|
|
15
|
-
background-color: #f8f9fa;
|
|
16
|
-
color: #333;
|
|
17
|
-
line-height: 1.6;
|
|
18
|
-
}
|
|
19
|
-
.container {
|
|
20
|
-
max-width: 1000px;
|
|
21
|
-
margin: 0 auto;
|
|
22
|
-
}
|
|
23
|
-
h1 {
|
|
24
|
-
text-align: center;
|
|
25
|
-
color: #2c3e50;
|
|
26
|
-
margin-bottom: 10px;
|
|
27
|
-
font-size: 2.5rem;
|
|
28
|
-
}
|
|
29
|
-
.subtitle {
|
|
30
|
-
text-align: center;
|
|
31
|
-
color: #7f8c8d;
|
|
32
|
-
margin-bottom: 40px;
|
|
33
|
-
font-size: 1.1rem;
|
|
34
|
-
}
|
|
35
|
-
.chart-container {
|
|
36
|
-
background: white;
|
|
37
|
-
padding: 30px;
|
|
38
|
-
border-radius: 8px;
|
|
39
|
-
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
|
40
|
-
margin-bottom: 30px;
|
|
41
|
-
}
|
|
42
|
-
.chart-wrapper {
|
|
43
|
-
position: relative;
|
|
44
|
-
height: 400px;
|
|
45
|
-
}
|
|
46
|
-
</style>
|
|
47
|
-
<script>
|
|
48
|
-
document.addEventListener("DOMContentLoaded", function () {
|
|
49
|
-
new Chart(document.getElementById("scatter-projection-chart"), {
|
|
50
|
-
type: 'scatter',
|
|
51
|
-
data: {
|
|
52
|
-
datasets: [
|
|
53
|
-
{
|
|
54
|
-
label: 'Data Points',
|
|
55
|
-
backgroundColor: '#3e95cd',
|
|
56
|
-
borderColor: '#2980b9',
|
|
57
|
-
pointRadius: 6,
|
|
58
|
-
pointHoverRadius: 8,
|
|
59
|
-
data: [
|
|
60
|
-
{x: 2, y: 1},
|
|
61
|
-
{x: 2.5, y: 2},
|
|
62
|
-
{x: 1.5, y: 3},
|
|
63
|
-
{x: 2, y: 4}
|
|
64
|
-
],
|
|
65
|
-
trendlineLinear: {
|
|
66
|
-
width: 2,
|
|
67
|
-
lineStyle: 'solid',
|
|
68
|
-
colorMin: '#e74c3c',
|
|
69
|
-
colorMax: '#e74c3c',
|
|
70
|
-
projection: true,
|
|
71
|
-
label: {
|
|
72
|
-
display: true,
|
|
73
|
-
text: 'Projected Trend',
|
|
74
|
-
displayValue: true
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
]
|
|
79
|
-
},
|
|
80
|
-
options: {
|
|
81
|
-
maintainAspectRatio: false,
|
|
82
|
-
responsive: true,
|
|
83
|
-
plugins: {
|
|
84
|
-
title: {
|
|
85
|
-
display: true,
|
|
86
|
-
text: 'Scatter Plot with Projected Trendline',
|
|
87
|
-
font: { size: 16 }
|
|
88
|
-
},
|
|
89
|
-
legend: {
|
|
90
|
-
display: true,
|
|
91
|
-
position: 'top'
|
|
92
|
-
},
|
|
93
|
-
tooltip: {
|
|
94
|
-
mode: 'point',
|
|
95
|
-
intersect: true
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
scales: {
|
|
99
|
-
x: {
|
|
100
|
-
type: 'linear',
|
|
101
|
-
position: 'bottom',
|
|
102
|
-
min: 0,
|
|
103
|
-
max: 4,
|
|
104
|
-
title: {
|
|
105
|
-
display: true,
|
|
106
|
-
text: 'X Value'
|
|
107
|
-
}
|
|
108
|
-
},
|
|
109
|
-
y: {
|
|
110
|
-
type: 'linear',
|
|
111
|
-
position: 'left',
|
|
112
|
-
min: 0,
|
|
113
|
-
title: {
|
|
114
|
-
display: true,
|
|
115
|
-
text: 'Y Value'
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
</script>
|
|
123
|
-
</head>
|
|
124
|
-
<body>
|
|
125
|
-
<div class="container">
|
|
126
|
-
<h1>Chart.js Trendline Plugin</h1>
|
|
127
|
-
<p class="subtitle">Scatter Chart with Projected Trendline</p>
|
|
128
|
-
|
|
129
|
-
<div class="chart-container">
|
|
130
|
-
<div class="chart-wrapper">
|
|
131
|
-
<canvas id="scatter-projection-chart"></canvas>
|
|
132
|
-
</div>
|
|
133
|
-
</div>
|
|
134
|
-
|
|
135
|
-
<div style="text-align: center; margin-top: 30px;">
|
|
136
|
-
<a href="../index.html" style="display: inline-block; margin: 0 10px; padding: 10px 20px; background: #3498db; color: white; text-decoration: none; border-radius: 4px; font-weight: 500;">← Back to Examples</a>
|
|
137
|
-
<a href="scatterChart.html" style="display: inline-block; margin: 0 10px; padding: 10px 20px; background: #3498db; color: white; text-decoration: none; border-radius: 4px; font-weight: 500;">← Scatter Chart</a>
|
|
138
|
-
</div>
|
|
139
|
-
</div>
|
|
140
|
-
</body>
|
|
141
|
-
</html>
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
|
7
|
+
<title>Scatter Chart Projection - Chart.js Trendline Plugin</title>
|
|
8
|
+
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.5.0/dist/chart.umd.js"></script>
|
|
9
|
+
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-trendline/dist/chartjs-plugin-trendline.min.js"></script>
|
|
10
|
+
<style>
|
|
11
|
+
body {
|
|
12
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
13
|
+
margin: 0;
|
|
14
|
+
padding: 40px 20px;
|
|
15
|
+
background-color: #f8f9fa;
|
|
16
|
+
color: #333;
|
|
17
|
+
line-height: 1.6;
|
|
18
|
+
}
|
|
19
|
+
.container {
|
|
20
|
+
max-width: 1000px;
|
|
21
|
+
margin: 0 auto;
|
|
22
|
+
}
|
|
23
|
+
h1 {
|
|
24
|
+
text-align: center;
|
|
25
|
+
color: #2c3e50;
|
|
26
|
+
margin-bottom: 10px;
|
|
27
|
+
font-size: 2.5rem;
|
|
28
|
+
}
|
|
29
|
+
.subtitle {
|
|
30
|
+
text-align: center;
|
|
31
|
+
color: #7f8c8d;
|
|
32
|
+
margin-bottom: 40px;
|
|
33
|
+
font-size: 1.1rem;
|
|
34
|
+
}
|
|
35
|
+
.chart-container {
|
|
36
|
+
background: white;
|
|
37
|
+
padding: 30px;
|
|
38
|
+
border-radius: 8px;
|
|
39
|
+
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
|
40
|
+
margin-bottom: 30px;
|
|
41
|
+
}
|
|
42
|
+
.chart-wrapper {
|
|
43
|
+
position: relative;
|
|
44
|
+
height: 400px;
|
|
45
|
+
}
|
|
46
|
+
</style>
|
|
47
|
+
<script>
|
|
48
|
+
document.addEventListener("DOMContentLoaded", function () {
|
|
49
|
+
new Chart(document.getElementById("scatter-projection-chart"), {
|
|
50
|
+
type: 'scatter',
|
|
51
|
+
data: {
|
|
52
|
+
datasets: [
|
|
53
|
+
{
|
|
54
|
+
label: 'Data Points',
|
|
55
|
+
backgroundColor: '#3e95cd',
|
|
56
|
+
borderColor: '#2980b9',
|
|
57
|
+
pointRadius: 6,
|
|
58
|
+
pointHoverRadius: 8,
|
|
59
|
+
data: [
|
|
60
|
+
{x: 2, y: 1},
|
|
61
|
+
{x: 2.5, y: 2},
|
|
62
|
+
{x: 1.5, y: 3},
|
|
63
|
+
{x: 2, y: 4}
|
|
64
|
+
],
|
|
65
|
+
trendlineLinear: {
|
|
66
|
+
width: 2,
|
|
67
|
+
lineStyle: 'solid',
|
|
68
|
+
colorMin: '#e74c3c',
|
|
69
|
+
colorMax: '#e74c3c',
|
|
70
|
+
projection: true,
|
|
71
|
+
label: {
|
|
72
|
+
display: true,
|
|
73
|
+
text: 'Projected Trend',
|
|
74
|
+
displayValue: true
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
]
|
|
79
|
+
},
|
|
80
|
+
options: {
|
|
81
|
+
maintainAspectRatio: false,
|
|
82
|
+
responsive: true,
|
|
83
|
+
plugins: {
|
|
84
|
+
title: {
|
|
85
|
+
display: true,
|
|
86
|
+
text: 'Scatter Plot with Projected Trendline',
|
|
87
|
+
font: { size: 16 }
|
|
88
|
+
},
|
|
89
|
+
legend: {
|
|
90
|
+
display: true,
|
|
91
|
+
position: 'top'
|
|
92
|
+
},
|
|
93
|
+
tooltip: {
|
|
94
|
+
mode: 'point',
|
|
95
|
+
intersect: true
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
scales: {
|
|
99
|
+
x: {
|
|
100
|
+
type: 'linear',
|
|
101
|
+
position: 'bottom',
|
|
102
|
+
min: 0,
|
|
103
|
+
max: 4,
|
|
104
|
+
title: {
|
|
105
|
+
display: true,
|
|
106
|
+
text: 'X Value'
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
y: {
|
|
110
|
+
type: 'linear',
|
|
111
|
+
position: 'left',
|
|
112
|
+
min: 0,
|
|
113
|
+
title: {
|
|
114
|
+
display: true,
|
|
115
|
+
text: 'Y Value'
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
</script>
|
|
123
|
+
</head>
|
|
124
|
+
<body>
|
|
125
|
+
<div class="container">
|
|
126
|
+
<h1>Chart.js Trendline Plugin</h1>
|
|
127
|
+
<p class="subtitle">Scatter Chart with Projected Trendline</p>
|
|
128
|
+
|
|
129
|
+
<div class="chart-container">
|
|
130
|
+
<div class="chart-wrapper">
|
|
131
|
+
<canvas id="scatter-projection-chart"></canvas>
|
|
132
|
+
</div>
|
|
133
|
+
</div>
|
|
134
|
+
|
|
135
|
+
<div style="text-align: center; margin-top: 30px;">
|
|
136
|
+
<a href="../index.html" style="display: inline-block; margin: 0 10px; padding: 10px 20px; background: #3498db; color: white; text-decoration: none; border-radius: 4px; font-weight: 500;">← Back to Examples</a>
|
|
137
|
+
<a href="scatterChart.html" style="display: inline-block; margin: 0 10px; padding: 10px 20px; background: #3498db; color: white; text-decoration: none; border-radius: 4px; font-weight: 500;">← Scatter Chart</a>
|
|
138
|
+
</div>
|
|
139
|
+
</div>
|
|
140
|
+
</body>
|
|
141
|
+
</html>
|
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8">
|
|
5
|
-
<title>Test Null Handling</title>
|
|
6
|
-
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.5.0/dist/chart.umd.js"></script>
|
|
7
|
-
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-trendline/dist/chartjs-plugin-trendline.min.js"></script>
|
|
8
|
-
</head>
|
|
9
|
-
<body>
|
|
10
|
-
<canvas id="test-chart" width="400" height="200"></canvas>
|
|
11
|
-
<script>
|
|
12
|
-
// Test with the exact data structure from lineChartProjection.html Dataset 3
|
|
13
|
-
const testData = [
|
|
14
|
-
{ x: 50, y: 10 },
|
|
15
|
-
{ x: 55, y: 12 },
|
|
16
|
-
{ x: 60, y: 15 },
|
|
17
|
-
null,
|
|
18
|
-
{ x: 70, y: 18 },
|
|
19
|
-
{ x: 75, y: 22 },
|
|
20
|
-
{x: 65, y: null}
|
|
21
|
-
];
|
|
22
|
-
|
|
23
|
-
console.log('Test data:', testData);
|
|
24
|
-
|
|
25
|
-
try {
|
|
26
|
-
const chart = new Chart(document.getElementById('test-chart'), {
|
|
27
|
-
type: 'line',
|
|
28
|
-
data: {
|
|
29
|
-
datasets: [{
|
|
30
|
-
data: testData,
|
|
31
|
-
label: "Test Dataset",
|
|
32
|
-
borderColor: "#4BC0C0",
|
|
33
|
-
trendlineLinear: {
|
|
34
|
-
colorMin: "#4BC0C0",
|
|
35
|
-
lineStyle: "solid",
|
|
36
|
-
width: 2,
|
|
37
|
-
projection: true
|
|
38
|
-
}
|
|
39
|
-
}]
|
|
40
|
-
},
|
|
41
|
-
options: {
|
|
42
|
-
scales: {
|
|
43
|
-
x: {
|
|
44
|
-
type: 'linear',
|
|
45
|
-
position: 'bottom'
|
|
46
|
-
},
|
|
47
|
-
y: {
|
|
48
|
-
type: 'linear',
|
|
49
|
-
position: 'left'
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
console.log('Chart created successfully');
|
|
55
|
-
} catch (error) {
|
|
56
|
-
console.error('Error creating chart:', error);
|
|
57
|
-
}
|
|
58
|
-
</script>
|
|
59
|
-
</body>
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<title>Test Null Handling</title>
|
|
6
|
+
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.5.0/dist/chart.umd.js"></script>
|
|
7
|
+
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-trendline/dist/chartjs-plugin-trendline.min.js"></script>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<canvas id="test-chart" width="400" height="200"></canvas>
|
|
11
|
+
<script>
|
|
12
|
+
// Test with the exact data structure from lineChartProjection.html Dataset 3
|
|
13
|
+
const testData = [
|
|
14
|
+
{ x: 50, y: 10 },
|
|
15
|
+
{ x: 55, y: 12 },
|
|
16
|
+
{ x: 60, y: 15 },
|
|
17
|
+
null,
|
|
18
|
+
{ x: 70, y: 18 },
|
|
19
|
+
{ x: 75, y: 22 },
|
|
20
|
+
{x: 65, y: null}
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
console.log('Test data:', testData);
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
const chart = new Chart(document.getElementById('test-chart'), {
|
|
27
|
+
type: 'line',
|
|
28
|
+
data: {
|
|
29
|
+
datasets: [{
|
|
30
|
+
data: testData,
|
|
31
|
+
label: "Test Dataset",
|
|
32
|
+
borderColor: "#4BC0C0",
|
|
33
|
+
trendlineLinear: {
|
|
34
|
+
colorMin: "#4BC0C0",
|
|
35
|
+
lineStyle: "solid",
|
|
36
|
+
width: 2,
|
|
37
|
+
projection: true
|
|
38
|
+
}
|
|
39
|
+
}]
|
|
40
|
+
},
|
|
41
|
+
options: {
|
|
42
|
+
scales: {
|
|
43
|
+
x: {
|
|
44
|
+
type: 'linear',
|
|
45
|
+
position: 'bottom'
|
|
46
|
+
},
|
|
47
|
+
y: {
|
|
48
|
+
type: 'linear',
|
|
49
|
+
position: 'left'
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
console.log('Chart created successfully');
|
|
55
|
+
} catch (error) {
|
|
56
|
+
console.error('Error creating chart:', error);
|
|
57
|
+
}
|
|
58
|
+
</script>
|
|
59
|
+
</body>
|
|
60
60
|
</html>
|