velo-plot 1.19.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 (86) hide show
  1. package/dist/{ChartCore-DQ691eXH.js → ChartCore-ivzLqxVb.js} +1376 -1153
  2. package/dist/ChartCore-ivzLqxVb.js.map +1 -0
  3. package/dist/SciPlot-CEU4ApgD.js +463 -0
  4. package/dist/SciPlot-CEU4ApgD.js.map +1 -0
  5. package/dist/axisFormat-CzumxpCL.js +200 -0
  6. package/dist/axisFormat-CzumxpCL.js.map +1 -0
  7. package/dist/core/InteractionManager.d.ts +1 -0
  8. package/dist/core/OverlayRenderer.d.ts +11 -0
  9. package/dist/core/chart/ChartAxisManager.d.ts +2 -0
  10. package/dist/core/chart/ChartCore.d.ts +20 -0
  11. package/dist/core/chart/ChartPluginBridge.d.ts +1 -0
  12. package/dist/core/chart/ChartRenderLoop.d.ts +7 -0
  13. package/dist/core/chart/ChartRenderer.d.ts +5 -0
  14. package/dist/core/chart/ChartStateManager.d.ts +2 -0
  15. package/dist/core/chart/positionLines.d.ts +12 -0
  16. package/dist/core/chart/types.d.ts +7 -0
  17. package/dist/core/format/axisFormat.d.ts +2 -1
  18. package/dist/core/indicator/addIndicator.d.ts +1 -1
  19. package/dist/core/indicator/indicatorPresets.d.ts +10 -2
  20. package/dist/core/sync/index.d.ts +0 -1
  21. package/dist/core/time/TimeScale.d.ts +2 -2
  22. package/dist/core/time/applyTimeScale.d.ts +10 -0
  23. package/dist/createStackedChart-DxNW0VkF.js +705 -0
  24. package/dist/createStackedChart-DxNW0VkF.js.map +1 -0
  25. package/dist/{index-D7dTq6VB.js → index-BBpJwOct.js} +17 -19
  26. package/dist/index-BBpJwOct.js.map +1 -0
  27. package/dist/{index-CUGS98p4.js → index-CaXWSOTk.js} +3 -6
  28. package/dist/index-CaXWSOTk.js.map +1 -0
  29. package/dist/{index-DjeWClO9.js → index-qunX30Xu.js} +2 -2
  30. package/dist/{index-DjeWClO9.js.map → index-qunX30Xu.js.map} +1 -1
  31. package/dist/{index.core-BtGFYMOu.js → index.core-COREBDNq.js} +25 -24
  32. package/dist/{index.core-BtGFYMOu.js.map → index.core-COREBDNq.js.map} +1 -1
  33. package/dist/index.d.ts +6 -1
  34. package/dist/mockDatafeed-927foCM4.js +511 -0
  35. package/dist/mockDatafeed-927foCM4.js.map +1 -0
  36. package/dist/plugins/analysis/contours.d.ts +31 -0
  37. package/dist/plugins/analysis.js +494 -407
  38. package/dist/plugins/analysis.js.map +1 -1
  39. package/dist/plugins/broken-axis.js +170 -181
  40. package/dist/plugins/broken-axis.js.map +1 -1
  41. package/dist/plugins/drawing-tools/index.d.ts +14 -1
  42. package/dist/plugins/drawing-tools/measure.d.ts +21 -0
  43. package/dist/plugins/drawing-tools/snapToCandle.d.ts +21 -0
  44. package/dist/plugins/forecasting/algorithms.d.ts +7 -2
  45. package/dist/plugins/forecasting/types.d.ts +13 -3
  46. package/dist/plugins/forecasting.js +355 -175
  47. package/dist/plugins/forecasting.js.map +1 -1
  48. package/dist/plugins/latex/symbols.d.ts +50 -0
  49. package/dist/plugins/latex/types.d.ts +13 -1
  50. package/dist/plugins/latex.js +351 -331
  51. package/dist/plugins/latex.js.map +1 -1
  52. package/dist/plugins/ml-integration/native-algorithms.d.ts +24 -4
  53. package/dist/plugins/ml-integration/types.d.ts +19 -0
  54. package/dist/plugins/ml-integration.js +191 -140
  55. package/dist/plugins/ml-integration.js.map +1 -1
  56. package/dist/plugins/pattern-recognition/types.d.ts +28 -1
  57. package/dist/plugins/pattern-recognition.js +416 -343
  58. package/dist/plugins/pattern-recognition.js.map +1 -1
  59. package/dist/plugins/snapshot.js +36 -36
  60. package/dist/plugins/snapshot.js.map +1 -1
  61. package/dist/plugins/sync.js +1 -1
  62. package/dist/plugins/tools.js +1 -1
  63. package/dist/plugins/virtualization.js +1 -1
  64. package/dist/react.js +5 -5
  65. package/dist/symbols-DT0eLlpW.js +568 -0
  66. package/dist/symbols-DT0eLlpW.js.map +1 -0
  67. package/dist/trading/datafeed.d.ts +48 -0
  68. package/dist/trading/index.d.ts +29 -0
  69. package/dist/trading/mockDatafeed.d.ts +9 -0
  70. package/dist/trading/ohlcvGenerator.d.ts +25 -0
  71. package/dist/trading.d.ts +1 -0
  72. package/dist/trading.js +95 -0
  73. package/dist/trading.js.map +1 -0
  74. package/dist/types.d.ts +1 -1
  75. package/dist/velo-plot.full.js +835 -1054
  76. package/dist/velo-plot.full.js.map +1 -1
  77. package/dist/velo-plot.js +13 -13
  78. package/dist/workers/indicatorsAsync.d.ts +24 -0
  79. package/package.json +13 -1
  80. package/dist/ChartCore-DQ691eXH.js.map +0 -1
  81. package/dist/axisFormat-B7o_uIEA.js +0 -127
  82. package/dist/axisFormat-B7o_uIEA.js.map +0 -1
  83. package/dist/createStackedChart-BPooTQ9z.js +0 -1164
  84. package/dist/createStackedChart-BPooTQ9z.js.map +0 -1
  85. package/dist/index-CUGS98p4.js.map +0 -1
  86. package/dist/index-D7dTq6VB.js.map +0 -1
