velo-plot 1.11.1 → 1.15.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 (118) hide show
  1. package/README.md +35 -2
  2. package/dist/{index.core-CYu3tydL.js → ChartCore-BimVvUEg.js} +1936 -1588
  3. package/dist/ChartCore-BimVvUEg.js.map +1 -0
  4. package/dist/axisFormat-B7o_uIEA.js +127 -0
  5. package/dist/axisFormat-B7o_uIEA.js.map +1 -0
  6. package/dist/core/OverlayRenderer.d.ts +1 -2
  7. package/dist/core/chart/ChartCore.d.ts +18 -1
  8. package/dist/core/chart/ChartRenderLoop.d.ts +4 -0
  9. package/dist/core/chart/ChartScaling.d.ts +11 -0
  10. package/dist/core/chart/NavigationUtils.d.ts +12 -0
  11. package/dist/core/chart/exporter/SVGExporter.d.ts +7 -2
  12. package/dist/core/chart/types.d.ts +13 -1
  13. package/dist/core/format/axisFormat.d.ts +16 -0
  14. package/dist/core/indicator/buildIndicatorPane.d.ts +22 -0
  15. package/dist/core/indicator/buildIndicatorSeries.d.ts +14 -0
  16. package/dist/core/indicator/index.d.ts +3 -0
  17. package/dist/core/indicator/types.d.ts +74 -0
  18. package/dist/core/render/pixelSnap.d.ts +8 -0
  19. package/dist/core/series/SeriesBounds.d.ts +1 -1
  20. package/dist/core/stacked/createStackedChart.d.ts +3 -0
  21. package/dist/core/stacked/index.d.ts +6 -0
  22. package/dist/core/stacked/paneAxis.d.ts +20 -0
  23. package/dist/core/stacked/paneResize.d.ts +29 -0
  24. package/dist/core/stacked/stackExport.d.ts +18 -0
  25. package/dist/core/stacked/types.d.ts +120 -0
  26. package/dist/core/sync/index.d.ts +25 -70
  27. package/dist/createStackedChart-CjsKcOvX.js +1088 -0
  28. package/dist/createStackedChart-CjsKcOvX.js.map +1 -0
  29. package/dist/index-CUGS98p4.js +277 -0
  30. package/dist/index-CUGS98p4.js.map +1 -0
  31. package/dist/index-ChgIdk3N.js +229 -0
  32. package/dist/index-ChgIdk3N.js.map +1 -0
  33. package/dist/{index-D8ifudJH.js → index-DjeWClO9.js} +601 -561
  34. package/dist/index-DjeWClO9.js.map +1 -0
  35. package/dist/index.core-C_-CFftD.js +167 -0
  36. package/dist/index.core-C_-CFftD.js.map +1 -0
  37. package/dist/index.d.ts +2 -0
  38. package/dist/math-Ddm2EZjj.js +85 -0
  39. package/dist/math-Ddm2EZjj.js.map +1 -0
  40. package/dist/plugins/analysis.js +132 -130
  41. package/dist/plugins/analysis.js.map +1 -1
  42. package/dist/plugins/anomaly-detection.d.ts +1 -0
  43. package/dist/plugins/anomaly-detection.js +221 -0
  44. package/dist/plugins/anomaly-detection.js.map +1 -0
  45. package/dist/plugins/broken-axis.d.ts +3 -0
  46. package/dist/plugins/broken-axis.js +262 -0
  47. package/dist/plugins/broken-axis.js.map +1 -0
  48. package/dist/plugins/caching.d.ts +3 -0
  49. package/dist/plugins/caching.js +182 -0
  50. package/dist/plugins/caching.js.map +1 -0
  51. package/dist/plugins/data-transform.d.ts +3 -0
  52. package/dist/plugins/data-transform.js +146 -0
  53. package/dist/plugins/data-transform.js.map +1 -0
  54. package/dist/plugins/debug.js +12 -11
  55. package/dist/plugins/debug.js.map +1 -1
  56. package/dist/plugins/forecasting.d.ts +1 -0
  57. package/dist/plugins/forecasting.js +236 -0
  58. package/dist/plugins/forecasting.js.map +1 -0
  59. package/dist/plugins/latex.d.ts +1 -0
  60. package/dist/plugins/latex.js +454 -0
  61. package/dist/plugins/latex.js.map +1 -0
  62. package/dist/plugins/lazy-load.d.ts +3 -0
  63. package/dist/plugins/lazy-load.js +189 -0
  64. package/dist/plugins/lazy-load.js.map +1 -0
  65. package/dist/plugins/ml-integration.d.ts +3 -0
  66. package/dist/plugins/ml-integration.js +355 -0
  67. package/dist/plugins/ml-integration.js.map +1 -0
  68. package/dist/plugins/offscreen.d.ts +3 -0
  69. package/dist/plugins/offscreen.js +169 -0
  70. package/dist/plugins/offscreen.js.map +1 -0
  71. package/dist/plugins/pattern-recognition.d.ts +3 -0
  72. package/dist/plugins/pattern-recognition.js +690 -0
  73. package/dist/plugins/pattern-recognition.js.map +1 -0
  74. package/dist/plugins/radar.d.ts +3 -0
  75. package/dist/plugins/radar.js +103 -0
  76. package/dist/plugins/radar.js.map +1 -0
  77. package/dist/plugins/regression.d.ts +3 -0
  78. package/dist/plugins/regression.js +634 -0
  79. package/dist/plugins/regression.js.map +1 -0
  80. package/dist/plugins/roi.d.ts +1 -0
  81. package/dist/plugins/roi.js +223 -0
  82. package/dist/plugins/roi.js.map +1 -0
  83. package/dist/plugins/snapshot/types.d.ts +1 -1
  84. package/dist/plugins/snapshot.d.ts +3 -0
  85. package/dist/plugins/snapshot.js +90 -0
  86. package/dist/plugins/snapshot.js.map +1 -0
  87. package/dist/plugins/sync/index.d.ts +2 -1
  88. package/dist/plugins/sync.js +12 -244
  89. package/dist/plugins/sync.js.map +1 -1
  90. package/dist/plugins/tools/tooltip/TooltipManager.d.ts +9 -1
  91. package/dist/plugins/tools/tooltip/format.d.ts +7 -0
  92. package/dist/plugins/tools/tooltip/types.d.ts +6 -8
  93. package/dist/plugins/tools.js +1 -1
  94. package/dist/plugins/video-recorder.d.ts +3 -0
  95. package/dist/plugins/video-recorder.js +104 -0
  96. package/dist/plugins/video-recorder.js.map +1 -0
  97. package/dist/plugins/virtualization.d.ts +3 -0
  98. package/dist/plugins/virtualization.js +6 -0
  99. package/dist/plugins/virtualization.js.map +1 -0
  100. package/dist/react/index.d.ts +2 -1
  101. package/dist/react/useStackedPlot.d.ts +17 -0
  102. package/dist/react.d.ts +1 -0
  103. package/dist/react.js +31 -0
  104. package/dist/react.js.map +1 -0
  105. package/dist/types.d.ts +21 -1
  106. package/dist/utils-BK5UUXxj.js +172 -0
  107. package/dist/utils-BK5UUXxj.js.map +1 -0
  108. package/dist/velo-plot.full.js +1000 -5576
  109. package/dist/velo-plot.full.js.map +1 -1
  110. package/dist/velo-plot.js +23 -22
  111. package/dist/velo-plot.js.map +1 -1
  112. package/package.json +17 -3
  113. package/dist/EventEmitter-DAbs2K1C.js +0 -60
  114. package/dist/EventEmitter-DAbs2K1C.js.map +0 -1
  115. package/dist/index-D8ifudJH.js.map +0 -1
  116. package/dist/index.core-CYu3tydL.js.map +0 -1
  117. package/dist/utils-Dbro9-qM.js +0 -254
  118. package/dist/utils-Dbro9-qM.js.map +0 -1
