velo-plot 1.15.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{ChartCore-BimVvUEg.js → ChartCore-BhQ4j7f5.js} +2213 -1489
- package/dist/ChartCore-BhQ4j7f5.js.map +1 -0
- package/dist/SciPlot-GJvw7GJo.js +463 -0
- package/dist/SciPlot-GJvw7GJo.js.map +1 -0
- package/dist/assets/downsample.worker-C70QJ04y.js +2 -0
- package/dist/assets/downsample.worker-C70QJ04y.js.map +1 -0
- package/dist/assets/indicator.worker-bv0zC4EX.js +2 -0
- package/dist/assets/indicator.worker-bv0zC4EX.js.map +1 -0
- package/dist/axisFormat-SPX-CD5s.js +200 -0
- package/dist/axisFormat-SPX-CD5s.js.map +1 -0
- package/dist/core/InteractionManager.d.ts +1 -0
- package/dist/core/OverlayRenderer.d.ts +13 -0
- package/dist/core/chart/ChartAlerts.d.ts +42 -0
- package/dist/core/chart/ChartCore.d.ts +24 -1
- package/dist/core/chart/ChartRenderLoop.d.ts +9 -2
- package/dist/core/chart/ChartRenderer.d.ts +8 -2
- package/dist/core/chart/candlestickMarkers.d.ts +23 -0
- package/dist/core/chart/heikinAshi.d.ts +10 -0
- package/dist/core/chart/positionLines.d.ts +12 -0
- package/dist/core/chart/series/types.d.ts +2 -2
- package/dist/core/chart/types.d.ts +9 -0
- package/dist/core/format/axisFormat.d.ts +2 -1
- package/dist/core/indicator/addIndicator.d.ts +36 -0
- package/dist/core/indicator/index.d.ts +2 -0
- package/dist/core/indicator/indicatorPresets.d.ts +45 -0
- package/dist/core/series/Series.d.ts +3 -0
- package/dist/core/stacked/types.d.ts +8 -0
- package/dist/core/time/TimeScale.d.ts +31 -0
- package/dist/core/time/applyTimeScale.d.ts +10 -0
- package/dist/createStackedChart-DJSmqerD.js +706 -0
- package/dist/createStackedChart-DJSmqerD.js.map +1 -0
- package/dist/gpu/adapter/gpuRenderer.d.ts +21 -0
- package/dist/gpu/backends/webgpu/WebGPUBackend.d.ts +2 -1
- package/dist/gpuRenderer-BpaMYz-k.js +1848 -0
- package/dist/gpuRenderer-BpaMYz-k.js.map +1 -0
- package/dist/{index-DjeWClO9.js → index-CWipqOLP.js} +2 -2
- package/dist/{index-DjeWClO9.js.map → index-CWipqOLP.js.map} +1 -1
- package/dist/index-D7dTq6VB.js +503 -0
- package/dist/index-D7dTq6VB.js.map +1 -0
- package/dist/{index-Ce2JgkH_.js → index-DoYxf1cV.js} +86 -43
- package/dist/{index-Ce2JgkH_.js.map → index-DoYxf1cV.js.map} +1 -1
- package/dist/{index.core-C_-CFftD.js → index.core-fpZ1dYN0.js} +3 -3
- package/dist/{index.core-C_-CFftD.js.map → index.core-fpZ1dYN0.js.map} +1 -1
- package/dist/index.d.ts +17 -4
- package/dist/indicators--eJGmVox.js +302 -0
- package/dist/indicators--eJGmVox.js.map +1 -0
- package/dist/mockDatafeed-Cdg5hKEo.js +511 -0
- package/dist/mockDatafeed-Cdg5hKEo.js.map +1 -0
- package/dist/plugins/analysis.js +530 -807
- package/dist/plugins/analysis.js.map +1 -1
- package/dist/plugins/caching.js +26 -21
- package/dist/plugins/caching.js.map +1 -1
- package/dist/plugins/drawing-tools/index.d.ts +29 -0
- package/dist/plugins/drawing-tools/measure.d.ts +21 -0
- package/dist/plugins/drawing-tools/snapToCandle.d.ts +21 -0
- package/dist/plugins/gpu.js +202 -1895
- package/dist/plugins/gpu.js.map +1 -1
- package/dist/plugins/index.d.ts +2 -0
- package/dist/plugins/keyboard/index.d.ts +1 -7
- package/dist/plugins/keyboard.js +1 -1
- package/dist/plugins/lazy-load/types.d.ts +7 -0
- package/dist/plugins/lazy-load.js +131 -108
- package/dist/plugins/lazy-load.js.map +1 -1
- package/dist/plugins/replay/index.d.ts +19 -0
- package/dist/plugins/tools.js +1 -1
- package/dist/plugins/virtualization/types.d.ts +12 -0
- package/dist/plugins/virtualization.js +1 -1
- package/dist/pool-15HMCNv8.js +88 -0
- package/dist/pool-15HMCNv8.js.map +1 -0
- package/dist/react.js +5 -5
- package/dist/renderer/CandlestickRenderer.d.ts +1 -1
- package/dist/renderer/ChartSeriesRenderer.d.ts +6 -0
- package/dist/renderer/GpuChartRenderer.d.ts +23 -0
- package/dist/renderer/index.d.ts +3 -0
- package/dist/renderer/spike/WebGLGridSpike.d.ts +40 -0
- package/dist/testing/baselines/v1.15.0.json.d.ts +51 -0
- package/dist/testing/gridSpikeBenchmark.d.ts +49 -0
- package/dist/testing/index.d.ts +5 -0
- package/dist/testing/rendererBenchmark.d.ts +13 -0
- package/dist/testing/stage1BrowserBench.d.ts +42 -0
- package/dist/trading/datafeed.d.ts +48 -0
- package/dist/trading/index.d.ts +29 -0
- package/dist/trading/mockDatafeed.d.ts +9 -0
- package/dist/trading/ohlcvGenerator.d.ts +25 -0
- package/dist/trading.d.ts +1 -0
- package/dist/trading.js +95 -0
- package/dist/trading.js.map +1 -0
- package/dist/types.d.ts +22 -2
- package/dist/velo-plot.full.js +1088 -776
- package/dist/velo-plot.full.js.map +1 -1
- package/dist/velo-plot.js +15 -15
- package/dist/workers/downsample.d.ts +38 -0
- package/dist/workers/downsampleAsync.d.ts +6 -0
- package/dist/workers/indicator.worker.d.ts +32 -0
- package/dist/workers/indicatorsAsync.d.ts +26 -0
- package/dist/workers/pool.d.ts +36 -0
- package/package.json +23 -1
- package/dist/ChartCore-BimVvUEg.js.map +0 -1
- package/dist/axisFormat-B7o_uIEA.js +0 -127
- package/dist/axisFormat-B7o_uIEA.js.map +0 -1
- package/dist/createStackedChart-CjsKcOvX.js +0 -1088
- package/dist/createStackedChart-CjsKcOvX.js.map +0 -1
- package/dist/index-ChgIdk3N.js +0 -229
- package/dist/index-ChgIdk3N.js.map +0 -1
|
@@ -0,0 +1,463 @@
|
|
|
1
|
+
import ne, { useState as I, useRef as q, useEffect as N, useCallback as O, forwardRef as oe, useImperativeHandle as ae, useMemo as se } from "react";
|
|
2
|
+
import { c as le } from "./ChartCore-BhQ4j7f5.js";
|
|
3
|
+
var G = { exports: {} }, A = {};
|
|
4
|
+
/**
|
|
5
|
+
* @license React
|
|
6
|
+
* react-jsx-runtime.production.js
|
|
7
|
+
*
|
|
8
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
9
|
+
*
|
|
10
|
+
* This source code is licensed under the MIT license found in the
|
|
11
|
+
* LICENSE file in the root directory of this source tree.
|
|
12
|
+
*/
|
|
13
|
+
var K;
|
|
14
|
+
function ie() {
|
|
15
|
+
if (K) return A;
|
|
16
|
+
K = 1;
|
|
17
|
+
var E = Symbol.for("react.transitional.element"), b = Symbol.for("react.fragment");
|
|
18
|
+
function t(d, s, l) {
|
|
19
|
+
var m = null;
|
|
20
|
+
if (l !== void 0 && (m = "" + l), s.key !== void 0 && (m = "" + s.key), "key" in s) {
|
|
21
|
+
l = {};
|
|
22
|
+
for (var v in s)
|
|
23
|
+
v !== "key" && (l[v] = s[v]);
|
|
24
|
+
} else l = s;
|
|
25
|
+
return s = l.ref, {
|
|
26
|
+
$$typeof: E,
|
|
27
|
+
type: d,
|
|
28
|
+
key: m,
|
|
29
|
+
ref: s !== void 0 ? s : null,
|
|
30
|
+
props: l
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return A.Fragment = b, A.jsx = t, A.jsxs = t, A;
|
|
34
|
+
}
|
|
35
|
+
var P = {};
|
|
36
|
+
/**
|
|
37
|
+
* @license React
|
|
38
|
+
* react-jsx-runtime.development.js
|
|
39
|
+
*
|
|
40
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
41
|
+
*
|
|
42
|
+
* This source code is licensed under the MIT license found in the
|
|
43
|
+
* LICENSE file in the root directory of this source tree.
|
|
44
|
+
*/
|
|
45
|
+
var ee;
|
|
46
|
+
function ue() {
|
|
47
|
+
return ee || (ee = 1, process.env.NODE_ENV !== "production" && function() {
|
|
48
|
+
function E(e) {
|
|
49
|
+
if (e == null) return null;
|
|
50
|
+
if (typeof e == "function")
|
|
51
|
+
return e.$$typeof === V ? null : e.displayName || e.name || null;
|
|
52
|
+
if (typeof e == "string") return e;
|
|
53
|
+
switch (e) {
|
|
54
|
+
case n:
|
|
55
|
+
return "Fragment";
|
|
56
|
+
case C:
|
|
57
|
+
return "Profiler";
|
|
58
|
+
case c:
|
|
59
|
+
return "StrictMode";
|
|
60
|
+
case _:
|
|
61
|
+
return "Suspense";
|
|
62
|
+
case $:
|
|
63
|
+
return "SuspenseList";
|
|
64
|
+
case g:
|
|
65
|
+
return "Activity";
|
|
66
|
+
}
|
|
67
|
+
if (typeof e == "object")
|
|
68
|
+
switch (typeof e.tag == "number" && console.error(
|
|
69
|
+
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
|
|
70
|
+
), e.$$typeof) {
|
|
71
|
+
case p:
|
|
72
|
+
return "Portal";
|
|
73
|
+
case Y:
|
|
74
|
+
return e.displayName || "Context";
|
|
75
|
+
case M:
|
|
76
|
+
return (e._context.displayName || "Context") + ".Consumer";
|
|
77
|
+
case z:
|
|
78
|
+
var r = e.render;
|
|
79
|
+
return e = e.displayName, e || (e = r.displayName || r.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
|
|
80
|
+
case f:
|
|
81
|
+
return r = e.displayName || null, r !== null ? r : E(e.type) || "Memo";
|
|
82
|
+
case S:
|
|
83
|
+
r = e._payload, e = e._init;
|
|
84
|
+
try {
|
|
85
|
+
return E(e(r));
|
|
86
|
+
} catch {
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
function b(e) {
|
|
92
|
+
return "" + e;
|
|
93
|
+
}
|
|
94
|
+
function t(e) {
|
|
95
|
+
try {
|
|
96
|
+
b(e);
|
|
97
|
+
var r = !1;
|
|
98
|
+
} catch {
|
|
99
|
+
r = !0;
|
|
100
|
+
}
|
|
101
|
+
if (r) {
|
|
102
|
+
r = console;
|
|
103
|
+
var o = r.error, i = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
|
|
104
|
+
return o.call(
|
|
105
|
+
r,
|
|
106
|
+
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
|
|
107
|
+
i
|
|
108
|
+
), b(e);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
function d(e) {
|
|
112
|
+
if (e === n) return "<>";
|
|
113
|
+
if (typeof e == "object" && e !== null && e.$$typeof === S)
|
|
114
|
+
return "<...>";
|
|
115
|
+
try {
|
|
116
|
+
var r = E(e);
|
|
117
|
+
return r ? "<" + r + ">" : "<...>";
|
|
118
|
+
} catch {
|
|
119
|
+
return "<...>";
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function s() {
|
|
123
|
+
var e = L.A;
|
|
124
|
+
return e === null ? null : e.getOwner();
|
|
125
|
+
}
|
|
126
|
+
function l() {
|
|
127
|
+
return Error("react-stack-top-frame");
|
|
128
|
+
}
|
|
129
|
+
function m(e) {
|
|
130
|
+
if (J.call(e, "key")) {
|
|
131
|
+
var r = Object.getOwnPropertyDescriptor(e, "key").get;
|
|
132
|
+
if (r && r.isReactWarning) return !1;
|
|
133
|
+
}
|
|
134
|
+
return e.key !== void 0;
|
|
135
|
+
}
|
|
136
|
+
function v(e, r) {
|
|
137
|
+
function o() {
|
|
138
|
+
X || (X = !0, console.error(
|
|
139
|
+
"%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
|
|
140
|
+
r
|
|
141
|
+
));
|
|
142
|
+
}
|
|
143
|
+
o.isReactWarning = !0, Object.defineProperty(e, "key", {
|
|
144
|
+
get: o,
|
|
145
|
+
configurable: !0
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
function k() {
|
|
149
|
+
var e = E(this.type);
|
|
150
|
+
return D[e] || (D[e] = !0, console.error(
|
|
151
|
+
"Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
|
|
152
|
+
)), e = this.props.ref, e !== void 0 ? e : null;
|
|
153
|
+
}
|
|
154
|
+
function x(e, r, o, i, F, U) {
|
|
155
|
+
var u = o.ref;
|
|
156
|
+
return e = {
|
|
157
|
+
$$typeof: a,
|
|
158
|
+
type: e,
|
|
159
|
+
key: r,
|
|
160
|
+
props: o,
|
|
161
|
+
_owner: i
|
|
162
|
+
}, (u !== void 0 ? u : null) !== null ? Object.defineProperty(e, "ref", {
|
|
163
|
+
enumerable: !1,
|
|
164
|
+
get: k
|
|
165
|
+
}) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
|
|
166
|
+
configurable: !1,
|
|
167
|
+
enumerable: !1,
|
|
168
|
+
writable: !0,
|
|
169
|
+
value: 0
|
|
170
|
+
}), Object.defineProperty(e, "_debugInfo", {
|
|
171
|
+
configurable: !1,
|
|
172
|
+
enumerable: !1,
|
|
173
|
+
writable: !0,
|
|
174
|
+
value: null
|
|
175
|
+
}), Object.defineProperty(e, "_debugStack", {
|
|
176
|
+
configurable: !1,
|
|
177
|
+
enumerable: !1,
|
|
178
|
+
writable: !0,
|
|
179
|
+
value: F
|
|
180
|
+
}), Object.defineProperty(e, "_debugTask", {
|
|
181
|
+
configurable: !1,
|
|
182
|
+
enumerable: !1,
|
|
183
|
+
writable: !0,
|
|
184
|
+
value: U
|
|
185
|
+
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
|
|
186
|
+
}
|
|
187
|
+
function y(e, r, o, i, F, U) {
|
|
188
|
+
var u = r.children;
|
|
189
|
+
if (u !== void 0)
|
|
190
|
+
if (i)
|
|
191
|
+
if (re(u)) {
|
|
192
|
+
for (i = 0; i < u.length; i++)
|
|
193
|
+
w(u[i]);
|
|
194
|
+
Object.freeze && Object.freeze(u);
|
|
195
|
+
} else
|
|
196
|
+
console.error(
|
|
197
|
+
"React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
|
|
198
|
+
);
|
|
199
|
+
else w(u);
|
|
200
|
+
if (J.call(r, "key")) {
|
|
201
|
+
u = E(e);
|
|
202
|
+
var h = Object.keys(r).filter(function(te) {
|
|
203
|
+
return te !== "key";
|
|
204
|
+
});
|
|
205
|
+
i = 0 < h.length ? "{key: someKey, " + h.join(": ..., ") + ": ...}" : "{key: someKey}", Q[u + i] || (h = 0 < h.length ? "{" + h.join(": ..., ") + ": ...}" : "{}", console.error(
|
|
206
|
+
`A props object containing a "key" prop is being spread into JSX:
|
|
207
|
+
let props = %s;
|
|
208
|
+
<%s {...props} />
|
|
209
|
+
React keys must be passed directly to JSX without using spread:
|
|
210
|
+
let props = %s;
|
|
211
|
+
<%s key={someKey} {...props} />`,
|
|
212
|
+
i,
|
|
213
|
+
u,
|
|
214
|
+
h,
|
|
215
|
+
u
|
|
216
|
+
), Q[u + i] = !0);
|
|
217
|
+
}
|
|
218
|
+
if (u = null, o !== void 0 && (t(o), u = "" + o), m(r) && (t(r.key), u = "" + r.key), "key" in r) {
|
|
219
|
+
o = {};
|
|
220
|
+
for (var B in r)
|
|
221
|
+
B !== "key" && (o[B] = r[B]);
|
|
222
|
+
} else o = r;
|
|
223
|
+
return u && v(
|
|
224
|
+
o,
|
|
225
|
+
typeof e == "function" ? e.displayName || e.name || "Unknown" : e
|
|
226
|
+
), x(
|
|
227
|
+
e,
|
|
228
|
+
u,
|
|
229
|
+
o,
|
|
230
|
+
s(),
|
|
231
|
+
F,
|
|
232
|
+
U
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
function w(e) {
|
|
236
|
+
T(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === S && (e._payload.status === "fulfilled" ? T(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
|
|
237
|
+
}
|
|
238
|
+
function T(e) {
|
|
239
|
+
return typeof e == "object" && e !== null && e.$$typeof === a;
|
|
240
|
+
}
|
|
241
|
+
var R = ne, a = Symbol.for("react.transitional.element"), p = Symbol.for("react.portal"), n = Symbol.for("react.fragment"), c = Symbol.for("react.strict_mode"), C = Symbol.for("react.profiler"), M = Symbol.for("react.consumer"), Y = Symbol.for("react.context"), z = Symbol.for("react.forward_ref"), _ = Symbol.for("react.suspense"), $ = Symbol.for("react.suspense_list"), f = Symbol.for("react.memo"), S = Symbol.for("react.lazy"), g = Symbol.for("react.activity"), V = Symbol.for("react.client.reference"), L = R.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, J = Object.prototype.hasOwnProperty, re = Array.isArray, W = console.createTask ? console.createTask : function() {
|
|
242
|
+
return null;
|
|
243
|
+
};
|
|
244
|
+
R = {
|
|
245
|
+
react_stack_bottom_frame: function(e) {
|
|
246
|
+
return e();
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
var X, D = {}, H = R.react_stack_bottom_frame.bind(
|
|
250
|
+
R,
|
|
251
|
+
l
|
|
252
|
+
)(), Z = W(d(l)), Q = {};
|
|
253
|
+
P.Fragment = n, P.jsx = function(e, r, o) {
|
|
254
|
+
var i = 1e4 > L.recentlyCreatedOwnerStacks++;
|
|
255
|
+
return y(
|
|
256
|
+
e,
|
|
257
|
+
r,
|
|
258
|
+
o,
|
|
259
|
+
!1,
|
|
260
|
+
i ? Error("react-stack-top-frame") : H,
|
|
261
|
+
i ? W(d(e)) : Z
|
|
262
|
+
);
|
|
263
|
+
}, P.jsxs = function(e, r, o) {
|
|
264
|
+
var i = 1e4 > L.recentlyCreatedOwnerStacks++;
|
|
265
|
+
return y(
|
|
266
|
+
e,
|
|
267
|
+
r,
|
|
268
|
+
o,
|
|
269
|
+
!0,
|
|
270
|
+
i ? Error("react-stack-top-frame") : H,
|
|
271
|
+
i ? W(d(e)) : Z
|
|
272
|
+
);
|
|
273
|
+
};
|
|
274
|
+
}()), P;
|
|
275
|
+
}
|
|
276
|
+
process.env.NODE_ENV === "production" ? G.exports = ie() : G.exports = ue();
|
|
277
|
+
var j = G.exports;
|
|
278
|
+
function ce(E, b = {}) {
|
|
279
|
+
const [t, d] = I(null), [s, l] = I(!1), [m, v] = I(null), [k, x] = I(null), y = q(b);
|
|
280
|
+
y.current = b, N(() => {
|
|
281
|
+
const n = E.current;
|
|
282
|
+
if (n) {
|
|
283
|
+
try {
|
|
284
|
+
const c = le({
|
|
285
|
+
...y.current,
|
|
286
|
+
container: n
|
|
287
|
+
});
|
|
288
|
+
c.on("zoom", () => {
|
|
289
|
+
x(c.getViewBounds());
|
|
290
|
+
}), d(c), l(!0), x(c.getViewBounds()), v(null);
|
|
291
|
+
} catch (c) {
|
|
292
|
+
console.error("[useSciPlot] Failed to initialize chart:", c), v(c instanceof Error ? c : new Error(String(c))), l(!1);
|
|
293
|
+
}
|
|
294
|
+
return () => {
|
|
295
|
+
t && (t.destroy(), d(null), l(!1));
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
}, [E]);
|
|
299
|
+
const w = O(
|
|
300
|
+
(n) => {
|
|
301
|
+
t && (t.addSeries(n), x(t.getViewBounds()));
|
|
302
|
+
},
|
|
303
|
+
[t]
|
|
304
|
+
), T = O(
|
|
305
|
+
(n, c) => {
|
|
306
|
+
t && t.updateSeries(n, c);
|
|
307
|
+
},
|
|
308
|
+
[t]
|
|
309
|
+
), R = O(
|
|
310
|
+
(n) => {
|
|
311
|
+
t && t.removeSeries(n);
|
|
312
|
+
},
|
|
313
|
+
[t]
|
|
314
|
+
), a = O(
|
|
315
|
+
(n) => {
|
|
316
|
+
t && t.zoom(n);
|
|
317
|
+
},
|
|
318
|
+
[t]
|
|
319
|
+
), p = O(() => {
|
|
320
|
+
t && (t.resetZoom(), x(t.getViewBounds()));
|
|
321
|
+
}, [t]);
|
|
322
|
+
return {
|
|
323
|
+
chart: t,
|
|
324
|
+
isReady: s,
|
|
325
|
+
error: m,
|
|
326
|
+
bounds: k,
|
|
327
|
+
addSeries: w,
|
|
328
|
+
updateSeries: T,
|
|
329
|
+
removeSeries: R,
|
|
330
|
+
zoom: a,
|
|
331
|
+
resetZoom: p
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
const me = oe(
|
|
335
|
+
function({
|
|
336
|
+
series: b = [],
|
|
337
|
+
zoom: t,
|
|
338
|
+
onZoomChange: d,
|
|
339
|
+
cursor: s,
|
|
340
|
+
width: l = "100%",
|
|
341
|
+
height: m = 400,
|
|
342
|
+
className: v = "",
|
|
343
|
+
style: k = {},
|
|
344
|
+
debug: x = !1,
|
|
345
|
+
...y
|
|
346
|
+
}, w) {
|
|
347
|
+
const T = q(null), R = q(/* @__PURE__ */ new Map()), {
|
|
348
|
+
chart: a,
|
|
349
|
+
isReady: p,
|
|
350
|
+
bounds: n,
|
|
351
|
+
addSeries: c,
|
|
352
|
+
updateSeries: C,
|
|
353
|
+
removeSeries: M,
|
|
354
|
+
resetZoom: Y
|
|
355
|
+
} = ce(T, y);
|
|
356
|
+
ae(
|
|
357
|
+
w,
|
|
358
|
+
() => ({
|
|
359
|
+
getChart: () => a,
|
|
360
|
+
resetZoom: Y,
|
|
361
|
+
getBounds: () => n
|
|
362
|
+
}),
|
|
363
|
+
[a, Y, n]
|
|
364
|
+
), N(() => {
|
|
365
|
+
if (!p || !a) return;
|
|
366
|
+
const _ = new Map(b.map((f) => [f.id, f])), $ = R.current;
|
|
367
|
+
$.forEach((f, S) => {
|
|
368
|
+
_.has(S) || M(S);
|
|
369
|
+
}), _.forEach((f, S) => {
|
|
370
|
+
const g = $.get(S);
|
|
371
|
+
if (g)
|
|
372
|
+
(g.x !== f.x || g.y !== f.y) && C(S, {
|
|
373
|
+
x: f.x,
|
|
374
|
+
y: f.y
|
|
375
|
+
});
|
|
376
|
+
else {
|
|
377
|
+
const V = {
|
|
378
|
+
id: f.id,
|
|
379
|
+
type: "line",
|
|
380
|
+
data: { x: f.x, y: f.y },
|
|
381
|
+
style: {
|
|
382
|
+
color: f.color ?? "#ff0055",
|
|
383
|
+
width: f.width ?? 1.5
|
|
384
|
+
},
|
|
385
|
+
visible: f.visible ?? !0
|
|
386
|
+
};
|
|
387
|
+
c(V), _.size === 1 && a.autoScale();
|
|
388
|
+
}
|
|
389
|
+
}), R.current = _;
|
|
390
|
+
}, [b, p, a, c, C, M]), N(() => {
|
|
391
|
+
!p || !a || !t || a.zoom(t);
|
|
392
|
+
}, [p, a, t]), N(() => {
|
|
393
|
+
!p || !a || !d || a.on("zoom", (_) => {
|
|
394
|
+
d({
|
|
395
|
+
xMin: _.x[0],
|
|
396
|
+
xMax: _.x[1],
|
|
397
|
+
yMin: _.y[0],
|
|
398
|
+
yMax: _.y[1]
|
|
399
|
+
});
|
|
400
|
+
});
|
|
401
|
+
}, [p, a, d]), N(() => {
|
|
402
|
+
!p || !a || (s != null && s.enabled ? a.enableCursor(s) : a.disableCursor());
|
|
403
|
+
}, [p, a, s]);
|
|
404
|
+
const z = se(
|
|
405
|
+
() => ({
|
|
406
|
+
position: "relative",
|
|
407
|
+
width: typeof l == "number" ? `${l}px` : l,
|
|
408
|
+
height: typeof m == "number" ? `${m}px` : m,
|
|
409
|
+
...k
|
|
410
|
+
}),
|
|
411
|
+
[l, m, k]
|
|
412
|
+
);
|
|
413
|
+
return /* @__PURE__ */ j.jsx(
|
|
414
|
+
"div",
|
|
415
|
+
{
|
|
416
|
+
ref: T,
|
|
417
|
+
className: `velo-plot-container ${v}`,
|
|
418
|
+
style: z,
|
|
419
|
+
children: x && n && /* @__PURE__ */ j.jsxs(
|
|
420
|
+
"div",
|
|
421
|
+
{
|
|
422
|
+
style: {
|
|
423
|
+
position: "absolute",
|
|
424
|
+
top: 8,
|
|
425
|
+
right: 8,
|
|
426
|
+
background: "rgba(0,0,0,0.7)",
|
|
427
|
+
color: "#0f0",
|
|
428
|
+
padding: "4px 8px",
|
|
429
|
+
borderRadius: 4,
|
|
430
|
+
fontSize: 11,
|
|
431
|
+
fontFamily: "monospace"
|
|
432
|
+
},
|
|
433
|
+
children: [
|
|
434
|
+
/* @__PURE__ */ j.jsxs("div", { children: [
|
|
435
|
+
"X: [",
|
|
436
|
+
n.xMin.toFixed(3),
|
|
437
|
+
", ",
|
|
438
|
+
n.xMax.toFixed(3),
|
|
439
|
+
"]"
|
|
440
|
+
] }),
|
|
441
|
+
/* @__PURE__ */ j.jsxs("div", { children: [
|
|
442
|
+
"Y: [",
|
|
443
|
+
n.yMin.toExponential(2),
|
|
444
|
+
", ",
|
|
445
|
+
n.yMax.toExponential(2),
|
|
446
|
+
"]"
|
|
447
|
+
] }),
|
|
448
|
+
/* @__PURE__ */ j.jsxs("div", { children: [
|
|
449
|
+
"Series: ",
|
|
450
|
+
b.length
|
|
451
|
+
] })
|
|
452
|
+
]
|
|
453
|
+
}
|
|
454
|
+
)
|
|
455
|
+
}
|
|
456
|
+
);
|
|
457
|
+
}
|
|
458
|
+
);
|
|
459
|
+
export {
|
|
460
|
+
me as S,
|
|
461
|
+
ce as u
|
|
462
|
+
};
|
|
463
|
+
//# sourceMappingURL=SciPlot-GJvw7GJo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SciPlot-GJvw7GJo.js","sources":["../node_modules/.pnpm/react@19.2.3/node_modules/react/cjs/react-jsx-runtime.production.js","../node_modules/.pnpm/react@19.2.3/node_modules/react/cjs/react-jsx-runtime.development.js","../node_modules/.pnpm/react@19.2.3/node_modules/react/jsx-runtime.js","../src/react/useSciPlot.ts","../src/react/SciPlot.tsx"],"sourcesContent":["/**\n * @license React\n * react-jsx-runtime.production.js\n *\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n\"use strict\";\nvar REACT_ELEMENT_TYPE = Symbol.for(\"react.transitional.element\"),\n REACT_FRAGMENT_TYPE = Symbol.for(\"react.fragment\");\nfunction jsxProd(type, config, maybeKey) {\n var key = null;\n void 0 !== maybeKey && (key = \"\" + maybeKey);\n void 0 !== config.key && (key = \"\" + config.key);\n if (\"key\" in config) {\n maybeKey = {};\n for (var propName in config)\n \"key\" !== propName && (maybeKey[propName] = config[propName]);\n } else maybeKey = config;\n config = maybeKey.ref;\n return {\n $$typeof: REACT_ELEMENT_TYPE,\n type: type,\n key: key,\n ref: void 0 !== config ? config : null,\n props: maybeKey\n };\n}\nexports.Fragment = REACT_FRAGMENT_TYPE;\nexports.jsx = jsxProd;\nexports.jsxs = jsxProd;\n","/**\n * @license React\n * react-jsx-runtime.development.js\n *\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n\"use strict\";\n\"production\" !== process.env.NODE_ENV &&\n (function () {\n function getComponentNameFromType(type) {\n if (null == type) return null;\n if (\"function\" === typeof type)\n return type.$$typeof === REACT_CLIENT_REFERENCE\n ? null\n : type.displayName || type.name || null;\n if (\"string\" === typeof type) return type;\n switch (type) {\n case REACT_FRAGMENT_TYPE:\n return \"Fragment\";\n case REACT_PROFILER_TYPE:\n return \"Profiler\";\n case REACT_STRICT_MODE_TYPE:\n return \"StrictMode\";\n case REACT_SUSPENSE_TYPE:\n return \"Suspense\";\n case REACT_SUSPENSE_LIST_TYPE:\n return \"SuspenseList\";\n case REACT_ACTIVITY_TYPE:\n return \"Activity\";\n }\n if (\"object\" === typeof type)\n switch (\n (\"number\" === typeof type.tag &&\n console.error(\n \"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue.\"\n ),\n type.$$typeof)\n ) {\n case REACT_PORTAL_TYPE:\n return \"Portal\";\n case REACT_CONTEXT_TYPE:\n return type.displayName || \"Context\";\n case REACT_CONSUMER_TYPE:\n return (type._context.displayName || \"Context\") + \".Consumer\";\n case REACT_FORWARD_REF_TYPE:\n var innerType = type.render;\n type = type.displayName;\n type ||\n ((type = innerType.displayName || innerType.name || \"\"),\n (type = \"\" !== type ? \"ForwardRef(\" + type + \")\" : \"ForwardRef\"));\n return type;\n case REACT_MEMO_TYPE:\n return (\n (innerType = type.displayName || null),\n null !== innerType\n ? innerType\n : getComponentNameFromType(type.type) || \"Memo\"\n );\n case REACT_LAZY_TYPE:\n innerType = type._payload;\n type = type._init;\n try {\n return getComponentNameFromType(type(innerType));\n } catch (x) {}\n }\n return null;\n }\n function testStringCoercion(value) {\n return \"\" + value;\n }\n function checkKeyStringCoercion(value) {\n try {\n testStringCoercion(value);\n var JSCompiler_inline_result = !1;\n } catch (e) {\n JSCompiler_inline_result = !0;\n }\n if (JSCompiler_inline_result) {\n JSCompiler_inline_result = console;\n var JSCompiler_temp_const = JSCompiler_inline_result.error;\n var JSCompiler_inline_result$jscomp$0 =\n (\"function\" === typeof Symbol &&\n Symbol.toStringTag &&\n value[Symbol.toStringTag]) ||\n value.constructor.name ||\n \"Object\";\n JSCompiler_temp_const.call(\n JSCompiler_inline_result,\n \"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.\",\n JSCompiler_inline_result$jscomp$0\n );\n return testStringCoercion(value);\n }\n }\n function getTaskName(type) {\n if (type === REACT_FRAGMENT_TYPE) return \"<>\";\n if (\n \"object\" === typeof type &&\n null !== type &&\n type.$$typeof === REACT_LAZY_TYPE\n )\n return \"<...>\";\n try {\n var name = getComponentNameFromType(type);\n return name ? \"<\" + name + \">\" : \"<...>\";\n } catch (x) {\n return \"<...>\";\n }\n }\n function getOwner() {\n var dispatcher = ReactSharedInternals.A;\n return null === dispatcher ? null : dispatcher.getOwner();\n }\n function UnknownOwner() {\n return Error(\"react-stack-top-frame\");\n }\n function hasValidKey(config) {\n if (hasOwnProperty.call(config, \"key\")) {\n var getter = Object.getOwnPropertyDescriptor(config, \"key\").get;\n if (getter && getter.isReactWarning) return !1;\n }\n return void 0 !== config.key;\n }\n function defineKeyPropWarningGetter(props, displayName) {\n function warnAboutAccessingKey() {\n specialPropKeyWarningShown ||\n ((specialPropKeyWarningShown = !0),\n console.error(\n \"%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)\",\n displayName\n ));\n }\n warnAboutAccessingKey.isReactWarning = !0;\n Object.defineProperty(props, \"key\", {\n get: warnAboutAccessingKey,\n configurable: !0\n });\n }\n function elementRefGetterWithDeprecationWarning() {\n var componentName = getComponentNameFromType(this.type);\n didWarnAboutElementRef[componentName] ||\n ((didWarnAboutElementRef[componentName] = !0),\n console.error(\n \"Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.\"\n ));\n componentName = this.props.ref;\n return void 0 !== componentName ? componentName : null;\n }\n function ReactElement(type, key, props, owner, debugStack, debugTask) {\n var refProp = props.ref;\n type = {\n $$typeof: REACT_ELEMENT_TYPE,\n type: type,\n key: key,\n props: props,\n _owner: owner\n };\n null !== (void 0 !== refProp ? refProp : null)\n ? Object.defineProperty(type, \"ref\", {\n enumerable: !1,\n get: elementRefGetterWithDeprecationWarning\n })\n : Object.defineProperty(type, \"ref\", { enumerable: !1, value: null });\n type._store = {};\n Object.defineProperty(type._store, \"validated\", {\n configurable: !1,\n enumerable: !1,\n writable: !0,\n value: 0\n });\n Object.defineProperty(type, \"_debugInfo\", {\n configurable: !1,\n enumerable: !1,\n writable: !0,\n value: null\n });\n Object.defineProperty(type, \"_debugStack\", {\n configurable: !1,\n enumerable: !1,\n writable: !0,\n value: debugStack\n });\n Object.defineProperty(type, \"_debugTask\", {\n configurable: !1,\n enumerable: !1,\n writable: !0,\n value: debugTask\n });\n Object.freeze && (Object.freeze(type.props), Object.freeze(type));\n return type;\n }\n function jsxDEVImpl(\n type,\n config,\n maybeKey,\n isStaticChildren,\n debugStack,\n debugTask\n ) {\n var children = config.children;\n if (void 0 !== children)\n if (isStaticChildren)\n if (isArrayImpl(children)) {\n for (\n isStaticChildren = 0;\n isStaticChildren < children.length;\n isStaticChildren++\n )\n validateChildKeys(children[isStaticChildren]);\n Object.freeze && Object.freeze(children);\n } else\n console.error(\n \"React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.\"\n );\n else validateChildKeys(children);\n if (hasOwnProperty.call(config, \"key\")) {\n children = getComponentNameFromType(type);\n var keys = Object.keys(config).filter(function (k) {\n return \"key\" !== k;\n });\n isStaticChildren =\n 0 < keys.length\n ? \"{key: someKey, \" + keys.join(\": ..., \") + \": ...}\"\n : \"{key: someKey}\";\n didWarnAboutKeySpread[children + isStaticChildren] ||\n ((keys =\n 0 < keys.length ? \"{\" + keys.join(\": ..., \") + \": ...}\" : \"{}\"),\n console.error(\n 'A props object containing a \"key\" prop is being spread into JSX:\\n let props = %s;\\n <%s {...props} />\\nReact keys must be passed directly to JSX without using spread:\\n let props = %s;\\n <%s key={someKey} {...props} />',\n isStaticChildren,\n children,\n keys,\n children\n ),\n (didWarnAboutKeySpread[children + isStaticChildren] = !0));\n }\n children = null;\n void 0 !== maybeKey &&\n (checkKeyStringCoercion(maybeKey), (children = \"\" + maybeKey));\n hasValidKey(config) &&\n (checkKeyStringCoercion(config.key), (children = \"\" + config.key));\n if (\"key\" in config) {\n maybeKey = {};\n for (var propName in config)\n \"key\" !== propName && (maybeKey[propName] = config[propName]);\n } else maybeKey = config;\n children &&\n defineKeyPropWarningGetter(\n maybeKey,\n \"function\" === typeof type\n ? type.displayName || type.name || \"Unknown\"\n : type\n );\n return ReactElement(\n type,\n children,\n maybeKey,\n getOwner(),\n debugStack,\n debugTask\n );\n }\n function validateChildKeys(node) {\n isValidElement(node)\n ? node._store && (node._store.validated = 1)\n : \"object\" === typeof node &&\n null !== node &&\n node.$$typeof === REACT_LAZY_TYPE &&\n (\"fulfilled\" === node._payload.status\n ? isValidElement(node._payload.value) &&\n node._payload.value._store &&\n (node._payload.value._store.validated = 1)\n : node._store && (node._store.validated = 1));\n }\n function isValidElement(object) {\n return (\n \"object\" === typeof object &&\n null !== object &&\n object.$$typeof === REACT_ELEMENT_TYPE\n );\n }\n var React = require(\"react\"),\n REACT_ELEMENT_TYPE = Symbol.for(\"react.transitional.element\"),\n REACT_PORTAL_TYPE = Symbol.for(\"react.portal\"),\n REACT_FRAGMENT_TYPE = Symbol.for(\"react.fragment\"),\n REACT_STRICT_MODE_TYPE = Symbol.for(\"react.strict_mode\"),\n REACT_PROFILER_TYPE = Symbol.for(\"react.profiler\"),\n REACT_CONSUMER_TYPE = Symbol.for(\"react.consumer\"),\n REACT_CONTEXT_TYPE = Symbol.for(\"react.context\"),\n REACT_FORWARD_REF_TYPE = Symbol.for(\"react.forward_ref\"),\n REACT_SUSPENSE_TYPE = Symbol.for(\"react.suspense\"),\n REACT_SUSPENSE_LIST_TYPE = Symbol.for(\"react.suspense_list\"),\n REACT_MEMO_TYPE = Symbol.for(\"react.memo\"),\n REACT_LAZY_TYPE = Symbol.for(\"react.lazy\"),\n REACT_ACTIVITY_TYPE = Symbol.for(\"react.activity\"),\n REACT_CLIENT_REFERENCE = Symbol.for(\"react.client.reference\"),\n ReactSharedInternals =\n React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,\n hasOwnProperty = Object.prototype.hasOwnProperty,\n isArrayImpl = Array.isArray,\n createTask = console.createTask\n ? console.createTask\n : function () {\n return null;\n };\n React = {\n react_stack_bottom_frame: function (callStackForError) {\n return callStackForError();\n }\n };\n var specialPropKeyWarningShown;\n var didWarnAboutElementRef = {};\n var unknownOwnerDebugStack = React.react_stack_bottom_frame.bind(\n React,\n UnknownOwner\n )();\n var unknownOwnerDebugTask = createTask(getTaskName(UnknownOwner));\n var didWarnAboutKeySpread = {};\n exports.Fragment = REACT_FRAGMENT_TYPE;\n exports.jsx = function (type, config, maybeKey) {\n var trackActualOwner =\n 1e4 > ReactSharedInternals.recentlyCreatedOwnerStacks++;\n return jsxDEVImpl(\n type,\n config,\n maybeKey,\n !1,\n trackActualOwner\n ? Error(\"react-stack-top-frame\")\n : unknownOwnerDebugStack,\n trackActualOwner ? createTask(getTaskName(type)) : unknownOwnerDebugTask\n );\n };\n exports.jsxs = function (type, config, maybeKey) {\n var trackActualOwner =\n 1e4 > ReactSharedInternals.recentlyCreatedOwnerStacks++;\n return jsxDEVImpl(\n type,\n config,\n maybeKey,\n !0,\n trackActualOwner\n ? Error(\"react-stack-top-frame\")\n : unknownOwnerDebugStack,\n trackActualOwner ? createTask(getTaskName(type)) : unknownOwnerDebugTask\n );\n };\n })();\n","'use strict';\n\nif (process.env.NODE_ENV === 'production') {\n module.exports = require('./cjs/react-jsx-runtime.production.js');\n} else {\n module.exports = require('./cjs/react-jsx-runtime.development.js');\n}\n","/**\n * useSciPlot - React hook for Sci Plot\n *\n * Manages chart lifecycle and provides a clean React API.\n */\n\nimport {\n useEffect,\n useRef,\n useState,\n useCallback,\n type RefObject,\n} from \"react\";\nimport { createChart, type Chart, type ChartOptions } from \"../core/Chart\";\nimport type {\n SeriesOptions,\n SeriesUpdateData,\n ZoomOptions,\n Bounds,\n} from \"../types\";\n\nexport interface UseSciPlotOptions extends Omit<ChartOptions, \"container\"> {\n /** Auto-resize on container changes */\n autoResize?: boolean;\n}\n\nexport interface UseSciPlotReturn {\n /** Chart instance (null until initialized) */\n chart: Chart | null;\n /** Whether the chart is ready */\n isReady: boolean;\n /** Error during initialization */\n error: Error | null;\n /** Current view bounds */\n bounds: Bounds | null;\n /** Add a series */\n addSeries: (options: SeriesOptions) => void;\n /** Update series data */\n updateSeries: (id: string, data: SeriesUpdateData) => void;\n /** Remove a series */\n removeSeries: (id: string) => void;\n /** Set zoom range */\n zoom: (options: ZoomOptions) => void;\n /** Reset zoom to show all data */\n resetZoom: () => void;\n}\n\n/**\n * React hook for using Sci Plot\n *\n * @example\n * ```tsx\n * function MyChart() {\n * const canvasRef = useRef<HTMLCanvasElement>(null);\n * const { chart, isReady, addSeries, zoom } = useSciPlot(canvasRef, {\n * xAxis: { label: 'E / V' },\n * yAxis: { label: 'I / A' }\n * });\n *\n * useEffect(() => {\n * if (isReady) {\n * addSeries({\n * id: 'cv-1',\n * type: 'line',\n * data: { x: xData, y: yData },\n * style: { color: '#ff0055' }\n * });\n * }\n * }, [isReady]);\n *\n * return <canvas ref={canvasRef} />;\n * }\n * ```\n */\nexport function useSciPlot(\n containerRef: RefObject<HTMLDivElement>,\n options: UseSciPlotOptions = {}\n): UseSciPlotReturn {\n const [chart, setChart] = useState<Chart | null>(null);\n const [isReady, setIsReady] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n const [bounds, setBounds] = useState<Bounds | null>(null);\n\n // Store options in ref to avoid re-creating chart on every render\n const optionsRef = useRef(options);\n optionsRef.current = options;\n\n // Initialize chart\n useEffect(() => {\n const container = containerRef.current;\n if (!container) return;\n\n try {\n const chartInstance = createChart({\n ...optionsRef.current,\n container,\n });\n\n // Listen to zoom events to update bounds\n chartInstance.on(\"zoom\", () => {\n setBounds(chartInstance.getViewBounds());\n });\n\n setChart(chartInstance);\n setIsReady(true);\n setBounds(chartInstance.getViewBounds());\n setError(null);\n\n } catch (err) {\n console.error(\"[useSciPlot] Failed to initialize chart:\", err);\n setError(err instanceof Error ? err : new Error(String(err)));\n setIsReady(false);\n }\n\n return () => {\n if (chart) {\n chart.destroy();\n setChart(null);\n setIsReady(false);\n }\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [containerRef]);\n\n // Memoized methods\n const addSeries = useCallback(\n (seriesOptions: SeriesOptions) => {\n if (chart) {\n chart.addSeries(seriesOptions);\n setBounds(chart.getViewBounds());\n }\n },\n [chart]\n );\n\n const updateSeries = useCallback(\n (id: string, data: SeriesUpdateData) => {\n if (chart) {\n chart.updateSeries(id, data);\n }\n },\n [chart]\n );\n\n const removeSeries = useCallback(\n (id: string) => {\n if (chart) {\n chart.removeSeries(id);\n }\n },\n [chart]\n );\n\n const zoom = useCallback(\n (zoomOptions: ZoomOptions) => {\n if (chart) {\n chart.zoom(zoomOptions);\n }\n },\n [chart]\n );\n\n const resetZoom = useCallback(() => {\n if (chart) {\n chart.resetZoom();\n setBounds(chart.getViewBounds());\n }\n }, [chart]);\n\n return {\n chart,\n isReady,\n error,\n bounds,\n addSeries,\n updateSeries,\n removeSeries,\n zoom,\n resetZoom,\n };\n}\n","/**\n * SciPlot - React Component for Scientific Charts\n *\n * A declarative React component that wraps the Sci Plot.\n */\n\nimport {\n useRef,\n useEffect,\n useImperativeHandle,\n forwardRef,\n useMemo,\n type CSSProperties,\n} from \"react\";\nimport { useSciPlot, type UseSciPlotOptions } from \"./useSciPlot\";\nimport type {\n SeriesOptions,\n ZoomOptions,\n CursorOptions,\n Bounds,\n} from \"../types\";\nimport type { Chart } from \"../core/Chart\";\n\n// ============================================\n// Types\n// ============================================\n\nexport interface SciPlotSeries {\n id: string;\n x: Float32Array | Float64Array;\n y: Float32Array | Float64Array;\n color?: string;\n width?: number;\n visible?: boolean;\n}\n\nexport interface SciPlotProps extends UseSciPlotOptions {\n /** Series data to display */\n series?: SciPlotSeries[];\n /** Zoom state (controlled) */\n zoom?: ZoomOptions;\n /** Callback when zoom changes */\n onZoomChange?: (bounds: Bounds) => void;\n /** Cursor configuration */\n cursor?: CursorOptions;\n /** Container width */\n width?: number | string;\n /** Container height */\n height?: number | string;\n /** Additional class name */\n className?: string;\n /** Additional styles */\n style?: CSSProperties;\n /** Debug mode - shows FPS counter */\n debug?: boolean;\n}\n\nexport interface SciPlotRef {\n /** Get the chart instance */\n getChart: () => Chart | null;\n /** Reset zoom to show all data */\n resetZoom: () => void;\n /** Get current bounds */\n getBounds: () => Bounds | null;\n}\n\n// ============================================\n// Component\n// ============================================\n\n/**\n * SciPlot React Component\n *\n * @example\n * ```tsx\n * <SciPlot\n * series={[\n * { id: 'cv-1', x: potentialData, y: currentData, color: '#ff0055' }\n * ]}\n * xAxis={{ label: 'E / V' }}\n * yAxis={{ label: 'I / A' }}\n * height={400}\n * cursor={{ enabled: true, snap: true }}\n * onZoomChange={(bounds) => console.log('Zoom:', bounds)}\n * />\n * ```\n */\nexport const SciPlot = forwardRef<SciPlotRef, SciPlotProps>(\n function SciPlot(\n {\n series = [],\n zoom: zoomProp,\n onZoomChange,\n cursor,\n width = \"100%\",\n height = 400,\n className = \"\",\n style = {},\n debug = false,\n ...chartOptions\n },\n ref\n ) {\n const containerRef = useRef<HTMLDivElement>(null);\n const previousSeriesRef = useRef<Map<string, SciPlotSeries>>(new Map());\n\n const {\n chart,\n isReady,\n bounds,\n addSeries,\n updateSeries,\n removeSeries,\n resetZoom,\n } = useSciPlot(containerRef, chartOptions);\n\n // Expose methods via ref\n useImperativeHandle(\n ref,\n () => ({\n getChart: () => chart,\n resetZoom,\n getBounds: () => bounds,\n }),\n [chart, resetZoom, bounds]\n );\n\n // Handle series changes\n useEffect(() => {\n if (!isReady || !chart) return;\n\n const currentSeriesMap = new Map(series.map((s) => [s.id, s]));\n const previousSeriesMap = previousSeriesRef.current;\n\n // Remove series that no longer exist\n previousSeriesMap.forEach((_, id) => {\n if (!currentSeriesMap.has(id)) {\n removeSeries(id);\n }\n });\n\n // Add or update series\n currentSeriesMap.forEach((seriesData, id) => {\n const prevSeries = previousSeriesMap.get(id);\n\n if (!prevSeries) {\n // New series - add it\n const options: SeriesOptions = {\n id: seriesData.id,\n type: \"line\",\n data: { x: seriesData.x, y: seriesData.y },\n style: {\n color: seriesData.color ?? \"#ff0055\",\n width: seriesData.width ?? 1.5,\n },\n visible: seriesData.visible ?? true,\n };\n addSeries(options);\n // Force an initial autoscale if it's the first series\n if (currentSeriesMap.size === 1) {\n chart.autoScale();\n }\n } else if (\n prevSeries.x !== seriesData.x ||\n prevSeries.y !== seriesData.y\n ) {\n // Data changed - update\n updateSeries(id, {\n x: seriesData.x,\n y: seriesData.y,\n });\n }\n });\n\n previousSeriesRef.current = currentSeriesMap;\n }, [series, isReady, chart, addSeries, updateSeries, removeSeries]);\n\n // Handle controlled zoom\n useEffect(() => {\n if (!isReady || !chart || !zoomProp) return;\n chart.zoom(zoomProp);\n }, [isReady, chart, zoomProp]);\n\n // Handle zoom change callback\n useEffect(() => {\n if (!isReady || !chart || !onZoomChange) return;\n\n chart.on(\"zoom\", (event) => {\n onZoomChange({\n xMin: event.x[0],\n xMax: event.x[1],\n yMin: event.y[0],\n yMax: event.y[1],\n });\n });\n }, [isReady, chart, onZoomChange]);\n\n // Handle cursor\n useEffect(() => {\n if (!isReady || !chart) return;\n\n if (cursor?.enabled) {\n chart.enableCursor(cursor);\n } else {\n chart.disableCursor();\n }\n }, [isReady, chart, cursor]);\n\n // Container styles\n const containerStyle = useMemo<CSSProperties>(\n () => ({\n position: \"relative\",\n width: typeof width === \"number\" ? `${width}px` : width,\n height: typeof height === \"number\" ? `${height}px` : height,\n ...style,\n }),\n [width, height, style]\n );\n\n return (\n <div\n ref={containerRef}\n className={`velo-plot-container ${className}`}\n style={containerStyle}\n >\n {/* Debug overlay */}\n {debug && bounds && (\n <div\n style={{\n position: \"absolute\",\n top: 8,\n right: 8,\n background: \"rgba(0,0,0,0.7)\",\n color: \"#0f0\",\n padding: \"4px 8px\",\n borderRadius: 4,\n fontSize: 11,\n fontFamily: \"monospace\",\n }}\n >\n <div>\n X: [{bounds.xMin.toFixed(3)}, {bounds.xMax.toFixed(3)}]\n </div>\n <div>\n Y: [{bounds.yMin.toExponential(2)}, {bounds.yMax.toExponential(2)}\n ]\n </div>\n <div>Series: {series.length}</div>\n </div>\n )}\n </div>\n );\n }\n);\n\nexport default SciPlot;\n"],"names":["REACT_ELEMENT_TYPE","REACT_FRAGMENT_TYPE","jsxProd","type","config","maybeKey","key","propName","reactJsxRuntime_production","getComponentNameFromType","REACT_CLIENT_REFERENCE","REACT_PROFILER_TYPE","REACT_STRICT_MODE_TYPE","REACT_SUSPENSE_TYPE","REACT_SUSPENSE_LIST_TYPE","REACT_ACTIVITY_TYPE","REACT_PORTAL_TYPE","REACT_CONTEXT_TYPE","REACT_CONSUMER_TYPE","REACT_FORWARD_REF_TYPE","innerType","REACT_MEMO_TYPE","REACT_LAZY_TYPE","testStringCoercion","value","checkKeyStringCoercion","JSCompiler_inline_result","JSCompiler_temp_const","JSCompiler_inline_result$jscomp$0","getTaskName","name","getOwner","dispatcher","ReactSharedInternals","UnknownOwner","hasValidKey","hasOwnProperty","getter","defineKeyPropWarningGetter","props","displayName","warnAboutAccessingKey","specialPropKeyWarningShown","elementRefGetterWithDeprecationWarning","componentName","didWarnAboutElementRef","ReactElement","owner","debugStack","debugTask","refProp","jsxDEVImpl","isStaticChildren","children","isArrayImpl","validateChildKeys","keys","k","didWarnAboutKeySpread","node","isValidElement","object","React","require$$0","createTask","callStackForError","unknownOwnerDebugStack","unknownOwnerDebugTask","reactJsxRuntime_development","trackActualOwner","jsxRuntimeModule","require$$1","useSciPlot","containerRef","options","chart","setChart","useState","isReady","setIsReady","error","setError","bounds","setBounds","optionsRef","useRef","useEffect","container","chartInstance","createChart","err","addSeries","useCallback","seriesOptions","updateSeries","id","data","removeSeries","zoom","zoomOptions","resetZoom","SciPlot","forwardRef","series","zoomProp","onZoomChange","cursor","width","height","className","style","debug","chartOptions","ref","previousSeriesRef","useImperativeHandle","currentSeriesMap","s","previousSeriesMap","_","seriesData","prevSeries","event","containerStyle","useMemo","jsx","jsxs"],"mappings":";;;;;;;;;;;;;;;;AAWA,MAAIA,IAAqB,OAAO,IAAI,4BAA4B,GAC9DC,IAAsB,OAAO,IAAI,gBAAgB;AACnD,WAASC,EAAQC,GAAMC,GAAQC,GAAU;AACvC,QAAIC,IAAM;AAGV,QAFWD,MAAX,WAAwBC,IAAM,KAAKD,IACxBD,EAAO,QAAlB,WAA0BE,IAAM,KAAKF,EAAO,MACxC,SAASA,GAAQ;AACnB,MAAAC,IAAW,CAAA;AACX,eAASE,KAAYH;AACnB,QAAUG,MAAV,UAAuBF,EAASE,CAAQ,IAAIH,EAAOG,CAAQ;AAAA,IACjE,MAAS,CAAAF,IAAWD;AAClB,WAAAA,IAASC,EAAS,KACX;AAAA,MACL,UAAUL;AAAA,MACV,MAAMG;AAAA,MACN,KAAKG;AAAA,MACL,KAAgBF,MAAX,SAAoBA,IAAS;AAAA,MAClC,OAAOC;AAAA,IACX;AAAA,EACA;AACA,SAAAG,EAAA,WAAmBP,GACnBO,EAAA,M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,UAAA;AAAA,gBAAA;AAAA,gBACEA,EAAO,KAAK,cAAc,CAAC;AAAA,gBAAE;AAAA,gBAAGA,EAAO,KAAK,cAAc,CAAC;AAAA,gBAAE;AAAA,cAAA,GAEpE;AAAA,qCACC,OAAA,EAAI,UAAA;AAAA,gBAAA;AAAA,gBAASqB,EAAO;AAAA,cAAA,EAAA,CAAO;AAAA,YAAA;AAAA,UAAA;AAAA,QAAA;AAAA,MAC9B;AAAA,IAAA;AAAA,EAIR;AACF;","x_google_ignoreList":[0,1,2]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
(function(){"use strict";function I(s,n,t){const e=s.length;if(t>=e||t<=2)return{x:new Float32Array(s),y:new Float32Array(n),indices:new Uint32Array(Array.from({length:e},(o,p)=>p))};const u=new Float32Array(t),l=new Float32Array(t),i=new Uint32Array(t);u[0]=s[0],l[0]=n[0],i[0]=0;const h=(e-2)/(t-2);let r=0,c=1;for(let o=0;o<t-2;o++){const p=Math.floor((o+1)*h)+1,y=Math.floor((o+2)*h)+1,w=Math.min(y,e-1),f=Math.min(Math.floor((o+3)*h)+1,e);let a=0,g=0,b=0;for(let d=w;d<f;d++)a+=s[d],g+=n[d],b++;b>0&&(a/=b,g/=b);let F=-1,m=p;const A=s[r],M=n[r];for(let d=p;d<y&&d<e;d++){const x=Math.abs((A-a)*(n[d]-M)-(A-s[d])*(g-M));x>F&&(F=x,m=d)}u[c]=s[m],l[c]=n[m],i[c]=m,r=m,c++}return u[t-1]=s[e-1],l[t-1]=n[e-1],i[t-1]=e-1,{x:u,y:l,indices:i}}function k(s,n,t){const e=s.length;if(t>=e/2)return{x:new Float32Array(s),y:new Float32Array(n),indices:new Uint32Array(Array.from({length:e},(r,c)=>c))};const u=e/t,l=[],i=[],h=[];for(let r=0;r<t;r++){const c=Math.floor(r*u),o=Math.floor((r+1)*u);let p=1/0,y=-1/0,w=c,f=c;for(let a=c;a<o&&a<e;a++)n[a]<p&&(p=n[a],w=a),n[a]>y&&(y=n[a],f=a);w<=f?(l.push(s[w],s[f]),i.push(n[w],n[f]),h.push(w,f)):(l.push(s[f],s[w]),i.push(n[f],n[w]),h.push(f,w))}return{x:new Float32Array(l),y:new Float32Array(i),indices:new Uint32Array(h)}}function S(s,n,t,e,u,l){const i=s.length;if(l>=i||l<=1||i===0)return{x:new Float32Array(s),open:new Float32Array(n),high:new Float32Array(t),low:new Float32Array(e),close:new Float32Array(u),indices:new Uint32Array(Array.from({length:i},(f,a)=>a))};const h=i/l,r=[],c=[],o=[],p=[],y=[],w=[];for(let f=0;f<l;f++){const a=Math.floor(f*h),g=Math.min(i,Math.floor((f+1)*h));if(a>=g)continue;let b=-1/0,F=1/0,m=a;for(let A=a;A<g;A++)t[A]>b&&(b=t[A]),e[A]<F&&(F=e[A]),m=A;c.push(n[a]),o.push(b),p.push(F),y.push(u[m]),r.push(s[m]),w.push(m)}return{x:new Float32Array(r),open:new Float32Array(c),high:new Float32Array(o),low:new Float32Array(p),close:new Float32Array(y),indices:new Uint32Array(w)}}self.onmessage=function(s){const n=s.data;try{if(n.type==="downsample"){const t=performance.now(),{x:e,y:u,targetPoints:l,algorithm:i="lttb",id:h}=n;let r;if(i==="minmax"){const p=Math.ceil(l/2);r=k(e,u,p)}else r=I(e,u,l);const c=performance.now()-t,o={type:"downsample-result",id:h,x:r.x,y:r.y,indices:r.indices,originalLength:e.length,duration:c};self.postMessage(o,[r.x.buffer,r.y.buffer,r.indices.buffer])}else if(n.type==="ohlc-downsample"){const t=performance.now(),{x:e,open:u,high:l,low:i,close:h,targetBars:r,id:c}=n,o=S(e,u,l,i,h,r),p=performance.now()-t,y={type:"ohlc-downsample-result",id:c,x:o.x,open:o.open,high:o.high,low:o.low,close:o.close,indices:o.indices,originalLength:e.length,duration:p};self.postMessage(y,[o.x.buffer,o.open.buffer,o.high.buffer,o.low.buffer,o.close.buffer,o.indices.buffer])}}catch(t){const e={type:"error",id:n.id,error:t instanceof Error?t.message:String(t)};self.postMessage(e)}}})();
|
|
2
|
+
//# sourceMappingURL=downsample.worker-C70QJ04y.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"downsample.worker-C70QJ04y.js","sources":["../src/workers/downsample.ts","../src/workers/downsample.worker.ts"],"sourcesContent":["/**\n * LTTB (Largest-Triangle-Three-Buckets) Downsampling Algorithm\n *\n * This algorithm downsamples time-series data while preserving visual features.\n * It's much better than naive sampling for preserving peaks and valleys.\n *\n * Reference: https://skemman.is/bitstream/1946/15343/3/SS_MSthesis.pdf\n */\n\nexport interface DownsampleResult {\n x: Float32Array;\n y: Float32Array;\n /** Original indices of selected points */\n indices: Uint32Array;\n}\n\n/**\n * Downsample data using LTTB algorithm\n *\n * @param x - X values (e.g., potential)\n * @param y - Y values (e.g., current)\n * @param targetPoints - Number of output points\n * @returns Downsampled data\n */\nexport function lttbDownsample(\n x: Float32Array | Float64Array,\n y: Float32Array | Float64Array,\n targetPoints: number\n): DownsampleResult {\n const length = x.length;\n\n // No need to downsample\n if (targetPoints >= length || targetPoints <= 2) {\n return {\n x: new Float32Array(x),\n y: new Float32Array(y),\n indices: new Uint32Array(Array.from({ length }, (_, i) => i)),\n };\n }\n\n const outX = new Float32Array(targetPoints);\n const outY = new Float32Array(targetPoints);\n const outIndices = new Uint32Array(targetPoints);\n\n // Always include first point\n outX[0] = x[0];\n outY[0] = y[0];\n outIndices[0] = 0;\n\n // Bucket size\n const bucketSize = (length - 2) / (targetPoints - 2);\n\n let a = 0; // Previous selected point index\n let outIdx = 1;\n\n for (let i = 0; i < targetPoints - 2; i++) {\n // Calculate bucket boundaries\n const bucketStart = Math.floor((i + 1) * bucketSize) + 1;\n const bucketEnd = Math.floor((i + 2) * bucketSize) + 1;\n\n // Calculate average point of next bucket\n const nextBucketStart = Math.min(bucketEnd, length - 1);\n const nextBucketEnd = Math.min(\n Math.floor((i + 3) * bucketSize) + 1,\n length\n );\n\n let avgX = 0;\n let avgY = 0;\n let avgCount = 0;\n\n for (let j = nextBucketStart; j < nextBucketEnd; j++) {\n avgX += x[j];\n avgY += y[j];\n avgCount++;\n }\n\n if (avgCount > 0) {\n avgX /= avgCount;\n avgY /= avgCount;\n }\n\n // Find point in current bucket with largest triangle area\n let maxArea = -1;\n let maxIndex = bucketStart;\n\n const aX = x[a];\n const aY = y[a];\n\n for (let j = bucketStart; j < bucketEnd && j < length; j++) {\n // Calculate triangle area (simplified: |x1(y2-y3) + x2(y3-y1) + x3(y1-y2)| / 2)\n const area = Math.abs(\n (aX - avgX) * (y[j] - aY) - (aX - x[j]) * (avgY - aY)\n );\n\n if (area > maxArea) {\n maxArea = area;\n maxIndex = j;\n }\n }\n\n // Store selected point\n outX[outIdx] = x[maxIndex];\n outY[outIdx] = y[maxIndex];\n outIndices[outIdx] = maxIndex;\n\n a = maxIndex;\n outIdx++;\n }\n\n // Always include last point\n outX[targetPoints - 1] = x[length - 1];\n outY[targetPoints - 1] = y[length - 1];\n outIndices[targetPoints - 1] = length - 1;\n\n return { x: outX, y: outY, indices: outIndices };\n}\n\n/**\n * Min-Max per bucket downsampling\n *\n * Simpler alternative to LTTB that preserves extremes in each bucket.\n * Uses 2 points per bucket (min and max), so output is ~2x target.\n */\nexport function minMaxDownsample(\n x: Float32Array | Float64Array,\n y: Float32Array | Float64Array,\n bucketCount: number\n): DownsampleResult {\n const length = x.length;\n\n if (bucketCount >= length / 2) {\n return {\n x: new Float32Array(x),\n y: new Float32Array(y),\n indices: new Uint32Array(Array.from({ length }, (_, i) => i)),\n };\n }\n\n const bucketSize = length / bucketCount;\n const outX: number[] = [];\n const outY: number[] = [];\n const outIndices: number[] = [];\n\n for (let b = 0; b < bucketCount; b++) {\n const start = Math.floor(b * bucketSize);\n const end = Math.floor((b + 1) * bucketSize);\n\n let minY = Infinity;\n let maxY = -Infinity;\n let minIdx = start;\n let maxIdx = start;\n\n for (let i = start; i < end && i < length; i++) {\n if (y[i] < minY) {\n minY = y[i];\n minIdx = i;\n }\n if (y[i] > maxY) {\n maxY = y[i];\n maxIdx = i;\n }\n }\n\n // Add points in order (min first if it comes before max)\n if (minIdx <= maxIdx) {\n outX.push(x[minIdx], x[maxIdx]);\n outY.push(y[minIdx], y[maxIdx]);\n outIndices.push(minIdx, maxIdx);\n } else {\n outX.push(x[maxIdx], x[minIdx]);\n outY.push(y[maxIdx], y[minIdx]);\n outIndices.push(maxIdx, minIdx);\n }\n }\n\n return {\n x: new Float32Array(outX),\n y: new Float32Array(outY),\n indices: new Uint32Array(outIndices),\n };\n}\n\n/**\n * Calculate optimal target points based on canvas width\n */\nexport function calculateTargetPoints(\n dataLength: number,\n canvasWidth: number,\n pointsPerPixel = 2\n): number {\n // Never draw more than pointsPerPixel per pixel\n const maxPoints = canvasWidth * pointsPerPixel;\n return Math.min(dataLength, maxPoints);\n}\n\nexport interface OhlcDownsampleResult {\n x: Float32Array;\n open: Float32Array;\n high: Float32Array;\n low: Float32Array;\n close: Float32Array;\n indices: Uint32Array;\n}\n\n/**\n * Aggregate OHLC bars into fewer buckets while preserving extremes.\n * Each bucket: open=first open, close=last close, high=max high, low=min low, x=last x.\n */\nexport function ohlcMinMaxDownsample(\n x: Float32Array | Float64Array,\n open: Float32Array | Float64Array,\n high: Float32Array | Float64Array,\n low: Float32Array | Float64Array,\n close: Float32Array | Float64Array,\n targetBars: number,\n): OhlcDownsampleResult {\n const length = x.length;\n if (targetBars >= length || targetBars <= 1 || length === 0) {\n return {\n x: new Float32Array(x),\n open: new Float32Array(open),\n high: new Float32Array(high),\n low: new Float32Array(low),\n close: new Float32Array(close),\n indices: new Uint32Array(Array.from({ length }, (_, i) => i)),\n };\n }\n\n const bucketSize = length / targetBars;\n const outX: number[] = [];\n const outOpen: number[] = [];\n const outHigh: number[] = [];\n const outLow: number[] = [];\n const outClose: number[] = [];\n const outIndices: number[] = [];\n\n for (let b = 0; b < targetBars; b++) {\n const start = Math.floor(b * bucketSize);\n const end = Math.min(length, Math.floor((b + 1) * bucketSize));\n if (start >= end) continue;\n\n let hi = -Infinity;\n let lo = Infinity;\n let lastIdx = start;\n\n for (let i = start; i < end; i++) {\n if (high[i] > hi) hi = high[i];\n if (low[i] < lo) lo = low[i];\n lastIdx = i;\n }\n\n outOpen.push(open[start]);\n outHigh.push(hi);\n outLow.push(lo);\n outClose.push(close[lastIdx]);\n outX.push(x[lastIdx]);\n outIndices.push(lastIdx);\n }\n\n return {\n x: new Float32Array(outX),\n open: new Float32Array(outOpen),\n high: new Float32Array(outHigh),\n low: new Float32Array(outLow),\n close: new Float32Array(outClose),\n indices: new Uint32Array(outIndices),\n };\n}\n\n/** Binary search lower bound: first index where x[i] >= value */\nexport function lowerBoundX(\n x: Float32Array | Float64Array,\n value: number,\n): number {\n let lo = 0;\n let hi = x.length;\n while (lo < hi) {\n const mid = (lo + hi) >>> 1;\n if (x[mid] < value) lo = mid + 1;\n else hi = mid;\n }\n return lo;\n}\n\n/** Binary search upper bound: first index where x[i] > value */\nexport function upperBoundX(\n x: Float32Array | Float64Array,\n value: number,\n): number {\n let lo = 0;\n let hi = x.length;\n while (lo < hi) {\n const mid = (lo + hi) >>> 1;\n if (x[mid] <= value) lo = mid + 1;\n else hi = mid;\n }\n return lo;\n}\n\nexport interface ViewportSlice {\n x: Float32Array;\n y?: Float32Array;\n open?: Float32Array;\n high?: Float32Array;\n low?: Float32Array;\n close?: Float32Array;\n start: number;\n end: number;\n}\n\n/**\n * Slice sorted x-series to visible range plus buffer (fraction of visible width).\n */\nexport function sliceSeriesToViewport(\n source: {\n x: Float32Array | Float64Array;\n y?: Float32Array | Float64Array;\n open?: Float32Array | Float64Array;\n high?: Float32Array | Float64Array;\n low?: Float32Array | Float64Array;\n close?: Float32Array | Float64Array;\n },\n xMin: number,\n xMax: number,\n bufferRatio = 0.5,\n): ViewportSlice {\n const length = source.x.length;\n if (length === 0) {\n return { x: new Float32Array(0), start: 0, end: 0 };\n }\n\n const range = Math.max(xMax - xMin, 1e-12);\n const paddedMin = xMin - range * bufferRatio;\n const paddedMax = xMax + range * bufferRatio;\n\n let start = lowerBoundX(source.x, paddedMin);\n let end = upperBoundX(source.x, paddedMax);\n start = Math.max(0, start);\n end = Math.min(length, Math.max(end, start + 1));\n\n const slice = <T extends Float32Array | Float64Array>(arr: T | undefined): Float32Array | undefined => {\n if (!arr) return undefined;\n return new Float32Array(arr.subarray(start, end));\n };\n\n return {\n x: new Float32Array(source.x.subarray(start, end)),\n y: slice(source.y),\n open: slice(source.open),\n high: slice(source.high),\n low: slice(source.low),\n close: slice(source.close),\n start,\n end,\n };\n}\n","/**\n * Downsampling Web Worker\n *\n * Performs CPU-intensive downsampling off the main thread.\n *\n * Usage:\n * ```typescript\n * const worker = new Worker(new URL('./downsample.worker.ts', import.meta.url));\n *\n * worker.postMessage({\n * type: 'downsample',\n * x: xArray,\n * y: yArray,\n * targetPoints: 1000,\n * algorithm: 'lttb'\n * });\n *\n * worker.onmessage = (e) => {\n * const { x, y, indices } = e.data;\n * chart.setDownsampledData(x, y);\n * };\n * ```\n */\n\nimport {\n lttbDownsample,\n minMaxDownsample,\n ohlcMinMaxDownsample,\n type DownsampleResult,\n} from './downsample';\n\n// ============================================\n// Message Types\n// ============================================\n\ninterface DownsampleRequestMessage {\n type: 'downsample';\n id?: string;\n x: Float32Array | Float64Array;\n y: Float32Array | Float64Array;\n targetPoints: number;\n algorithm?: 'lttb' | 'minmax';\n}\n\ninterface DownsampleResponseMessage {\n type: 'downsample-result';\n id?: string;\n x: Float32Array;\n y: Float32Array;\n indices: Uint32Array;\n originalLength: number;\n duration: number;\n}\n\ninterface ErrorMessage {\n type: 'error';\n id?: string;\n error: string;\n}\n\ninterface OhlcDownsampleRequestMessage {\n type: 'ohlc-downsample';\n id?: string;\n x: Float32Array | Float64Array;\n open: Float32Array | Float64Array;\n high: Float32Array | Float64Array;\n low: Float32Array | Float64Array;\n close: Float32Array | Float64Array;\n targetBars: number;\n}\n\ninterface OhlcDownsampleResponseMessage {\n type: 'ohlc-downsample-result';\n id?: string;\n x: Float32Array;\n open: Float32Array;\n high: Float32Array;\n low: Float32Array;\n close: Float32Array;\n indices: Uint32Array;\n originalLength: number;\n duration: number;\n}\n\ntype WorkerMessage = DownsampleRequestMessage | OhlcDownsampleRequestMessage;\n\n// ============================================\n// Worker Logic\n// ============================================\n\nself.onmessage = function (e: MessageEvent<WorkerMessage>) {\n const message = e.data;\n\n try {\n if (message.type === 'downsample') {\n const start = performance.now();\n\n const { x, y, targetPoints, algorithm = 'lttb', id } = message;\n\n let result: DownsampleResult;\n\n if (algorithm === 'minmax') {\n // Min-max uses bucket count, not target points\n const bucketCount = Math.ceil(targetPoints / 2);\n result = minMaxDownsample(x, y, bucketCount);\n } else {\n result = lttbDownsample(x, y, targetPoints);\n }\n\n const duration = performance.now() - start;\n\n const response: DownsampleResponseMessage = {\n type: 'downsample-result',\n id,\n x: result.x,\n y: result.y,\n indices: result.indices,\n originalLength: x.length,\n duration,\n };\n\n // Transfer ownership of buffers for zero-copy\n (self.postMessage as (message: unknown, transfer: Transferable[]) => void)(\n response,\n [result.x.buffer, result.y.buffer, result.indices.buffer]\n );\n } else if (message.type === 'ohlc-downsample') {\n const start = performance.now();\n const { x, open, high, low, close, targetBars, id } = message;\n\n const result = ohlcMinMaxDownsample(x, open, high, low, close, targetBars);\n const duration = performance.now() - start;\n\n const response: OhlcDownsampleResponseMessage = {\n type: 'ohlc-downsample-result',\n id,\n x: result.x,\n open: result.open,\n high: result.high,\n low: result.low,\n close: result.close,\n indices: result.indices,\n originalLength: x.length,\n duration,\n };\n\n (self.postMessage as (message: unknown, transfer: Transferable[]) => void)(\n response,\n [\n result.x.buffer,\n result.open.buffer,\n result.high.buffer,\n result.low.buffer,\n result.close.buffer,\n result.indices.buffer,\n ]\n );\n }\n } catch (error) {\n const errorResponse: ErrorMessage = {\n type: 'error',\n id: (message as DownsampleRequestMessage).id,\n error: error instanceof Error ? error.message : String(error),\n };\n self.postMessage(errorResponse);\n }\n};\n\n// Export types for TypeScript\nexport type { DownsampleRequestMessage, DownsampleResponseMessage, ErrorMessage };\n"],"names":["lttbDownsample","x","y","targetPoints","length","_","i","outX","outY","outIndices","bucketSize","a","outIdx","bucketStart","bucketEnd","nextBucketStart","nextBucketEnd","avgX","avgY","avgCount","j","maxArea","maxIndex","aX","aY","area","minMaxDownsample","bucketCount","b","start","end","minY","maxY","minIdx","maxIdx","ohlcMinMaxDownsample","open","high","low","close","targetBars","outOpen","outHigh","outLow","outClose","hi","lo","lastIdx","e","message","algorithm","id","result","duration","response","error","errorResponse"],"mappings":"yBAwBO,SAASA,EACdC,EACAC,EACAC,EACkB,CAClB,MAAMC,EAASH,EAAE,OAGjB,GAAIE,GAAgBC,GAAUD,GAAgB,EAC5C,MAAO,CACL,EAAG,IAAI,aAAaF,CAAC,EACrB,EAAG,IAAI,aAAaC,CAAC,EACrB,QAAS,IAAI,YAAY,MAAM,KAAK,CAAE,OAAAE,CAAA,EAAU,CAACC,EAAGC,IAAMA,CAAC,CAAC,CAAA,EAIhE,MAAMC,EAAO,IAAI,aAAaJ,CAAY,EACpCK,EAAO,IAAI,aAAaL,CAAY,EACpCM,EAAa,IAAI,YAAYN,CAAY,EAG/CI,EAAK,CAAC,EAAIN,EAAE,CAAC,EACbO,EAAK,CAAC,EAAIN,EAAE,CAAC,EACbO,EAAW,CAAC,EAAI,EAGhB,MAAMC,GAAcN,EAAS,IAAMD,EAAe,GAElD,IAAIQ,EAAI,EACJC,EAAS,EAEb,QAASN,EAAI,EAAGA,EAAIH,EAAe,EAAGG,IAAK,CAEzC,MAAMO,EAAc,KAAK,OAAOP,EAAI,GAAKI,CAAU,EAAI,EACjDI,EAAY,KAAK,OAAOR,EAAI,GAAKI,CAAU,EAAI,EAG/CK,EAAkB,KAAK,IAAID,EAAWV,EAAS,CAAC,EAChDY,EAAgB,KAAK,IACzB,KAAK,OAAOV,EAAI,GAAKI,CAAU,EAAI,EACnCN,CAAA,EAGF,IAAIa,EAAO,EACPC,EAAO,EACPC,EAAW,EAEf,QAASC,EAAIL,EAAiBK,EAAIJ,EAAeI,IAC/CH,GAAQh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
@@ -0,0 +1,2 @@
|
|
|
1
|
+
(function(){"use strict";function g(o,t){const a=o instanceof Float32Array||o instanceof Float64Array?o:Float32Array.from(o),r=new Float32Array(a.length);if(t<1||t>a.length)return r.fill(NaN),r;for(let n=0;n<t-1;n++)r[n]=NaN;let e=0;for(let n=0;n<t;n++)e+=a[n];r[t-1]=e/t;for(let n=t;n<a.length;n++)e=e-a[n-t]+a[n],r[n]=e/t;return r}function u(o,t){const a=o instanceof Float32Array||o instanceof Float64Array?o:Float32Array.from(o),r=new Float32Array(a.length);if(t<1||t>a.length)return r.fill(NaN),r;const e=2/(t+1);for(let s=0;s<t-1;s++)r[s]=NaN;let n=0;for(let s=0;s<t;s++)n+=a[s];r[t-1]=n/t;for(let s=t;s<a.length;s++)r[s]=(a[s]-r[s-1])*e+r[s-1];return r}function h(o,t=14){const a=o instanceof Float32Array||o instanceof Float64Array?o:Float32Array.from(o),r=new Float32Array(a.length);if(t<1||a.length<t+1)return r.fill(NaN),r;for(let s=0;s<t;s++)r[s]=NaN;let e=0,n=0;for(let s=1;s<=t;s++){const l=a[s]-a[s-1];l>0?e+=l:n+=Math.abs(l)}if(e/=t,n/=t,n===0)r[t]=100;else{const s=e/n;r[t]=100-100/(1+s)}for(let s=t+1;s<a.length;s++){const l=a[s]-a[s-1];let f=0,c=0;if(l>0?f=l:c=Math.abs(l),e=(e*(t-1)+f)/t,n=(n*(t-1)+c)/t,n===0)r[s]=100;else{const i=e/n;r[s]=100-100/(1+i)}}return r}function y(o,t=12,a=26,r=9){const e=o instanceof Float32Array||o instanceof Float64Array?o:Float32Array.from(o),n=u(e,t),s=u(e,a),l=new Float32Array(e.length);for(let i=0;i<e.length;i++)l[i]=n[i]-s[i];const f=u(l,r),c=new Float32Array(e.length);for(let i=0;i<e.length;i++)c[i]=l[i]-f[i];return{values:l,signal:f,histogram:c}}function w(o,t=20,a=2){const r=o instanceof Float32Array||o instanceof Float64Array?o:Float32Array.from(o),e=g(r,t),n=new Float32Array(r.length),s=new Float32Array(r.length);for(let l=0;l<r.length;l++){if(l<t-1){n[l]=NaN,s[l]=NaN;continue}let f=0;for(let i=l-t+1;i<=l;i++){const m=r[i]-e[l];f+=m*m}const c=Math.sqrt(f/t);n[l]=e[l]+a*c,s[l]=e[l]-a*c}return{values:e,upper:n,lower:s}}self.onmessage=function(o){const t=o.data;try{const a=performance.now();let r;switch(t.indicator){case"rsi":{const e=h(t.data,t.period??14);r={id:t.id,type:"indicator-result",indicator:"rsi",values:e,duration:performance.now()-a},self.postMessage(r,[e.buffer]);return}case"sma":{const e=g(t.data,t.period??14);r={id:t.id,type:"indicator-result",indicator:"sma",values:e,duration:performance.now()-a},self.postMessage(r,[e.buffer]);return}case"ema":{const e=u(t.data,t.period??14);r={id:t.id,type:"indicator-result",indicator:"ema",values:e,duration:performance.now()-a},self.postMessage(r,[e.buffer]);return}case"macd":{const e=y(t.data,t.fastPeriod??12,t.slowPeriod??26,t.signalPeriod??9);r={id:t.id,type:"indicator-result",indicator:"macd",values:e.values,signal:e.signal,histogram:e.histogram,duration:performance.now()-a};const n=[e.values.buffer];e.signal&&n.push(e.signal.buffer),e.histogram&&n.push(e.histogram.buffer),self.postMessage(r,n);return}case"bollingerBands":{const e=w(t.data,t.period??20,t.stdDev??2);r={id:t.id,type:"indicator-result",indicator:"bollingerBands",values:e.values,upper:e.upper,lower:e.lower,duration:performance.now()-a};const n=[e.values.buffer];e.upper&&n.push(e.upper.buffer),e.lower&&n.push(e.lower.buffer),self.postMessage(r,n);return}default:{const e={id:t.id,type:"error",error:`Unknown indicator: ${t.indicator}`};self.postMessage(e)}}}catch(a){const r={id:t.id,type:"error",error:a instanceof Error?a.message:String(a)};self.postMessage(r)}}})();
|
|
2
|
+
//# sourceMappingURL=indicator.worker-bv0zC4EX.js.map
|