@radishcandy/h-charts 0.1.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/index.js ADDED
@@ -0,0 +1,1377 @@
1
+ var w = Object.defineProperty;
2
+ var k = (l, o, t) => o in l ? w(l, o, { enumerable: !0, configurable: !0, writable: !0, value: t }) : l[o] = t;
3
+ var r = (l, o, t) => k(l, typeof o != "symbol" ? o + "" : o, t);
4
+ import { H as nt } from "./HChart-B61851DE.js";
5
+ import A from "highcharts";
6
+ class E {
7
+ constructor(o = {}) {
8
+ r(this, "chart", null);
9
+ r(this, "enabled", !1);
10
+ r(this, "options", {});
11
+ this.options = o;
12
+ }
13
+ init(o) {
14
+ this.chart = o, this.options.enabled !== !1 && this.enable();
15
+ }
16
+ destroy() {
17
+ this.disable(), this.chart = null;
18
+ }
19
+ enable() {
20
+ this.enabled = !0;
21
+ }
22
+ disable() {
23
+ this.enabled = !1;
24
+ }
25
+ isEnabled() {
26
+ return this.enabled;
27
+ }
28
+ update(o) {
29
+ this.options = { ...this.options, ...o };
30
+ }
31
+ }
32
+ class v {
33
+ /**
34
+ * Find the index of the data point closest to a given value using binary search.
35
+ * Assumes data is sorted in ascending order.
36
+ * @param value The value to search for (e.g., x-axis value)
37
+ * @param data The array of values to search in
38
+ * @returns The index of the nearest value
39
+ */
40
+ static getMostNearIndex(o, t) {
41
+ if (!t || t.length === 0)
42
+ return -1;
43
+ let e = 0, i = t.length - 1;
44
+ if (o >= t[i]) return i;
45
+ if (o <= t[e]) return 0;
46
+ let n = 0;
47
+ for (; i >= e; ) {
48
+ const s = Math.round((e + i) / 2);
49
+ if (t[s] > o) {
50
+ if (s === 0) {
51
+ n = 0;
52
+ break;
53
+ }
54
+ if (t[s - 1] > o)
55
+ i = s - 1;
56
+ else {
57
+ n = o - t[s - 1] >= t[s] - o ? s : s - 1;
58
+ break;
59
+ }
60
+ } else if (t[s] < o) {
61
+ if (s === t.length - 1) {
62
+ n = t.length - 1;
63
+ break;
64
+ }
65
+ if (t[s + 1] < o)
66
+ e = s + 1;
67
+ else {
68
+ n = o - t[s] >= t[s + 1] - o ? s + 1 : s;
69
+ break;
70
+ }
71
+ } else {
72
+ n = s;
73
+ break;
74
+ }
75
+ }
76
+ return n;
77
+ }
78
+ /**
79
+ * Helper to format numbers with precision
80
+ */
81
+ static formatNumber(o, t = 2) {
82
+ return o.toFixed(t);
83
+ }
84
+ }
85
+ function N() {
86
+ return { active: !1 };
87
+ }
88
+ class W extends E {
89
+ constructor(t) {
90
+ super({ enabled: t.enabled !== !1 });
91
+ r(this, "name");
92
+ r(this, "target");
93
+ r(this, "syncState");
94
+ this.name = t.name || "CursorLinkPlugin", this.target = t.target, this.syncState = t.syncState || N();
95
+ }
96
+ onCursorChange(t) {
97
+ if (!this.enabled || this.syncState.active || !Number.isFinite(t.x)) return;
98
+ const e = this.target();
99
+ if (!(!e || typeof e.setCursorX != "function")) {
100
+ this.syncState.active = !0;
101
+ try {
102
+ e.setCursorX(t.x);
103
+ } finally {
104
+ this.syncState.active = !1;
105
+ }
106
+ }
107
+ }
108
+ }
109
+ const P = "data-hchart-suppress-cursor-click", L = "activePoint-cursor-line", T = 8, D = 220;
110
+ function I(l, o = D) {
111
+ l && (l.setAttribute(P, "1"), window.setTimeout(() => l.removeAttribute(P), o));
112
+ }
113
+ function U(l) {
114
+ return (l == null ? void 0 : l.hasAttribute(P)) ?? !1;
115
+ }
116
+ class K extends E {
117
+ constructor(t = {}) {
118
+ super(t);
119
+ r(this, "name", "CursorPlugin");
120
+ r(this, "cursorLabel", null);
121
+ r(this, "cursorHitLine", null);
122
+ r(this, "activePoint", null);
123
+ r(this, "onKeyDownBound");
124
+ r(this, "labelFormatter", null);
125
+ r(this, "onCursorMove", null);
126
+ r(this, "isDragging", !1);
127
+ r(this, "hoverDebounceTimer", null);
128
+ r(this, "multiLine", !0);
129
+ r(this, "draggable", !0);
130
+ r(this, "pointerDown", null);
131
+ r(this, "pointerDragged", !1);
132
+ r(this, "suppressClickUntil", 0);
133
+ r(this, "eventsBound", !1);
134
+ r(this, "unbindAfterSetExtremes", null);
135
+ r(this, "onPointerDownBound");
136
+ r(this, "onPointerMoveBound");
137
+ r(this, "onPointerUpBound");
138
+ r(this, "onContainerMouseMoveBound");
139
+ r(this, "onContainerMouseUpBound");
140
+ this.onKeyDownBound = this.onKeyDown.bind(this), this.onPointerDownBound = this.onPointerDown.bind(this), this.onPointerMoveBound = this.onPointerMove.bind(this), this.onPointerUpBound = this.onPointerUp.bind(this), this.onContainerMouseMoveBound = this.onContainerMouseMove.bind(this), this.onContainerMouseUpBound = this.onContainerMouseUp.bind(this), this.labelFormatter = t.labelFormatter || null, this.onCursorMove = t.onCursorMove || null, this.multiLine = t.multiLine !== !1, this.draggable = t.draggable !== !1;
141
+ }
142
+ onContainerMouseMove(t) {
143
+ var n;
144
+ this.trackPointerDrag(t);
145
+ const e = this.getNativeChart(), i = (n = e == null ? void 0 : e.xAxis) == null ? void 0 : n[0];
146
+ if (this.isDragging && e && i) {
147
+ const s = e.pointer.normalize(t), a = i.toValue(s.chartX);
148
+ this.updateCursor(a);
149
+ }
150
+ }
151
+ onPointerDown(t) {
152
+ t.button === 0 && (this.pointerDown = { x: t.clientX, y: t.clientY }, this.pointerDragged = !1);
153
+ }
154
+ onPointerMove(t) {
155
+ this.trackPointerDrag(t);
156
+ }
157
+ trackPointerDrag(t) {
158
+ if (!this.pointerDown) return;
159
+ Math.hypot(t.clientX - this.pointerDown.x, t.clientY - this.pointerDown.y) > T && (this.pointerDragged = !0);
160
+ }
161
+ onPointerUp(t) {
162
+ var e;
163
+ t.button === 0 && (this.pointerDragged && (this.suppressClickUntil = Date.now() + D, I((e = this.chart) == null ? void 0 : e.container, D)), this.pointerDown = null, this.pointerDragged = !1);
164
+ }
165
+ shouldIgnoreChartClick() {
166
+ var e;
167
+ const t = (e = this.chart) == null ? void 0 : e.container;
168
+ return !!(U(t) || Date.now() < this.suppressClickUntil);
169
+ }
170
+ onContainerMouseUp() {
171
+ this.isDragging && (this.isDragging = !1), this.scheduleSeriesHoverState(!1);
172
+ }
173
+ init(t) {
174
+ super.init(t);
175
+ }
176
+ enable() {
177
+ super.enable(), this.bindEvents();
178
+ }
179
+ disable() {
180
+ super.disable(), this.unbindEvents();
181
+ }
182
+ onCursorChange(t) {
183
+ !this.enabled || !this.chart || this.activePoint && this.activePoint.x === t.x && this.activePoint.y === t.y && this.activePoint.index === t.index || (this.activePoint = t, this.drawCursor());
184
+ }
185
+ bindEvents() {
186
+ var e;
187
+ if (this.eventsBound || !((e = this.chart) != null && e.chart)) return;
188
+ this.eventsBound = !0;
189
+ const t = this.chart.chart.xAxis[0];
190
+ t && (this.unbindAfterSetExtremes = A.addEvent(t, "afterSetExtremes", () => {
191
+ setTimeout(() => this.refreshCursor(), 0);
192
+ })), this.chart.container.addEventListener("keydown", this.onKeyDownBound), this.chart.container.addEventListener("mousedown", this.onPointerDownBound, !0), document.addEventListener("mousemove", this.onPointerMoveBound), document.addEventListener("mouseup", this.onPointerUpBound), this.chart.container.addEventListener("mousemove", this.onContainerMouseMoveBound), document.addEventListener("mouseup", this.onContainerMouseUpBound);
193
+ }
194
+ unbindEvents() {
195
+ var t, e;
196
+ this.eventsBound && (this.eventsBound = !1, (t = this.unbindAfterSetExtremes) == null || t.call(this), this.unbindAfterSetExtremes = null, (e = this.chart) != null && e.container && (this.chart.container.removeEventListener("keydown", this.onKeyDownBound), this.chart.container.removeEventListener("mousedown", this.onPointerDownBound, !0), this.chart.container.removeEventListener("mousemove", this.onContainerMouseMoveBound)), document.removeEventListener("mousemove", this.onPointerMoveBound), document.removeEventListener("mouseup", this.onPointerUpBound), document.removeEventListener("mouseup", this.onContainerMouseUpBound));
197
+ }
198
+ getNativeChart() {
199
+ var e;
200
+ const t = (e = this.chart) == null ? void 0 : e.chart;
201
+ return !t || t.destroyed ? null : t;
202
+ }
203
+ getSeriesList() {
204
+ var e;
205
+ const t = (e = this.getNativeChart()) == null ? void 0 : e.series;
206
+ return Array.isArray(t) ? t : [];
207
+ }
208
+ getXData(t) {
209
+ if (!t) return null;
210
+ if (t.options.data) {
211
+ const i = t.options.data;
212
+ if (Array.isArray(i)) {
213
+ if (Array.isArray(i[0]))
214
+ return i.map((n) => n[0]);
215
+ if (typeof i[0] == "object")
216
+ return i.map((n) => n.x);
217
+ if (typeof i[0] == "number")
218
+ return i.map(
219
+ (n, s) => (t.options.pointStart || 0) + s * (t.options.pointInterval || 1)
220
+ );
221
+ }
222
+ }
223
+ let e = t.xData;
224
+ return e || (e = t.processedXData, e ? (console.warn(
225
+ "CursorPlugin: Using processedXData as fallback. Precision might be lost during zoom."
226
+ ), e) : null);
227
+ }
228
+ onKeyDown(t) {
229
+ if (!this.activePoint || !this.getNativeChart()) return;
230
+ let e = 0;
231
+ if (t.key === "ArrowLeft" ? e = -1 : t.key === "ArrowRight" && (e = 1), e !== 0) {
232
+ t.preventDefault();
233
+ const i = this.getSeriesList()[0], n = this.getXData(i);
234
+ if (n) {
235
+ let s = this.activePoint.index + e;
236
+ s < 0 && (s = 0), s >= n.length && (s = n.length - 1), s !== this.activePoint.index && this.updateCursor(n[s]);
237
+ }
238
+ }
239
+ }
240
+ onChartClick(t) {
241
+ var s;
242
+ if (!((s = this.chart) != null && s.chart) || this.shouldIgnoreChartClick()) return;
243
+ this.chart.container && this.chart.container.focus();
244
+ let e;
245
+ const i = t, n = t;
246
+ i.xAxis && i.xAxis.length > 0 ? e = i.xAxis[0].value : n.point && (e = n.point.x), e !== void 0 && this.updateCursor(e);
247
+ }
248
+ /**
249
+ * Update cursor position based on X value.
250
+ * Uses raw xData to ensure accuracy across zoom levels.
251
+ */
252
+ updateCursor(t) {
253
+ var h, c;
254
+ if (!this.getNativeChart()) return;
255
+ const e = this.getSeriesList()[0];
256
+ if (!e) return;
257
+ const i = this.getXData(e), n = e.yData || e.processedYData;
258
+ if (!(i != null && i.length)) return;
259
+ const s = v.getMostNearIndex(t, i);
260
+ if (s === -1) return;
261
+ const a = i[s];
262
+ let u;
263
+ if (n && n[s] !== void 0)
264
+ u = n[s];
265
+ else if (e.options.data && e.options.data[s]) {
266
+ const d = e.options.data[s];
267
+ u = Array.isArray(d) ? d[1] : typeof d == "object" ? d.y : d;
268
+ } else
269
+ u = 0;
270
+ this.activePoint = { x: a, y: u, index: s }, this.drawCursor(), this.scheduleSeriesHoverState(!0), (h = this.chart) == null || h.setCursor({ x: a, y: u, index: s }), (c = this.onCursorMove) == null || c.call(this, { x: a, y: u, index: s });
271
+ }
272
+ /**
273
+ * Re-applies the cursor based on the last active point.
274
+ * Called after zoom/pan to ensure cursor stays on the correct data point.
275
+ */
276
+ refreshCursor() {
277
+ this.activePoint && this.updateCursor(this.activePoint.x);
278
+ }
279
+ drawCursor() {
280
+ var m, x, g, C;
281
+ const t = this.getNativeChart();
282
+ if (!t || !this.activePoint) return;
283
+ const { x: e, y: i } = this.activePoint, n = (m = t.xAxis) == null ? void 0 : m[0], s = (x = t.yAxis) == null ? void 0 : x[0];
284
+ if (!n || !s) return;
285
+ const a = n.toPixels(e, !1), u = [
286
+ ["M", a, t.plotTop],
287
+ ["L", a, t.plotTop + t.plotHeight]
288
+ ];
289
+ t.removeAnnotation("activePoint"), t.removeAnnotation("activePoint-line"), t.removeAnnotation("activePoint-marker"), t.removeAnnotation("activePoint-label"), t.removeAnnotation("active"), n.removePlotLine(L), n.addPlotLine({
290
+ id: L,
291
+ value: e,
292
+ color: "red",
293
+ width: 1,
294
+ dashStyle: "DashDot",
295
+ zIndex: 9999
296
+ }), (C = (g = n.plotLinesAndBands.find((b) => b.id === L)) == null ? void 0 : g.svgElem) == null || C.css({ pointerEvents: "none" });
297
+ const h = s.getExtremes();
298
+ t.addAnnotation({
299
+ id: "activePoint-line",
300
+ shapes: [
301
+ {
302
+ type: "path",
303
+ points: [
304
+ { xAxis: 0, yAxis: 0, x: e, y: h.min },
305
+ { xAxis: 0, yAxis: 0, x: e, y: h.max }
306
+ ],
307
+ stroke: "red",
308
+ strokeWidth: 1,
309
+ dashStyle: "LongDashDot"
310
+ }
311
+ ],
312
+ zIndex: 9998,
313
+ visible: !0
314
+ }), this.draggable ? this.cursorHitLine ? this.cursorHitLine.attr({ d: u }) : this.cursorHitLine = t.renderer.path(u).attr({
315
+ stroke: "transparent",
316
+ "stroke-width": 10,
317
+ zIndex: 1e4
318
+ }).css({ cursor: "col-resize" }).on("mousedown", (b) => {
319
+ const M = (b == null ? void 0 : b.originalEvent) ?? b;
320
+ M != null && M.shiftKey && (this.isDragging = !0, typeof M.preventDefault == "function" && M.preventDefault(), typeof M.stopPropagation == "function" && M.stopPropagation());
321
+ }).on("mouseover", () => {
322
+ this.scheduleSeriesHoverState(!0);
323
+ }).on("mouseout", () => {
324
+ this.scheduleSeriesHoverState(!1);
325
+ }).add() : this.cursorHitLine && (this.cursorHitLine.destroy(), this.cursorHitLine = null);
326
+ const c = this.multiLine ? this.getOrderedVisibleSeriesPointsAtX(e) : [{ x: e, y: i, index: this.activePoint.index, color: "red", name: "active" }], d = [];
327
+ c.forEach((b) => {
328
+ d.push({
329
+ type: "circle",
330
+ point: {
331
+ xAxis: 0,
332
+ yAxis: 0,
333
+ x: b.x,
334
+ y: b.y
335
+ },
336
+ r: 2.5,
337
+ fill: "red",
338
+ stroke: "red"
339
+ }), d.push({
340
+ type: "circle",
341
+ point: {
342
+ xAxis: 0,
343
+ yAxis: 0,
344
+ x: b.x,
345
+ y: b.y
346
+ },
347
+ r: 8,
348
+ fill: "transparent",
349
+ stroke: "transparent"
350
+ });
351
+ });
352
+ const f = {
353
+ id: "activePoint-marker",
354
+ shapes: d,
355
+ zIndex: 9999,
356
+ visible: !0
357
+ };
358
+ t.addAnnotation(f);
359
+ const p = this.buildCursorLabelText(e, i);
360
+ this.cursorLabel ? this.cursorLabel.attr({ text: p }) : this.cursorLabel = t.renderer.label(p, t.plotLeft + 10, t.plotTop, "rect", void 0, void 0, !0).css({
361
+ color: "var(--hchart-text-color, #606266)",
362
+ fontSize: "12px",
363
+ lineHeight: "18px"
364
+ }).attr({
365
+ fill: "rgba(255,255,255,0)",
366
+ stroke: "transparent",
367
+ "stroke-width": 0,
368
+ padding: 8,
369
+ r: 4,
370
+ zIndex: 10001
371
+ }).add(), window.setTimeout(() => this.applyPassiveCursorLayer(), 0);
372
+ }
373
+ /** 边频/阈值线等可拖拽辅助线,需保留 pointer-events */
374
+ isInteractivePlotLine(t) {
375
+ return t ? !!(t.endsWith("-hit") || t.startsWith("sideband-") || t === "threshold-line") : !1;
376
+ }
377
+ applyPassiveCursorLayer() {
378
+ var n, s, a, u;
379
+ if (this.draggable) return;
380
+ const t = this.getNativeChart(), e = (n = this.chart) == null ? void 0 : n.container;
381
+ if (!t || !e) return;
382
+ const i = t;
383
+ t.axes.forEach((h) => {
384
+ h.plotLinesAndBands.forEach((c) => {
385
+ var d;
386
+ this.isInteractivePlotLine(c.id) || (d = c.svgElem) == null || d.css({ pointerEvents: "none" });
387
+ });
388
+ }), (s = i.annotations) == null || s.forEach((h) => {
389
+ var c, d, f;
390
+ (c = h.group) == null || c.css({ pointerEvents: "none" }), (d = h.labels) == null || d.forEach((p) => {
391
+ var m;
392
+ return (m = p.graphic) == null ? void 0 : m.css({ pointerEvents: "none" });
393
+ }), (f = h.shapes) == null || f.forEach((p) => {
394
+ var m;
395
+ return (m = p.graphic) == null ? void 0 : m.css({ pointerEvents: "none" });
396
+ });
397
+ }), (a = this.cursorLabel) == null || a.css({ pointerEvents: "none" }), this.draggable || (u = this.cursorHitLine) == null || u.css({ pointerEvents: "none" }), e.querySelectorAll(".highcharts-annotation, .highcharts-crosshair").forEach((h) => {
398
+ h.style.pointerEvents = "none";
399
+ });
400
+ }
401
+ buildCursorLabelText(t, e) {
402
+ var c;
403
+ const i = this.labelFormatter ? this.labelFormatter(t, e) : `${v.formatNumber(t)}, ${v.formatNumber(e)}`, s = [`<div><strong>${this.formatXText(t)}</strong></div>`];
404
+ if (!this.getNativeChart())
405
+ return i;
406
+ const a = this.getOrderedVisibleSeriesPointsAtX(t);
407
+ if (a.length <= 1) {
408
+ const d = (c = a[0]) == null ? void 0 : c.y;
409
+ return typeof d == "number" ? this.labelFormatter ? this.labelFormatter(t, d) : `${v.formatNumber(t)}, ${v.formatNumber(d)}` : i;
410
+ }
411
+ if (a.length > 0)
412
+ return a.forEach((d) => {
413
+ s.push(
414
+ `<div><span style="display:inline-block;width:8px;height:8px;border-radius:50%;background:${d.color};margin-right:6px;"></span>${d.name}: ${v.formatNumber(d.y, 4)}</div>`
415
+ );
416
+ }), s.join("");
417
+ const u = this.getOrderedSeries().find((d) => d && d.visible !== !1), h = u != null && u.name ? String(u.name) : "值";
418
+ return s.push(`<div>${h}: ${v.formatNumber(e, 4)}</div>`), s.join("");
419
+ }
420
+ formatXText(t) {
421
+ if (Number.isFinite(t) && Math.abs(t) > 1e11) {
422
+ const e = new Date(t);
423
+ if (!Number.isNaN(e.getTime())) {
424
+ const i = (n) => String(n).padStart(2, "0");
425
+ return `${e.getFullYear()}/${i(e.getMonth() + 1)}/${i(e.getDate())} ${i(e.getHours())}:${i(e.getMinutes())}:${i(e.getSeconds())}`;
426
+ }
427
+ }
428
+ return `X: ${v.formatNumber(t, 4)}`;
429
+ }
430
+ getOrderedSeries() {
431
+ return this.getSeriesList().slice().sort((t, e) => {
432
+ var s, a;
433
+ const i = typeof ((s = t.options) == null ? void 0 : s.legendIndex) == "number" ? t.options.legendIndex : Number(t.index || 0), n = typeof ((a = e.options) == null ? void 0 : a.legendIndex) == "number" ? e.options.legendIndex : Number(e.index || 0);
434
+ return i - n;
435
+ });
436
+ }
437
+ getOrderedVisibleSeriesPointsAtX(t) {
438
+ const e = [];
439
+ return this.getOrderedSeries().forEach((i) => {
440
+ if (!i || i.visible === !1) return;
441
+ const n = this.getSeriesPointByX(i, t);
442
+ n && e.push({
443
+ ...n,
444
+ color: i.color || "#409EFF",
445
+ name: String(i.name || "Series")
446
+ });
447
+ }), e;
448
+ }
449
+ getSeriesPointByX(t, e) {
450
+ const i = this.getXData(t);
451
+ if (!(i != null && i.length)) return null;
452
+ const n = v.getMostNearIndex(e, i);
453
+ if (n < 0) return null;
454
+ const s = i[n];
455
+ let a;
456
+ const u = t.yData || t.processedYData;
457
+ if (u && u[n] !== void 0)
458
+ a = u[n];
459
+ else if (t.options.data && t.options.data[n] !== void 0) {
460
+ const h = t.options.data[n];
461
+ a = Array.isArray(h) ? h[1] : typeof h == "object" ? h.y : h;
462
+ }
463
+ return typeof a != "number" || Number.isNaN(a) ? null : { x: s, y: a, index: n };
464
+ }
465
+ scheduleSeriesHoverState(t) {
466
+ var e;
467
+ !this.multiLine || !((e = this.chart) != null && e.chart) || (this.hoverDebounceTimer !== null && window.clearTimeout(this.hoverDebounceTimer), this.hoverDebounceTimer = window.setTimeout(() => {
468
+ this.applySeriesHoverState(t), this.hoverDebounceTimer = null;
469
+ }, 32));
470
+ }
471
+ applySeriesHoverState(t) {
472
+ this.getSeriesList().forEach((e) => {
473
+ !e || e.visible === !1 || typeof e.setState == "function" && e.setState(t ? "hover" : "");
474
+ });
475
+ }
476
+ destroy() {
477
+ var t, e, i;
478
+ this.hoverDebounceTimer !== null && (window.clearTimeout(this.hoverDebounceTimer), this.hoverDebounceTimer = null), this.applySeriesHoverState(!1), (t = this.chart) != null && t.chart && ((i = (e = this.chart.chart.xAxis) == null ? void 0 : e[0]) == null || i.removePlotLine(L), this.chart.chart.removeAnnotation("activePoint"), this.chart.chart.removeAnnotation("activePoint-line"), this.chart.chart.removeAnnotation("activePoint-marker"), this.chart.chart.removeAnnotation("activePoint-label"), this.chart.chart.removeAnnotation("active")), this.cursorLabel && (this.cursorLabel.destroy(), this.cursorLabel = null), this.cursorHitLine && (this.cursorHitLine.destroy(), this.cursorHitLine = null), this.unbindEvents(), super.destroy();
479
+ }
480
+ }
481
+ class F extends E {
482
+ constructor(t = {}) {
483
+ super(t);
484
+ r(this, "name", "SidebandPlugin");
485
+ r(this, "delta", 0);
486
+ r(this, "lineCount", 5);
487
+ r(this, "lineIds", []);
488
+ r(this, "isDragging", !1);
489
+ r(this, "draggedLineIndex", null);
490
+ // -3 to 3, excluding 0
491
+ r(this, "onDeltaChange", null);
492
+ r(this, "lineColor", "green");
493
+ r(this, "dashStyle", "Dash");
494
+ r(this, "labelOptions", {
495
+ align: "center",
496
+ style: { color: "green" },
497
+ y: 30
498
+ });
499
+ r(this, "directShow", !1);
500
+ r(this, "xAxisUnit", "Hz");
501
+ r(this, "onMouseUpBound");
502
+ r(this, "onContainerMouseMoveBound");
503
+ r(this, "eventsBound", !1);
504
+ this.delta = t.initialDelta || 0, this.lineCount = t.lineCount || 5, this.directShow = !!t.directShow, this.xAxisUnit = t.xAxisUnit || "Hz", this.lineColor = t.color || "green", this.dashStyle = t.dashStyle || "Dash", t.labelColor && (this.labelOptions = {
505
+ ...this.labelOptions,
506
+ style: { ...this.labelOptions.style, color: t.labelColor }
507
+ }), this.onDeltaChange = typeof t.onDeltaChange == "function" ? t.onDeltaChange : null, this.onMouseUpBound = this.onMouseUp.bind(this), this.onContainerMouseMoveBound = this.onContainerMouseMove.bind(this);
508
+ }
509
+ setLineCount(t) {
510
+ this.lineCount = t, this.enabled && this.chart && this.chart.activePoint && this.renderSidebands(this.chart.activePoint);
511
+ }
512
+ getLineCount() {
513
+ return this.lineCount;
514
+ }
515
+ setDelta(t) {
516
+ this.delta = t, this.onDeltaChange && this.onDeltaChange(this.delta), this.enabled && this.chart && this.chart.activePoint && this.renderSidebands(this.chart.activePoint);
517
+ }
518
+ getDelta() {
519
+ return this.delta;
520
+ }
521
+ /** 边频标签:频谱图直接显示 Hz;时域图将 ms 间隔换算为 Hz */
522
+ formatSidebandLabel(t) {
523
+ if (this.xAxisUnit === "ms") {
524
+ if (t <= 0) return "▲ -- HZ";
525
+ const e = 1e3 / t;
526
+ return `▲ ${v.formatNumber(e, 2)}HZ`;
527
+ }
528
+ return `▲${v.formatNumber(t, 3)} HZ`;
529
+ }
530
+ isEnabled() {
531
+ return super.isEnabled();
532
+ }
533
+ setDirectShow(t) {
534
+ this.directShow = t, t && this.chart && this.chart.activePoint && this.renderSidebands(this.chart.activePoint);
535
+ }
536
+ init(t) {
537
+ super.init(t), this.directShow && this.enable();
538
+ }
539
+ bindEvents() {
540
+ this.eventsBound || !this.chart || !this.chart.container || (this.eventsBound = !0, this.chart.container.addEventListener("mousemove", this.onContainerMouseMoveBound), document.addEventListener("mouseup", this.onMouseUpBound));
541
+ }
542
+ unbindEvents() {
543
+ var t, e;
544
+ this.eventsBound && (this.eventsBound = !1, document.removeEventListener("mouseup", this.onMouseUpBound), (e = (t = this.chart) == null ? void 0 : t.container) == null || e.removeEventListener("mousemove", this.onContainerMouseMoveBound));
545
+ }
546
+ onMouseUp() {
547
+ const t = this.isDragging;
548
+ this.isDragging = !1, this.draggedLineIndex = null, t && this.onDeltaChange && this.onDeltaChange(this.delta);
549
+ }
550
+ onCursorChange(t) {
551
+ this.enabled && this.renderSidebands(t);
552
+ }
553
+ enable() {
554
+ if (super.enable(), this.bindEvents(), this.chart && this.chart.activePoint) {
555
+ if (this.delta === 0) {
556
+ const e = this.chart.chart.xAxis[0].getExtremes();
557
+ this.delta = (e.max - e.min) / 20;
558
+ }
559
+ this.renderSidebands(this.chart.activePoint);
560
+ }
561
+ }
562
+ disable() {
563
+ super.disable(), this.unbindEvents(), this.clearLines();
564
+ }
565
+ clearLines() {
566
+ if (!this.chart || !this.chart.chart) return;
567
+ const t = this.chart.chart.xAxis[0];
568
+ this.lineIds.forEach((e) => t.removePlotLine(e)), this.lineIds = [];
569
+ }
570
+ renderSidebands(t) {
571
+ if (!this.chart || !this.chart.chart) return;
572
+ this.clearLines();
573
+ const e = this.chart.chart.xAxis[0], i = [];
574
+ for (let n = 1; n <= this.lineCount; n++)
575
+ i.push(-n), i.push(n);
576
+ i.forEach((n) => {
577
+ const s = t.x + n * this.delta, a = `sideband-${n}`;
578
+ this.lineIds.push(a);
579
+ const u = Math.abs(n) === 1, h = Math.abs(s - t.x);
580
+ e.addPlotLine({
581
+ id: a,
582
+ value: s,
583
+ color: this.lineColor,
584
+ width: 1,
585
+ dashStyle: this.dashStyle,
586
+ zIndex: 4,
587
+ label: u ? {
588
+ text: this.formatSidebandLabel(h),
589
+ ...this.labelOptions
590
+ } : void 0
591
+ });
592
+ const c = `${a}-hit`;
593
+ this.lineIds.push(c), e.addPlotLine({
594
+ id: c,
595
+ value: s,
596
+ color: "transparent",
597
+ width: 10,
598
+ zIndex: 5,
599
+ events: {
600
+ mousedown: (f) => {
601
+ this.isDragging = !0, this.draggedLineIndex = n, f.preventDefault(), f.stopPropagation();
602
+ },
603
+ mouseover: () => {
604
+ const f = e.plotLinesAndBands.find((p) => p.id === c);
605
+ f && f.svgElem && f.svgElem.css({ cursor: "col-resize" });
606
+ }
607
+ }
608
+ });
609
+ const d = e.plotLinesAndBands.find((f) => f.id === a);
610
+ d && d.svgElem && d.svgElem.css({ cursor: "col-resize" });
611
+ });
612
+ }
613
+ onContainerMouseMove(t) {
614
+ if (this.isDragging && this.draggedLineIndex !== null && this.chart && this.chart.activePoint) {
615
+ const e = this.chart.chart.pointer.normalize(t), i = this.chart.chart.xAxis[0].toValue(e.chartX), n = this.chart.activePoint.x, s = (i - n) / this.draggedLineIndex;
616
+ this.delta = Math.abs(s), this.renderSidebands(this.chart.activePoint);
617
+ }
618
+ }
619
+ destroy() {
620
+ super.destroy();
621
+ }
622
+ }
623
+ class X extends E {
624
+ constructor(t = {}) {
625
+ super(t);
626
+ r(this, "name", "ThresholdLinePlugin");
627
+ r(this, "yValue", 0);
628
+ r(this, "lineId", "threshold-line");
629
+ r(this, "isDragging", !1);
630
+ r(this, "annotationId", "threshold-line-annotation");
631
+ r(this, "onContainerMouseMoveBound");
632
+ r(this, "onMouseUpBound");
633
+ r(this, "eventsBound", !1);
634
+ this.yValue = t.initialValue || 0, this.onContainerMouseMoveBound = this.onContainerMouseMove.bind(this), this.onMouseUpBound = this.onMouseUp.bind(this);
635
+ }
636
+ init(t) {
637
+ super.init(t);
638
+ }
639
+ bindEvents() {
640
+ this.eventsBound || !this.chart || !this.chart.container || (this.eventsBound = !0, this.chart.container.addEventListener("mousemove", this.onContainerMouseMoveBound), document.addEventListener("mouseup", this.onMouseUpBound));
641
+ }
642
+ unbindEvents() {
643
+ var t, e;
644
+ this.eventsBound && (this.eventsBound = !1, (e = (t = this.chart) == null ? void 0 : t.container) == null || e.removeEventListener("mousemove", this.onContainerMouseMoveBound), document.removeEventListener("mouseup", this.onMouseUpBound));
645
+ }
646
+ destroy() {
647
+ super.destroy();
648
+ }
649
+ onMouseUp() {
650
+ this.isDragging = !1, this.chart && this.chart.container && (this.chart.container.style.cursor = "default");
651
+ }
652
+ enable() {
653
+ if (super.enable(), this.bindEvents(), this.chart && this.chart.chart) {
654
+ const e = this.chart.chart.yAxis[0].getExtremes();
655
+ this.yValue === 0 && (this.yValue = (e.max + e.min) / 2), this.renderLine();
656
+ }
657
+ }
658
+ disable() {
659
+ super.disable(), this.unbindEvents(), this.clear();
660
+ }
661
+ clear() {
662
+ if (!this.chart || !this.chart.chart) return;
663
+ const t = this.chart.chart.yAxis[0];
664
+ t.removePlotLine(this.lineId), t.removePlotLine(`${this.lineId}-hit`), this.clearMarkers();
665
+ }
666
+ setValue(t) {
667
+ this.yValue = t, this.enabled && this.renderLine();
668
+ }
669
+ getValue() {
670
+ return this.yValue;
671
+ }
672
+ clearMarkers() {
673
+ if (this.chart && this.chart.chart) {
674
+ const t = this.chart.chart;
675
+ t.removeAnnotation && t.removeAnnotation(this.annotationId);
676
+ }
677
+ }
678
+ renderLine() {
679
+ if (!this.chart || !this.chart.chart) return;
680
+ const e = this.chart.chart.yAxis[0];
681
+ e.removePlotLine(this.lineId), e.addPlotLine({
682
+ id: this.lineId,
683
+ value: this.yValue,
684
+ color: "purple",
685
+ width: 1,
686
+ dashStyle: "Solid",
687
+ zIndex: 5,
688
+ label: {
689
+ text: `Threshold: ${v.formatNumber(this.yValue)}`,
690
+ align: "right",
691
+ style: { color: "purple" },
692
+ x: -10
693
+ },
694
+ events: {
695
+ mouseover: () => {
696
+ const s = e.plotLinesAndBands.find((a) => a.id === this.lineId);
697
+ s && s.svgElem && s.svgElem.css({ cursor: "row-resize" });
698
+ },
699
+ mousedown: (s) => {
700
+ this.isDragging = !0, s.preventDefault(), s.stopPropagation();
701
+ }
702
+ }
703
+ });
704
+ const i = `${this.lineId}-hit`;
705
+ e.removePlotLine(i), e.addPlotLine({
706
+ id: i,
707
+ value: this.yValue,
708
+ color: "transparent",
709
+ width: 10,
710
+ zIndex: 6,
711
+ events: {
712
+ mouseover: () => {
713
+ const s = e.plotLinesAndBands.find((a) => a.id === i);
714
+ s && s.svgElem && s.svgElem.css({ cursor: "row-resize" });
715
+ },
716
+ mousedown: (s) => {
717
+ this.isDragging = !0, s.preventDefault(), s.stopPropagation();
718
+ }
719
+ }
720
+ });
721
+ const n = e.plotLinesAndBands.find((s) => s.id === this.lineId);
722
+ n && n.svgElem && n.svgElem.css({ cursor: "row-resize" }), this.markPointsAboveThreshold();
723
+ }
724
+ getData(t) {
725
+ let e = t.xData || t.processedXData, i = t.yData || t.processedYData;
726
+ if (e && i) return { xData: e, yData: i };
727
+ if (t.options && t.options.data) {
728
+ const n = t.options.data;
729
+ if (Array.isArray(n)) {
730
+ if (n.length === 0) return { xData: [], yData: [] };
731
+ if (Array.isArray(n[0]))
732
+ e = n.map((s) => s[0]), i = n.map((s) => s[1]);
733
+ else if (typeof n[0] == "object" && n[0] !== null)
734
+ e = n.map((s) => s.x), i = n.map((s) => s.y);
735
+ else if (typeof n[0] == "number") {
736
+ const s = t.options.pointStart || 0, a = t.options.pointInterval || 1;
737
+ i = n, e = i.map((u, h) => s + h * a);
738
+ }
739
+ }
740
+ }
741
+ return { xData: e || null, yData: i || null };
742
+ }
743
+ markPointsAboveThreshold() {
744
+ if (!this.chart || !this.chart.chart) return;
745
+ const t = this.chart.chart, e = t.series[0];
746
+ if (!e) return;
747
+ this.clearMarkers();
748
+ const { xData: i, yData: n } = this.getData(e);
749
+ if (!i || !n) return;
750
+ const s = [];
751
+ for (let u = 0; u < n.length; u++) {
752
+ const h = n[u];
753
+ h > this.yValue && s.push({ x: i[u], y: h });
754
+ }
755
+ if (s.length === 0) return;
756
+ const a = s.map((u, h) => ({
757
+ point: {
758
+ xAxis: 0,
759
+ yAxis: 0,
760
+ x: u.x,
761
+ y: u.y
762
+ },
763
+ text: `${h + 1}`
764
+ }));
765
+ t.addAnnotation({
766
+ id: this.annotationId,
767
+ labelOptions: {
768
+ allowOverlap: !0,
769
+ backgroundColor: "rgba(255,255,255,0)",
770
+ borderColor: "transparent",
771
+ style: {
772
+ color: "purple",
773
+ fontSize: "10px",
774
+ fontWeight: "bold",
775
+ textOutline: "none"
776
+ },
777
+ y: -5
778
+ },
779
+ labels: a,
780
+ zIndex: 6
781
+ });
782
+ }
783
+ onContainerMouseMove(t) {
784
+ if (this.isDragging && this.chart) {
785
+ const e = this.chart.chart.pointer.normalize(t), i = this.chart.chart.yAxis[0].toValue(e.chartY);
786
+ this.yValue = i, this.renderLine();
787
+ }
788
+ }
789
+ }
790
+ class j extends E {
791
+ constructor(t = {}) {
792
+ super(t);
793
+ r(this, "name", "ZoomPlugin");
794
+ r(this, "startX", 0);
795
+ r(this, "onMouseDownBound");
796
+ r(this, "onMouseUpBound");
797
+ r(this, "onContextMenuBound");
798
+ r(this, "onMouseMoveBound");
799
+ r(this, "isPanning", !1);
800
+ r(this, "lastX", 0);
801
+ r(this, "rightMouseDown", !1);
802
+ r(this, "panMoved", !1);
803
+ r(this, "eventsBound", !1);
804
+ this.onMouseDownBound = this.onMouseDown.bind(this), this.onMouseUpBound = this.onMouseUp.bind(this), this.onContextMenuBound = this.onContextMenu.bind(this), this.onMouseMoveBound = this.onMouseMove.bind(this);
805
+ }
806
+ init(t) {
807
+ super.init(t);
808
+ }
809
+ bindEvents() {
810
+ this.eventsBound || !this.chart || !this.chart.container || (this.eventsBound = !0, this.chart.container.addEventListener("mousedown", this.onMouseDownBound), document.addEventListener("mouseup", this.onMouseUpBound), this.chart.container.addEventListener("contextmenu", this.onContextMenuBound), document.addEventListener("mousemove", this.onMouseMoveBound));
811
+ }
812
+ unbindEvents() {
813
+ var t, e, i, n;
814
+ this.eventsBound && (this.eventsBound = !1, (e = (t = this.chart) == null ? void 0 : t.container) == null || e.removeEventListener("mousedown", this.onMouseDownBound), (n = (i = this.chart) == null ? void 0 : i.container) == null || n.removeEventListener("contextmenu", this.onContextMenuBound), document.removeEventListener("mouseup", this.onMouseUpBound), document.removeEventListener("mousemove", this.onMouseMoveBound));
815
+ }
816
+ enable() {
817
+ super.enable(), this.bindEvents();
818
+ }
819
+ disable() {
820
+ super.disable(), this.rightMouseDown = !1, this.isPanning = !1, this.unbindEvents();
821
+ }
822
+ onContextMenu(t) {
823
+ (this.isPanning || this.panMoved) && t.preventDefault();
824
+ }
825
+ onMouseDown(t) {
826
+ t.button === 0 ? this.startX = t.clientX : t.button === 2 && (this.rightMouseDown = !0, this.panMoved = !1, this.isPanning = !1, this.lastX = t.clientX);
827
+ }
828
+ onMouseMove(t) {
829
+ var x, g;
830
+ if (!((x = this.chart) != null && x.chart) || !this.rightMouseDown) return;
831
+ const e = t.clientX - this.lastX;
832
+ if (this.lastX = t.clientX, !this.isPanning) {
833
+ if (Math.abs(e) < 2) return;
834
+ this.isPanning = !0, this.panMoved = !0, (g = this.chart) != null && g.container && (this.chart.container.style.cursor = "move");
835
+ }
836
+ const i = this.chart.chart, n = i.xAxis[0], s = n.getExtremes(), a = typeof n.dataMin == "number" && Number.isFinite(n.dataMin) ? n.dataMin : s.dataMin, u = typeof n.dataMax == "number" && Number.isFinite(n.dataMax) ? n.dataMax : s.dataMax, h = s.max - s.min, c = i.plotWidth;
837
+ if (!Number.isFinite(h) || h <= 0 || !Number.isFinite(c) || c <= 0)
838
+ return;
839
+ const d = h / c, f = e * d;
840
+ let p = s.min - f, m = s.max - f;
841
+ p < a && (p = a, m = p + h), m > u && (m = u, p = m - h), n.setExtremes(p, m, !0, !1), t.preventDefault();
842
+ }
843
+ onMouseUp(t) {
844
+ var e, i, n;
845
+ if (t.button === 0) {
846
+ const s = t.clientX;
847
+ if (this.startX - s > 10) {
848
+ const u = (e = this.chart) == null ? void 0 : e.chart.xAxis[0];
849
+ if (!u) return;
850
+ const h = u.getExtremes(), c = typeof u.dataMin == "number" && Number.isFinite(u.dataMin) ? u.dataMin : h.dataMin, d = typeof u.dataMax == "number" && Number.isFinite(u.dataMax) ? u.dataMax : h.dataMax;
851
+ if (c != null && d != null && Math.abs(h.min - c) < 1e-9 && Math.abs(h.max - d) < 1e-9) return;
852
+ I((i = this.chart) == null ? void 0 : i.container), setTimeout(() => {
853
+ var g, C;
854
+ const p = (g = this.chart) == null ? void 0 : g.chart.xAxis[0];
855
+ if (!p) return;
856
+ const m = p.dataMin !== void 0 ? p.dataMin : p.getExtremes().dataMin, x = p.dataMax !== void 0 ? p.dataMax : p.getExtremes().dataMax;
857
+ m !== void 0 && x !== void 0 ? p.setExtremes(m, x) : (C = this.chart) == null || C.chart.zoomOut();
858
+ }, 10);
859
+ }
860
+ }
861
+ t.button === 2 && (this.rightMouseDown = !1, this.isPanning = !1, (n = this.chart) != null && n.container && (this.chart.container.style.cursor = ""), setTimeout(() => {
862
+ this.panMoved = !1;
863
+ }, 0));
864
+ }
865
+ destroy() {
866
+ super.destroy();
867
+ }
868
+ }
869
+ const S = "hchart-context-menu";
870
+ function z(l) {
871
+ return l.replace(/[\\/:*?"<>|]+/g, "_").replace(/\s+/g, " ").trim();
872
+ }
873
+ function H(l, o) {
874
+ var e;
875
+ const t = l.getPlugin("SidebandPlugin");
876
+ (e = t == null ? void 0 : t.setLineCount) == null || e.call(t, o);
877
+ }
878
+ function $(l, o) {
879
+ var a, u, h, c;
880
+ const t = l.chart, e = typeof (o == null ? void 0 : o.fileName) == "function" ? o.fileName(l) : o == null ? void 0 : o.fileName, i = e ? z(e) : void 0, n = {
881
+ type: "image/png",
882
+ ...(o == null ? void 0 : o.exportOptions) || {},
883
+ ...i ? { filename: i } : {}
884
+ }, s = {
885
+ ...(o == null ? void 0 : o.exportChartOptions) || {},
886
+ chart: {
887
+ ...((a = o == null ? void 0 : o.exportChartOptions) == null ? void 0 : a.chart) || {},
888
+ backgroundColor: ((h = (u = o == null ? void 0 : o.exportChartOptions) == null ? void 0 : u.chart) == null ? void 0 : h.backgroundColor) || (o == null ? void 0 : o.exportBackgroundColor) || "#ffffff"
889
+ }
890
+ };
891
+ typeof t.exportChartLocal == "function" ? t.exportChartLocal(n, s) : (c = t.exportChart) == null || c.call(t, n, s);
892
+ }
893
+ const y = class y extends E {
894
+ constructor(t = {}) {
895
+ super(t);
896
+ r(this, "name", "ContextMenuPlugin");
897
+ r(this, "items");
898
+ r(this, "labels");
899
+ r(this, "translate");
900
+ r(this, "menu", null);
901
+ r(this, "eventsBound", !1);
902
+ r(this, "contextStart", null);
903
+ r(this, "onContextMenuBound", (t) => this.onContextMenu(t));
904
+ r(this, "onMouseDownBound", (t) => this.onMouseDown(t));
905
+ r(this, "onDocumentClickBound", () => this.hideMenu());
906
+ this.labels = t.labels || {}, this.translate = t.translate, this.items = this.resolveItems(t.items);
907
+ }
908
+ static get BUILTIN_ITEMS() {
909
+ return {
910
+ sideband: { label: "Sideband", pluginName: "SidebandPlugin" },
911
+ threshold_line: { label: "Threshold line", pluginName: "ThresholdLinePlugin" },
912
+ band_count: {
913
+ label: "Band count",
914
+ inputType: "number",
915
+ value: 5,
916
+ min: 1,
917
+ max: 10,
918
+ onInput: (t, e) => {
919
+ const i = Number.parseInt(t, 10);
920
+ Number.isFinite(i) && H(e, Math.min(10, Math.max(1, i)));
921
+ }
922
+ },
923
+ export: { label: "Export PNG", action: $ }
924
+ };
925
+ }
926
+ static get DEFAULT_ITEMS() {
927
+ return Object.values(y.BUILTIN_ITEMS);
928
+ }
929
+ init(t) {
930
+ super.init(t), y.activeInstances.add(this), this.addRequiredPlugins(t);
931
+ }
932
+ enable() {
933
+ super.enable(), this.createMenu(), this.bindEvents();
934
+ }
935
+ disable() {
936
+ this.hideMenu(), this.unbindEvents(), super.disable();
937
+ }
938
+ destroy() {
939
+ var t;
940
+ y.activeInstances.delete(this), super.destroy(), (t = this.menu) == null || t.remove(), this.menu = null;
941
+ }
942
+ resolveItems(t) {
943
+ const e = this.localizedBuiltinItems();
944
+ return (t || Object.keys(e)).map((n) => {
945
+ if (typeof n == "string") {
946
+ const a = e[n];
947
+ return a ? { ...a, id: n, type: "builtin" } : { label: n, type: "custom" };
948
+ }
949
+ const s = n.id;
950
+ if (n.type === "builtin" || s && e[s]) {
951
+ const a = s ? e[s] : void 0;
952
+ return a ? { ...a, ...n, id: s, type: "builtin" } : n;
953
+ }
954
+ return n;
955
+ });
956
+ }
957
+ localizedBuiltinItems() {
958
+ const t = y.BUILTIN_ITEMS;
959
+ return Object.keys(t).forEach((e) => {
960
+ var n;
961
+ const i = t[e].label || e;
962
+ t[e] = {
963
+ ...t[e],
964
+ label: this.labels[e] || ((n = this.translate) == null ? void 0 : n.call(this, e, i)) || i
965
+ };
966
+ }), t;
967
+ }
968
+ addRequiredPlugins(t) {
969
+ this.items.forEach((e) => {
970
+ if (!e.pluginName || t.getPlugin(e.pluginName)) return;
971
+ const i = this.createPlugin(e.pluginName);
972
+ i && t.addPlugin(i);
973
+ });
974
+ }
975
+ createPlugin(t) {
976
+ switch (t) {
977
+ case "SidebandPlugin":
978
+ return new F({ enabled: !1 });
979
+ case "ThresholdLinePlugin":
980
+ return new X({ enabled: !1 });
981
+ default:
982
+ return null;
983
+ }
984
+ }
985
+ createMenu() {
986
+ if (this.menu || typeof document > "u") return;
987
+ const t = document.createElement("div");
988
+ t.className = S, t.style.position = "fixed", t.style.display = "none", t.style.minWidth = "160px", t.style.padding = "5px 0", t.style.background = "var(--hchart-menu-background, #ffffff)", t.style.border = "1px solid var(--hchart-menu-border, #dcdfe6)", t.style.borderRadius = "4px", t.style.boxShadow = "var(--hchart-menu-shadow, 2px 2px 8px rgba(0, 0, 0, 0.15))", t.style.color = "var(--hchart-menu-color, #303133)", t.style.fontSize = "12px", t.style.zIndex = String(this.resolveZIndex()), document.body.appendChild(t), this.menu = t;
989
+ }
990
+ bindEvents() {
991
+ var t;
992
+ this.eventsBound || !((t = this.chart) != null && t.container) || (this.eventsBound = !0, this.chart.container.addEventListener("contextmenu", this.onContextMenuBound), this.chart.container.addEventListener("mousedown", this.onMouseDownBound), document.addEventListener("click", this.onDocumentClickBound));
993
+ }
994
+ unbindEvents() {
995
+ var t, e, i, n;
996
+ this.eventsBound && (this.eventsBound = !1, (e = (t = this.chart) == null ? void 0 : t.container) == null || e.removeEventListener("contextmenu", this.onContextMenuBound), (n = (i = this.chart) == null ? void 0 : i.container) == null || n.removeEventListener("mousedown", this.onMouseDownBound), document.removeEventListener("click", this.onDocumentClickBound));
997
+ }
998
+ onMouseDown(t) {
999
+ this.contextStart = t.button === 2 ? { x: t.clientX, y: t.clientY } : null;
1000
+ }
1001
+ onContextMenu(t) {
1002
+ if (!this.enabled) return;
1003
+ const e = this.contextStart && Math.hypot(t.clientX - this.contextStart.x, t.clientY - this.contextStart.y) > 5;
1004
+ this.contextStart = null, !(e || t.ctrlKey) && (t.preventDefault(), t.stopPropagation(), this.showMenu(t.clientX, t.clientY));
1005
+ }
1006
+ showMenu(t, e) {
1007
+ if (!this.menu || !this.chart) return;
1008
+ y.activeInstances.forEach((s) => {
1009
+ s !== this && s.hideMenu();
1010
+ }), this.menu.replaceChildren(...this.items.map((s) => this.createMenuItem(s))), this.menu.style.display = "block", this.menu.style.visibility = "hidden", this.menu.style.zIndex = String(this.resolveZIndex());
1011
+ const i = Math.max(0, Math.min(t, window.innerWidth - this.menu.offsetWidth)), n = Math.max(0, Math.min(e, window.innerHeight - this.menu.offsetHeight));
1012
+ this.menu.style.left = `${i}px`, this.menu.style.top = `${n}px`, this.menu.style.visibility = "visible";
1013
+ }
1014
+ createMenuItem(t) {
1015
+ var s, a, u;
1016
+ const e = document.createElement("div");
1017
+ e.style.display = "flex", e.style.alignItems = "center", e.style.gap = "6px", e.style.minHeight = "30px", e.style.padding = "0 10px", e.style.whiteSpace = "nowrap", e.style.position = "relative";
1018
+ const i = (h) => {
1019
+ e.style.background = h ? "var(--hchart-menu-hover, #f0f0f0)" : "transparent";
1020
+ };
1021
+ if (e.addEventListener("mouseenter", () => i(!0)), e.addEventListener("mouseleave", () => i(!1)), t.inputType)
1022
+ return this.createInputItem(e, t), e;
1023
+ if (t.pluginName) {
1024
+ const h = (s = this.chart) == null ? void 0 : s.getPlugin(t.pluginName), c = document.createElement("span");
1025
+ c.style.width = "12px", c.textContent = (a = h == null ? void 0 : h.isEnabled) != null && a.call(h) ? "*" : "", e.appendChild(c);
1026
+ }
1027
+ const n = document.createElement("span");
1028
+ return n.textContent = t.label || "", n.style.flex = "1", e.appendChild(n), (u = t.items) != null && u.length ? (this.createSubmenu(e, t.items), e) : (e.style.cursor = "pointer", e.addEventListener("click", (h) => {
1029
+ h.stopPropagation(), this.handleItem(t), this.hideMenu();
1030
+ }), e);
1031
+ }
1032
+ createInputItem(t, e) {
1033
+ const i = document.createElement("span");
1034
+ i.textContent = e.label || "", i.style.flex = "1", t.appendChild(i);
1035
+ const n = document.createElement("input");
1036
+ n.type = e.inputType || "text", n.value = String(this.resolveInputValue(e)), n.style.width = "64px", n.style.border = "1px solid var(--hchart-menu-border, #dcdfe6)", n.style.borderRadius = "3px", n.style.padding = "2px 4px", e.min !== void 0 && (n.min = String(e.min)), e.max !== void 0 && (n.max = String(e.max)), n.addEventListener("click", (s) => s.stopPropagation()), n.addEventListener("change", () => {
1037
+ var a;
1038
+ const s = this.clampInputValue(n.value, e);
1039
+ n.value = s, this.chart && ((a = e.onInput) == null || a.call(e, s, this.chart));
1040
+ }), t.appendChild(n);
1041
+ }
1042
+ createSubmenu(t, e) {
1043
+ const i = document.createElement("span");
1044
+ i.textContent = ">", t.appendChild(i);
1045
+ const n = document.createElement("div");
1046
+ n.className = `${S}-sub`, n.style.display = "none", n.style.position = "absolute", n.style.left = "100%", n.style.top = "0", n.style.minWidth = "150px", n.style.padding = "5px 0", n.style.background = "var(--hchart-menu-background, #ffffff)", n.style.border = "1px solid var(--hchart-menu-border, #dcdfe6)", n.style.boxShadow = "var(--hchart-menu-shadow, 2px 2px 8px rgba(0, 0, 0, 0.15))", n.replaceChildren(...e.map((s) => this.createMenuItem(s))), t.appendChild(n), t.addEventListener("mouseenter", () => {
1047
+ n.style.display = "block";
1048
+ }), t.addEventListener("mouseleave", () => {
1049
+ n.style.display = "none";
1050
+ });
1051
+ }
1052
+ resolveInputValue(t) {
1053
+ var i;
1054
+ if (t.id !== "band_count" || !this.chart) return t.value || "";
1055
+ const e = this.chart.getPlugin("SidebandPlugin");
1056
+ return ((i = e == null ? void 0 : e.getLineCount) == null ? void 0 : i.call(e)) || t.value || "";
1057
+ }
1058
+ clampInputValue(t, e) {
1059
+ if (e.inputType !== "number") return t;
1060
+ let i = Number.parseFloat(t);
1061
+ return Number.isFinite(i) ? (e.min !== void 0 && (i = Math.max(e.min, i)), e.max !== void 0 && (i = Math.min(e.max, i)), String(i)) : t;
1062
+ }
1063
+ handleItem(t) {
1064
+ var i;
1065
+ if (!this.chart) return;
1066
+ if (t.action) {
1067
+ t.action(this.chart, t);
1068
+ return;
1069
+ }
1070
+ if (!t.pluginName) return;
1071
+ const e = this.chart.getPlugin(t.pluginName);
1072
+ (i = e == null ? void 0 : e.isEnabled) != null && i.call(e) ? e.disable() : e == null || e.enable();
1073
+ }
1074
+ hideMenu() {
1075
+ this.menu && (this.menu.style.display = "none");
1076
+ }
1077
+ resolveZIndex() {
1078
+ return typeof this.options.zIndex == "number" && this.options.zIndex > 0 ? this.options.zIndex : 1e4;
1079
+ }
1080
+ };
1081
+ r(y, "activeInstances", /* @__PURE__ */ new Set());
1082
+ let B = y;
1083
+ function R(l, o) {
1084
+ var e;
1085
+ const t = l.getPlugin("SidebandPlugin");
1086
+ (e = t == null ? void 0 : t.setLineCount) == null || e.call(t, o);
1087
+ }
1088
+ function O(l, o) {
1089
+ const t = Number.parseFloat(l);
1090
+ if (!Number.isFinite(t)) return;
1091
+ const e = o.chart.xAxis[0], { min: i, max: n } = e.getExtremes();
1092
+ !Number.isFinite(i) || !Number.isFinite(n) || e.setExtremes(i, t > i ? t : n);
1093
+ }
1094
+ function V(l, o) {
1095
+ const [t, e] = l.split(",").map((i) => Number.parseFloat(i.trim()));
1096
+ !Number.isFinite(t) || !Number.isFinite(e) || t >= e || o.chart.xAxis[0].setExtremes(t, e);
1097
+ }
1098
+ function _(l, o) {
1099
+ const t = Number.parseFloat(l);
1100
+ if (!Number.isFinite(t)) return;
1101
+ const e = o.chart.xAxis[0];
1102
+ e.removePlotLine("hchart-feature-frequency"), e.addPlotLine({
1103
+ id: "hchart-feature-frequency",
1104
+ value: t,
1105
+ color: "#909399",
1106
+ width: 1,
1107
+ dashStyle: "ShortDash",
1108
+ zIndex: 6,
1109
+ label: {
1110
+ text: `Feature ${t}`,
1111
+ style: { color: "#909399" }
1112
+ }
1113
+ });
1114
+ }
1115
+ function Z() {
1116
+ return [
1117
+ { id: "sideband", type: "builtin", label: "Sidebands" },
1118
+ { id: "threshold_line", type: "builtin", label: "Threshold line" },
1119
+ {
1120
+ id: "band_count",
1121
+ type: "builtin",
1122
+ label: "Band count",
1123
+ inputType: "number",
1124
+ value: 5,
1125
+ min: 1,
1126
+ max: 10
1127
+ },
1128
+ { id: "export", type: "builtin", label: "Export PNG" },
1129
+ {
1130
+ label: "Stop frequency",
1131
+ inputType: "number",
1132
+ value: "",
1133
+ onInput: O
1134
+ },
1135
+ {
1136
+ label: "Data range (min, max)",
1137
+ inputType: "text",
1138
+ value: "",
1139
+ onInput: V
1140
+ },
1141
+ {
1142
+ label: "Feature frequency",
1143
+ inputType: "number",
1144
+ value: "",
1145
+ onInput: _
1146
+ }
1147
+ ];
1148
+ }
1149
+ function G() {
1150
+ return [
1151
+ { id: "sideband", type: "builtin", label: "Sidebands" },
1152
+ { id: "threshold_line", type: "builtin", label: "Threshold line" },
1153
+ { id: "export", type: "builtin", label: "Export PNG" }
1154
+ ];
1155
+ }
1156
+ function J() {
1157
+ return [
1158
+ {
1159
+ id: "band_count",
1160
+ type: "builtin",
1161
+ label: "Band count",
1162
+ inputType: "number",
1163
+ value: 1,
1164
+ min: 1,
1165
+ max: 50,
1166
+ onInput: (l, o) => {
1167
+ const t = Number.parseInt(l, 10);
1168
+ Number.isFinite(t) && R(o, Math.min(50, Math.max(1, t)));
1169
+ }
1170
+ },
1171
+ { id: "sideband", type: "builtin", label: "Sidebands" }
1172
+ ];
1173
+ }
1174
+ class Q extends E {
1175
+ constructor(t = {}) {
1176
+ super(t);
1177
+ r(this, "name", "AnnotationPlugin");
1178
+ r(this, "cursorPoint", null);
1179
+ r(this, "labelFormatter", null);
1180
+ r(this, "markerRadius", 2);
1181
+ r(this, "markerColor", "#ff4d4f");
1182
+ r(this, "marks", []);
1183
+ r(this, "seq", 0);
1184
+ r(this, "draggingId", null);
1185
+ r(this, "dragStart", { x: 0, y: 0, dx: 0, dy: 0 });
1186
+ r(this, "onMouseMoveBound", null);
1187
+ r(this, "onMouseUpBound", null);
1188
+ r(this, "unbindRedraw", null);
1189
+ this.labelFormatter = t.labelFormatter || null, typeof t.markerRadius == "number" && (this.markerRadius = t.markerRadius), typeof t.markerColor == "string" && (this.markerColor = t.markerColor);
1190
+ }
1191
+ init(t) {
1192
+ super.init(t);
1193
+ }
1194
+ onCursorChange(t) {
1195
+ this.cursorPoint = t;
1196
+ }
1197
+ enable() {
1198
+ super.enable(), this.bindEvents(), this.render();
1199
+ }
1200
+ disable() {
1201
+ this.clearAllMarks(), this.unbindEvents(), super.disable();
1202
+ }
1203
+ bindEvents() {
1204
+ var t;
1205
+ this.unbindRedraw || !((t = this.chart) != null && t.chart) || (this.unbindRedraw = A.addEvent(this.chart.chart, "redraw", () => {
1206
+ this.updateAllPositions();
1207
+ }));
1208
+ }
1209
+ unbindEvents() {
1210
+ this.unbindRedraw && this.unbindRedraw(), this.unbindRedraw = null, this.stopDragging();
1211
+ }
1212
+ update(t) {
1213
+ super.update(t), typeof t.markerRadius == "number" && (this.markerRadius = t.markerRadius), typeof t.markerColor == "string" && (this.markerColor = t.markerColor), typeof t.labelFormatter == "function" && (this.labelFormatter = t.labelFormatter), this.render();
1214
+ }
1215
+ markCurrentPoint() {
1216
+ var e;
1217
+ const t = ((e = this.chart) == null ? void 0 : e.activePoint) || this.cursorPoint;
1218
+ t && this.markPoint(t);
1219
+ }
1220
+ markPoint(t) {
1221
+ const i = {
1222
+ id: `m${++this.seq}`,
1223
+ point: { ...t },
1224
+ labelEl: null,
1225
+ connectorEl: null,
1226
+ offset: { dx: 0, dy: 0 }
1227
+ };
1228
+ this.marks.push(i), this.renderMark(i);
1229
+ }
1230
+ clearMark() {
1231
+ this.clearAllMarks();
1232
+ }
1233
+ getMarkedPoint() {
1234
+ const t = this.marks[this.marks.length - 1];
1235
+ return t ? { ...t.point } : null;
1236
+ }
1237
+ getMarkedPoints() {
1238
+ return this.marks.map((t) => ({ ...t.point }));
1239
+ }
1240
+ render() {
1241
+ var t;
1242
+ this.enabled && (t = this.chart) != null && t.chart && this.marks.forEach((e) => this.renderMark(e));
1243
+ }
1244
+ clearAllMarks() {
1245
+ var e;
1246
+ if (!((e = this.chart) != null && e.chart)) return;
1247
+ const t = this.chart.chart;
1248
+ this.marks.forEach((i) => {
1249
+ t.removeAnnotation(this.getMarkerAnnotationId(i.id)), i.labelEl && (i.labelEl.destroy(), i.labelEl = null), i.connectorEl && (i.connectorEl.destroy(), i.connectorEl = null);
1250
+ }), this.marks = [], this.draggingId = null, t.redraw();
1251
+ }
1252
+ getMarkerAnnotationId(t) {
1253
+ return `hchart-annotation-marker-${t}`;
1254
+ }
1255
+ renderMark(t) {
1256
+ var e;
1257
+ this.enabled && (e = this.chart) != null && e.chart && (this.drawMarker(t), this.ensureLabel(t), this.ensureConnector(t), this.updateMarkPosition(t));
1258
+ }
1259
+ drawMarker(t) {
1260
+ var s;
1261
+ if (!((s = this.chart) != null && s.chart)) return;
1262
+ const e = this.chart.chart, i = this.getMarkerAnnotationId(t.id);
1263
+ e.removeAnnotation(i);
1264
+ const n = {
1265
+ id: i,
1266
+ zIndex: 9999,
1267
+ shapes: [
1268
+ {
1269
+ type: "circle",
1270
+ point: {
1271
+ xAxis: 0,
1272
+ yAxis: 0,
1273
+ x: t.point.x,
1274
+ y: t.point.y
1275
+ },
1276
+ r: this.markerRadius,
1277
+ fill: this.markerColor,
1278
+ stroke: this.markerColor,
1279
+ strokeWidth: 1
1280
+ }
1281
+ ]
1282
+ };
1283
+ e.addAnnotation(n);
1284
+ }
1285
+ ensureLabel(t) {
1286
+ var n;
1287
+ if (!((n = this.chart) != null && n.chart)) return;
1288
+ const e = this.chart.chart, i = this.labelFormatter ? this.labelFormatter(t.point.x, t.point.y) : `${v.formatNumber(t.point.x)}, ${v.formatNumber(t.point.y)}`;
1289
+ if (t.labelEl)
1290
+ t.labelEl.attr({ text: i });
1291
+ else {
1292
+ t.labelEl = e.renderer.label(i, e.plotLeft, e.plotTop).css({
1293
+ color: "var(--hchart-text-color, #606266)",
1294
+ fontSize: "12px"
1295
+ }).attr({
1296
+ zIndex: 1e4
1297
+ }).add();
1298
+ const s = t.labelEl.element;
1299
+ s.style.cursor = "move", s.addEventListener("mousedown", (a) => this.onLabelMouseDown(a, t.id));
1300
+ }
1301
+ }
1302
+ ensureConnector(t) {
1303
+ var i;
1304
+ if (!((i = this.chart) != null && i.chart)) return;
1305
+ const e = this.chart.chart;
1306
+ t.connectorEl || (t.connectorEl = e.renderer.path([]).attr({
1307
+ zIndex: 9999
1308
+ }).css({
1309
+ stroke: this.markerColor,
1310
+ strokeWidth: 1,
1311
+ fill: "none"
1312
+ }).add());
1313
+ }
1314
+ updateAllPositions() {
1315
+ var t;
1316
+ (t = this.chart) != null && t.chart && this.marks.forEach((e) => this.updateMarkPosition(e));
1317
+ }
1318
+ updateMarkPosition(t) {
1319
+ var f;
1320
+ if (!((f = this.chart) != null && f.chart) || !t.labelEl) return;
1321
+ const e = this.chart.chart, i = e.xAxis[0], n = e.yAxis[0], s = i.toPixels(t.point.x, !1), a = n.toPixels(t.point.y, !1), u = 10, h = -28, c = s + u + t.offset.dx, d = a + h + t.offset.dy;
1322
+ t.labelEl.attr({ x: c, y: d }), this.updateConnectorPosition(t, s, a, c, d);
1323
+ }
1324
+ updateConnectorPosition(t, e, i, n, s) {
1325
+ if (!t.connectorEl || !t.labelEl) return;
1326
+ const a = t.labelEl.getBBox(), u = n, h = s + Math.max(10, a.height * 0.5);
1327
+ t.connectorEl.attr({
1328
+ d: ["M", e, i, "L", u, h]
1329
+ });
1330
+ }
1331
+ onLabelMouseDown(t, e) {
1332
+ const i = this.marks.find((n) => n.id === e);
1333
+ !i || !i.labelEl || (t.preventDefault(), t.stopPropagation(), this.draggingId = e, this.dragStart = {
1334
+ x: t.clientX,
1335
+ y: t.clientY,
1336
+ dx: i.offset.dx,
1337
+ dy: i.offset.dy
1338
+ }, this.onMouseMoveBound = (n) => this.onLabelMouseMove(n), this.onMouseUpBound = (n) => this.onLabelMouseUp(n), document.addEventListener("mousemove", this.onMouseMoveBound), document.addEventListener("mouseup", this.onMouseUpBound));
1339
+ }
1340
+ onLabelMouseMove(t) {
1341
+ if (!this.draggingId) return;
1342
+ const e = this.marks.find((s) => s.id === this.draggingId);
1343
+ if (!e) return;
1344
+ const i = t.clientX - this.dragStart.x, n = t.clientY - this.dragStart.y;
1345
+ e.offset = {
1346
+ dx: this.dragStart.dx + i,
1347
+ dy: this.dragStart.dy + n
1348
+ }, this.updateMarkPosition(e);
1349
+ }
1350
+ onLabelMouseUp(t) {
1351
+ this.draggingId && (this.draggingId = null, this.onMouseMoveBound && document.removeEventListener("mousemove", this.onMouseMoveBound), this.onMouseUpBound && document.removeEventListener("mouseup", this.onMouseUpBound), this.onMouseMoveBound = null, this.onMouseUpBound = null);
1352
+ }
1353
+ stopDragging() {
1354
+ this.draggingId = null, this.onMouseMoveBound && document.removeEventListener("mousemove", this.onMouseMoveBound), this.onMouseUpBound && document.removeEventListener("mouseup", this.onMouseUpBound), this.onMouseMoveBound = null, this.onMouseUpBound = null;
1355
+ }
1356
+ destroy() {
1357
+ this.clearAllMarks(), this.unbindEvents(), super.destroy();
1358
+ }
1359
+ }
1360
+ export {
1361
+ Q as AnnotationPlugin,
1362
+ E as BasePlugin,
1363
+ B as ContextMenuPlugin,
1364
+ W as CursorLinkPlugin,
1365
+ K as CursorPlugin,
1366
+ nt as HChart,
1367
+ F as SidebandPlugin,
1368
+ X as ThresholdLinePlugin,
1369
+ v as Utils,
1370
+ j as ZoomPlugin,
1371
+ N as createCursorSyncState,
1372
+ G as createEnvelopeContextMenuItems,
1373
+ Z as createSpectrumContextMenuItems,
1374
+ J as createWaveContextMenuItems,
1375
+ U as shouldSuppressCursorClick,
1376
+ I as suppressCursorClick
1377
+ };