@@ -1,38 +1,38 @@
1
- function C(s) {
2
- const e = [], n = [];
3
- for (let t = 1; t < s.length - 1; t++) {
4
- const o = s[t - 1], i = s[t], g = s[t + 1];
5
- i.y > o.y && i.y > g.y ? e.push({ ...i, type: "peak" }) : i.y < o.y && i.y < g.y && n.push({ ...i, type: "valley" });
1
+ function R(o) {
2
+ const n = [], e = [];
3
+ for (let s = 1; s < o.length - 1; s++) {
4
+ const l = o[s - 1], a = o[s], f = o[s + 1];
5
+ a.y > l.y && a.y > f.y ? n.push({ ...a, type: "peak" }) : a.y < l.y && a.y < f.y && e.push({ ...a, type: "valley" });
6
6
  }
7
- return { peaks: e, valleys: n };
7
+ return { peaks: n, valleys: e };
8
8
  }
9
- function I(s, e) {
10
- return (e.y - s.y) / (e.x - s.x);
9
+ function C(o, n) {
10
+ return (n.y - o.y) / (n.x - o.x);
11
11
  }
12
- function T(s) {
13
- const e = s.map((g) => g.y), n = s.map((g) => g.x), t = Math.max(...e) - Math.min(...e), o = Math.max(...n) - Math.min(...n), i = I(s[0], s[s.length - 1]);
12
+ function T(o) {
13
+ const n = o.map((f) => f.y), e = o.map((f) => f.x), s = Math.max(...n) - Math.min(...n), l = Math.max(...e) - Math.min(...e), a = C(o[0], o[o.length - 1]);
14
14
  return {
15
- height: t,
16
- width: o,
17
- slope: i,
15
+ height: s,
16
+ width: l,
17
+ slope: a,
18
18
  volumeProfile: {
19
19
  increasing: 0.4,
20
20
  // Mock values
21
21
  decreasing: 0.3,
22
22
  neutral: 0.3
23
23
  },
24
- breakoutTarget: Math.max(...e) + t * 0.8,
25
- stopLoss: Math.min(...e) - t * 0.2
24
+ breakoutTarget: Math.max(...n) + s * 0.8,
25
+ stopLoss: Math.min(...n) - s * 0.2
26
26
  };
27
27
  }
28
- function D(s) {
29
- if (s.length < 5)
28
+ function _(o) {
29
+ if (o.length < 5)
30
30
  return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Insufficient points for head-shoulders pattern"] };
31
- const { peaks: e, valleys: n } = C(s);
32
- if (e.length < 3 || n.length < 2)
31
+ const { peaks: n, valleys: e } = R(o);
32
+ if (n.length < 3 || e.length < 2)
33
33
  return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Insufficient peaks/valleys"] };
34
- const t = e[0], o = e[1], i = e[2], g = n[0], u = n[1], p = o.y > t.y && o.y > i.y, y = Math.abs(t.y - i.y) / t.y < 0.1, k = g.y < t.y && u.y < i.y;
35
- if (!p || !y || !k)
34
+ const s = n[0], l = n[1], a = n[2], f = e[0], m = e[1], v = l.y > s.y && l.y > a.y, y = Math.abs(s.y - a.y) / s.y < 0.1, S = f.y < s.y && m.y < a.y;
35
+ if (!v || !y || !S)
36
36
  return {
37
37
  valid: !1,
38
38
  confidence: 0,
@@ -40,89 +40,89 @@ function D(s) {
40
40
  keyPoints: [],
41
41
  errors: ["Invalid head-shoulders structure"]
42
42
  };
43
- const x = [
44
- { start: t, end: g, type: "resistance", strength: 0.8 },
45
- { start: g, end: o, type: "support", strength: 0.7 },
46
- { start: o, end: u, type: "resistance", strength: 0.8 },
47
- { start: u, end: i, type: "support", strength: 0.7 }
48
- ], b = [t, g, o, u, i], M = T(s), a = 1 - Math.abs(t.y - i.y) / o.y, l = 1 - Math.abs(g.y - u.y) / o.y;
43
+ const w = [
44
+ { start: s, end: f, type: "resistance", strength: 0.8 },
45
+ { start: f, end: l, type: "support", strength: 0.7 },
46
+ { start: l, end: m, type: "resistance", strength: 0.8 },
47
+ { start: m, end: a, type: "support", strength: 0.7 }
48
+ ], x = [s, f, l, m, a], M = T(o), k = 1 - Math.abs(s.y - a.y) / l.y, z = 1 - Math.abs(f.y - m.y) / l.y;
49
49
  return {
50
50
  valid: !0,
51
- confidence: (a + l) / 2,
52
- segments: x,
53
- keyPoints: b,
51
+ confidence: (k + z) / 2,
52
+ segments: w,
53
+ keyPoints: x,
54
54
  measurements: M
55
55
  };
56
56
  }
57
- function q(s) {
58
- if (s.length < 4)
57
+ function N(o) {
58
+ if (o.length < 4)
59
59
  return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Insufficient points for double top"] };
60
- const { peaks: e, valleys: n } = C(s);
61
- if (e.length < 2 || n.length < 1)
60
+ const { peaks: n, valleys: e } = R(o);
61
+ if (n.length < 2 || e.length < 1)
62
62
  return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Insufficient peaks/valleys"] };
63
- const t = e[0], o = e[1], i = n[0], g = Math.abs(t.y - o.y) / t.y < 0.05, u = i.y < t.y && i.y < o.y, p = (t.y - i.y) / t.y > 0.1;
64
- if (!g || !u || !p)
63
+ const s = n[0], l = n[1], a = e[0], f = Math.abs(s.y - l.y) / s.y < 0.05, m = a.y < s.y && a.y < l.y, v = (s.y - a.y) / s.y > 0.1;
64
+ if (!f || !m || !v)
65
65
  return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Invalid double top structure"] };
66
66
  const y = [
67
- { start: t, end: i, type: "resistance", strength: 0.9 },
68
- { start: i, end: o, type: "support", strength: 0.8 },
69
- { start: t, end: o, type: "resistance", strength: 0.9 }
70
- ], k = [t, i, o], x = T(s), b = 1 - Math.abs(t.y - o.y) / t.y, M = (t.y - i.y) / t.y;
67
+ { start: s, end: a, type: "resistance", strength: 0.9 },
68
+ { start: a, end: l, type: "support", strength: 0.8 },
69
+ { start: s, end: l, type: "resistance", strength: 0.9 }
70
+ ], S = [s, a, l], w = T(o), x = 1 - Math.abs(s.y - l.y) / s.y, M = (s.y - a.y) / s.y;
71
71
  return {
72
72
  valid: !0,
73
- confidence: (b + Math.min(M * 2, 1)) / 2,
73
+ confidence: (x + Math.min(M * 2, 1)) / 2,
74
74
  segments: y,
75
- keyPoints: k,
76
- measurements: x
75
+ keyPoints: S,
76
+ measurements: w
77
77
  };
78
78
  }
79
- function E(s) {
80
- if (s.length < 4)
79
+ function V(o) {
80
+ if (o.length < 4)
81
81
  return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Insufficient points for double bottom"] };
82
- const { peaks: e, valleys: n } = C(s);
83
- if (n.length < 2 || e.length < 1)
82
+ const { peaks: n, valleys: e } = R(o);
83
+ if (e.length < 2 || n.length < 1)
84
84
  return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Insufficient peaks/valleys"] };
85
- const t = n[0], o = n[1], i = e[0], g = Math.abs(t.y - o.y) / t.y < 0.05, u = i.y > t.y && i.y > o.y, p = (i.y - t.y) / t.y > 0.1;
86
- if (!g || !u || !p)
85
+ const s = e[0], l = e[1], a = n[0], f = Math.abs(s.y - l.y) / s.y < 0.05, m = a.y > s.y && a.y > l.y, v = (a.y - s.y) / s.y > 0.1;
86
+ if (!f || !m || !v)
87
87
  return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Invalid double bottom structure"] };
88
88
  const y = [
89
- { start: t, end: i, type: "support", strength: 0.9 },
90
- { start: i, end: o, type: "resistance", strength: 0.8 },
91
- { start: t, end: o, type: "support", strength: 0.9 }
92
- ], k = [t, i, o], x = T(s), b = 1 - Math.abs(t.y - o.y) / t.y, M = (i.y - t.y) / t.y;
89
+ { start: s, end: a, type: "support", strength: 0.9 },
90
+ { start: a, end: l, type: "resistance", strength: 0.8 },
91
+ { start: s, end: l, type: "support", strength: 0.9 }
92
+ ], S = [s, a, l], w = T(o), x = 1 - Math.abs(s.y - l.y) / s.y, M = (a.y - s.y) / s.y;
93
93
  return {
94
94
  valid: !0,
95
- confidence: (b + Math.min(M * 2, 1)) / 2,
95
+ confidence: (x + Math.min(M * 2, 1)) / 2,
96
96
  segments: y,
97
- keyPoints: k,
98
- measurements: x
97
+ keyPoints: S,
98
+ measurements: w
99
99
  };
100
100
  }
101
- function _(s) {
102
- if (s.length < 4)
101
+ function q(o) {
102
+ if (o.length < 4)
103
103
  return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Insufficient points for ascending triangle"] };
104
- const e = s.map((a) => a.y), n = Math.max(...e), t = s.filter((a) => Math.abs(a.y - n) / n < 0.02);
105
- if (t.length < 2)
104
+ const n = o.map((k) => k.y), e = Math.max(...n), s = o.filter((k) => Math.abs(k.y - e) / e < 0.02);
105
+ if (s.length < 2)
106
106
  return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Insufficient resistance points"] };
107
- const o = s.filter((a, l) => l === 0 || a.y < s[l - 1].y);
108
- if (o.length < 2)
107
+ const l = o.filter((k, z) => z === 0 || k.y < o[z - 1].y);
108
+ if (l.length < 2)
109
109
  return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Insufficient low points"] };
110
- const i = o[0], g = o[o.length - 1], u = I(i, g);
111
- if (u <= 0)
110
+ const a = l[0], f = l[l.length - 1], m = C(a, f);
111
+ if (m <= 0)
112
112
  return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Support not ascending"] };
113
- const p = [
114
- { start: t[0], end: t[t.length - 1], type: "resistance", strength: 0.8 },
115
- { start: i, end: g, type: "support", strength: 0.7 }
116
- ], y = [...t.slice(0, 2), i, g], k = T(s), x = 1 - Math.abs(t[0].y - t[t.length - 1].y) / n, b = Math.min(u / 0.01, 1);
113
+ const v = [
114
+ { start: s[0], end: s[s.length - 1], type: "resistance", strength: 0.8 },
115
+ { start: a, end: f, type: "support", strength: 0.7 }
116
+ ], y = [...s.slice(0, 2), a, f], S = T(o), w = 1 - Math.abs(s[0].y - s[s.length - 1].y) / e, x = Math.min(m / 0.01, 1);
117
117
  return {
118
118
  valid: !0,
119
- confidence: (x + b) / 2,
120
- segments: p,
119
+ confidence: (w + x) / 2,
120
+ segments: v,
121
121
  keyPoints: y,
122
- measurements: k
122
+ measurements: S
123
123
  };
124
124
  }
125
- const B = {
125
+ const A = {
126
126
  "head-shoulders": {
127
127
  id: "head-shoulders",
128
128
  type: "head-shoulders",
@@ -130,7 +130,7 @@ const B = {
130
130
  description: "Bearish reversal pattern with three peaks",
131
131
  minPoints: 5,
132
132
  maxPoints: 7,
133
- validator: D
133
+ validator: _
134
134
  },
135
135
  "inverse-head-shoulders": {
136
136
  id: "inverse-head-shoulders",
@@ -139,9 +139,9 @@ const B = {
139
139
  description: "Bullish reversal pattern with three valleys",
140
140
  minPoints: 5,
141
141
  maxPoints: 7,
142
- validator: (s) => {
143
- const e = s.map((t) => ({ ...t, y: -t.y }));
144
- return D(e);
142
+ validator: (o) => {
143
+ const n = o.map((s) => ({ ...s, y: -s.y }));
144
+ return _(n);
145
145
  }
146
146
  },
147
147
  "double-top": {
@@ -151,7 +151,7 @@ const B = {
151
151
  description: "Bearish reversal pattern with two equal peaks",
152
152
  minPoints: 4,
153
153
  maxPoints: 6,
154
- validator: q
154
+ validator: N
155
155
  },
156
156
  "double-bottom": {
157
157
  id: "double-bottom",
@@ -160,7 +160,7 @@ const B = {
160
160
  description: "Bullish reversal pattern with two equal valleys",
161
161
  minPoints: 4,
162
162
  maxPoints: 6,
163
- validator: E
163
+ validator: V
164
164
  },
165
165
  "triple-top": {
166
166
  id: "triple-top",
@@ -169,24 +169,24 @@ const B = {
169
169
  description: "Bearish reversal pattern with three equal peaks",
170
170
  minPoints: 5,
171
171
  maxPoints: 7,
172
- validator: (s) => {
173
- if (s.length < 5)
172
+ validator: (o) => {
173
+ if (o.length < 5)
174
174
  return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Insufficient points"] };
175
- const { peaks: e } = C(s);
176
- if (e.length < 3)
175
+ const { peaks: n } = R(o);
176
+ if (n.length < 3)
177
177
  return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Need at least 3 peaks"] };
178
- const n = e[0].y, t = e[1].y, o = e[2].y, i = 0.05;
179
- if (!(Math.abs(n - t) / n < i && Math.abs(t - o) / t < i))
178
+ const e = n[0].y, s = n[1].y, l = n[2].y, a = 0.05;
179
+ if (!(Math.abs(e - s) / e < a && Math.abs(s - l) / s < a))
180
180
  return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Peaks not equal"] };
181
- const u = [
182
- { start: e[0], end: e[1], type: "resistance", strength: 0.8 },
183
- { start: e[1], end: e[2], type: "resistance", strength: 0.8 }
184
- ], p = [e[0], e[1], e[2]], y = T(s);
181
+ const m = [
182
+ { start: n[0], end: n[1], type: "resistance", strength: 0.8 },
183
+ { start: n[1], end: n[2], type: "resistance", strength: 0.8 }
184
+ ], v = [n[0], n[1], n[2]], y = T(o);
185
185
  return {
186
186
  valid: !0,
187
187
  confidence: 0.8,
188
- segments: u,
189
- keyPoints: p,
188
+ segments: m,
189
+ keyPoints: v,
190
190
  measurements: y
191
191
  };
192
192
  }
@@ -198,9 +198,9 @@ const B = {
198
198
  description: "Bullish reversal pattern with three equal valleys",
199
199
  minPoints: 5,
200
200
  maxPoints: 7,
201
- validator: (s) => {
202
- const e = s.map((n) => ({ ...n, y: -n.y }));
203
- return B["triple-top"].validator(e);
201
+ validator: (o) => {
202
+ const n = o.map((e) => ({ ...e, y: -e.y }));
203
+ return A["triple-top"].validator(n);
204
204
  }
205
205
  },
206
206
  "ascending-triangle": {
@@ -210,7 +210,7 @@ const B = {
210
210
  description: "Continuation pattern with horizontal resistance and ascending support",
211
211
  minPoints: 4,
212
212
  maxPoints: 8,
213
- validator: _
213
+ validator: q
214
214
  },
215
215
  "descending-triangle": {
216
216
  id: "descending-triangle",
@@ -219,9 +219,9 @@ const B = {
219
219
  description: "Continuation pattern with horizontal support and descending resistance",
220
220
  minPoints: 4,
221
221
  maxPoints: 8,
222
- validator: (s) => {
223
- const e = s.map((t) => ({ ...t, y: -t.y }));
224
- return _(e);
222
+ validator: (o) => {
223
+ const n = o.map((s) => ({ ...s, y: -s.y }));
224
+ return q(n);
225
225
  }
226
226
  },
227
227
  "symmetrical-triangle": {
@@ -231,22 +231,22 @@ const B = {
231
231
  description: "Continuation pattern with converging support and resistance",
232
232
  minPoints: 4,
233
233
  maxPoints: 8,
234
- validator: (s) => {
235
- if (s.length < 4)
234
+ validator: (o) => {
235
+ if (o.length < 4)
236
236
  return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Insufficient points"] };
237
- const e = s.slice(0, Math.floor(s.length / 2)), n = s.slice(Math.floor(s.length / 2)), t = I(e[0], e[e.length - 1]), o = I(n[0], n[n.length - 1]);
238
- if (!(t > 0 && o < 0 || t < 0 && o > 0))
237
+ const n = o.slice(0, Math.floor(o.length / 2)), e = o.slice(Math.floor(o.length / 2)), s = C(n[0], n[n.length - 1]), l = C(e[0], e[e.length - 1]);
238
+ if (!(s > 0 && l < 0 || s < 0 && l > 0))
239
239
  return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Lines not converging"] };
240
- const g = [
241
- { start: e[0], end: e[e.length - 1], type: "trendline", strength: 0.7 },
242
- { start: n[0], end: n[n.length - 1], type: "trendline", strength: 0.7 }
243
- ], u = [e[0], e[e.length - 1], n[0], n[n.length - 1]], p = T(s);
240
+ const f = [
241
+ { start: n[0], end: n[n.length - 1], type: "trendline", strength: 0.7 },
242
+ { start: e[0], end: e[e.length - 1], type: "trendline", strength: 0.7 }
243
+ ], m = [n[0], n[n.length - 1], e[0], e[e.length - 1]], v = T(o);
244
244
  return {
245
245
  valid: !0,
246
246
  confidence: 0.7,
247
- segments: g,
248
- keyPoints: u,
249
- measurements: p
247
+ segments: f,
248
+ keyPoints: m,
249
+ measurements: v
250
250
  };
251
251
  }
252
252
  },
@@ -257,25 +257,25 @@ const B = {
257
257
  description: "Bearish reversal pattern with two converging upward lines",
258
258
  minPoints: 4,
259
259
  maxPoints: 8,
260
- validator: (s) => {
261
- if (s.length < 4)
260
+ validator: (o) => {
261
+ if (o.length < 4)
262
262
  return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Insufficient points"] };
263
- const { peaks: e, valleys: n } = C(s);
264
- if (e.length < 2 || n.length < 2)
263
+ const { peaks: n, valleys: e } = R(o);
264
+ if (n.length < 2 || e.length < 2)
265
265
  return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Insufficient peaks/valleys"] };
266
- const t = I(e[0], e[e.length - 1]), o = I(n[0], n[n.length - 1]);
267
- if (!(t > 0 && o > 0 && o > t))
266
+ const s = C(n[0], n[n.length - 1]), l = C(e[0], e[e.length - 1]);
267
+ if (!(s > 0 && l > 0 && l > s))
268
268
  return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Not a rising wedge pattern"] };
269
- const g = [
270
- { start: e[0], end: e[e.length - 1], type: "resistance", strength: 0.8 },
271
- { start: n[0], end: n[n.length - 1], type: "support", strength: 0.8 }
272
- ], u = [e[0], e[e.length - 1], n[0], n[n.length - 1]], p = T(s);
269
+ const f = [
270
+ { start: n[0], end: n[n.length - 1], type: "resistance", strength: 0.8 },
271
+ { start: e[0], end: e[e.length - 1], type: "support", strength: 0.8 }
272
+ ], m = [n[0], n[n.length - 1], e[0], e[e.length - 1]], v = T(o);
273
273
  return {
274
274
  valid: !0,
275
275
  confidence: 0.75,
276
- segments: g,
277
- keyPoints: u,
278
- measurements: p
276
+ segments: f,
277
+ keyPoints: m,
278
+ measurements: v
279
279
  };
280
280
  }
281
281
  },
@@ -286,9 +286,9 @@ const B = {
286
286
  description: "Bullish reversal pattern with two converging downward lines",
287
287
  minPoints: 4,
288
288
  maxPoints: 8,
289
- validator: (s) => {
290
- const e = s.map((t) => ({ ...t, y: -t.y }));
291
- return B["rising-wedge"].validator(e);
289
+ validator: (o) => {
290
+ const n = o.map((s) => ({ ...s, y: -s.y }));
291
+ return A["rising-wedge"].validator(n);
292
292
  }
293
293
  },
294
294
  rectangle: {
@@ -298,22 +298,22 @@ const B = {
298
298
  description: "Continuation pattern with horizontal support and resistance",
299
299
  minPoints: 4,
300
300
  maxPoints: 10,
301
- validator: (s) => {
302
- if (s.length < 4)
301
+ validator: (o) => {
302
+ if (o.length < 4)
303
303
  return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Insufficient points"] };
304
- const e = s.map((y) => y.y), n = Math.max(...e), t = Math.min(...e), o = s.filter((y) => Math.abs(y.y - n) / n < 0.05), i = s.filter((y) => Math.abs(y.y - t) / t < 0.05);
305
- if (o.length < 2 || i.length < 2)
304
+ const n = o.map((y) => y.y), e = Math.max(...n), s = Math.min(...n), l = o.filter((y) => Math.abs(y.y - e) / e < 0.05), a = o.filter((y) => Math.abs(y.y - s) / s < 0.05);
305
+ if (l.length < 2 || a.length < 2)
306
306
  return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Insufficient horizontal lines"] };
307
- const g = [
308
- { start: o[0], end: o[o.length - 1], type: "resistance", strength: 0.9 },
309
- { start: i[0], end: i[i.length - 1], type: "support", strength: 0.9 }
310
- ], u = [o[0], o[o.length - 1], i[0], i[i.length - 1]], p = T(s);
307
+ const f = [
308
+ { start: l[0], end: l[l.length - 1], type: "resistance", strength: 0.9 },
309
+ { start: a[0], end: a[a.length - 1], type: "support", strength: 0.9 }
310
+ ], m = [l[0], l[l.length - 1], a[0], a[a.length - 1]], v = T(o);
311
311
  return {
312
312
  valid: !0,
313
313
  confidence: 0.8,
314
- segments: g,
315
- keyPoints: u,
316
- measurements: p
314
+ segments: f,
315
+ keyPoints: m,
316
+ measurements: v
317
317
  };
318
318
  }
319
319
  },
@@ -324,21 +324,21 @@ const B = {
324
324
  description: "Short-term continuation pattern after strong move",
325
325
  minPoints: 3,
326
326
  maxPoints: 6,
327
- validator: (s) => {
328
- if (s.length < 3)
327
+ validator: (o) => {
328
+ if (o.length < 3)
329
329
  return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Insufficient points"] };
330
- const e = I(s[0], s[s.length - 1]);
331
- if (!(Math.abs(e) < 0.01))
330
+ const n = C(o[0], o[o.length - 1]);
331
+ if (!(Math.abs(n) < 0.01))
332
332
  return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Not horizontal enough"] };
333
- const t = [
334
- { start: s[0], end: s[s.length - 1], type: "trendline", strength: 0.6 }
335
- ], o = [s[0], s[s.length - 1]], i = T(s);
333
+ const s = [
334
+ { start: o[0], end: o[o.length - 1], type: "trendline", strength: 0.6 }
335
+ ], l = [o[0], o[o.length - 1]], a = T(o);
336
336
  return {
337
337
  valid: !0,
338
338
  confidence: 0.6,
339
- segments: t,
340
- keyPoints: o,
341
- measurements: i
339
+ segments: s,
340
+ keyPoints: l,
341
+ measurements: a
342
342
  };
343
343
  }
344
344
  },
@@ -349,7 +349,7 @@ const B = {
349
349
  description: "Short-term continuation pattern with converging lines",
350
350
  minPoints: 3,
351
351
  maxPoints: 5,
352
- validator: (s) => B["symmetrical-triangle"].validator(s)
352
+ validator: (o) => A["symmetrical-triangle"].validator(o)
353
353
  },
354
354
  custom: {
355
355
  id: "custom",
@@ -357,15 +357,15 @@ const B = {
357
357
  name: "Custom Pattern",
358
358
  description: "User-defined pattern",
359
359
  minPoints: 3,
360
- validator: (s) => ({ valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Custom pattern not implemented"] })
360
+ validator: (o) => ({ valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Custom pattern not implemented"] })
361
361
  }
362
- }, L = {
362
+ }, F = {
363
363
  name: "pattern-recognition",
364
364
  version: "1.0.0",
365
365
  description: "Technical pattern recognition for financial and scientific data",
366
366
  author: "Sci Plot Team",
367
367
  provides: ["patterns", "technical-analysis", "chart-patterns"]
368
- }, V = {
368
+ }, H = {
369
369
  defaultParameters: {
370
370
  minConfidence: 0.7,
371
371
  maxPatterns: 10,
@@ -411,211 +411,284 @@ const B = {
411
411
  alertTypes: ["head-shoulders", "double-top", "double-bottom"]
412
412
  }
413
413
  };
414
- function F(s = {}) {
415
- const e = { ...V, ...s };
416
- let n = null;
417
- const t = /* @__PURE__ */ new Map(), o = new Map(Object.entries(B)), i = /* @__PURE__ */ new Set(), g = /* @__PURE__ */ new Map();
418
- async function u(a, l, d) {
419
- const r = { ...e.defaultParameters, ...d }, f = performance.now(), c = [], m = {}, h = p(l, r.sensitivity);
420
- for (const v of r.patternTypes) {
421
- const w = o.get(v);
422
- if (w) {
423
- for (let z = r.minPatternSize; z <= Math.min(h.length, r.maxPatternSize); z++) {
424
- const $ = h.slice(Math.max(0, z - r.maxPatternSize), z);
425
- if ($.length < w.minPoints || w.maxPoints && $.length > w.maxPoints) continue;
426
- const R = w.validator($);
427
- if (R.valid && R.confidence >= r.minConfidence) {
428
- const A = {
429
- pattern: w,
430
- confidence: R.confidence,
431
- location: {
432
- startIndex: Math.max(0, z - r.maxPatternSize),
433
- endIndex: z,
434
- startPoint: $[0],
435
- endPoint: $[$.length - 1]
436
- },
437
- validation: R,
438
- timestamp: Date.now(),
439
- seriesId: a
440
- };
441
- if (!y(A, c, r.overlapTolerance) && (c.push(A), m[v] = (m[v] || 0) + 1, c.length >= r.maxPatterns))
442
- break;
443
- }
444
- }
445
- if (c.length >= r.maxPatterns)
446
- break;
414
+ function O(o = {}) {
415
+ const n = { ...H, ...o };
416
+ let e = null;
417
+ const s = /* @__PURE__ */ new Map(), l = new Map(Object.entries(A)), a = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Set(), m = /* @__PURE__ */ new Map(), v = {
418
+ "head-shoulders": "bearish",
419
+ "inverse-head-shoulders": "bullish",
420
+ "double-top": "bearish",
421
+ "double-bottom": "bullish",
422
+ "triple-top": "bearish",
423
+ "triple-bottom": "bullish",
424
+ "ascending-triangle": "bullish",
425
+ "descending-triangle": "bearish",
426
+ "symmetrical-triangle": "neutral",
427
+ "rising-wedge": "bearish",
428
+ "falling-wedge": "bullish",
429
+ rectangle: "neutral",
430
+ flag: "neutral",
431
+ pennant: "neutral",
432
+ custom: "neutral"
433
+ };
434
+ function y(t, r, c, i, u, d, h) {
435
+ for (let g = i.minPatternSize; g <= Math.min(c.length, i.maxPatternSize); g++) {
436
+ const p = c.slice(Math.max(0, g - i.maxPatternSize), g);
437
+ if (p.length < t.minPoints || t.maxPoints && p.length > t.maxPoints) continue;
438
+ const P = t.validator(p);
439
+ if (P.valid && P.confidence >= i.minConfidence) {
440
+ const $ = {
441
+ pattern: t,
442
+ confidence: P.confidence,
443
+ location: {
444
+ startIndex: Math.max(0, g - i.maxPatternSize),
445
+ endIndex: g,
446
+ startPoint: p[0],
447
+ endPoint: p[p.length - 1]
448
+ },
449
+ validation: P,
450
+ timestamp: Date.now(),
451
+ seriesId: u
452
+ };
453
+ if (!M($, d, i.overlapTolerance) && (d.push($), h[r] = (h[r] || 0) + 1, d.length >= i.maxPatterns))
454
+ return !0;
455
+ }
456
+ }
457
+ return !1;
458
+ }
459
+ function S(t) {
460
+ var c, i;
461
+ const r = v[t.pattern.type] ?? "neutral";
462
+ e == null || e.events.emit("pattern:signal", {
463
+ seriesId: t.seriesId,
464
+ patternType: t.pattern.type,
465
+ patternName: t.pattern.name,
466
+ direction: r,
467
+ confidence: t.confidence,
468
+ price: t.location.endPoint.y,
469
+ x: t.location.endPoint.x,
470
+ target: (c = t.validation.measurements) == null ? void 0 : c.breakoutTarget,
471
+ stopLoss: (i = t.validation.measurements) == null ? void 0 : i.stopLoss,
472
+ timestamp: t.timestamp
473
+ });
474
+ }
475
+ async function w(t, r, c) {
476
+ const i = { ...n.defaultParameters, ...c }, u = performance.now(), d = [], h = {}, g = x(r, i.sensitivity);
477
+ let p = !1;
478
+ for (const b of i.patternTypes) {
479
+ const I = l.get(b);
480
+ if (I && y(I, b, g, i, t, d, h)) {
481
+ p = !0;
482
+ break;
447
483
  }
448
484
  }
449
- c.sort((v, w) => w.confidence - v.confidence), t.set(a, c);
450
- const P = performance.now() - f;
451
- for (const v of c)
452
- v.confidence >= e.notifications.minAlertConfidence && e.notifications.alertTypes.includes(v.pattern.type) && (n == null || n.events.emit("pattern:detected", {
453
- match: v,
454
- seriesId: a,
485
+ if (!p && a.size > 0 && i.patternTypes.includes("custom")) {
486
+ for (const [b, I] of a)
487
+ if (y(I, b, g, i, t, d, h))
488
+ break;
489
+ }
490
+ d.sort((b, I) => I.confidence - b.confidence), s.set(t, d);
491
+ const P = performance.now() - u;
492
+ for (const b of d)
493
+ b.confidence >= n.notifications.minAlertConfidence && S(b), b.confidence >= n.notifications.minAlertConfidence && n.notifications.alertTypes.includes(b.pattern.type) && (e == null || e.events.emit("pattern:detected", {
494
+ match: b,
495
+ seriesId: t,
455
496
  timestamp: Date.now()
456
497
  }));
457
- const S = {
458
- matches: c,
498
+ const $ = {
499
+ matches: d,
459
500
  summary: {
460
- totalPatterns: c.length,
461
- patternsByType: m,
462
- averageConfidence: c.length > 0 ? c.reduce((v, w) => v + w.confidence, 0) / c.length : 0,
501
+ totalPatterns: d.length,
502
+ patternsByType: h,
503
+ averageConfidence: d.length > 0 ? d.reduce((b, I) => b + I.confidence, 0) / d.length : 0,
463
504
  detectionTime: P
464
505
  },
465
- processedPoints: h.length,
466
- parameters: r
506
+ processedPoints: g.length,
507
+ parameters: i
467
508
  };
468
- return n == null || n.log.info(`Pattern detection completed for ${a}: ${c.length} patterns found`), S;
509
+ return e == null || e.log.info(`Pattern detection completed for ${t}: ${d.length} patterns found`), $;
469
510
  }
470
- function p(a, l) {
471
- return a.filter((d, r) => {
472
- if (r === 0 || r === a.length - 1) return !0;
473
- const f = a[r - 1];
474
- return Math.abs(d.y - f.y) / f.y >= l * 0.01;
511
+ function x(t, r) {
512
+ return t.filter((c, i) => {
513
+ if (i === 0 || i === t.length - 1) return !0;
514
+ const u = t[i - 1];
515
+ return Math.abs(c.y - u.y) / u.y >= r * 0.01;
475
516
  });
476
517
  }
477
- function y(a, l, d) {
478
- for (const r of l) {
479
- const f = Math.max(a.location.startIndex, r.location.startIndex), m = Math.min(a.location.endIndex, r.location.endIndex) - f, h = a.location.endIndex - a.location.startIndex, P = r.location.endIndex - r.location.startIndex;
480
- if (m / Math.min(h, P) > d)
518
+ function M(t, r, c) {
519
+ for (const i of r) {
520
+ const u = Math.max(t.location.startIndex, i.location.startIndex), h = Math.min(t.location.endIndex, i.location.endIndex) - u, g = t.location.endIndex - t.location.startIndex, p = i.location.endIndex - i.location.startIndex;
521
+ if (h / Math.min(g, p) > c)
481
522
  return !0;
482
523
  }
483
524
  return !1;
484
525
  }
485
- function k(a) {
486
- const l = {
487
- id: a.id,
526
+ function k(t) {
527
+ const r = {
528
+ id: t.id,
488
529
  type: "custom",
489
- name: a.name,
490
- minPoints: a.pointSequence.length,
491
- maxPoints: a.pointSequence.length,
492
- validator: (d) => x(d, a)
530
+ name: t.name,
531
+ minPoints: t.pointSequence.length,
532
+ maxPoints: t.pointSequence.length,
533
+ validator: (c) => L(c, t)
493
534
  };
494
- o.set("custom", l), n == null || n.log.info(`Custom pattern registered: ${a.id}`);
535
+ a.set(t.id, r), e == null || e.log.info(`Custom pattern registered: ${t.id}`);
495
536
  }
496
- function x(a, l) {
497
- if (a.length < l.pointSequence.length)
537
+ function z(t, r) {
538
+ if ("pointSequence" in r) {
539
+ k({ ...r, id: t });
540
+ return;
541
+ }
542
+ const c = r;
543
+ if (typeof c.validator != "function") {
544
+ e == null || e.log.error(`Cannot register pattern '${t}': a validator function is required`);
545
+ return;
546
+ }
547
+ const i = {
548
+ id: t,
549
+ type: "custom",
550
+ name: c.name ?? t,
551
+ description: c.description,
552
+ minPoints: c.minPoints ?? 3,
553
+ maxPoints: c.maxPoints,
554
+ validator: c.validator,
555
+ confidenceCalculator: c.confidenceCalculator
556
+ };
557
+ a.set(t, i), e == null || e.log.info(`Custom pattern registered: ${t}`);
558
+ }
559
+ function D(t) {
560
+ const r = a.delete(t);
561
+ return r && (e == null || e.log.info(`Custom pattern removed: ${t}`)), r;
562
+ }
563
+ function L(t, r) {
564
+ if (t.length < r.pointSequence.length)
498
565
  return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Insufficient points"] };
499
- let d = 1;
500
- const r = [];
501
- for (let f = 0; f < l.pointSequence.length; f++) {
502
- const c = l.pointSequence[f], m = a[f];
503
- if (c.constraints) {
504
- const h = c.constraints;
505
- if (h.higherThanPrevious && f > 0 && m.y <= a[f - 1].y && (d *= 0.8, r.push(`Point ${f} not higher than previous`)), h.lowerThanPrevious && f > 0 && m.y >= a[f - 1].y && (d *= 0.8, r.push(`Point ${f} not lower than previous`)), h.withinRange) {
506
- const [P, S] = h.withinRange;
507
- (m.y < P || m.y > S) && (d *= 0.7, r.push(`Point ${f} not within range [${P}, ${S}]`));
566
+ let c = 1;
567
+ const i = [];
568
+ for (let u = 0; u < r.pointSequence.length; u++) {
569
+ const d = r.pointSequence[u], h = t[u];
570
+ if (d.constraints) {
571
+ const g = d.constraints;
572
+ if (g.higherThanPrevious && u > 0 && h.y <= t[u - 1].y && (c *= 0.8, i.push(`Point ${u} not higher than previous`)), g.lowerThanPrevious && u > 0 && h.y >= t[u - 1].y && (c *= 0.8, i.push(`Point ${u} not lower than previous`)), g.withinRange) {
573
+ const [p, P] = g.withinRange;
574
+ (h.y < p || h.y > P) && (c *= 0.7, i.push(`Point ${u} not within range [${p}, ${P}]`));
508
575
  }
509
576
  }
510
577
  }
511
578
  return {
512
- valid: d >= 0.5,
513
- confidence: d,
579
+ valid: c >= 0.5,
580
+ confidence: c,
514
581
  segments: [],
515
- keyPoints: a,
516
- errors: r.length > 0 ? r : void 0
582
+ keyPoints: t,
583
+ errors: i.length > 0 ? i : void 0
517
584
  };
518
585
  }
519
- const b = {
520
- detectPatterns: u,
586
+ const B = {
587
+ detectPatterns: w,
521
588
  registerCustomPattern: k,
589
+ register: z,
590
+ unregister: D,
591
+ onSignal(t) {
592
+ return (e == null ? void 0 : e.events.onPlugin("pattern:signal", (r) => t(r))) ?? (() => {
593
+ });
594
+ },
522
595
  getRegisteredPatterns() {
523
- return Array.from(o.values());
596
+ return [...l.values(), ...a.values()];
524
597
  },
525
- getPatternMatches(a) {
526
- return t.get(a) || [];
598
+ getPatternMatches(t) {
599
+ return s.get(t) || [];
527
600
  },
528
- clearPatternMatches(a) {
529
- t.delete(a), n == null || n.log.info(`Pattern matches cleared for series: ${a}`);
601
+ clearPatternMatches(t) {
602
+ s.delete(t), e == null || e.log.info(`Pattern matches cleared for series: ${t}`);
530
603
  },
531
- enableRealtimeDetection(a, l) {
532
- i.add(a);
533
- const d = n == null ? void 0 : n.chart;
534
- if (d) {
535
- const r = d.getSeries(a);
536
- if (r) {
537
- const f = r.getData();
538
- if (f && f.x.length > 0) {
539
- const c = Array.from(f.x).map((m, h) => ({
540
- x: m,
541
- y: f.y[h]
604
+ enableRealtimeDetection(t, r) {
605
+ f.add(t);
606
+ const c = e == null ? void 0 : e.chart;
607
+ if (c) {
608
+ const i = c.getSeries(t);
609
+ if (i) {
610
+ const u = i.getData();
611
+ if (u && u.x.length > 0) {
612
+ const d = Array.from(u.x).map((h, g) => ({
613
+ x: h,
614
+ y: u.y[g]
542
615
  }));
543
- u(a, c, l);
616
+ w(t, d, r);
544
617
  }
545
618
  }
546
619
  }
547
- n == null || n.log.info(`Real-time pattern detection enabled for series: ${a}`);
620
+ e == null || e.log.info(`Real-time pattern detection enabled for series: ${t}`);
548
621
  },
549
- disableRealtimeDetection(a) {
550
- i.delete(a);
551
- const l = g.get(a);
552
- l && (clearTimeout(l), g.delete(a)), n == null || n.log.info(`Real-time pattern detection disabled for series: ${a}`);
622
+ disableRealtimeDetection(t) {
623
+ f.delete(t);
624
+ const r = m.get(t);
625
+ r && (clearTimeout(r), m.delete(t)), e == null || e.log.info(`Real-time pattern detection disabled for series: ${t}`);
553
626
  },
554
- getStatistics(a) {
555
- if (a) {
556
- const l = t.get(a) || [], d = {};
557
- for (const r of l)
558
- d[r.pattern.type] = (d[r.pattern.type] || 0) + 1;
627
+ getStatistics(t) {
628
+ if (t) {
629
+ const r = s.get(t) || [], c = {};
630
+ for (const i of r)
631
+ c[i.pattern.type] = (c[i.pattern.type] || 0) + 1;
559
632
  return {
560
- totalDetections: l.length,
561
- patternsByType: d,
562
- averageConfidence: l.length > 0 ? l.reduce((r, f) => r + f.confidence, 0) / l.length : 0,
563
- detectionRate: l.length / 100
633
+ totalDetections: r.length,
634
+ patternsByType: c,
635
+ averageConfidence: r.length > 0 ? r.reduce((i, u) => i + u.confidence, 0) / r.length : 0,
636
+ detectionRate: r.length / 100
564
637
  };
565
638
  } else {
566
- let l = 0;
567
- const d = {}, r = [];
568
- for (const f of t.values()) {
569
- l += f.length, r.push(...f.map((c) => c.confidence));
570
- for (const c of f)
571
- d[c.pattern.type] = (d[c.pattern.type] || 0) + 1;
639
+ let r = 0;
640
+ const c = {}, i = [];
641
+ for (const u of s.values()) {
642
+ r += u.length, i.push(...u.map((d) => d.confidence));
643
+ for (const d of u)
644
+ c[d.pattern.type] = (c[d.pattern.type] || 0) + 1;
572
645
  }
573
646
  return {
574
- totalDetections: l,
575
- patternsByType: d,
576
- averageConfidence: r.length > 0 ? r.reduce((f, c) => f + c, 0) / r.length : 0,
577
- detectionRate: l / 100
647
+ totalDetections: r,
648
+ patternsByType: c,
649
+ averageConfidence: i.length > 0 ? i.reduce((u, d) => u + d, 0) / i.length : 0,
650
+ detectionRate: r / 100
578
651
  };
579
652
  }
580
653
  },
581
- updateConfig: (a) => {
582
- Object.assign(e, a);
654
+ updateConfig: (t) => {
655
+ Object.assign(n, t);
583
656
  },
584
- getConfig: () => ({ ...e }),
585
- visualizePatterns(a, l) {
586
- const d = n == null ? void 0 : n.chart;
587
- if (!d) return;
588
- const r = t.get(a) || [], f = l ? r.filter((c) => l.includes(c.pattern.type)) : r;
589
- b.hidePatterns(a);
590
- for (const c of f) {
591
- const m = e.visualization.colorScheme[c.pattern.type] || "#666666";
592
- for (const h of c.validation.segments) {
593
- const P = `${a}_pattern_${c.pattern.id}_${c.location.startIndex}`;
594
- d.addSeries({
595
- id: P,
657
+ getConfig: () => ({ ...n }),
658
+ visualizePatterns(t, r) {
659
+ const c = e == null ? void 0 : e.chart;
660
+ if (!c) return;
661
+ const i = s.get(t) || [], u = r ? i.filter((d) => r.includes(d.pattern.type)) : i;
662
+ B.hidePatterns(t);
663
+ for (const d of u) {
664
+ const h = n.visualization.colorScheme[d.pattern.type] || "#666666";
665
+ for (const g of d.validation.segments) {
666
+ const p = `${t}_pattern_${d.pattern.id}_${d.location.startIndex}`;
667
+ c.addSeries({
668
+ id: p,
596
669
  type: "line",
597
670
  data: {
598
- x: new Float32Array([h.start.x, h.end.x]),
599
- y: new Float32Array([h.start.y, h.end.y])
671
+ x: new Float32Array([g.start.x, g.end.x]),
672
+ y: new Float32Array([g.start.y, g.end.y])
600
673
  },
601
674
  style: {
602
- color: m,
603
- width: e.visualization.lineWidth,
604
- opacity: e.visualization.opacity,
675
+ color: h,
676
+ width: n.visualization.lineWidth,
677
+ opacity: n.visualization.opacity,
605
678
  lineDash: [5, 5]
606
679
  }
607
680
  });
608
681
  }
609
- if (e.visualization.showLabels) {
610
- const h = `${a}_label_${c.pattern.id}_${c.location.startIndex}`, P = (c.location.startPoint.x + c.location.endPoint.x) / 2, S = (c.location.startPoint.y + c.location.endPoint.y) / 2;
611
- d.addAnnotation({
612
- id: h,
682
+ if (n.visualization.showLabels) {
683
+ const g = `${t}_label_${d.pattern.id}_${d.location.startIndex}`, p = (d.location.startPoint.x + d.location.endPoint.x) / 2, P = (d.location.startPoint.y + d.location.endPoint.y) / 2;
684
+ c.addAnnotation({
685
+ id: g,
613
686
  type: "text",
614
- text: c.pattern.name,
615
- x: P,
616
- y: S,
687
+ text: d.pattern.name,
688
+ x: p,
689
+ y: P,
617
690
  style: {
618
- color: m,
691
+ color: h,
619
692
  fontSize: 12,
620
693
  backgroundColor: "rgba(255, 255, 255, 0.8)"
621
694
  }
@@ -623,68 +696,68 @@ function F(s = {}) {
623
696
  }
624
697
  }
625
698
  },
626
- hidePatterns(a) {
627
- const l = n == null ? void 0 : n.chart;
628
- if (!l) return;
629
- const d = t.get(a) || [];
630
- for (const r of d) {
631
- for (let c = 0; c < r.validation.segments.length; c++) {
632
- const m = `${a}_pattern_${r.pattern.id}_${r.location.startIndex}`;
633
- l.getSeries(m) && l.removeSeries(m);
699
+ hidePatterns(t) {
700
+ const r = e == null ? void 0 : e.chart;
701
+ if (!r) return;
702
+ const c = s.get(t) || [];
703
+ for (const i of c) {
704
+ for (let d = 0; d < i.validation.segments.length; d++) {
705
+ const h = `${t}_pattern_${i.pattern.id}_${i.location.startIndex}`;
706
+ r.getSeries(h) && r.removeSeries(h);
634
707
  }
635
- const f = `${a}_label_${r.pattern.id}_${r.location.startIndex}`;
636
- l.getAnnotation(f) && l.removeAnnotation(f);
708
+ const u = `${t}_label_${i.pattern.id}_${i.location.startIndex}`;
709
+ r.getAnnotation(u) && r.removeAnnotation(u);
637
710
  }
638
711
  }
639
712
  };
640
- function M(a, l) {
641
- if (!e.enableRealtime) return;
642
- const { seriesId: d } = l;
643
- if (i.has(d)) {
644
- const r = g.get(d);
645
- r && clearTimeout(r);
646
- const f = setTimeout(() => {
647
- const c = a.chart;
648
- if (c) {
649
- const m = c.getSeries(d);
650
- if (m) {
651
- const h = m.getData();
652
- if (h && h.x.length > 0) {
653
- const P = Array.from(h.x).map((S, v) => ({
654
- x: S,
655
- y: h.y[v]
713
+ function E(t, r) {
714
+ if (!n.enableRealtime) return;
715
+ const { seriesId: c } = r;
716
+ if (f.has(c)) {
717
+ const i = m.get(c);
718
+ i && clearTimeout(i);
719
+ const u = setTimeout(() => {
720
+ const d = t.chart;
721
+ if (d) {
722
+ const h = d.getSeries(c);
723
+ if (h) {
724
+ const g = h.getData();
725
+ if (g && g.x.length > 0) {
726
+ const p = Array.from(g.x).map((P, $) => ({
727
+ x: P,
728
+ y: g.y[$]
656
729
  }));
657
- u(d, P), e.visualization.showPatterns && b.visualizePatterns(d);
730
+ w(c, p), n.visualization.showPatterns && B.visualizePatterns(c);
658
731
  }
659
732
  }
660
733
  }
661
- }, e.debounceTime);
662
- g.set(d, f);
734
+ }, n.debounceTime);
735
+ m.set(c, u);
663
736
  }
664
737
  }
665
738
  return {
666
- manifest: L,
667
- onInit(a) {
668
- if (n = a, e.customPatterns)
669
- for (const l of e.customPatterns)
670
- k(l);
671
- n.log.info(`Pattern Recognition plugin initialized with ${o.size} patterns`);
739
+ manifest: F,
740
+ onInit(t) {
741
+ if (e = t, n.customPatterns)
742
+ for (const r of n.customPatterns)
743
+ k(r);
744
+ e.log.info(`Pattern Recognition plugin initialized with ${l.size} patterns`);
672
745
  },
673
- onConfigChange(a, l) {
746
+ onConfigChange(t, r) {
674
747
  },
675
- onBeforeRender(a, l) {
748
+ onBeforeRender(t, r) {
676
749
  },
677
- onDataUpdate: M,
678
- onDestroy(a) {
679
- for (const l of g.values())
680
- clearTimeout(l);
681
- g.clear(), t.clear(), i.clear(), o.clear();
750
+ onDataUpdate: E,
751
+ onDestroy(t) {
752
+ for (const r of m.values())
753
+ clearTimeout(r);
754
+ m.clear(), s.clear(), f.clear(), l.clear(), a.clear();
682
755
  },
683
- api: b
756
+ api: B
684
757
  };
685
758
  }
686
759
  export {
687
- F as PluginPatternRecognition,
688
- F as default
760
+ O as PluginPatternRecognition,
761
+ O as default
689
762
  };
690
763
  //# sourceMappingURL=pattern-recognition.js.map