@@ -0,0 +1,634 @@
1
+ import { s as P } from "../math-Ddm2EZjj.js";
2
+ function T(f) {
3
+ return Array.from(f);
4
+ }
5
+ function v(f) {
6
+ return new Float32Array(f);
7
+ }
8
+ function _(f) {
9
+ return f.reduce((h, i) => h + i, 0) / f.length;
10
+ }
11
+ function z(f) {
12
+ const h = _(f);
13
+ return f.reduce((i, c) => i + Math.pow(c - h, 2), 0) / f.length;
14
+ }
15
+ function O(f, h) {
16
+ const i = _(f);
17
+ let c = 0, l = 0;
18
+ for (let g = 0; g < f.length; g++)
19
+ c += Math.pow(f[g] - h[g], 2), l += Math.pow(f[g] - i, 2);
20
+ return 1 - c / l;
21
+ }
22
+ function C(f, h, i) {
23
+ return 1 - (1 - f) * (h - 1) / (h - i - 1);
24
+ }
25
+ function E(f, h) {
26
+ let i = 0;
27
+ for (let c = 0; c < f.length; c++)
28
+ i += Math.pow(f[c] - h[c], 2);
29
+ return Math.sqrt(i / f.length);
30
+ }
31
+ function V(f, h = {}) {
32
+ const i = performance.now(), c = T(f.x), l = T(f.y), g = f.weights ? T(f.weights) : null, { forceOrigin: M = !1 } = h, d = c.length;
33
+ if (M) {
34
+ let w = 0, p = 0;
35
+ for (let t = 0; t < d; t++) {
36
+ const e = g ? g[t] : 1;
37
+ w += e * c[t] * l[t], p += e * c[t] * c[t];
38
+ }
39
+ const R = w / p, $ = c.map((t) => R * t), S = l.map((t, e) => t - $[e]), y = O(l, $), q = C(y, d, 1), x = E(l, $);
40
+ return {
41
+ method: "linear",
42
+ parameters: {
43
+ parameters: [R],
44
+ uncertainties: [Math.sqrt(p / (d * w))],
45
+ // Simplified
46
+ correlationMatrix: [[1]]
47
+ },
48
+ statistics: {
49
+ rSquared: y,
50
+ adjustedRSquared: q,
51
+ rmse: x,
52
+ rss: S.reduce((t, e) => t + e * e, 0),
53
+ tss: l.reduce((t, e) => t + Math.pow(e - _(l), 2), 0),
54
+ n: d,
55
+ k: 1
56
+ },
57
+ fittedValues: v($),
58
+ residuals: v(S),
59
+ goodnessOfFit: y > 0.9 ? "excellent" : y > 0.7 ? "good" : y > 0.5 ? "fair" : "poor",
60
+ converged: !0,
61
+ iterations: 1,
62
+ processingTime: performance.now() - i
63
+ };
64
+ } else {
65
+ let w = 0, p = 0, R = 0, $ = 0, S = 0, y = 0;
66
+ for (let u = 0; u < d; u++) {
67
+ const m = g ? g[u] : 1;
68
+ w += m * c[u], p += m * l[u], R += m * c[u] * l[u], $ += m * c[u] * c[u], S += m * l[u] * l[u], y += m;
69
+ }
70
+ const q = w / y, x = p / y, t = (R - y * q * x) / ($ - y * q * q), e = x - t * q, s = c.map((u) => t * u + e), o = l.map((u, m) => u - s[m]), r = O(l, s), n = C(r, d, 2), a = E(l, s);
71
+ return {
72
+ method: "linear",
73
+ parameters: {
74
+ parameters: [t, e],
75
+ uncertainties: [0.1, 0.1],
76
+ // Simplified
77
+ correlationMatrix: [[1, -0.5], [-0.5, 1]]
78
+ // Simplified
79
+ },
80
+ statistics: {
81
+ rSquared: r,
82
+ adjustedRSquared: n,
83
+ rmse: a,
84
+ rss: o.reduce((u, m) => u + m * m, 0),
85
+ tss: l.reduce((u, m) => u + Math.pow(m - x, 2), 0),
86
+ n: d,
87
+ k: 2
88
+ },
89
+ fittedValues: v(s),
90
+ residuals: v(o),
91
+ goodnessOfFit: r > 0.9 ? "excellent" : r > 0.7 ? "good" : r > 0.5 ? "fair" : "poor",
92
+ converged: !0,
93
+ iterations: 1,
94
+ processingTime: performance.now() - i
95
+ };
96
+ }
97
+ }
98
+ function U(f, h) {
99
+ const i = performance.now(), c = T(f.x), l = T(f.y), { degree: g } = h, M = c.length, d = g + 1, w = [];
100
+ for (let x = 0; x < M; x++) {
101
+ const t = [];
102
+ for (let e = 0; e <= g; e++)
103
+ t.push(Math.pow(c[x], e));
104
+ w.push(t);
105
+ }
106
+ const p = Y(w, l, 0), R = c.map((x) => {
107
+ let t = 0;
108
+ for (let e = 0; e <= g; e++)
109
+ t += p[e] * Math.pow(x, e);
110
+ return t;
111
+ }), $ = l.map((x, t) => x - R[t]), S = O(l, R), y = C(S, M, d), q = E(l, R);
112
+ return {
113
+ method: "polynomial",
114
+ parameters: {
115
+ parameters: p,
116
+ uncertainties: new Array(d).fill(0.1),
117
+ // Simplified
118
+ correlationMatrix: Array(d).fill(0).map(() => Array(d).fill(0))
119
+ // Simplified
120
+ },
121
+ statistics: {
122
+ rSquared: S,
123
+ adjustedRSquared: y,
124
+ rmse: q,
125
+ rss: $.reduce((x, t) => x + t * t, 0),
126
+ tss: l.reduce((x, t) => x + Math.pow(t - _(l), 2), 0),
127
+ n: M,
128
+ k: d
129
+ },
130
+ fittedValues: v(R),
131
+ residuals: v($),
132
+ goodnessOfFit: S > 0.9 ? "excellent" : S > 0.7 ? "good" : S > 0.5 ? "fair" : "poor",
133
+ converged: !0,
134
+ iterations: 10,
135
+ // Simplified
136
+ processingTime: performance.now() - i
137
+ };
138
+ }
139
+ function N(f, h = {}) {
140
+ const i = performance.now(), c = T(f.x), l = T(f.y);
141
+ let g = Math.min(...l) - 1;
142
+ const M = l.map((t) => {
143
+ const e = t - g;
144
+ return e > 0 ? Math.log(e) : 0;
145
+ }), d = V(
146
+ { x: c, y: M },
147
+ { forceOrigin: !1 }
148
+ ), [w, p] = d.parameters.parameters, R = Math.exp(p), $ = c.map((t) => R * Math.exp(w * t) + g), S = l.map((t, e) => t - $[e]), y = O(l, $), q = C(y, c.length, 3), x = E(l, $);
149
+ return {
150
+ method: "exponential",
151
+ parameters: {
152
+ parameters: [R, w, g],
153
+ uncertainties: [0.1, 0.01, 0.1],
154
+ // Simplified
155
+ correlationMatrix: [[1, 0.5, 0.2], [0.5, 1, 0.3], [0.2, 0.3, 1]]
156
+ // Simplified
157
+ },
158
+ statistics: {
159
+ rSquared: y,
160
+ adjustedRSquared: q,
161
+ rmse: x,
162
+ rss: S.reduce((t, e) => t + e * e, 0),
163
+ tss: l.reduce((t, e) => t + Math.pow(e - _(l), 2), 0),
164
+ n: c.length,
165
+ k: 3
166
+ },
167
+ fittedValues: v($),
168
+ residuals: v(S),
169
+ goodnessOfFit: y > 0.9 ? "excellent" : y > 0.7 ? "good" : y > 0.5 ? "fair" : "poor",
170
+ converged: !0,
171
+ iterations: 5,
172
+ // Simplified
173
+ processingTime: performance.now() - i
174
+ };
175
+ }
176
+ function X(f, h = {}) {
177
+ const i = performance.now(), c = T(f.x), l = T(f.y);
178
+ let g = Math.max(...l), M = c.reduce((e, s) => e + s, 0) / c.length, d = Math.sqrt(z(c)), w = Math.min(...l);
179
+ const p = 1e-3, R = 100, $ = 1e-6;
180
+ for (let e = 0; e < R; e++) {
181
+ let s = 0, o = 0, r = 0, n = 0, a = 0;
182
+ for (let u = 0; u < c.length; u++) {
183
+ const m = c[u], A = l[u], b = -Math.pow(m - M, 2) / (2 * d * d), j = g * Math.exp(b) + w, F = A - j;
184
+ a += F * F;
185
+ const k = Math.exp(b);
186
+ s += F * k, o += F * g * k * (m - M) / (d * d), r += F * g * k * Math.pow(m - M, 2) / Math.pow(d, 3), n += F;
187
+ }
188
+ if (g += p * s, M += p * o, d += p * r, w += p * n, d = Math.max(d, 0.01), a < $) break;
189
+ }
190
+ const S = c.map((e) => {
191
+ const s = -Math.pow(e - M, 2) / (2 * d * d);
192
+ return g * Math.exp(s) + w;
193
+ }), y = l.map((e, s) => e - S[s]), q = O(l, S), x = C(q, c.length, 4), t = E(l, S);
194
+ return {
195
+ method: "gaussian",
196
+ parameters: {
197
+ parameters: [g, M, d, w],
198
+ uncertainties: [0.1, 0.1, 0.01, 0.1],
199
+ // Simplified
200
+ correlationMatrix: Array(4).fill(0).map(() => Array(4).fill(0))
201
+ // Simplified
202
+ },
203
+ statistics: {
204
+ rSquared: q,
205
+ adjustedRSquared: x,
206
+ rmse: t,
207
+ rss: y.reduce((e, s) => e + s * s, 0),
208
+ tss: l.reduce((e, s) => e + Math.pow(s - _(l), 2), 0),
209
+ n: c.length,
210
+ k: 4
211
+ },
212
+ fittedValues: v(S),
213
+ residuals: v(y),
214
+ goodnessOfFit: q > 0.9 ? "excellent" : q > 0.7 ? "good" : q > 0.5 ? "fair" : "poor",
215
+ converged: !0,
216
+ iterations: R,
217
+ processingTime: performance.now() - i
218
+ };
219
+ }
220
+ function Y(f, h, i = 0) {
221
+ const c = f.length, l = f[0].length, g = Array(l).fill(0).map(() => Array(l).fill(0)), M = Array(l).fill(0);
222
+ for (let d = 0; d < c; d++)
223
+ for (let w = 0; w < l; w++) {
224
+ for (let p = 0; p < l; p++)
225
+ g[w][p] += f[d][w] * f[d][p];
226
+ M[w] += f[d][w] * h[d];
227
+ }
228
+ if (i > 0)
229
+ for (let d = 0; d < l; d++)
230
+ g[d][d] += i;
231
+ return P(g, M);
232
+ }
233
+ const L = {
234
+ name: "regression",
235
+ version: "1.0.0",
236
+ description: "Advanced scientific regression and curve fitting",
237
+ author: "Sci Plot Team",
238
+ provides: ["regression", "curve-fitting", "scientific-analysis"]
239
+ }, J = {
240
+ defaultMethod: "linear",
241
+ enableAutoSelection: !1,
242
+ modelSelectionCriteria: "aic",
243
+ enableWeightedRegression: !1,
244
+ enableRobustRegression: !1,
245
+ robustMethod: "huber",
246
+ maxIterations: 100,
247
+ convergenceTolerance: 1e-6,
248
+ defaultConfidenceLevel: 0.95,
249
+ enableParallelProcessing: !1,
250
+ parallelChunkSize: 1e3
251
+ };
252
+ function B(f = {}) {
253
+ const h = { ...J, ...f };
254
+ let i = null;
255
+ const c = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Set(), g = /* @__PURE__ */ new Map();
256
+ async function M(t, e, s = h.defaultMethod, o = {}) {
257
+ try {
258
+ p.hideVisualization(t);
259
+ let r;
260
+ switch (s) {
261
+ case "linear":
262
+ r = V(e, o);
263
+ break;
264
+ case "polynomial":
265
+ r = U(e, o);
266
+ break;
267
+ case "exponential":
268
+ r = N(e, o);
269
+ break;
270
+ case "gaussian":
271
+ r = X(e, o);
272
+ break;
273
+ case "logarithmic":
274
+ const n = Array.from(e.x).map((m) => Math.log(m));
275
+ r = V({ ...e, x: new Float32Array(n) }, o), r.method = "logarithmic";
276
+ break;
277
+ case "power":
278
+ const a = Array.from(e.y).map((m) => Math.log(m)), u = Array.from(e.x).map((m) => Math.log(m));
279
+ r = V({ ...e, x: new Float32Array(u), y: new Float32Array(a) }, o), r.method = "power";
280
+ break;
281
+ case "lorentzian":
282
+ case "sigmoid":
283
+ case "custom":
284
+ r = V(e, o);
285
+ break;
286
+ default:
287
+ throw new Error(`Unsupported regression method: ${s}`);
288
+ }
289
+ return c.set(t, [r]), i && i.events.emit("regression:completed", {
290
+ result: r,
291
+ seriesId: t,
292
+ method: s,
293
+ timestamp: Date.now()
294
+ }), i == null || i.log.info(`Regression completed for ${t}: ${s} (R² = ${r.statistics.rSquared.toFixed(3)})`), r;
295
+ } catch (r) {
296
+ throw i && i.events.emit("regression:failed", {
297
+ error: r,
298
+ seriesId: t,
299
+ method: s,
300
+ reason: `Fitting failed: ${r}`,
301
+ timestamp: Date.now()
302
+ }), r;
303
+ }
304
+ }
305
+ async function d(t, e, s, o) {
306
+ const r = [];
307
+ for (let a = 0; a < s.length; a++) {
308
+ const u = s[a], m = o ? o[a] : {};
309
+ try {
310
+ const A = await M(t, e, u, m);
311
+ r.push(A);
312
+ } catch (A) {
313
+ i == null || i.log.warn(`Regression failed for ${u}: ${A}`);
314
+ }
315
+ }
316
+ const n = h.modelSelectionCriteria;
317
+ return r.sort((a, u) => {
318
+ switch (n) {
319
+ case "aic":
320
+ return (a.statistics.aic || 0) - (u.statistics.aic || 0);
321
+ case "bic":
322
+ return (a.statistics.bic || 0) - (u.statistics.bic || 0);
323
+ case "adjusted-r2":
324
+ return u.statistics.adjustedRSquared - a.statistics.adjustedRSquared;
325
+ default:
326
+ return u.statistics.rSquared - a.statistics.rSquared;
327
+ }
328
+ }), r;
329
+ }
330
+ async function w(t, e, s = ["linear", "polynomial", "exponential", "gaussian"]) {
331
+ const o = s.map((a) => {
332
+ switch (a) {
333
+ case "polynomial":
334
+ return { degree: 2 };
335
+ case "exponential":
336
+ return {};
337
+ case "gaussian":
338
+ return {};
339
+ default:
340
+ return {};
341
+ }
342
+ }), r = await d(t, e, s, o);
343
+ if (r.length === 0)
344
+ throw new Error("No regression methods succeeded");
345
+ const n = r[0];
346
+ return i && i.events.emit("model:selected", {
347
+ selectedMethod: n.method,
348
+ candidateResults: r,
349
+ selectionCriteria: h.modelSelectionCriteria,
350
+ seriesId: t,
351
+ timestamp: Date.now()
352
+ }), i == null || i.log.info(`Auto-fit selected ${n.method} for ${t} (R² = ${n.statistics.rSquared.toFixed(3)})`), n;
353
+ }
354
+ const p = {
355
+ fit: M,
356
+ fitAndCompare: d,
357
+ autoFit: w,
358
+ getResults(t) {
359
+ return c.get(t) || [];
360
+ },
361
+ clearResults(t) {
362
+ c.delete(t), i == null || i.log.info(`Regression results cleared for series: ${t}`);
363
+ },
364
+ predict(t, e, s = 0) {
365
+ const o = c.get(t);
366
+ if (!o || o.length === 0)
367
+ throw new Error(`No regression results found for series: ${t}`);
368
+ const r = o[Math.min(s, o.length - 1)], n = Array.from(e), a = r.parameters.parameters, u = n.map((m) => {
369
+ switch (r.method) {
370
+ case "linear":
371
+ return a[0] * m + (a[1] || 0);
372
+ case "polynomial":
373
+ let A = 0;
374
+ for (let j = 0; j < a.length; j++)
375
+ A += a[j] * Math.pow(m, j);
376
+ return A;
377
+ case "exponential":
378
+ return a[0] * Math.exp(a[1] * m) + (a[2] || 0);
379
+ case "gaussian":
380
+ const b = -Math.pow(m - a[1], 2) / (2 * a[2] * a[2]);
381
+ return a[0] * Math.exp(b) + (a[3] || 0);
382
+ case "logarithmic":
383
+ return a[0] * Math.log(m) + (a[1] || 0);
384
+ case "power":
385
+ return a[0] * Math.pow(m, a[1]);
386
+ default:
387
+ return 0;
388
+ }
389
+ });
390
+ return new Float32Array(u);
391
+ },
392
+ getConfidenceIntervals(t, e, s = h.defaultConfidenceLevel, o = 0) {
393
+ const r = this.predict(t, e, o), n = 0.1, a = r.map((m) => m - n), u = r.map((m) => m + n);
394
+ return {
395
+ lower: new Float32Array(a),
396
+ upper: new Float32Array(u)
397
+ };
398
+ },
399
+ evaluate(t, e, s = 0) {
400
+ const o = c.get(t);
401
+ if (!o || o.length === 0)
402
+ throw new Error(`No regression results found for series: ${t}`);
403
+ const r = o[Math.min(s, o.length - 1)], n = Array.from(e.x), a = Array.from(e.y), u = p.predict(t, n, s), m = Array.from(u), A = $(a, m), b = S(A, a.length, r.parameters.parameters.length), j = y(a, m);
404
+ return {
405
+ rSquared: A,
406
+ adjustedRSquared: b,
407
+ rmse: j,
408
+ rss: a.reduce((F, k, D) => F + Math.pow(k - m[D], 2), 0),
409
+ tss: a.reduce((F, k) => F + Math.pow(k - R(a), 2), 0),
410
+ n: a.length,
411
+ k: r.parameters.parameters.length
412
+ };
413
+ },
414
+ enableRealtimeFitting(t, e = h.defaultMethod, s = {}) {
415
+ l.add(t);
416
+ const o = i == null ? void 0 : i.chart;
417
+ if (o) {
418
+ const r = o.getSeries(t);
419
+ if (r) {
420
+ const n = r.getData();
421
+ n && n.x.length > 0 && M(t, {
422
+ x: n.x,
423
+ y: n.y
424
+ }, e, s);
425
+ }
426
+ }
427
+ i == null || i.log.info(`Real-time regression fitting enabled for series: ${t}`);
428
+ },
429
+ disableRealtimeFitting(t) {
430
+ l.delete(t);
431
+ const e = g.get(t);
432
+ e && (clearTimeout(e), g.delete(t)), i == null || i.log.info(`Real-time regression fitting disabled for series: ${t}`);
433
+ },
434
+ getStatistics(t) {
435
+ if (t) {
436
+ const e = c.get(t) || [], s = {};
437
+ for (const o of e)
438
+ s[o.method] = (s[o.method] || 0) + 1;
439
+ return {
440
+ totalFittings: e.length,
441
+ methodsUsed: s,
442
+ averageRSquared: e.length > 0 ? e.reduce((o, r) => o + r.statistics.rSquared, 0) / e.length : 0,
443
+ averageProcessingTime: e.length > 0 ? e.reduce((o, r) => o + r.processingTime, 0) / e.length : 0
444
+ };
445
+ } else {
446
+ let e = 0;
447
+ const s = {}, o = [], r = [];
448
+ for (const n of c.values()) {
449
+ e += n.length, o.push(...n.map((a) => a.statistics.rSquared)), r.push(...n.map((a) => a.processingTime));
450
+ for (const a of n)
451
+ s[a.method] = (s[a.method] || 0) + 1;
452
+ }
453
+ return {
454
+ totalFittings: e,
455
+ methodsUsed: s,
456
+ averageRSquared: o.length > 0 ? o.reduce((n, a) => n + a, 0) / o.length : 0,
457
+ averageProcessingTime: r.length > 0 ? r.reduce((n, a) => n + a, 0) / r.length : 0
458
+ };
459
+ }
460
+ },
461
+ updateConfig: (t) => {
462
+ Object.assign(h, t);
463
+ },
464
+ getConfig: () => ({ ...h }),
465
+ visualizeFit(t, e = 0) {
466
+ const s = i == null ? void 0 : i.chart;
467
+ if (!s) return;
468
+ const o = c.get(t);
469
+ if (!o || o.length === 0) return;
470
+ const r = o[Math.min(e, o.length - 1)], n = s.getSeries(t);
471
+ if (!n) return;
472
+ const a = n.getData();
473
+ if (!a) return;
474
+ this.hideVisualization(t);
475
+ const u = `${t}_fit_${r.method}`, m = p.predict(t, a.x, e);
476
+ s.addSeries({
477
+ id: u,
478
+ type: "line",
479
+ data: {
480
+ x: new Float32Array(Array.from(a.x)),
481
+ y: new Float32Array(m)
482
+ },
483
+ style: {
484
+ color: "#ff6b6b",
485
+ width: 2,
486
+ opacity: 0.8,
487
+ lineDash: [5, 5]
488
+ }
489
+ });
490
+ const A = q(r), b = `${t}_equation_${r.method}`;
491
+ s.addAnnotation({
492
+ id: b,
493
+ type: "text",
494
+ text: `${r.method.toUpperCase()}: ${A}\\nR² = ${r.statistics.rSquared.toFixed(3)}`,
495
+ x: a.x[0],
496
+ y: Math.max(...Array.from(m)),
497
+ style: {
498
+ color: "#ff6b6b",
499
+ fontSize: 12,
500
+ backgroundColor: "rgba(255, 255, 255, 0.9)"
501
+ }
502
+ });
503
+ },
504
+ hideVisualization(t) {
505
+ const e = i == null ? void 0 : i.chart;
506
+ if (!e) return;
507
+ const s = [
508
+ "linear",
509
+ "polynomial",
510
+ "exponential",
511
+ "gaussian",
512
+ "logarithmic",
513
+ "power",
514
+ "lorentzian",
515
+ "sigmoid",
516
+ "custom"
517
+ ];
518
+ for (const o of s) {
519
+ const r = `${t}_fit_${o}`;
520
+ e.getSeries(r) && e.removeSeries(r);
521
+ const n = `${t}_equation_${o}`;
522
+ e.getAnnotation(n) && e.removeAnnotation(n);
523
+ }
524
+ },
525
+ exportResults(t, e = "json") {
526
+ const s = c.get(t) || [];
527
+ switch (e) {
528
+ case "json":
529
+ return JSON.stringify(s, null, 2);
530
+ case "csv":
531
+ let o = `Method,R²,RMSE,Parameters,ProcessingTime
532
+ `;
533
+ for (const n of s)
534
+ o += `${n.method},${n.statistics.rSquared},${n.statistics.rmse},"${n.parameters.parameters.join(", ")}",${n.processingTime}
535
+ `;
536
+ return o;
537
+ case "matlab":
538
+ let r = `% Regression results for ${t}
539
+ `;
540
+ for (let n = 0; n < s.length; n++) {
541
+ const a = s[n];
542
+ r += `result${n + 1}.method = '${a.method}';
543
+ `, r += `result${n + 1}.rSquared = ${a.statistics.rSquared};
544
+ `, r += `result${n + 1}.parameters = [${a.parameters.parameters.join(", ")}];
545
+ `;
546
+ }
547
+ return r;
548
+ default:
549
+ return JSON.stringify(s, null, 2);
550
+ }
551
+ }
552
+ };
553
+ function R(t) {
554
+ return t.reduce((e, s) => e + s, 0) / t.length;
555
+ }
556
+ function $(t, e) {
557
+ const s = R(t);
558
+ let o = 0, r = 0;
559
+ for (let n = 0; n < t.length; n++)
560
+ o += Math.pow(t[n] - e[n], 2), r += Math.pow(t[n] - s, 2);
561
+ return 1 - o / r;
562
+ }
563
+ function S(t, e, s) {
564
+ return 1 - (1 - t) * (e - 1) / (e - s - 1);
565
+ }
566
+ function y(t, e) {
567
+ let s = 0;
568
+ for (let o = 0; o < t.length; o++)
569
+ s += Math.pow(t[o] - e[o], 2);
570
+ return Math.sqrt(s / t.length);
571
+ }
572
+ function q(t) {
573
+ var s, o;
574
+ const e = t.parameters.parameters;
575
+ switch (t.method) {
576
+ case "linear":
577
+ return e.length === 1 ? `y = ${e[0].toFixed(3)}x` : `y = ${e[0].toFixed(3)}x + ${e[1].toFixed(3)}`;
578
+ case "polynomial":
579
+ let r = "y = ";
580
+ for (let n = e.length - 1; n >= 0; n--)
581
+ e[n] !== 0 && (n === 0 ? r += e[n].toFixed(3) : n === 1 ? r += `${e[n].toFixed(3)}x + ` : r += `${e[n].toFixed(3)}x^${n} + `);
582
+ return r.replace(" + ", "").trim();
583
+ case "exponential":
584
+ return `y = ${e[0].toFixed(3)} * exp(${e[1].toFixed(3)}x) + ${((s = e[2]) == null ? void 0 : s.toFixed(3)) || 0}`;
585
+ case "gaussian":
586
+ return `y = ${e[0].toFixed(3)} * exp(-((x - ${e[1].toFixed(3)})² / (2 * ${e[2].toFixed(3)}²))) + ${((o = e[3]) == null ? void 0 : o.toFixed(3)) || 0}`;
587
+ default:
588
+ return "y = f(x, parameters)";
589
+ }
590
+ }
591
+ function x(t, e) {
592
+ const { seriesId: s } = e;
593
+ if (l.has(s)) {
594
+ const o = g.get(s);
595
+ o && clearTimeout(o);
596
+ const r = setTimeout(() => {
597
+ const n = t.chart;
598
+ if (n) {
599
+ const a = n.getSeries(s);
600
+ if (a) {
601
+ const u = a.getData();
602
+ u && u.x.length > 0 && (M(s, {
603
+ x: u.x,
604
+ y: u.y
605
+ }), p.visualizeFit(s));
606
+ }
607
+ }
608
+ }, 500);
609
+ g.set(s, r);
610
+ }
611
+ }
612
+ return {
613
+ manifest: L,
614
+ onInit(t) {
615
+ i = t, i.log.info("Regression plugin initialized");
616
+ },
617
+ onConfigChange(t, e) {
618
+ },
619
+ onBeforeRender(t, e) {
620
+ },
621
+ onDataUpdate: x,
622
+ onDestroy(t) {
623
+ for (const e of g.values())
624
+ clearTimeout(e);
625
+ g.clear(), c.clear(), l.clear();
626
+ },
627
+ api: p
628
+ };
629
+ }
630
+ export {
631
+ B as PluginRegression,
632
+ B as default
633
+ };
634
+ //# sourceMappingURL=regression.js.map