velo-plot 2.0.0 → 2.20.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 (65) hide show
  1. package/dist/{ChartCore-BhQ4j7f5.js → ChartCore-ivzLqxVb.js} +419 -393
  2. package/dist/ChartCore-ivzLqxVb.js.map +1 -0
  3. package/dist/{SciPlot-GJvw7GJo.js → SciPlot-CEU4ApgD.js} +2 -2
  4. package/dist/{SciPlot-GJvw7GJo.js.map → SciPlot-CEU4ApgD.js.map} +1 -1
  5. package/dist/{axisFormat-SPX-CD5s.js → axisFormat-CzumxpCL.js} +3 -3
  6. package/dist/axisFormat-CzumxpCL.js.map +1 -0
  7. package/dist/core/chart/ChartAxisManager.d.ts +2 -0
  8. package/dist/core/chart/ChartCore.d.ts +15 -0
  9. package/dist/core/chart/ChartPluginBridge.d.ts +1 -0
  10. package/dist/core/chart/ChartRenderLoop.d.ts +2 -0
  11. package/dist/core/chart/ChartStateManager.d.ts +2 -0
  12. package/dist/core/chart/types.d.ts +5 -0
  13. package/dist/core/sync/index.d.ts +0 -1
  14. package/dist/{createStackedChart-DJSmqerD.js → createStackedChart-DxNW0VkF.js} +178 -179
  15. package/dist/createStackedChart-DxNW0VkF.js.map +1 -0
  16. package/dist/{index-D7dTq6VB.js → index-BBpJwOct.js} +17 -19
  17. package/dist/index-BBpJwOct.js.map +1 -0
  18. package/dist/{index-CUGS98p4.js → index-CaXWSOTk.js} +3 -6
  19. package/dist/index-CaXWSOTk.js.map +1 -0
  20. package/dist/{index-CWipqOLP.js → index-qunX30Xu.js} +2 -2
  21. package/dist/{index-CWipqOLP.js.map → index-qunX30Xu.js.map} +1 -1
  22. package/dist/{index.core-fpZ1dYN0.js → index.core-COREBDNq.js} +25 -24
  23. package/dist/{index.core-fpZ1dYN0.js.map → index.core-COREBDNq.js.map} +1 -1
  24. package/dist/index.d.ts +1 -1
  25. package/dist/{mockDatafeed-Cdg5hKEo.js → mockDatafeed-927foCM4.js} +2 -2
  26. package/dist/mockDatafeed-927foCM4.js.map +1 -0
  27. package/dist/plugins/analysis/contours.d.ts +31 -0
  28. package/dist/plugins/analysis.js +494 -407
  29. package/dist/plugins/analysis.js.map +1 -1
  30. package/dist/plugins/broken-axis.js +170 -181
  31. package/dist/plugins/broken-axis.js.map +1 -1
  32. package/dist/plugins/forecasting/algorithms.d.ts +7 -2
  33. package/dist/plugins/forecasting/types.d.ts +13 -3
  34. package/dist/plugins/forecasting.js +355 -175
  35. package/dist/plugins/forecasting.js.map +1 -1
  36. package/dist/plugins/latex/symbols.d.ts +50 -0
  37. package/dist/plugins/latex/types.d.ts +13 -1
  38. package/dist/plugins/latex.js +351 -331
  39. package/dist/plugins/latex.js.map +1 -1
  40. package/dist/plugins/ml-integration/native-algorithms.d.ts +24 -4
  41. package/dist/plugins/ml-integration/types.d.ts +19 -0
  42. package/dist/plugins/ml-integration.js +191 -140
  43. package/dist/plugins/ml-integration.js.map +1 -1
  44. package/dist/plugins/pattern-recognition/types.d.ts +28 -1
  45. package/dist/plugins/pattern-recognition.js +416 -343
  46. package/dist/plugins/pattern-recognition.js.map +1 -1
  47. package/dist/plugins/snapshot.js +36 -36
  48. package/dist/plugins/snapshot.js.map +1 -1
  49. package/dist/plugins/sync.js +1 -1
  50. package/dist/plugins/tools.js +1 -1
  51. package/dist/plugins/virtualization.js +1 -1
  52. package/dist/react.js +2 -2
  53. package/dist/symbols-DT0eLlpW.js +568 -0
  54. package/dist/symbols-DT0eLlpW.js.map +1 -0
  55. package/dist/trading.js +5 -5
  56. package/dist/velo-plot.full.js +184 -182
  57. package/dist/velo-plot.js +3 -3
  58. package/dist/workers/indicatorsAsync.d.ts +24 -0
  59. package/package.json +1 -1
  60. package/dist/ChartCore-BhQ4j7f5.js.map +0 -1
  61. package/dist/axisFormat-SPX-CD5s.js.map +0 -1
  62. package/dist/createStackedChart-DJSmqerD.js.map +0 -1
  63. package/dist/index-CUGS98p4.js.map +0 -1
  64. package/dist/index-D7dTq6VB.js.map +0 -1
  65. package/dist/mockDatafeed-Cdg5hKEo.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
  import { SeriesData } from '../../types';
