@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.
@@ -0,0 +1,245 @@
1
+ var m = Object.defineProperty;
2
+ var g = (i, e, t) => e in i ? m(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
+ var a = (i, e, t) => g(i, typeof e != "symbol" ? e + "" : e, t);
4
+ import * as c from "highcharts";
5
+ import x from "highcharts/highcharts-more";
6
+ import b from "highcharts/modules/exporting";
7
+ import p from "highcharts/modules/annotations";
8
+ import y from "highcharts/modules/boost";
9
+ import v from "highcharts/modules/mouse-wheel-zoom";
10
+ const d = () => typeof window < "u" && typeof document < "u";
11
+ let u = !1;
12
+ function s(i) {
13
+ typeof i == "function" && i(c);
14
+ }
15
+ function w() {
16
+ u || !d() || (s(x), s(b), s(p), s(y), s(v), u = !0);
17
+ }
18
+ const l = 24 * 60 * 60 * 1e3, C = () => Intl.DateTimeFormat().resolvedOptions().timeZone || "Asia/Shanghai", D = function() {
19
+ const i = Number(this.value);
20
+ if (!Number.isFinite(i)) return this.text ?? "";
21
+ const { min: e, max: t } = this.axis.getExtremes(), r = Math.abs(Number(t) - Number(e));
22
+ return r >= 365 * l ? this.chart.time.dateFormat("%Y", i) : r >= 90 * l ? this.chart.time.dateFormat("%Y-%m", i) : r >= 2 * l ? this.chart.time.dateFormat("%Y-%m-%d", i) : r >= l ? this.chart.time.dateFormat("%m-%d %H:%M", i) : this.chart.time.dateFormat("%Y-%m-%d %H:%M:%S", i);
23
+ };
24
+ class L {
25
+ constructor(e) {
26
+ a(this, "chart");
27
+ a(this, "plugins", /* @__PURE__ */ new Map());
28
+ a(this, "container");
29
+ a(this, "activePoint", null);
30
+ a(this, "resizeObserver", null);
31
+ a(this, "reflowFrame", null);
32
+ if (!d())
33
+ throw new Error("HChart requires a browser DOM. Create the chart in onMounted or another client-only lifecycle hook.");
34
+ if (w(), this.container = typeof e.container == "string" ? document.getElementById(e.container) : e.container, !this.container)
35
+ throw new Error("HChart container was not found. Pass an HTMLElement or a mounted element id.");
36
+ typeof ResizeObserver < "u" && (this.resizeObserver = new ResizeObserver(() => this.requestReflow()), this.resizeObserver.observe(this.container)), this.container.setAttribute("tabindex", "0"), this.container.style.outline = "none";
37
+ const t = {
38
+ boost: { enabled: !1 },
39
+ accessibility: { enabled: !1 },
40
+ // 与 dayjs/new Date 的浏览器本地时区保持一致,避免 datetime X 轴按 UTC 渲染。
41
+ time: { timezone: C() },
42
+ scrollbar: { enabled: !0 },
43
+ chart: {
44
+ backgroundColor: "rgba(0, 0, 0, 0)",
45
+ zooming: {
46
+ type: "x",
47
+ // Native zooming (Left->Right)
48
+ mouseWheel: {
49
+ enabled: !0,
50
+ type: "x"
51
+ }
52
+ },
53
+ panning: {
54
+ enabled: !1,
55
+ // Disable native panning to avoid conflict with custom Ctrl+Right
56
+ type: "x"
57
+ },
58
+ spacing: [10, 5, 5, 20],
59
+ // Compact layout
60
+ panKey: "shift",
61
+ animation: !1,
62
+ resetZoomButton: { position: { x: 0, y: -300 } },
63
+ events: {
64
+ click: (n) => this.onChartClick(n),
65
+ selection: () => !0
66
+ }
67
+ },
68
+ title: { text: void 0 },
69
+ subtitle: { text: void 0 },
70
+ legend: { enabled: !1 },
71
+ exporting: { enabled: !1 },
72
+ credits: { enabled: !1 },
73
+ tooltip: { enabled: !1 },
74
+ plotOptions: {
75
+ series: {
76
+ color: "var(--hchart-primary-color, #409eff)",
77
+ cursor: "pointer",
78
+ lineWidth: 1.2,
79
+ // Align with aes-analysis-admin
80
+ marker: this.resolveMarkerConfig(e),
81
+ // Dynamic marker config
82
+ states: {
83
+ hover: { enabled: !1 },
84
+ // Disable hover effect
85
+ inactive: { opacity: 1 }
86
+ },
87
+ events: {
88
+ click: (n) => this.onChartClick(n)
89
+ }
90
+ }
91
+ },
92
+ xAxis: {
93
+ gridLineColor: "rgba(128,128,128,0.2)",
94
+ minorGridLineColor: "rgba(128,128,128,0.2)",
95
+ lineColor: "rgba(128,128,128,0.2)",
96
+ minorGridLineDashStyle: "Dot",
97
+ minorTickInterval: "auto",
98
+ gridLineDashStyle: "Solid",
99
+ title: {
100
+ style: { color: "var(--hchart-text-color, #606266)" }
101
+ },
102
+ labels: {
103
+ formatter: function() {
104
+ return this.axis.options.type === "datetime" ? D.call(this) : this.text ?? "";
105
+ },
106
+ style: { fontSize: "10px", color: "var(--hchart-text-color, #606266)" },
107
+ // Compact font
108
+ y: 15
109
+ // Compact spacing
110
+ }
111
+ },
112
+ yAxis: {
113
+ gridLineColor: "rgba(128,128,128,0.2)",
114
+ minorGridLineColor: "rgba(128,128,128,0.2)",
115
+ minorGridLineDashStyle: "Dot",
116
+ minorTickInterval: "auto",
117
+ title: {
118
+ align: "high",
119
+ offset: 0,
120
+ rotation: 0,
121
+ y: -15,
122
+ x: 0,
123
+ textAlign: "left",
124
+ reserveSpace: !1,
125
+ style: { color: "var(--hchart-text-color, #606266)" }
126
+ },
127
+ labels: {
128
+ style: { fontSize: "10px", color: "var(--hchart-text-color, #606266)" },
129
+ // Compact font
130
+ x: -5
131
+ // Compact spacing
132
+ }
133
+ }
134
+ }, r = c.merge(t, e.options || {});
135
+ this.chart = c.chart(this.container, r), e.plugins && e.plugins.forEach((n) => {
136
+ this.addPlugin(n);
137
+ });
138
+ }
139
+ addPlugin(e) {
140
+ if (this.plugins.has(e.name)) {
141
+ console.warn(`Plugin ${e.name} already exists.`);
142
+ return;
143
+ }
144
+ e.init(this), this.plugins.set(e.name, e);
145
+ }
146
+ getPlugin(e) {
147
+ return this.plugins.get(e);
148
+ }
149
+ removePlugin(e) {
150
+ const t = this.plugins.get(e);
151
+ t && (t.destroy(), this.plugins.delete(e));
152
+ }
153
+ /**
154
+ * Coalesce multiple size changes into one chart reflow in the next animation frame.
155
+ * ResizeObserver can fire repeatedly while split panes and cards are animating.
156
+ */
157
+ requestReflow() {
158
+ if (this.reflowFrame !== null) return;
159
+ const e = typeof window.requestAnimationFrame == "function" ? window.requestAnimationFrame.bind(window) : (t) => window.setTimeout(t, 0);
160
+ this.reflowFrame = e(() => {
161
+ this.reflowFrame = null, this.chart && this.chart.reflow();
162
+ });
163
+ }
164
+ destroy() {
165
+ this.reflowFrame !== null && (typeof window.cancelAnimationFrame == "function" ? window.cancelAnimationFrame(this.reflowFrame) : window.clearTimeout(this.reflowFrame), this.reflowFrame = null), this.resizeObserver && (this.resizeObserver.disconnect(), this.resizeObserver = null), this.plugins.forEach((e) => e.destroy()), this.plugins.clear(), this.chart && this.chart.destroy();
166
+ }
167
+ onChartClick(e) {
168
+ this.plugins.forEach((t) => {
169
+ t.onChartClick && t.onChartClick(e);
170
+ });
171
+ }
172
+ setCursor(e) {
173
+ this.activePoint && e.x === this.activePoint.x && e.y === this.activePoint.y && e.index === this.activePoint.index || (this.activePoint = e, this.plugins.forEach((t) => {
174
+ t.onCursorChange && t.onCursorChange(e);
175
+ }));
176
+ }
177
+ /**
178
+ * Set cursor by X value (will snap to nearest point)
179
+ */
180
+ setCursorX(e) {
181
+ const t = this.getPlugin("CursorPlugin");
182
+ t && typeof t.updateCursor == "function" && t.updateCursor(e);
183
+ }
184
+ /**
185
+ * Toggle a plugin by name
186
+ */
187
+ togglePlugin(e, t) {
188
+ const r = this.getPlugin(e);
189
+ r && (t ? r.enable() : r.disable());
190
+ }
191
+ /** Update the underlying Highcharts options without recreating plugins. */
192
+ updateOptions(e, t = !0) {
193
+ this.chart.update(e, t);
194
+ }
195
+ /** Replace one series data set through the stable HChart API. */
196
+ setSeriesData(e, t = 0, r = !0) {
197
+ const n = this.chart.series[t];
198
+ n && n.setData(e, r);
199
+ }
200
+ getSeriesData() {
201
+ const e = this.chart.series[0];
202
+ if (!e) return [];
203
+ const t = e.processedXData || e.xData, r = e.processedYData || e.yData;
204
+ return !t || !r ? [] : t.map((n, o) => [n, r[o]]);
205
+ }
206
+ resolveMarkerConfig(e) {
207
+ var r, n, o;
208
+ const t = e.markerConfig || {};
209
+ if (t.enabled !== void 0)
210
+ return { enabled: t.enabled, radius: 2.5 };
211
+ if (t.auto) {
212
+ const f = t.threshold || 50, h = (n = (r = e.options) == null ? void 0 : r.series) == null ? void 0 : n[0];
213
+ return { enabled: (((o = h == null ? void 0 : h.data) == null ? void 0 : o.length) || 0) <= f, radius: 2.5 };
214
+ }
215
+ return { enabled: !1, radius: 2.5 };
216
+ }
217
+ /**
218
+ * Adds a static reference line (vertical or horizontal) to the chart.
219
+ * Useful for thresholds, limits, or markers.
220
+ *
221
+ * @param options Configuration for the reference line
222
+ * @returns The unique ID of the added line (use to remove later)
223
+ */
224
+ addReferenceLine(e) {
225
+ const t = e.axis === "y" ? this.chart.yAxis[0] : this.chart.xAxis[0], r = `ref-line-${Date.now()}-${Math.random()}`;
226
+ return t.addPlotLine({
227
+ id: r,
228
+ value: e.value,
229
+ color: e.color || "red",
230
+ width: e.width || 2,
231
+ dashStyle: e.dashStyle || "Dash",
232
+ zIndex: e.zIndex || 5,
233
+ label: e.text ? {
234
+ text: e.text,
235
+ style: { color: e.color || "red" }
236
+ } : void 0
237
+ }), r;
238
+ }
239
+ removeReferenceLine(e, t = "x") {
240
+ (t === "y" ? this.chart.yAxis[0] : this.chart.xAxis[0]).removePlotLine(e);
241
+ }
242
+ }
243
+ export {
244
+ L as H
245
+ };
@@ -0,0 +1 @@
1
+ "use strict";var m=Object.defineProperty;var g=(i,e,t)=>e in i?m(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var s=(i,e,t)=>g(i,typeof e!="symbol"?e+"":e,t);const b=require("highcharts"),y=require("highcharts/highcharts-more"),x=require("highcharts/modules/exporting"),p=require("highcharts/modules/annotations"),v=require("highcharts/modules/boost"),w=require("highcharts/modules/mouse-wheel-zoom");function C(i){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(i){for(const t in i)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(i,t);Object.defineProperty(e,t,r.get?r:{enumerable:!0,get:()=>i[t]})}}return e.default=i,Object.freeze(e)}const h=C(b),d=()=>typeof window<"u"&&typeof document<"u";let u=!1;function a(i){typeof i=="function"&&i(h)}function D(){u||!d()||(a(y),a(x),a(p),a(v),a(w),u=!0)}const l=24*60*60*1e3,P=()=>Intl.DateTimeFormat().resolvedOptions().timeZone||"Asia/Shanghai",F=function(){const i=Number(this.value);if(!Number.isFinite(i))return this.text??"";const{min:e,max:t}=this.axis.getExtremes(),r=Math.abs(Number(t)-Number(e));return r>=365*l?this.chart.time.dateFormat("%Y",i):r>=90*l?this.chart.time.dateFormat("%Y-%m",i):r>=2*l?this.chart.time.dateFormat("%Y-%m-%d",i):r>=l?this.chart.time.dateFormat("%m-%d %H:%M",i):this.chart.time.dateFormat("%Y-%m-%d %H:%M:%S",i)};class O{constructor(e){s(this,"chart");s(this,"plugins",new Map);s(this,"container");s(this,"activePoint",null);s(this,"resizeObserver",null);s(this,"reflowFrame",null);if(!d())throw new Error("HChart requires a browser DOM. Create the chart in onMounted or another client-only lifecycle hook.");if(D(),this.container=typeof e.container=="string"?document.getElementById(e.container):e.container,!this.container)throw new Error("HChart container was not found. Pass an HTMLElement or a mounted element id.");typeof ResizeObserver<"u"&&(this.resizeObserver=new ResizeObserver(()=>this.requestReflow()),this.resizeObserver.observe(this.container)),this.container.setAttribute("tabindex","0"),this.container.style.outline="none";const t={boost:{enabled:!1},accessibility:{enabled:!1},time:{timezone:P()},scrollbar:{enabled:!0},chart:{backgroundColor:"rgba(0, 0, 0, 0)",zooming:{type:"x",mouseWheel:{enabled:!0,type:"x"}},panning:{enabled:!1,type:"x"},spacing:[10,5,5,20],panKey:"shift",animation:!1,resetZoomButton:{position:{x:0,y:-300}},events:{click:n=>this.onChartClick(n),selection:()=>!0}},title:{text:void 0},subtitle:{text:void 0},legend:{enabled:!1},exporting:{enabled:!1},credits:{enabled:!1},tooltip:{enabled:!1},plotOptions:{series:{color:"var(--hchart-primary-color, #409eff)",cursor:"pointer",lineWidth:1.2,marker:this.resolveMarkerConfig(e),states:{hover:{enabled:!1},inactive:{opacity:1}},events:{click:n=>this.onChartClick(n)}}},xAxis:{gridLineColor:"rgba(128,128,128,0.2)",minorGridLineColor:"rgba(128,128,128,0.2)",lineColor:"rgba(128,128,128,0.2)",minorGridLineDashStyle:"Dot",minorTickInterval:"auto",gridLineDashStyle:"Solid",title:{style:{color:"var(--hchart-text-color, #606266)"}},labels:{formatter:function(){return this.axis.options.type==="datetime"?F.call(this):this.text??""},style:{fontSize:"10px",color:"var(--hchart-text-color, #606266)"},y:15}},yAxis:{gridLineColor:"rgba(128,128,128,0.2)",minorGridLineColor:"rgba(128,128,128,0.2)",minorGridLineDashStyle:"Dot",minorTickInterval:"auto",title:{align:"high",offset:0,rotation:0,y:-15,x:0,textAlign:"left",reserveSpace:!1,style:{color:"var(--hchart-text-color, #606266)"}},labels:{style:{fontSize:"10px",color:"var(--hchart-text-color, #606266)"},x:-5}}},r=h.merge(t,e.options||{});this.chart=h.chart(this.container,r),e.plugins&&e.plugins.forEach(n=>{this.addPlugin(n)})}addPlugin(e){if(this.plugins.has(e.name)){console.warn(`Plugin ${e.name} already exists.`);return}e.init(this),this.plugins.set(e.name,e)}getPlugin(e){return this.plugins.get(e)}removePlugin(e){const t=this.plugins.get(e);t&&(t.destroy(),this.plugins.delete(e))}requestReflow(){if(this.reflowFrame!==null)return;const e=typeof window.requestAnimationFrame=="function"?window.requestAnimationFrame.bind(window):t=>window.setTimeout(t,0);this.reflowFrame=e(()=>{this.reflowFrame=null,this.chart&&this.chart.reflow()})}destroy(){this.reflowFrame!==null&&(typeof window.cancelAnimationFrame=="function"?window.cancelAnimationFrame(this.reflowFrame):window.clearTimeout(this.reflowFrame),this.reflowFrame=null),this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null),this.plugins.forEach(e=>e.destroy()),this.plugins.clear(),this.chart&&this.chart.destroy()}onChartClick(e){this.plugins.forEach(t=>{t.onChartClick&&t.onChartClick(e)})}setCursor(e){this.activePoint&&e.x===this.activePoint.x&&e.y===this.activePoint.y&&e.index===this.activePoint.index||(this.activePoint=e,this.plugins.forEach(t=>{t.onCursorChange&&t.onCursorChange(e)}))}setCursorX(e){const t=this.getPlugin("CursorPlugin");t&&typeof t.updateCursor=="function"&&t.updateCursor(e)}togglePlugin(e,t){const r=this.getPlugin(e);r&&(t?r.enable():r.disable())}updateOptions(e,t=!0){this.chart.update(e,t)}setSeriesData(e,t=0,r=!0){const n=this.chart.series[t];n&&n.setData(e,r)}getSeriesData(){const e=this.chart.series[0];if(!e)return[];const t=e.processedXData||e.xData,r=e.processedYData||e.yData;return!t||!r?[]:t.map((n,o)=>[n,r[o]])}resolveMarkerConfig(e){var r,n,o;const t=e.markerConfig||{};if(t.enabled!==void 0)return{enabled:t.enabled,radius:2.5};if(t.auto){const f=t.threshold||50,c=(n=(r=e.options)==null?void 0:r.series)==null?void 0:n[0];return{enabled:(((o=c==null?void 0:c.data)==null?void 0:o.length)||0)<=f,radius:2.5}}return{enabled:!1,radius:2.5}}addReferenceLine(e){const t=e.axis==="y"?this.chart.yAxis[0]:this.chart.xAxis[0],r=`ref-line-${Date.now()}-${Math.random()}`;return t.addPlotLine({id:r,value:e.value,color:e.color||"red",width:e.width||2,dashStyle:e.dashStyle||"Dash",zIndex:e.zIndex||5,label:e.text?{text:e.text,style:{color:e.color||"red"}}:void 0}),r}removeReferenceLine(e,t="x"){(t==="y"?this.chart.yAxis[0]:this.chart.xAxis[0]).removePlotLine(e)}}exports.HChart=O;
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";var U=Object.defineProperty;var F=(l,o,t)=>o in l?U(l,o,{enumerable:!0,configurable:!0,writable:!0,value:t}):l[o]=t;var r=(l,o,t)=>F(l,typeof o!="symbol"?o+"":o,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const X=require("./HChart-DKVtg5A8.cjs"),I=require("highcharts");class M{constructor(o={}){r(this,"chart",null);r(this,"enabled",!1);r(this,"options",{});this.options=o}init(o){this.chart=o,this.options.enabled!==!1&&this.enable()}destroy(){this.disable(),this.chart=null}enable(){this.enabled=!0}disable(){this.enabled=!1}isEnabled(){return this.enabled}update(o){this.options={...this.options,...o}}}class v{static getMostNearIndex(o,t){if(!t||t.length===0)return-1;let e=0,i=t.length-1;if(o>=t[i])return i;if(o<=t[e])return 0;let n=0;for(;i>=e;){const s=Math.round((e+i)/2);if(t[s]>o){if(s===0){n=0;break}if(t[s-1]>o)i=s-1;else{n=o-t[s-1]>=t[s]-o?s:s-1;break}}else if(t[s]<o){if(s===t.length-1){n=t.length-1;break}if(t[s+1]<o)e=s+1;else{n=o-t[s]>=t[s+1]-o?s+1:s;break}}else{n=s;break}}return n}static formatNumber(o,t=2){return o.toFixed(t)}}function w(){return{active:!1}}class z extends M{constructor(t){super({enabled:t.enabled!==!1});r(this,"name");r(this,"target");r(this,"syncState");this.name=t.name||"CursorLinkPlugin",this.target=t.target,this.syncState=t.syncState||w()}onCursorChange(t){if(!this.enabled||this.syncState.active||!Number.isFinite(t.x))return;const e=this.target();if(!(!e||typeof e.setCursorX!="function")){this.syncState.active=!0;try{e.setCursorX(t.x)}finally{this.syncState.active=!1}}}}const L="data-hchart-suppress-cursor-click",P="activePoint-cursor-line",H=8,S=220;function B(l,o=S){l&&(l.setAttribute(L,"1"),window.setTimeout(()=>l.removeAttribute(L),o))}function k(l){return(l==null?void 0:l.hasAttribute(L))??!1}class $ extends M{constructor(t={}){super(t);r(this,"name","CursorPlugin");r(this,"cursorLabel",null);r(this,"cursorHitLine",null);r(this,"activePoint",null);r(this,"onKeyDownBound");r(this,"labelFormatter",null);r(this,"onCursorMove",null);r(this,"isDragging",!1);r(this,"hoverDebounceTimer",null);r(this,"multiLine",!0);r(this,"draggable",!0);r(this,"pointerDown",null);r(this,"pointerDragged",!1);r(this,"suppressClickUntil",0);r(this,"eventsBound",!1);r(this,"unbindAfterSetExtremes",null);r(this,"onPointerDownBound");r(this,"onPointerMoveBound");r(this,"onPointerUpBound");r(this,"onContainerMouseMoveBound");r(this,"onContainerMouseUpBound");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}onContainerMouseMove(t){var n;this.trackPointerDrag(t);const e=this.getNativeChart(),i=(n=e==null?void 0:e.xAxis)==null?void 0:n[0];if(this.isDragging&&e&&i){const s=e.pointer.normalize(t),a=i.toValue(s.chartX);this.updateCursor(a)}}onPointerDown(t){t.button===0&&(this.pointerDown={x:t.clientX,y:t.clientY},this.pointerDragged=!1)}onPointerMove(t){this.trackPointerDrag(t)}trackPointerDrag(t){if(!this.pointerDown)return;Math.hypot(t.clientX-this.pointerDown.x,t.clientY-this.pointerDown.y)>H&&(this.pointerDragged=!0)}onPointerUp(t){var e;t.button===0&&(this.pointerDragged&&(this.suppressClickUntil=Date.now()+S,B((e=this.chart)==null?void 0:e.container,S)),this.pointerDown=null,this.pointerDragged=!1)}shouldIgnoreChartClick(){var e;const t=(e=this.chart)==null?void 0:e.container;return!!(k(t)||Date.now()<this.suppressClickUntil)}onContainerMouseUp(){this.isDragging&&(this.isDragging=!1),this.scheduleSeriesHoverState(!1)}init(t){super.init(t)}enable(){super.enable(),this.bindEvents()}disable(){super.disable(),this.unbindEvents()}onCursorChange(t){!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())}bindEvents(){var e;if(this.eventsBound||!((e=this.chart)!=null&&e.chart))return;this.eventsBound=!0;const t=this.chart.chart.xAxis[0];t&&(this.unbindAfterSetExtremes=I.addEvent(t,"afterSetExtremes",()=>{setTimeout(()=>this.refreshCursor(),0)})),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)}unbindEvents(){var t,e;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))}getNativeChart(){var e;const t=(e=this.chart)==null?void 0:e.chart;return!t||t.destroyed?null:t}getSeriesList(){var e;const t=(e=this.getNativeChart())==null?void 0:e.series;return Array.isArray(t)?t:[]}getXData(t){if(!t)return null;if(t.options.data){const i=t.options.data;if(Array.isArray(i)){if(Array.isArray(i[0]))return i.map(n=>n[0]);if(typeof i[0]=="object")return i.map(n=>n.x);if(typeof i[0]=="number")return i.map((n,s)=>(t.options.pointStart||0)+s*(t.options.pointInterval||1))}}let e=t.xData;return e||(e=t.processedXData,e?(console.warn("CursorPlugin: Using processedXData as fallback. Precision might be lost during zoom."),e):null)}onKeyDown(t){if(!this.activePoint||!this.getNativeChart())return;let e=0;if(t.key==="ArrowLeft"?e=-1:t.key==="ArrowRight"&&(e=1),e!==0){t.preventDefault();const i=this.getSeriesList()[0],n=this.getXData(i);if(n){let s=this.activePoint.index+e;s<0&&(s=0),s>=n.length&&(s=n.length-1),s!==this.activePoint.index&&this.updateCursor(n[s])}}}onChartClick(t){var s;if(!((s=this.chart)!=null&&s.chart)||this.shouldIgnoreChartClick())return;this.chart.container&&this.chart.container.focus();let e;const i=t,n=t;i.xAxis&&i.xAxis.length>0?e=i.xAxis[0].value:n.point&&(e=n.point.x),e!==void 0&&this.updateCursor(e)}updateCursor(t){var h,c;if(!this.getNativeChart())return;const e=this.getSeriesList()[0];if(!e)return;const i=this.getXData(e),n=e.yData||e.processedYData;if(!(i!=null&&i.length))return;const s=v.getMostNearIndex(t,i);if(s===-1)return;const a=i[s];let u;if(n&&n[s]!==void 0)u=n[s];else if(e.options.data&&e.options.data[s]){const d=e.options.data[s];u=Array.isArray(d)?d[1]:typeof d=="object"?d.y:d}else u=0;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})}refreshCursor(){this.activePoint&&this.updateCursor(this.activePoint.x)}drawCursor(){var m,x,g,C;const t=this.getNativeChart();if(!t||!this.activePoint)return;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];if(!n||!s)return;const a=n.toPixels(e,!1),u=[["M",a,t.plotTop],["L",a,t.plotTop+t.plotHeight]];t.removeAnnotation("activePoint"),t.removeAnnotation("activePoint-line"),t.removeAnnotation("activePoint-marker"),t.removeAnnotation("activePoint-label"),t.removeAnnotation("active"),n.removePlotLine(P),n.addPlotLine({id:P,value:e,color:"red",width:1,dashStyle:"DashDot",zIndex:9999}),(C=(g=n.plotLinesAndBands.find(b=>b.id===P))==null?void 0:g.svgElem)==null||C.css({pointerEvents:"none"});const h=s.getExtremes();t.addAnnotation({id:"activePoint-line",shapes:[{type:"path",points:[{xAxis:0,yAxis:0,x:e,y:h.min},{xAxis:0,yAxis:0,x:e,y:h.max}],stroke:"red",strokeWidth:1,dashStyle:"LongDashDot"}],zIndex:9998,visible:!0}),this.draggable?this.cursorHitLine?this.cursorHitLine.attr({d:u}):this.cursorHitLine=t.renderer.path(u).attr({stroke:"transparent","stroke-width":10,zIndex:1e4}).css({cursor:"col-resize"}).on("mousedown",b=>{const E=(b==null?void 0:b.originalEvent)??b;E!=null&&E.shiftKey&&(this.isDragging=!0,typeof E.preventDefault=="function"&&E.preventDefault(),typeof E.stopPropagation=="function"&&E.stopPropagation())}).on("mouseover",()=>{this.scheduleSeriesHoverState(!0)}).on("mouseout",()=>{this.scheduleSeriesHoverState(!1)}).add():this.cursorHitLine&&(this.cursorHitLine.destroy(),this.cursorHitLine=null);const c=this.multiLine?this.getOrderedVisibleSeriesPointsAtX(e):[{x:e,y:i,index:this.activePoint.index,color:"red",name:"active"}],d=[];c.forEach(b=>{d.push({type:"circle",point:{xAxis:0,yAxis:0,x:b.x,y:b.y},r:2.5,fill:"red",stroke:"red"}),d.push({type:"circle",point:{xAxis:0,yAxis:0,x:b.x,y:b.y},r:8,fill:"transparent",stroke:"transparent"})});const f={id:"activePoint-marker",shapes:d,zIndex:9999,visible:!0};t.addAnnotation(f);const p=this.buildCursorLabelText(e,i);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({color:"var(--hchart-text-color, #606266)",fontSize:"12px",lineHeight:"18px"}).attr({fill:"rgba(255,255,255,0)",stroke:"transparent","stroke-width":0,padding:8,r:4,zIndex:10001}).add(),window.setTimeout(()=>this.applyPassiveCursorLayer(),0)}isInteractivePlotLine(t){return t?!!(t.endsWith("-hit")||t.startsWith("sideband-")||t==="threshold-line"):!1}applyPassiveCursorLayer(){var n,s,a,u;if(this.draggable)return;const t=this.getNativeChart(),e=(n=this.chart)==null?void 0:n.container;if(!t||!e)return;const i=t;t.axes.forEach(h=>{h.plotLinesAndBands.forEach(c=>{var d;this.isInteractivePlotLine(c.id)||(d=c.svgElem)==null||d.css({pointerEvents:"none"})})}),(s=i.annotations)==null||s.forEach(h=>{var c,d,f;(c=h.group)==null||c.css({pointerEvents:"none"}),(d=h.labels)==null||d.forEach(p=>{var m;return(m=p.graphic)==null?void 0:m.css({pointerEvents:"none"})}),(f=h.shapes)==null||f.forEach(p=>{var m;return(m=p.graphic)==null?void 0:m.css({pointerEvents:"none"})})}),(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=>{h.style.pointerEvents="none"})}buildCursorLabelText(t,e){var c;const i=this.labelFormatter?this.labelFormatter(t,e):`${v.formatNumber(t)}, ${v.formatNumber(e)}`,s=[`<div><strong>${this.formatXText(t)}</strong></div>`];if(!this.getNativeChart())return i;const a=this.getOrderedVisibleSeriesPointsAtX(t);if(a.length<=1){const d=(c=a[0])==null?void 0:c.y;return typeof d=="number"?this.labelFormatter?this.labelFormatter(t,d):`${v.formatNumber(t)}, ${v.formatNumber(d)}`:i}if(a.length>0)return a.forEach(d=>{s.push(`<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>`)}),s.join("");const u=this.getOrderedSeries().find(d=>d&&d.visible!==!1),h=u!=null&&u.name?String(u.name):"值";return s.push(`<div>${h}: ${v.formatNumber(e,4)}</div>`),s.join("")}formatXText(t){if(Number.isFinite(t)&&Math.abs(t)>1e11){const e=new Date(t);if(!Number.isNaN(e.getTime())){const i=n=>String(n).padStart(2,"0");return`${e.getFullYear()}/${i(e.getMonth()+1)}/${i(e.getDate())} ${i(e.getHours())}:${i(e.getMinutes())}:${i(e.getSeconds())}`}}return`X: ${v.formatNumber(t,4)}`}getOrderedSeries(){return this.getSeriesList().slice().sort((t,e)=>{var s,a;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);return i-n})}getOrderedVisibleSeriesPointsAtX(t){const e=[];return this.getOrderedSeries().forEach(i=>{if(!i||i.visible===!1)return;const n=this.getSeriesPointByX(i,t);n&&e.push({...n,color:i.color||"#409EFF",name:String(i.name||"Series")})}),e}getSeriesPointByX(t,e){const i=this.getXData(t);if(!(i!=null&&i.length))return null;const n=v.getMostNearIndex(e,i);if(n<0)return null;const s=i[n];let a;const u=t.yData||t.processedYData;if(u&&u[n]!==void 0)a=u[n];else if(t.options.data&&t.options.data[n]!==void 0){const h=t.options.data[n];a=Array.isArray(h)?h[1]:typeof h=="object"?h.y:h}return typeof a!="number"||Number.isNaN(a)?null:{x:s,y:a,index:n}}scheduleSeriesHoverState(t){var e;!this.multiLine||!((e=this.chart)!=null&&e.chart)||(this.hoverDebounceTimer!==null&&window.clearTimeout(this.hoverDebounceTimer),this.hoverDebounceTimer=window.setTimeout(()=>{this.applySeriesHoverState(t),this.hoverDebounceTimer=null},32))}applySeriesHoverState(t){this.getSeriesList().forEach(e=>{!e||e.visible===!1||typeof e.setState=="function"&&e.setState(t?"hover":"")})}destroy(){var t,e,i;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(P),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()}}class N extends M{constructor(t={}){super(t);r(this,"name","SidebandPlugin");r(this,"delta",0);r(this,"lineCount",5);r(this,"lineIds",[]);r(this,"isDragging",!1);r(this,"draggedLineIndex",null);r(this,"onDeltaChange",null);r(this,"lineColor","green");r(this,"dashStyle","Dash");r(this,"labelOptions",{align:"center",style:{color:"green"},y:30});r(this,"directShow",!1);r(this,"xAxisUnit","Hz");r(this,"onMouseUpBound");r(this,"onContainerMouseMoveBound");r(this,"eventsBound",!1);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={...this.labelOptions,style:{...this.labelOptions.style,color:t.labelColor}}),this.onDeltaChange=typeof t.onDeltaChange=="function"?t.onDeltaChange:null,this.onMouseUpBound=this.onMouseUp.bind(this),this.onContainerMouseMoveBound=this.onContainerMouseMove.bind(this)}setLineCount(t){this.lineCount=t,this.enabled&&this.chart&&this.chart.activePoint&&this.renderSidebands(this.chart.activePoint)}getLineCount(){return this.lineCount}setDelta(t){this.delta=t,this.onDeltaChange&&this.onDeltaChange(this.delta),this.enabled&&this.chart&&this.chart.activePoint&&this.renderSidebands(this.chart.activePoint)}getDelta(){return this.delta}formatSidebandLabel(t){if(this.xAxisUnit==="ms"){if(t<=0)return"▲ -- HZ";const e=1e3/t;return`▲ ${v.formatNumber(e,2)}HZ`}return`▲${v.formatNumber(t,3)} HZ`}isEnabled(){return super.isEnabled()}setDirectShow(t){this.directShow=t,t&&this.chart&&this.chart.activePoint&&this.renderSidebands(this.chart.activePoint)}init(t){super.init(t),this.directShow&&this.enable()}bindEvents(){this.eventsBound||!this.chart||!this.chart.container||(this.eventsBound=!0,this.chart.container.addEventListener("mousemove",this.onContainerMouseMoveBound),document.addEventListener("mouseup",this.onMouseUpBound))}unbindEvents(){var t,e;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))}onMouseUp(){const t=this.isDragging;this.isDragging=!1,this.draggedLineIndex=null,t&&this.onDeltaChange&&this.onDeltaChange(this.delta)}onCursorChange(t){this.enabled&&this.renderSidebands(t)}enable(){if(super.enable(),this.bindEvents(),this.chart&&this.chart.activePoint){if(this.delta===0){const e=this.chart.chart.xAxis[0].getExtremes();this.delta=(e.max-e.min)/20}this.renderSidebands(this.chart.activePoint)}}disable(){super.disable(),this.unbindEvents(),this.clearLines()}clearLines(){if(!this.chart||!this.chart.chart)return;const t=this.chart.chart.xAxis[0];this.lineIds.forEach(e=>t.removePlotLine(e)),this.lineIds=[]}renderSidebands(t){if(!this.chart||!this.chart.chart)return;this.clearLines();const e=this.chart.chart.xAxis[0],i=[];for(let n=1;n<=this.lineCount;n++)i.push(-n),i.push(n);i.forEach(n=>{const s=t.x+n*this.delta,a=`sideband-${n}`;this.lineIds.push(a);const u=Math.abs(n)===1,h=Math.abs(s-t.x);e.addPlotLine({id:a,value:s,color:this.lineColor,width:1,dashStyle:this.dashStyle,zIndex:4,label:u?{text:this.formatSidebandLabel(h),...this.labelOptions}:void 0});const c=`${a}-hit`;this.lineIds.push(c),e.addPlotLine({id:c,value:s,color:"transparent",width:10,zIndex:5,events:{mousedown:f=>{this.isDragging=!0,this.draggedLineIndex=n,f.preventDefault(),f.stopPropagation()},mouseover:()=>{const f=e.plotLinesAndBands.find(p=>p.id===c);f&&f.svgElem&&f.svgElem.css({cursor:"col-resize"})}}});const d=e.plotLinesAndBands.find(f=>f.id===a);d&&d.svgElem&&d.svgElem.css({cursor:"col-resize"})})}onContainerMouseMove(t){if(this.isDragging&&this.draggedLineIndex!==null&&this.chart&&this.chart.activePoint){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;this.delta=Math.abs(s),this.renderSidebands(this.chart.activePoint)}}destroy(){super.destroy()}}class T extends M{constructor(t={}){super(t);r(this,"name","ThresholdLinePlugin");r(this,"yValue",0);r(this,"lineId","threshold-line");r(this,"isDragging",!1);r(this,"annotationId","threshold-line-annotation");r(this,"onContainerMouseMoveBound");r(this,"onMouseUpBound");r(this,"eventsBound",!1);this.yValue=t.initialValue||0,this.onContainerMouseMoveBound=this.onContainerMouseMove.bind(this),this.onMouseUpBound=this.onMouseUp.bind(this)}init(t){super.init(t)}bindEvents(){this.eventsBound||!this.chart||!this.chart.container||(this.eventsBound=!0,this.chart.container.addEventListener("mousemove",this.onContainerMouseMoveBound),document.addEventListener("mouseup",this.onMouseUpBound))}unbindEvents(){var t,e;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))}destroy(){super.destroy()}onMouseUp(){this.isDragging=!1,this.chart&&this.chart.container&&(this.chart.container.style.cursor="default")}enable(){if(super.enable(),this.bindEvents(),this.chart&&this.chart.chart){const e=this.chart.chart.yAxis[0].getExtremes();this.yValue===0&&(this.yValue=(e.max+e.min)/2),this.renderLine()}}disable(){super.disable(),this.unbindEvents(),this.clear()}clear(){if(!this.chart||!this.chart.chart)return;const t=this.chart.chart.yAxis[0];t.removePlotLine(this.lineId),t.removePlotLine(`${this.lineId}-hit`),this.clearMarkers()}setValue(t){this.yValue=t,this.enabled&&this.renderLine()}getValue(){return this.yValue}clearMarkers(){if(this.chart&&this.chart.chart){const t=this.chart.chart;t.removeAnnotation&&t.removeAnnotation(this.annotationId)}}renderLine(){if(!this.chart||!this.chart.chart)return;const e=this.chart.chart.yAxis[0];e.removePlotLine(this.lineId),e.addPlotLine({id:this.lineId,value:this.yValue,color:"purple",width:1,dashStyle:"Solid",zIndex:5,label:{text:`Threshold: ${v.formatNumber(this.yValue)}`,align:"right",style:{color:"purple"},x:-10},events:{mouseover:()=>{const s=e.plotLinesAndBands.find(a=>a.id===this.lineId);s&&s.svgElem&&s.svgElem.css({cursor:"row-resize"})},mousedown:s=>{this.isDragging=!0,s.preventDefault(),s.stopPropagation()}}});const i=`${this.lineId}-hit`;e.removePlotLine(i),e.addPlotLine({id:i,value:this.yValue,color:"transparent",width:10,zIndex:6,events:{mouseover:()=>{const s=e.plotLinesAndBands.find(a=>a.id===i);s&&s.svgElem&&s.svgElem.css({cursor:"row-resize"})},mousedown:s=>{this.isDragging=!0,s.preventDefault(),s.stopPropagation()}}});const n=e.plotLinesAndBands.find(s=>s.id===this.lineId);n&&n.svgElem&&n.svgElem.css({cursor:"row-resize"}),this.markPointsAboveThreshold()}getData(t){let e=t.xData||t.processedXData,i=t.yData||t.processedYData;if(e&&i)return{xData:e,yData:i};if(t.options&&t.options.data){const n=t.options.data;if(Array.isArray(n)){if(n.length===0)return{xData:[],yData:[]};if(Array.isArray(n[0]))e=n.map(s=>s[0]),i=n.map(s=>s[1]);else if(typeof n[0]=="object"&&n[0]!==null)e=n.map(s=>s.x),i=n.map(s=>s.y);else if(typeof n[0]=="number"){const s=t.options.pointStart||0,a=t.options.pointInterval||1;i=n,e=i.map((u,h)=>s+h*a)}}}return{xData:e||null,yData:i||null}}markPointsAboveThreshold(){if(!this.chart||!this.chart.chart)return;const t=this.chart.chart,e=t.series[0];if(!e)return;this.clearMarkers();const{xData:i,yData:n}=this.getData(e);if(!i||!n)return;const s=[];for(let u=0;u<n.length;u++){const h=n[u];h>this.yValue&&s.push({x:i[u],y:h})}if(s.length===0)return;const a=s.map((u,h)=>({point:{xAxis:0,yAxis:0,x:u.x,y:u.y},text:`${h+1}`}));t.addAnnotation({id:this.annotationId,labelOptions:{allowOverlap:!0,backgroundColor:"rgba(255,255,255,0)",borderColor:"transparent",style:{color:"purple",fontSize:"10px",fontWeight:"bold",textOutline:"none"},y:-5},labels:a,zIndex:6})}onContainerMouseMove(t){if(this.isDragging&&this.chart){const e=this.chart.chart.pointer.normalize(t),i=this.chart.chart.yAxis[0].toValue(e.chartY);this.yValue=i,this.renderLine()}}}class R extends M{constructor(t={}){super(t);r(this,"name","ZoomPlugin");r(this,"startX",0);r(this,"onMouseDownBound");r(this,"onMouseUpBound");r(this,"onContextMenuBound");r(this,"onMouseMoveBound");r(this,"isPanning",!1);r(this,"lastX",0);r(this,"rightMouseDown",!1);r(this,"panMoved",!1);r(this,"eventsBound",!1);this.onMouseDownBound=this.onMouseDown.bind(this),this.onMouseUpBound=this.onMouseUp.bind(this),this.onContextMenuBound=this.onContextMenu.bind(this),this.onMouseMoveBound=this.onMouseMove.bind(this)}init(t){super.init(t)}bindEvents(){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))}unbindEvents(){var t,e,i,n;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))}enable(){super.enable(),this.bindEvents()}disable(){super.disable(),this.rightMouseDown=!1,this.isPanning=!1,this.unbindEvents()}onContextMenu(t){(this.isPanning||this.panMoved)&&t.preventDefault()}onMouseDown(t){t.button===0?this.startX=t.clientX:t.button===2&&(this.rightMouseDown=!0,this.panMoved=!1,this.isPanning=!1,this.lastX=t.clientX)}onMouseMove(t){var x,g;if(!((x=this.chart)!=null&&x.chart)||!this.rightMouseDown)return;const e=t.clientX-this.lastX;if(this.lastX=t.clientX,!this.isPanning){if(Math.abs(e)<2)return;this.isPanning=!0,this.panMoved=!0,(g=this.chart)!=null&&g.container&&(this.chart.container.style.cursor="move")}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;if(!Number.isFinite(h)||h<=0||!Number.isFinite(c)||c<=0)return;const d=h/c,f=e*d;let p=s.min-f,m=s.max-f;p<a&&(p=a,m=p+h),m>u&&(m=u,p=m-h),n.setExtremes(p,m,!0,!1),t.preventDefault()}onMouseUp(t){var e,i,n;if(t.button===0){const s=t.clientX;if(this.startX-s>10){const u=(e=this.chart)==null?void 0:e.chart.xAxis[0];if(!u)return;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;if(c!=null&&d!=null&&Math.abs(h.min-c)<1e-9&&Math.abs(h.max-d)<1e-9)return;B((i=this.chart)==null?void 0:i.container),setTimeout(()=>{var g,C;const p=(g=this.chart)==null?void 0:g.chart.xAxis[0];if(!p)return;const m=p.dataMin!==void 0?p.dataMin:p.getExtremes().dataMin,x=p.dataMax!==void 0?p.dataMax:p.getExtremes().dataMax;m!==void 0&&x!==void 0?p.setExtremes(m,x):(C=this.chart)==null||C.chart.zoomOut()},10)}}t.button===2&&(this.rightMouseDown=!1,this.isPanning=!1,(n=this.chart)!=null&&n.container&&(this.chart.container.style.cursor=""),setTimeout(()=>{this.panMoved=!1},0))}destroy(){super.destroy()}}const A="hchart-context-menu";function O(l){return l.replace(/[\\/:*?"<>|]+/g,"_").replace(/\s+/g," ").trim()}function V(l,o){var e;const t=l.getPlugin("SidebandPlugin");(e=t==null?void 0:t.setLineCount)==null||e.call(t,o)}function _(l,o){var a,u,h,c;const t=l.chart,e=typeof(o==null?void 0:o.fileName)=="function"?o.fileName(l):o==null?void 0:o.fileName,i=e?O(e):void 0,n={type:"image/png",...(o==null?void 0:o.exportOptions)||{},...i?{filename:i}:{}},s={...(o==null?void 0:o.exportChartOptions)||{},chart:{...((a=o==null?void 0:o.exportChartOptions)==null?void 0:a.chart)||{},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"}};typeof t.exportChartLocal=="function"?t.exportChartLocal(n,s):(c=t.exportChart)==null||c.call(t,n,s)}const y=class y extends M{constructor(t={}){super(t);r(this,"name","ContextMenuPlugin");r(this,"items");r(this,"labels");r(this,"translate");r(this,"menu",null);r(this,"eventsBound",!1);r(this,"contextStart",null);r(this,"onContextMenuBound",t=>this.onContextMenu(t));r(this,"onMouseDownBound",t=>this.onMouseDown(t));r(this,"onDocumentClickBound",()=>this.hideMenu());this.labels=t.labels||{},this.translate=t.translate,this.items=this.resolveItems(t.items)}static get BUILTIN_ITEMS(){return{sideband:{label:"Sideband",pluginName:"SidebandPlugin"},threshold_line:{label:"Threshold line",pluginName:"ThresholdLinePlugin"},band_count:{label:"Band count",inputType:"number",value:5,min:1,max:10,onInput:(t,e)=>{const i=Number.parseInt(t,10);Number.isFinite(i)&&V(e,Math.min(10,Math.max(1,i)))}},export:{label:"Export PNG",action:_}}}static get DEFAULT_ITEMS(){return Object.values(y.BUILTIN_ITEMS)}init(t){super.init(t),y.activeInstances.add(this),this.addRequiredPlugins(t)}enable(){super.enable(),this.createMenu(),this.bindEvents()}disable(){this.hideMenu(),this.unbindEvents(),super.disable()}destroy(){var t;y.activeInstances.delete(this),super.destroy(),(t=this.menu)==null||t.remove(),this.menu=null}resolveItems(t){const e=this.localizedBuiltinItems();return(t||Object.keys(e)).map(n=>{if(typeof n=="string"){const a=e[n];return a?{...a,id:n,type:"builtin"}:{label:n,type:"custom"}}const s=n.id;if(n.type==="builtin"||s&&e[s]){const a=s?e[s]:void 0;return a?{...a,...n,id:s,type:"builtin"}:n}return n})}localizedBuiltinItems(){const t=y.BUILTIN_ITEMS;return Object.keys(t).forEach(e=>{var n;const i=t[e].label||e;t[e]={...t[e],label:this.labels[e]||((n=this.translate)==null?void 0:n.call(this,e,i))||i}}),t}addRequiredPlugins(t){this.items.forEach(e=>{if(!e.pluginName||t.getPlugin(e.pluginName))return;const i=this.createPlugin(e.pluginName);i&&t.addPlugin(i)})}createPlugin(t){switch(t){case"SidebandPlugin":return new N({enabled:!1});case"ThresholdLinePlugin":return new T({enabled:!1});default:return null}}createMenu(){if(this.menu||typeof document>"u")return;const t=document.createElement("div");t.className=A,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}bindEvents(){var t;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))}unbindEvents(){var t,e,i,n;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))}onMouseDown(t){this.contextStart=t.button===2?{x:t.clientX,y:t.clientY}:null}onContextMenu(t){if(!this.enabled)return;const e=this.contextStart&&Math.hypot(t.clientX-this.contextStart.x,t.clientY-this.contextStart.y)>5;this.contextStart=null,!(e||t.ctrlKey)&&(t.preventDefault(),t.stopPropagation(),this.showMenu(t.clientX,t.clientY))}showMenu(t,e){if(!this.menu||!this.chart)return;y.activeInstances.forEach(s=>{s!==this&&s.hideMenu()}),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());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));this.menu.style.left=`${i}px`,this.menu.style.top=`${n}px`,this.menu.style.visibility="visible"}createMenuItem(t){var s,a,u;const e=document.createElement("div");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";const i=h=>{e.style.background=h?"var(--hchart-menu-hover, #f0f0f0)":"transparent"};if(e.addEventListener("mouseenter",()=>i(!0)),e.addEventListener("mouseleave",()=>i(!1)),t.inputType)return this.createInputItem(e,t),e;if(t.pluginName){const h=(s=this.chart)==null?void 0:s.getPlugin(t.pluginName),c=document.createElement("span");c.style.width="12px",c.textContent=(a=h==null?void 0:h.isEnabled)!=null&&a.call(h)?"*":"",e.appendChild(c)}const n=document.createElement("span");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=>{h.stopPropagation(),this.handleItem(t),this.hideMenu()}),e)}createInputItem(t,e){const i=document.createElement("span");i.textContent=e.label||"",i.style.flex="1",t.appendChild(i);const n=document.createElement("input");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",()=>{var a;const s=this.clampInputValue(n.value,e);n.value=s,this.chart&&((a=e.onInput)==null||a.call(e,s,this.chart))}),t.appendChild(n)}createSubmenu(t,e){const i=document.createElement("span");i.textContent=">",t.appendChild(i);const n=document.createElement("div");n.className=`${A}-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",()=>{n.style.display="block"}),t.addEventListener("mouseleave",()=>{n.style.display="none"})}resolveInputValue(t){var i;if(t.id!=="band_count"||!this.chart)return t.value||"";const e=this.chart.getPlugin("SidebandPlugin");return((i=e==null?void 0:e.getLineCount)==null?void 0:i.call(e))||t.value||""}clampInputValue(t,e){if(e.inputType!=="number")return t;let i=Number.parseFloat(t);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}handleItem(t){var i;if(!this.chart)return;if(t.action){t.action(this.chart,t);return}if(!t.pluginName)return;const e=this.chart.getPlugin(t.pluginName);(i=e==null?void 0:e.isEnabled)!=null&&i.call(e)?e.disable():e==null||e.enable()}hideMenu(){this.menu&&(this.menu.style.display="none")}resolveZIndex(){return typeof this.options.zIndex=="number"&&this.options.zIndex>0?this.options.zIndex:1e4}};r(y,"activeInstances",new Set);let D=y;function q(l,o){var e;const t=l.getPlugin("SidebandPlugin");(e=t==null?void 0:t.setLineCount)==null||e.call(t,o)}function Y(l,o){const t=Number.parseFloat(l);if(!Number.isFinite(t))return;const e=o.chart.xAxis[0],{min:i,max:n}=e.getExtremes();!Number.isFinite(i)||!Number.isFinite(n)||e.setExtremes(i,t>i?t:n)}function W(l,o){const[t,e]=l.split(",").map(i=>Number.parseFloat(i.trim()));!Number.isFinite(t)||!Number.isFinite(e)||t>=e||o.chart.xAxis[0].setExtremes(t,e)}function K(l,o){const t=Number.parseFloat(l);if(!Number.isFinite(t))return;const e=o.chart.xAxis[0];e.removePlotLine("hchart-feature-frequency"),e.addPlotLine({id:"hchart-feature-frequency",value:t,color:"#909399",width:1,dashStyle:"ShortDash",zIndex:6,label:{text:`Feature ${t}`,style:{color:"#909399"}}})}function j(){return[{id:"sideband",type:"builtin",label:"Sidebands"},{id:"threshold_line",type:"builtin",label:"Threshold line"},{id:"band_count",type:"builtin",label:"Band count",inputType:"number",value:5,min:1,max:10},{id:"export",type:"builtin",label:"Export PNG"},{label:"Stop frequency",inputType:"number",value:"",onInput:Y},{label:"Data range (min, max)",inputType:"text",value:"",onInput:W},{label:"Feature frequency",inputType:"number",value:"",onInput:K}]}function Z(){return[{id:"sideband",type:"builtin",label:"Sidebands"},{id:"threshold_line",type:"builtin",label:"Threshold line"},{id:"export",type:"builtin",label:"Export PNG"}]}function G(){return[{id:"band_count",type:"builtin",label:"Band count",inputType:"number",value:1,min:1,max:50,onInput:(l,o)=>{const t=Number.parseInt(l,10);Number.isFinite(t)&&q(o,Math.min(50,Math.max(1,t)))}},{id:"sideband",type:"builtin",label:"Sidebands"}]}class J extends M{constructor(t={}){super(t);r(this,"name","AnnotationPlugin");r(this,"cursorPoint",null);r(this,"labelFormatter",null);r(this,"markerRadius",2);r(this,"markerColor","#ff4d4f");r(this,"marks",[]);r(this,"seq",0);r(this,"draggingId",null);r(this,"dragStart",{x:0,y:0,dx:0,dy:0});r(this,"onMouseMoveBound",null);r(this,"onMouseUpBound",null);r(this,"unbindRedraw",null);this.labelFormatter=t.labelFormatter||null,typeof t.markerRadius=="number"&&(this.markerRadius=t.markerRadius),typeof t.markerColor=="string"&&(this.markerColor=t.markerColor)}init(t){super.init(t)}onCursorChange(t){this.cursorPoint=t}enable(){super.enable(),this.bindEvents(),this.render()}disable(){this.clearAllMarks(),this.unbindEvents(),super.disable()}bindEvents(){var t;this.unbindRedraw||!((t=this.chart)!=null&&t.chart)||(this.unbindRedraw=I.addEvent(this.chart.chart,"redraw",()=>{this.updateAllPositions()}))}unbindEvents(){this.unbindRedraw&&this.unbindRedraw(),this.unbindRedraw=null,this.stopDragging()}update(t){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()}markCurrentPoint(){var e;const t=((e=this.chart)==null?void 0:e.activePoint)||this.cursorPoint;t&&this.markPoint(t)}markPoint(t){const i={id:`m${++this.seq}`,point:{...t},labelEl:null,connectorEl:null,offset:{dx:0,dy:0}};this.marks.push(i),this.renderMark(i)}clearMark(){this.clearAllMarks()}getMarkedPoint(){const t=this.marks[this.marks.length-1];return t?{...t.point}:null}getMarkedPoints(){return this.marks.map(t=>({...t.point}))}render(){var t;this.enabled&&(t=this.chart)!=null&&t.chart&&this.marks.forEach(e=>this.renderMark(e))}clearAllMarks(){var e;if(!((e=this.chart)!=null&&e.chart))return;const t=this.chart.chart;this.marks.forEach(i=>{t.removeAnnotation(this.getMarkerAnnotationId(i.id)),i.labelEl&&(i.labelEl.destroy(),i.labelEl=null),i.connectorEl&&(i.connectorEl.destroy(),i.connectorEl=null)}),this.marks=[],this.draggingId=null,t.redraw()}getMarkerAnnotationId(t){return`hchart-annotation-marker-${t}`}renderMark(t){var e;this.enabled&&(e=this.chart)!=null&&e.chart&&(this.drawMarker(t),this.ensureLabel(t),this.ensureConnector(t),this.updateMarkPosition(t))}drawMarker(t){var s;if(!((s=this.chart)!=null&&s.chart))return;const e=this.chart.chart,i=this.getMarkerAnnotationId(t.id);e.removeAnnotation(i);const n={id:i,zIndex:9999,shapes:[{type:"circle",point:{xAxis:0,yAxis:0,x:t.point.x,y:t.point.y},r:this.markerRadius,fill:this.markerColor,stroke:this.markerColor,strokeWidth:1}]};e.addAnnotation(n)}ensureLabel(t){var n;if(!((n=this.chart)!=null&&n.chart))return;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)}`;if(t.labelEl)t.labelEl.attr({text:i});else{t.labelEl=e.renderer.label(i,e.plotLeft,e.plotTop).css({color:"var(--hchart-text-color, #606266)",fontSize:"12px"}).attr({zIndex:1e4}).add();const s=t.labelEl.element;s.style.cursor="move",s.addEventListener("mousedown",a=>this.onLabelMouseDown(a,t.id))}}ensureConnector(t){var i;if(!((i=this.chart)!=null&&i.chart))return;const e=this.chart.chart;t.connectorEl||(t.connectorEl=e.renderer.path([]).attr({zIndex:9999}).css({stroke:this.markerColor,strokeWidth:1,fill:"none"}).add())}updateAllPositions(){var t;(t=this.chart)!=null&&t.chart&&this.marks.forEach(e=>this.updateMarkPosition(e))}updateMarkPosition(t){var f;if(!((f=this.chart)!=null&&f.chart)||!t.labelEl)return;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;t.labelEl.attr({x:c,y:d}),this.updateConnectorPosition(t,s,a,c,d)}updateConnectorPosition(t,e,i,n,s){if(!t.connectorEl||!t.labelEl)return;const a=t.labelEl.getBBox(),u=n,h=s+Math.max(10,a.height*.5);t.connectorEl.attr({d:["M",e,i,"L",u,h]})}onLabelMouseDown(t,e){const i=this.marks.find(n=>n.id===e);!i||!i.labelEl||(t.preventDefault(),t.stopPropagation(),this.draggingId=e,this.dragStart={x:t.clientX,y:t.clientY,dx:i.offset.dx,dy:i.offset.dy},this.onMouseMoveBound=n=>this.onLabelMouseMove(n),this.onMouseUpBound=n=>this.onLabelMouseUp(n),document.addEventListener("mousemove",this.onMouseMoveBound),document.addEventListener("mouseup",this.onMouseUpBound))}onLabelMouseMove(t){if(!this.draggingId)return;const e=this.marks.find(s=>s.id===this.draggingId);if(!e)return;const i=t.clientX-this.dragStart.x,n=t.clientY-this.dragStart.y;e.offset={dx:this.dragStart.dx+i,dy:this.dragStart.dy+n},this.updateMarkPosition(e)}onLabelMouseUp(t){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)}stopDragging(){this.draggingId=null,this.onMouseMoveBound&&document.removeEventListener("mousemove",this.onMouseMoveBound),this.onMouseUpBound&&document.removeEventListener("mouseup",this.onMouseUpBound),this.onMouseMoveBound=null,this.onMouseUpBound=null}destroy(){this.clearAllMarks(),this.unbindEvents(),super.destroy()}}exports.HChart=X.HChart;exports.AnnotationPlugin=J;exports.BasePlugin=M;exports.ContextMenuPlugin=D;exports.CursorLinkPlugin=z;exports.CursorPlugin=$;exports.SidebandPlugin=N;exports.ThresholdLinePlugin=T;exports.Utils=v;exports.ZoomPlugin=R;exports.createCursorSyncState=w;exports.createEnvelopeContextMenuItems=Z;exports.createSpectrumContextMenuItems=j;exports.createWaveContextMenuItems=G;exports.shouldSuppressCursorClick=k;exports.suppressCursorClick=B;