2
2
 
3
- export type ForecastingMethod = 'sma' | 'ema' | 'wma' | 'linear' | 'expSmoothing' | 'holt' | 'holtWinters';
3
+ export type ForecastingMethod = 'sma' | 'ema' | 'wma' | 'linear' | 'expSmoothing' | 'holt' | 'holtWinters' | 'arima';
4
4
  export interface ForecastingOptions {
5
5
  /** Method to use for forecasting */
6
6
  method: ForecastingMethod;
@@ -24,6 +24,12 @@ export interface ForecastingParams {
24
24
  period?: number;
25
25
  /** Polynomial order for trend fitting (default: 1) */
26
26
  polynomialOrder?: number;
27
+ /** ARIMA autoregressive order (p, default: 1) */
28
+ p?: number;
29
+ /** ARIMA differencing order (d, default: 1) */
30
+ d?: number;
31
+ /** ARIMA moving-average order (q, default: 0) */
32
+ q?: number;
27
33
  }
28
34
  export interface ForecastingResult {
29
35
  /** Forecasted points (X values) */
@@ -39,9 +45,12 @@ export interface ForecastingResult {
39
45
  /** Metadata and fit statistics */
40
46
  metadata: {
41
47
  mse?: number;
48
+ rmse?: number;
42
49
  mae?: number;
43
50
  r2?: number;
44
51
  aic?: number;
52
+ /** Confidence level used to build the prediction band (e.g. 0.95) */
53
+ confidence?: number;
45
54
  };
46
55
  }
47
56
  export interface ForecastingVisualizationConfig {
@@ -69,9 +78,10 @@ export interface PluginForecastingConfig {
69
78
  }
70
79
  export interface ForecastingAPI {
71
80
  /**
72
- * Forecast future values for a given dataset
81
+ * Forecast future values for a given dataset, or for a series by id when a
82
+ * string is passed (e.g. `forecast('s1', { method: 'arima', horizon: 50 })`).
73
83
  */
74
- forecast(data: SeriesData | number[] | Float32Array, options: ForecastingOptions): ForecastingResult;
84
+ forecast(data: SeriesData | number[] | Float32Array | string, options: ForecastingOptions): ForecastingResult;
75
85
  /**
76
86
  * Forecast future values for a series by ID
77
87
  */
@@ -1,236 +1,416 @@
1
- function p(n, s, r, o, l = {}) {
2
- const t = n.length;
3
- if (t === 0) throw new Error("Dataset is empty");
4
- const c = t > 1 ? (n[t - 1] - n[0]) / (t - 1) : 1, a = n[t - 1];
5
- let e;
6
- switch (r) {
1
+ function E(l) {
2
+ return Array.from(l);
3
+ }
4
+ function D(l) {
5
+ const a = [
6
+ [0.5, 0.674],
7
+ [0.68, 0.994],
8
+ [0.8, 1.282],
9
+ [0.9, 1.645],
10
+ [0.95, 1.96],
11
+ [0.975, 2.241],
12
+ [0.99, 2.576],
13
+ [0.995, 2.807]
14
+ ];
15
+ let o = a[0], e = 1 / 0;
16
+ for (const c of a) {
17
+ const t = Math.abs(c[0] - l);
18
+ t < e && (e = t, o = c);
19
+ }
20
+ return o[1];
21
+ }
22
+ function C(l, a, o, e, c = {}, t = 0.95) {
23
+ const r = l.length;
24
+ if (r === 0) throw new Error("Dataset is empty");
25
+ const s = E(a), n = E(l), i = r > 1 ? (n[r - 1] - n[0]) / (r - 1) : 1, m = n[r - 1];
26
+ let f;
27
+ switch (o) {
7
28
  case "sma":
8
- e = L(s, o, l.windowSize || 10);
29
+ f = X(s, e, c.windowSize || 10);
9
30
  break;
10
31
  case "ema":
11
- e = W(s, o, l.alpha || 0.3);
32
+ f = R(s, e, c.alpha ?? 0.3);
12
33
  break;
13
34
  case "linear":
14
- e = F(n, s, o);
35
+ f = j(n, s, e);
15
36
  break;
16
37
  case "expSmoothing":
17
- e = x(s, o, l.alpha || 0.3);
38
+ f = B(s, e, c.alpha ?? 0.3);
18
39
  break;
19
40
  case "holt":
20
- e = k(s, o, l.alpha || 0.3, l.beta || 0.1);
41
+ f = F(s, e, c.alpha ?? 0.3, c.beta ?? 0.1);
21
42
  break;
22
43
  case "wma":
23
- e = E(s, o, l.windowSize || 10);
44
+ f = W(s, e, c.windowSize || 10);
24
45
  break;
25
46
  case "holtWinters":
26
- e = C(
47
+ f = Y(
48
+ s,
49
+ e,
50
+ c.period || 12,
51
+ c.alpha ?? 0.3,
52
+ c.beta ?? 0.1,
53
+ c.gamma ?? 0.1
54
+ );
55
+ break;
56
+ case "arima":
57
+ f = H(
27
58
  s,
28
- o,
29
- l.period || 12,
30
- l.alpha || 0.3,
31
- l.beta || 0.1,
32
- l.gamma || 0.1
59
+ e,
60
+ c.p ?? 1,
61
+ c.d ?? 1,
62
+ c.q ?? 0
33
63
  );
34
64
  break;
35
65
  default:
36
- throw new Error(`Method ${r} not implemented yet`);
66
+ throw new Error(`Method ${o} not implemented yet`);
37
67
  }
38
- const u = new Array(o);
39
- for (let w = 0; w < o; w++)
40
- u[w] = a + (w + 1) * c;
68
+ const w = new Array(e);
69
+ for (let S = 0; S < e; S++)
70
+ w[S] = m + (S + 1) * i;
71
+ const u = J(s, f.fitted), y = D(t), h = u.rmse, { lower: v, upper: x } = I(
72
+ f.yValues,
73
+ h,
74
+ y,
75
+ f.accumulates
76
+ );
41
77
  return {
42
- xValues: u,
43
- yValues: e.yValues,
44
- lowerBound: e.lower,
45
- upperBound: e.upper,
46
- method: r,
47
- metadata: Y(s, e.yValues)
48
- // Simplified for now
78
+ xValues: w,
79
+ yValues: f.yValues,
80
+ lowerBound: v,
81
+ upperBound: x,
82
+ method: o,
83
+ metadata: { ...u, confidence: t }
49
84
  };
50
85
  }
51
- function E(n, s, r) {
52
- const o = n.length, l = Math.min(r, o);
53
- let t = 0, c = 0;
54
- for (let e = 0; e < l; e++) {
55
- const u = e + 1;
56
- t += n[o - l + e] * u, c += u;
57
- }
58
- const a = t / c;
59
- return { yValues: new Array(s).fill(a) };
60
- }
61
- function L(n, s, r) {
62
- const o = n.length, l = Math.min(r, o);
63
- let t = 0;
64
- for (let a = o - l; a < o; a++)
65
- t += n[a];
66
- const c = t / l;
67
- return {
68
- yValues: new Array(s).fill(c)
69
- };
86
+ function I(l, a, o, e) {
87
+ const c = new Array(l.length), t = new Array(l.length);
88
+ for (let r = 0; r < l.length; r++) {
89
+ const s = e ? Math.sqrt(r + 1) : 1, n = o * a * s;
90
+ c[r] = l[r] - n, t[r] = l[r] + n;
91
+ }
92
+ return { lower: c, upper: t };
70
93
  }
71
- function W(n, s, r) {
72
- const o = n.length;
73
- let l = n[0];
74
- for (let t = 1; t < o; t++)
75
- l = r * n[t] + (1 - r) * l;
76
- return {
77
- yValues: new Array(s).fill(l)
78
- };
94
+ function W(l, a, o) {
95
+ const e = l.length, c = Math.min(o, e), t = (n) => {
96
+ const i = Math.min(c, n);
97
+ let m = 0, f = 0;
98
+ for (let w = 0; w < i; w++) {
99
+ const u = w + 1;
100
+ m += l[n - i + w] * u, f += u;
101
+ }
102
+ return m / f;
103
+ }, r = new Array(e).fill(null);
104
+ for (let n = 1; n < e; n++) r[n] = t(n);
105
+ const s = t(e);
106
+ return { yValues: new Array(a).fill(s), fitted: r, accumulates: !1 };
79
107
  }
80
- function F(n, s, r) {
81
- const o = n.length;
82
- let l = 0, t = 0, c = 0, a = 0;
83
- for (let f = 0; f < o; f++)
84
- l += n[f], t += s[f], c += n[f] * s[f], a += n[f] * n[f];
85
- const e = (o * c - l * t) / (o * a - l * l), u = (t - e * l) / o, w = n[o - 1], h = o > 1 ? (n[o - 1] - n[0]) / (o - 1) : 1, i = new Array(r);
86
- for (let f = 0; f < r; f++) {
87
- const g = w + (f + 1) * h;
88
- i[f] = e * g + u;
89
- }
90
- return { yValues: i };
91
- }
92
- function x(n, s, r) {
93
- const o = n.length;
94
- let l = n[0];
95
- for (let t = 1; t < o; t++)
96
- l = r * n[t] + (1 - r) * l;
97
- return {
98
- yValues: new Array(s).fill(l)
99
- };
108
+ function X(l, a, o) {
109
+ const e = l.length, c = Math.min(o, e), t = (n) => {
110
+ const i = Math.min(c, n);
111
+ let m = 0;
112
+ for (let f = n - i; f < n; f++) m += l[f];
113
+ return m / i;
114
+ }, r = new Array(e).fill(null);
115
+ for (let n = 1; n < e; n++) r[n] = t(n);
116
+ const s = t(e);
117
+ return { yValues: new Array(a).fill(s), fitted: r, accumulates: !1 };
118
+ }
119
+ function R(l, a, o) {
120
+ const e = l.length;
121
+ let c = l[0];
122
+ const t = new Array(e).fill(null);
123
+ for (let r = 1; r < e; r++)
124
+ t[r] = c, c = o * l[r] + (1 - o) * c;
125
+ return { yValues: new Array(a).fill(c), fitted: t, accumulates: !1 };
126
+ }
127
+ function j(l, a, o) {
128
+ const e = l.length;
129
+ let c = 0, t = 0, r = 0, s = 0;
130
+ for (let h = 0; h < e; h++)
131
+ c += l[h], t += a[h], r += l[h] * a[h], s += l[h] * l[h];
132
+ const n = e * s - c * c, i = n !== 0 ? (e * r - c * t) / n : 0, m = (t - i * c) / e, f = new Array(e);
133
+ for (let h = 0; h < e; h++) f[h] = i * l[h] + m;
134
+ const w = l[e - 1], u = e > 1 ? (l[e - 1] - l[0]) / (e - 1) : 1, y = new Array(o);
135
+ for (let h = 0; h < o; h++) {
136
+ const v = w + (h + 1) * u;
137
+ y[h] = i * v + m;
138
+ }
139
+ return { yValues: y, fitted: f, accumulates: !0 };
140
+ }
141
+ function B(l, a, o) {
142
+ const e = l.length;
143
+ let c = l[0];
144
+ const t = new Array(e).fill(null);
145
+ for (let r = 1; r < e; r++)
146
+ t[r] = c, c = o * l[r] + (1 - o) * c;
147
+ return { yValues: new Array(a).fill(c), fitted: t, accumulates: !1 };
148
+ }
149
+ function F(l, a, o, e) {
150
+ const c = l.length;
151
+ if (c < 2)
152
+ return { yValues: new Array(a).fill(l[0] || 0), fitted: [], accumulates: !0 };
153
+ let t = l[0], r = l[1] - l[0];
154
+ const s = new Array(c).fill(null);
155
+ for (let i = 1; i < c; i++) {
156
+ s[i] = t + r;
157
+ const m = t;
158
+ t = o * l[i] + (1 - o) * (t + r), r = e * (t - m) + (1 - e) * r;
159
+ }
160
+ const n = new Array(a);
161
+ for (let i = 0; i < a; i++) n[i] = t + (i + 1) * r;
162
+ return { yValues: n, fitted: s, accumulates: !0 };
163
+ }
164
+ function Y(l, a, o, e, c, t) {
165
+ const r = l.length;
166
+ if (r < o * 2)
167
+ return F(l, a, e, c);
168
+ const s = new Array(o), n = new Array(Math.floor(r / o));
169
+ for (let u = 0; u < n.length; u++) {
170
+ let y = 0;
171
+ for (let h = 0; h < o; h++) y += l[u * o + h];
172
+ n[u] = y / o;
173
+ }
174
+ for (let u = 0; u < o; u++) {
175
+ let y = 0;
176
+ for (let h = 0; h < n.length; h++)
177
+ y += l[h * o + u] - n[h];
178
+ s[u] = y / n.length;
179
+ }
180
+ let i = n[0], m = (n[n.length - 1] - n[0]) / ((n.length - 1) * o);
181
+ const f = new Array(r).fill(null);
182
+ for (let u = 0; u < r; u++) {
183
+ const y = s[u % o];
184
+ u > 0 && (f[u] = i + m + y);
185
+ const h = i, v = l[u];
186
+ i = e * (v - y) + (1 - e) * (i + m), m = c * (i - h) + (1 - c) * m, s[u % o] = t * (v - i) + (1 - t) * y;
187
+ }
188
+ const w = new Array(a);
189
+ for (let u = 0; u < a; u++) {
190
+ const y = u + 1;
191
+ w[u] = i + y * m + s[(r + u) % o];
192
+ }
193
+ return { yValues: w, fitted: f, accumulates: !0 };
194
+ }
195
+ function H(l, a, o, e, c) {
196
+ const t = l.length, r = Math.max(o, c);
197
+ if (t < e + r + 2 || t < 4)
198
+ return F(l, a, 0.3, 0.1);
199
+ const s = [l.slice()];
200
+ for (let g = 0; g < e; g++)
201
+ s.push($(s[g]));
202
+ const n = s[e], i = n.length, m = n.reduce((g, A) => g + A, 0) / i, f = n.map((g) => g - m);
203
+ let w = new Array(i).fill(0);
204
+ if (c > 0) {
205
+ const g = Math.min(Math.max(o + c + 2, 5), Math.floor(i / 2)), { residuals: A } = _(f, g);
206
+ w = A;
207
+ }
208
+ const u = Math.max(o, c), y = [], h = [];
209
+ for (let g = u; g < i; g++) {
210
+ const A = [];
211
+ for (let d = 1; d <= o; d++) A.push(f[g - d]);
212
+ for (let d = 1; d <= c; d++) A.push(w[g - d]);
213
+ y.push(A), h.push(f[g]);
214
+ }
215
+ let v = [];
216
+ if (y.length > 0 && y[0].length > 0 && (v = L(y, h)), v.length !== o + c || v.some((g) => !Number.isFinite(g)))
217
+ return F(l, a, 0.3, 0.1);
218
+ const x = v.slice(0, o), S = v.slice(o, o + c), k = new Array(t).fill(null), T = new Array(i).fill(0);
219
+ for (let g = u; g < i; g++) {
220
+ let A = 0;
221
+ for (let d = 1; d <= o; d++) A += x[d - 1] * f[g - d];
222
+ for (let d = 1; d <= c; d++) A += S[d - 1] * T[g - d];
223
+ T[g] = f[g] - A, k[g + (t - i)] = O(s, e, g, A + m);
224
+ }
225
+ const V = f.slice(), b = T.slice(), p = [];
226
+ for (let g = 0; g < a; g++) {
227
+ let A = 0;
228
+ for (let d = 1; d <= o; d++)
229
+ A += x[d - 1] * V[V.length - d];
230
+ for (let d = 1; d <= c; d++)
231
+ A += S[d - 1] * b[b.length - d];
232
+ V.push(A), b.push(0), p.push(A + m);
233
+ }
234
+ return { yValues: N(s, e, p), fitted: k, accumulates: !0 };
235
+ }
236
+ function $(l) {
237
+ const a = new Array(l.length - 1);
238
+ for (let o = 1; o < l.length; o++) a[o - 1] = l[o] - l[o - 1];
239
+ return a;
240
+ }
241
+ function N(l, a, o) {
242
+ let e = o.slice();
243
+ for (let c = a; c >= 1; c--) {
244
+ const t = l[c - 1];
245
+ let r = t[t.length - 1];
246
+ const s = new Array(e.length);
247
+ for (let n = 0; n < e.length; n++)
248
+ r += e[n], s[n] = r;
249
+ e = s;
250
+ }
251
+ return e;
100
252
  }
101
- function k(n, s, r, o) {
102
- const l = n.length;
103
- if (l < 2) return { yValues: new Array(s).fill(n[0] || 0) };
104
- let t = n[0], c = n[1] - n[0];
105
- for (let e = 1; e < l; e++) {
106
- const u = t;
107
- t = r * n[e] + (1 - r) * (t + c), c = o * (t - u) + (1 - o) * c;
108
- }
109
- const a = new Array(s);
110
- for (let e = 0; e < s; e++)
111
- a[e] = t + (e + 1) * c;
112
- return { yValues: a };
113
- }
114
- function C(n, s, r, o, l, t) {
115
- const c = n.length;
116
- if (c < r * 2)
117
- return k(n, s, o, l);
118
- const a = new Array(r), e = new Array(Math.floor(c / r));
119
- for (let i = 0; i < e.length; i++) {
120
- let f = 0;
121
- for (let g = 0; g < r; g++)
122
- f += n[i * r + g];
123
- e[i] = f / r;
124
- }
125
- for (let i = 0; i < r; i++) {
126
- let f = 0;
127
- for (let g = 0; g < e.length; g++)
128
- f += n[g * r + i] - e[g];
129
- a[i] = f / e.length;
130
- }
131
- let u = e[0], w = (e[e.length - 1] - e[0]) / ((e.length - 1) * r);
132
- for (let i = 0; i < c; i++) {
133
- const f = u, g = n[i];
134
- u = o * (g - a[i % r]) + (1 - o) * (u + w), w = l * (u - f) + (1 - l) * w, a[i % r] = t * (g - u) + (1 - t) * a[i % r];
135
- }
136
- const h = new Array(s);
137
- for (let i = 0; i < s; i++) {
138
- const f = i + 1;
139
- h[i] = u + f * w + a[(c + i) % r];
140
- }
141
- return { yValues: h };
142
- }
143
- function Y(n, s) {
253
+ function O(l, a, o, e) {
254
+ return a === 0 ? e : l[a - 1][o] + e;
255
+ }
256
+ function _(l, a) {
257
+ const o = l.length, e = [], c = [];
258
+ for (let s = a; s < o; s++) {
259
+ const n = [];
260
+ for (let i = 1; i <= a; i++) n.push(l[s - i]);
261
+ e.push(n), c.push(l[s]);
262
+ }
263
+ const t = e.length > 0 ? L(e, c) : new Array(a).fill(0), r = new Array(o).fill(0);
264
+ for (let s = a; s < o; s++) {
265
+ let n = 0;
266
+ for (let i = 1; i <= a; i++) n += (t[i - 1] || 0) * l[s - i];
267
+ r[s] = l[s] - n;
268
+ }
269
+ return { coeffs: t, residuals: r };
270
+ }
271
+ function L(l, a) {
272
+ const o = l.length, e = l[0].length, c = Array.from({ length: e }, () => new Array(e).fill(0)), t = new Array(e).fill(0);
273
+ for (let r = 0; r < o; r++)
274
+ for (let s = 0; s < e; s++) {
275
+ t[s] += l[r][s] * a[r];
276
+ for (let n = 0; n < e; n++)
277
+ c[s][n] += l[r][s] * l[r][n];
278
+ }
279
+ for (let r = 0; r < e; r++) c[r][r] += 1e-8;
280
+ return G(c, t);
281
+ }
282
+ function G(l, a) {
283
+ const o = a.length, e = l.map((t, r) => [...t, a[r]]);
284
+ for (let t = 0; t < o; t++) {
285
+ let r = t;
286
+ for (let s = t + 1; s < o; s++)
287
+ Math.abs(e[s][t]) > Math.abs(e[r][t]) && (r = s);
288
+ if (Math.abs(e[r][t]) < 1e-12) return [];
289
+ [e[t], e[r]] = [e[r], e[t]];
290
+ for (let s = 0; s < o; s++) {
291
+ if (s === t) continue;
292
+ const n = e[s][t] / e[t][t];
293
+ for (let i = t; i <= o; i++) e[s][i] -= n * e[t][i];
294
+ }
295
+ }
296
+ const c = new Array(o);
297
+ for (let t = 0; t < o; t++) c[t] = e[t][o] / e[t][t];
298
+ return c;
299
+ }
300
+ function J(l, a) {
301
+ if (!a || a.length === 0)
302
+ return { mse: 0, rmse: 0, mae: 0, r2: 0 };
303
+ let o = 0, e = 0, c = 0;
304
+ const t = [];
305
+ for (let w = 0; w < a.length && w < l.length; w++) {
306
+ const u = a[w];
307
+ if (u == null || !Number.isFinite(u)) continue;
308
+ const y = l[w] - u;
309
+ o += y * y, e += Math.abs(y), t.push(l[w]), c++;
310
+ }
311
+ if (c === 0) return { mse: 0, rmse: 0, mae: 0, r2: 0 };
312
+ const r = o / c, s = Math.sqrt(r), n = e / c, i = t.reduce((w, u) => w + u, 0) / t.length, m = t.reduce((w, u) => w + (u - i) * (u - i), 0), f = m > 0 ? 1 - o / m : 0;
144
313
  return {
145
- mse: 0,
146
- mae: 0,
147
- r2: 1
314
+ mse: P(r),
315
+ rmse: P(s),
316
+ mae: P(n),
317
+ r2: P(f)
148
318
  };
149
319
  }
150
- const B = {
320
+ function P(l) {
321
+ return Math.round(l * 1e6) / 1e6;
322
+ }
323
+ const K = {
151
324
  name: "velo-plot-forecasting",
152
325
  version: "1.0.0",
153
326
  description: "Time series forecasting for velo-plot",
154
327
  provides: ["analysis", "forecasting"],
155
328
  tags: ["statistics", "forecasting", "analysis"]
156
329
  };
157
- function D(n = {}) {
158
- let s = null;
159
- const r = /* @__PURE__ */ new Map(), o = {
160
- forecast(t, c) {
161
- let a, e;
162
- if (Array.isArray(t))
163
- e = t, a = t.map((u, w) => w);
330
+ function Q(l = {}) {
331
+ let a = null;
332
+ const o = /* @__PURE__ */ new Map(), e = {
333
+ forecast(t, r) {
334
+ let s, n;
335
+ if (typeof t == "string") {
336
+ if (!a) throw new Error("Plugin not initialized");
337
+ const i = a.data.getAllSeries().find((f) => f.getId() === t);
338
+ if (!i) throw new Error(`Series not found: ${t}`);
339
+ const m = i.getData();
340
+ s = m.x, n = m.y;
341
+ } else if (Array.isArray(t))
342
+ n = t, s = t.map((i, m) => m);
164
343
  else if (t.x && t.y)
165
- a = t.x, e = t.y;
344
+ s = t.x, n = t.y;
166
345
  else
167
346
  throw new Error("Invalid data format for forecasting");
168
- return p(a, e, c.method, c.horizon, c.params);
347
+ return C(s, n, r.method, r.horizon, r.params, r.confidence);
169
348
  },
170
- async forecastSeries(t, c) {
171
- if (!s) throw new Error("Plugin not initialized");
172
- const a = s.data.getAllSeries().find((u) => u.getId() === t);
173
- if (!a) throw new Error(`Series not found: ${t}`);
174
- const e = a.getData();
175
- return this.forecast(e, c);
349
+ async forecastSeries(t, r) {
350
+ if (!a) throw new Error("Plugin not initialized");
351
+ const s = a.data.getAllSeries().find((i) => i.getId() === t);
352
+ if (!s) throw new Error(`Series not found: ${t}`);
353
+ const n = s.getData();
354
+ return this.forecast(n, r);
176
355
  },
177
- visualize(t, c = {}) {
178
- const a = `forecast-${Math.random().toString(36).substr(2, 9)}`, e = {
356
+ visualize(t, r = {}) {
357
+ const s = `forecast-${Math.random().toString(36).substr(2, 9)}`, n = {
179
358
  showLine: !0,
180
359
  showConfidenceInterval: !0,
181
- ...n.defaultVisualization,
182
- ...c
360
+ ...l.defaultVisualization,
361
+ ...r
183
362
  };
184
- return r.set(a, { result: t, config: e }), s == null || s.requestRender(), a;
363
+ return o.set(s, { result: t, config: n }), a == null || a.requestRender(), s;
185
364
  },
186
365
  clear(t) {
187
- t ? r.delete(t) : r.clear(), s == null || s.requestRender();
366
+ t ? o.delete(t) : o.clear(), a == null || a.requestRender();
188
367
  }
189
368
  };
190
- function l(t) {
191
- const { render: c, coords: a } = t, { ctx2d: e } = c;
192
- e && r.forEach((u) => {
193
- var V, T, b, M, P, X;
194
- const { result: w, config: h } = u, { xValues: i, yValues: f, lowerBound: g, upperBound: A } = w;
195
- if (e.save(), h.showConfidenceInterval && g && A) {
196
- e.beginPath();
197
- const v = ((V = h.intervalStyle) == null ? void 0 : V.opacity) ?? 0.15, m = ((T = h.intervalStyle) == null ? void 0 : T.fillColor) || ((b = h.lineStyle) == null ? void 0 : b.color) || "#3b82f6";
198
- e.fillStyle = m.startsWith("rgba") ? m : m + Math.floor(v * 255).toString(16).padStart(2, "0");
199
- for (let d = 0; d < i.length; d++) {
200
- const y = a.dataToPixelX(i[d]), S = a.dataToPixelY(A[d]);
201
- d === 0 ? e.moveTo(y, S) : e.lineTo(y, S);
369
+ function c(t) {
370
+ const { render: r, coords: s } = t, { ctx2d: n } = r;
371
+ n && o.forEach((i) => {
372
+ var v, x, S, k, T, V;
373
+ const { result: m, config: f } = i, { xValues: w, yValues: u, lowerBound: y, upperBound: h } = m;
374
+ if (n.save(), f.showConfidenceInterval && y && h) {
375
+ n.beginPath();
376
+ const b = ((v = f.intervalStyle) == null ? void 0 : v.opacity) ?? 0.15, p = ((x = f.intervalStyle) == null ? void 0 : x.fillColor) || ((S = f.lineStyle) == null ? void 0 : S.color) || "#3b82f6";
377
+ n.fillStyle = p.startsWith("rgba") ? p : p + Math.floor(b * 255).toString(16).padStart(2, "0");
378
+ for (let M = 0; M < w.length; M++) {
379
+ const g = s.dataToPixelX(w[M]), A = s.dataToPixelY(h[M]);
380
+ M === 0 ? n.moveTo(g, A) : n.lineTo(g, A);
202
381
  }
203
- for (let d = i.length - 1; d >= 0; d--) {
204
- const y = a.dataToPixelX(i[d]), S = a.dataToPixelY(g[d]);
205
- e.lineTo(y, S);
382
+ for (let M = w.length - 1; M >= 0; M--) {
383
+ const g = s.dataToPixelX(w[M]), A = s.dataToPixelY(y[M]);
384
+ n.lineTo(g, A);
206
385
  }
207
- e.closePath(), e.fill();
386
+ n.closePath(), n.fill();
208
387
  }
209
- if (h.showLine) {
210
- e.beginPath(), e.strokeStyle = ((M = h.lineStyle) == null ? void 0 : M.color) || "#3b82f6", e.lineWidth = ((P = h.lineStyle) == null ? void 0 : P.width) || 2, (X = h.lineStyle) != null && X.dash ? e.setLineDash(h.lineStyle.dash) : e.setLineDash([5, 5]);
211
- for (let v = 0; v < i.length; v++) {
212
- const m = a.dataToPixelX(i[v]), d = a.dataToPixelY(f[v]);
213
- v === 0 ? e.moveTo(m, d) : e.lineTo(m, d);
388
+ if (f.showLine) {
389
+ n.beginPath(), n.strokeStyle = ((k = f.lineStyle) == null ? void 0 : k.color) || "#3b82f6", n.lineWidth = ((T = f.lineStyle) == null ? void 0 : T.width) || 2, (V = f.lineStyle) != null && V.dash ? n.setLineDash(f.lineStyle.dash) : n.setLineDash([5, 5]);
390
+ for (let b = 0; b < w.length; b++) {
391
+ const p = s.dataToPixelX(w[b]), M = s.dataToPixelY(u[b]);
392
+ b === 0 ? n.moveTo(p, M) : n.lineTo(p, M);
214
393
  }
215
- e.stroke();
394
+ n.stroke();
216
395
  }
217
- e.restore();
396
+ n.restore();
218
397
  });
219
398
  }
220
399
  return {
221
- manifest: B,
400
+ manifest: K,
222
401
  onInit(t) {
223
- s = t;
402
+ a = t;
224
403
  },
225
- onRenderOverlay(t, c) {
226
- l(t);
404
+ onRenderOverlay(t, r) {
405
+ c(t);
227
406
  },
228
- api: o
407
+ api: e
229
408
  };
230
409
  }
231
410
  export {
232
- D as PluginForecasting,
233
- p as calculateForecast,
234
- B as manifestForecasting
411
+ Q as PluginForecasting,
412
+ C as calculateForecast,
413
+ G as gaussianSolve,
414
+ K as manifestForecasting
235
415
  };
236
416
  //# sourceMappingURL=forecasting.js.map