goro-charts 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,990 @@
1
+ //#region src/defaults.ts
2
+ var e = {
3
+ series: [{
4
+ name: "Series 0",
5
+ color: "#4ea8ff",
6
+ lineWidth: 1.5
7
+ }],
8
+ padding: [
9
+ 16,
10
+ 16,
11
+ 32,
12
+ 56
13
+ ],
14
+ lineColor: "#4ea8ff",
15
+ lineWidth: 1.5,
16
+ fillColor: "#4ea8ff",
17
+ fillOpacity: .15,
18
+ pointColor: "#4ea8ff",
19
+ gridColor: "rgba(255,255,255,0.08)",
20
+ axisColor: "rgba(255,255,255,0.25)",
21
+ textColor: "rgba(255,255,255,0.5)",
22
+ fontSize: 11,
23
+ fontFamily: "system-ui, -apple-system, sans-serif",
24
+ crosshairColor: "rgba(255,255,255,0.3)",
25
+ crosshairWidth: 1,
26
+ pointRadius: 4,
27
+ bgColor: "#111",
28
+ xTicks: 8,
29
+ yTicks: 6,
30
+ maxPoints: 0,
31
+ autoDraw: !1,
32
+ yMin: 0,
33
+ yMax: 0,
34
+ maxDots: 2e3
35
+ }, t = class {
36
+ cap;
37
+ vMin;
38
+ sMin;
39
+ hMin = 0;
40
+ nMin = 0;
41
+ vMax;
42
+ sMax;
43
+ hMax = 0;
44
+ nMax = 0;
45
+ constructor(e) {
46
+ this.cap = e, this.vMin = new Float64Array(e), this.sMin = new Float64Array(e), this.vMax = new Float64Array(e), this.sMax = new Float64Array(e);
47
+ }
48
+ clear() {
49
+ this.hMin = this.nMin = this.hMax = this.nMax = 0;
50
+ }
51
+ push(e, t, n) {
52
+ let r = this.cap, i = this.vMin, a = this.sMin;
53
+ for (; this.nMin > 0 && a[this.hMin] < n;) this.hMin = this.hMin + 1 === r ? 0 : this.hMin + 1, this.nMin--;
54
+ for (; this.nMin > 0 && i[(this.hMin + this.nMin - 1) % r] >= e;) this.nMin--;
55
+ let o = (this.hMin + this.nMin) % r;
56
+ i[o] = e, a[o] = t, this.nMin++;
57
+ let s = this.vMax, c = this.sMax;
58
+ for (; this.nMax > 0 && c[this.hMax] < n;) this.hMax = this.hMax + 1 === r ? 0 : this.hMax + 1, this.nMax--;
59
+ for (; this.nMax > 0 && s[(this.hMax + this.nMax - 1) % r] <= e;) this.nMax--;
60
+ o = (this.hMax + this.nMax) % r, s[o] = e, c[o] = t, this.nMax++;
61
+ }
62
+ get min() {
63
+ return this.vMin[this.hMin];
64
+ }
65
+ get max() {
66
+ return this.vMax[this.hMax];
67
+ }
68
+ }, n = class {
69
+ cap;
70
+ x;
71
+ y;
72
+ head = 0;
73
+ count = 0;
74
+ seq = 0;
75
+ ext;
76
+ constructor(e) {
77
+ this.cap = e, this.x = new Float64Array(e), this.y = new Float64Array(e), this.ext = new t(e);
78
+ }
79
+ get yMin() {
80
+ return this.ext.min;
81
+ }
82
+ get yMax() {
83
+ return this.ext.max;
84
+ }
85
+ get xFirst() {
86
+ return this.x[this.head];
87
+ }
88
+ get xLast() {
89
+ let e = this.head + this.count - 1;
90
+ return this.x[e >= this.cap ? e - this.cap : e];
91
+ }
92
+ get lastY() {
93
+ let e = this.head + this.count - 1;
94
+ return this.y[e >= this.cap ? e - this.cap : e];
95
+ }
96
+ physOf(e) {
97
+ let t = this.head + e;
98
+ return t >= this.cap ? t - this.cap : t;
99
+ }
100
+ push(e, t) {
101
+ let n;
102
+ this.count < this.cap ? (n = this.head + this.count, n >= this.cap && (n -= this.cap), this.count++) : (n = this.head, this.head = this.head + 1 === this.cap ? 0 : this.head + 1), this.x[n] = e, this.y[n] = t;
103
+ let r = this.seq++;
104
+ this.ext.push(t, r, r - this.count + 1);
105
+ }
106
+ clear() {
107
+ this.head = 0, this.count = 0, this.seq = 0, this.ext.clear();
108
+ }
109
+ resize(e) {
110
+ if (e === this.cap || e < 1) return;
111
+ let n = Math.min(this.count, e), r = this.count - n, i = new Float64Array(n), a = new Float64Array(n);
112
+ for (let e = 0; e < n; e++) {
113
+ let t = this.physOf(r + e);
114
+ i[e] = this.x[t], a[e] = this.y[t];
115
+ }
116
+ this.cap = e, this.x = new Float64Array(e), this.y = new Float64Array(e), this.ext = new t(e), this.head = 0, this.count = 0, this.seq = 0;
117
+ for (let e = 0; e < n; e++) this.push(i[e], a[e]);
118
+ }
119
+ }, r = class {
120
+ xArr = /* @__PURE__ */ new Float64Array();
121
+ yArr = /* @__PURE__ */ new Float64Array();
122
+ head = 0;
123
+ count = 0;
124
+ cap = 0;
125
+ xMin = 0;
126
+ xMax = 0;
127
+ yMin = 0;
128
+ yMax = 0;
129
+ ring = null;
130
+ get isRing() {
131
+ return this.ring !== null;
132
+ }
133
+ initRing(e) {
134
+ if (e < 1) throw Error("maxPoints must be >= 1");
135
+ this.ring = new n(e), this.bindRing();
136
+ }
137
+ setData(e, t) {
138
+ if (e.length !== t.length) throw Error("x and y must have same length");
139
+ if (e.length === 0) throw Error("data arrays must not be empty");
140
+ this.ring = null, this.xArr = e, this.yArr = t, this.head = 0, this.count = e.length, this.cap = e.length, this.xMin = e[0], this.xMax = e[e.length - 1];
141
+ let n = Infinity, r = -Infinity;
142
+ for (let e = 0; e < t.length; e++) {
143
+ let i = t[e];
144
+ i < n && (n = i), i > r && (r = i);
145
+ }
146
+ this.applyExtent(n, r);
147
+ }
148
+ append(e, t) {
149
+ let n = this.requireRing("append");
150
+ n.count > 0 && e < n.xLast && console.warn(`[goro-charts] append x=${e} is < last x=${n.xLast}; x values must be monotonically increasing`), n.push(e, t), this.syncFromRing();
151
+ }
152
+ appendBatch(e, t) {
153
+ let n = this.requireRing("appendBatch");
154
+ if (e.length !== t.length) throw Error("xs and ys must have same length");
155
+ for (let r = 0; r < e.length; r++) n.push(e[r], t[r]);
156
+ this.syncFromRing();
157
+ }
158
+ setMaxPoints(e) {
159
+ if (e < 1) throw Error("maxPoints must be >= 1");
160
+ this.ring ? this.ring.resize(e) : this.ring = new n(e), this.bindRing(), this.syncFromRing();
161
+ }
162
+ clear() {
163
+ this.ring ? (this.ring.clear(), this.syncFromRing()) : (this.head = this.count = this.cap = 0, this.xArr = /* @__PURE__ */ new Float64Array(), this.yArr = /* @__PURE__ */ new Float64Array());
164
+ }
165
+ get lastValue() {
166
+ return this.count === 0 ? NaN : this.yArr[this.physOf(this.count - 1)];
167
+ }
168
+ physOf(e) {
169
+ let t = this.head + e;
170
+ return t >= this.cap ? t - this.cap : t;
171
+ }
172
+ bracketLogical(e) {
173
+ let t = this.count, n = 0, r = t - 1;
174
+ if (e <= this.xArr[this.physOf(0)]) return 0;
175
+ if (e >= this.xArr[this.physOf(r)]) return r;
176
+ for (; n < r;) {
177
+ let t = n + r + 1 >>> 1;
178
+ this.xArr[this.physOf(t)] <= e ? n = t : r = t - 1;
179
+ }
180
+ return n;
181
+ }
182
+ requireRing(e) {
183
+ if (!this.ring) throw Error(`${e}() requires the chart to be created with { maxPoints }`);
184
+ return this.ring;
185
+ }
186
+ bindRing() {
187
+ let e = this.ring;
188
+ this.xArr = e.x, this.yArr = e.y;
189
+ }
190
+ syncFromRing() {
191
+ let e = this.ring;
192
+ this.xArr !== e.x && this.bindRing(), this.head = e.head, this.count = e.count, this.cap = e.cap, e.count > 0 && (this.xMin = e.xFirst, this.xMax = e.xLast, this.applyExtent(e.yMin, e.yMax));
193
+ }
194
+ applyExtent(e, t) {
195
+ t - e === 0 ? (this.yMin = e - 1, this.yMax = t + 1) : (this.yMin = e, this.yMax = t);
196
+ }
197
+ }, i = class {
198
+ canvas;
199
+ ctx;
200
+ dpr;
201
+ cssW = 0;
202
+ cssH = 0;
203
+ offCanvas = null;
204
+ offCtx = null;
205
+ constructor(e) {
206
+ this.canvas = e, e.setAttribute("role", "img"), e.tabIndex = 0, this.dpr = window.devicePixelRatio || 1;
207
+ let t = e.getContext("2d");
208
+ if (!t) throw Error("Canvas 2D context not available");
209
+ this.ctx = t, this.measure();
210
+ }
211
+ measure() {
212
+ let e = this.canvas.getBoundingClientRect(), t = Math.floor(e.width), n = Math.floor(e.height);
213
+ if (t <= 0 || n <= 0) return !1;
214
+ let r = t * this.dpr, i = n * this.dpr;
215
+ return this.cssW === t && this.cssH === n && this.canvas.width === r ? !1 : (this.cssW = t, this.cssH = n, this.canvas.width = r, this.canvas.height = i, this.ctx.setTransform(this.dpr, 0, 0, this.dpr, 0, 0), this.offCanvas = null, this.offCtx = null, !0);
216
+ }
217
+ offscreenCtx() {
218
+ let e = this.canvas.width, t = this.canvas.height;
219
+ if (this.offCanvas && this.offCanvas.width === e && this.offCanvas.height === t) return this.offCtx;
220
+ let n = document.createElement("canvas");
221
+ n.width = e, n.height = t;
222
+ let r = n.getContext("2d");
223
+ if (!r) throw Error("Offscreen 2D context not available");
224
+ return r.setTransform(this.dpr, 0, 0, this.dpr, 0, 0), this.offCanvas = n, this.offCtx = r, r;
225
+ }
226
+ blit() {
227
+ this.offCanvas && (this.ctx.setTransform(1, 0, 0, 1, 0, 0), this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height), this.ctx.drawImage(this.offCanvas, 0, 0), this.ctx.setTransform(this.dpr, 0, 0, this.dpr, 0, 0));
228
+ }
229
+ dispose() {
230
+ this.offCanvas = null, this.offCtx = null;
231
+ }
232
+ };
233
+ //#endregion
234
+ //#region src/math/ticks.ts
235
+ function a(e, t) {
236
+ let n = t - e;
237
+ return n === 0 ? 1 : n;
238
+ }
239
+ function o(e, t) {
240
+ let n = Math.floor(Math.log10(e / t)), r = e / t / 10 ** n, i;
241
+ return i = r <= 1.5 ? 1 : r <= 3.5 ? 2 : r <= 7.5 ? 5 : 10, i * 10 ** n;
242
+ }
243
+ function s(e, t, n) {
244
+ let r = o(a(e, t), n), i = Math.ceil(e / r) * r, s = Math.floor(t / r) * r, c = [];
245
+ for (let e = i; e <= s + r * .5; e += r) c.push(e);
246
+ return c;
247
+ }
248
+ //#endregion
249
+ //#region src/math/format.ts
250
+ function c(e) {
251
+ if (Number.isInteger(e)) return e.toFixed(0);
252
+ let t = Math.abs(e);
253
+ return (t >= 1e6 || t <= 1e-4 && t > 0) && isFinite(e) ? e.toExponential(2) : t >= 1 ? e.toFixed(2) : e.toPrecision(3);
254
+ }
255
+ //#endregion
256
+ //#region src/math/scale.ts
257
+ function l(e, t, n) {
258
+ let r = t.xMax - t.xMin;
259
+ return r <= 0 ? n.x : n.x + (e - t.xMin) / r * n.w;
260
+ }
261
+ function u(e, t, n) {
262
+ let r = t.yMax - t.yMin;
263
+ return r <= 0 ? n.y : n.y + (1 - (e - t.yMin) / r) * n.h;
264
+ }
265
+ function d(e, t, n) {
266
+ let r = t.xMax - t.xMin;
267
+ return r <= 0 ? t.xMin : t.xMin + (e - n.x) / n.w * r;
268
+ }
269
+ //#endregion
270
+ //#region src/render/axes.ts
271
+ function f(e, t, n, r) {
272
+ e.setLineDash([6, 4]);
273
+ let i = n.y + n.h, a = n.x + n.w;
274
+ e.strokeStyle = r.gridColor, e.lineWidth = .5;
275
+ let o = s(t.yMin, t.yMax, r.yTicks);
276
+ e.beginPath();
277
+ for (let r of o) {
278
+ let o = u(r, t, n);
279
+ o <= n.y || o >= i || (e.moveTo(n.x, o), e.lineTo(a, o));
280
+ }
281
+ e.stroke();
282
+ let c = s(t.xMin, t.xMax, r.xTicks);
283
+ e.beginPath();
284
+ for (let r of c) {
285
+ let o = l(r, t, n);
286
+ o <= n.x || o >= a || (e.moveTo(o, n.y), e.lineTo(o, i));
287
+ }
288
+ e.stroke(), e.strokeStyle = r.axisColor, e.lineWidth = .8, e.strokeRect(n.x, n.y, n.w, n.h), e.setLineDash([]);
289
+ }
290
+ function p(e, t, n, r, i = "left") {
291
+ e.font = `${r.fontSize}px ${r.fontFamily}`, e.fillStyle = r.textColor;
292
+ let a = s(t.yMin, t.yMax, r.yTicks);
293
+ e.textAlign = i === "right" ? "left" : "right", e.textBaseline = "middle";
294
+ let o = i === "right" ? n.x + n.w + 6 : n.x - 6;
295
+ for (let r of a) e.fillText(c(r), o, u(r, t, n));
296
+ if (i === "left") {
297
+ let i = s(t.xMin, t.xMax, r.xTicks);
298
+ e.textAlign = "center", e.textBaseline = "top";
299
+ for (let r of i) e.fillText(c(r), l(r, t, n), n.y + n.h + 6);
300
+ }
301
+ }
302
+ //#endregion
303
+ //#region src/render/shape.ts
304
+ function m(e, t, n, r, i, a) {
305
+ if (r <= 0 || i <= 0) return;
306
+ let o = Math.min(a, r / 2, i / 2);
307
+ e.moveTo(t + o, n), e.arcTo(t + r, n, t + r, n + i, o), e.arcTo(t + r, n + i, t, n + i, o), e.arcTo(t, n + i, t, n, o), e.arcTo(t, n, t + r, n, o), e.closePath();
308
+ }
309
+ //#endregion
310
+ //#region src/render/crosshair.ts
311
+ function h(e, t, n, r) {
312
+ let i = [];
313
+ for (let a = 0; a < e.length; a++) {
314
+ let o = e[a], s = o.count;
315
+ if (s === 0) continue;
316
+ let c = d(r, o, n), f = o.bracketLogical(c), p = f + 1 < s ? f + 1 : s - 1, m = o.physOf(f), h = o.physOf(p), g = o.xArr[m], _ = o.xArr[h], v = o.yArr[m], y = o.yArr[h], b = _ > g ? (c - g) / (_ - g) : 0;
317
+ b < 0 ? b = 0 : b > 1 && (b = 1);
318
+ let x = g + (_ - g) * b, S = v + (y - v) * b;
319
+ i.push({
320
+ px: l(x, o, n),
321
+ py: u(S, o, n),
322
+ xVal: x,
323
+ yVal: S,
324
+ color: t[a].color,
325
+ label: t[a].name
326
+ });
327
+ }
328
+ return i;
329
+ }
330
+ function g(e, t, n, r, i, a, o) {
331
+ if (a.x < r.x || a.x > r.x + r.w || a.y < r.y || a.y > r.y + r.h) return;
332
+ let s = h(t, n, r, a.x);
333
+ if (s.length === 0) return;
334
+ let l = s[0].px, u = s[0].xVal;
335
+ if (e.strokeStyle = i.crosshairColor, e.lineWidth = i.crosshairWidth, e.setLineDash([4, 3]), e.beginPath(), e.moveTo(l, r.y), e.lineTo(l, r.y + r.h), e.stroke(), e.setLineDash([]), s.length === 1) {
336
+ let t = s[0];
337
+ e.strokeStyle = i.crosshairColor, e.lineWidth = i.crosshairWidth, e.setLineDash([4, 3]), e.beginPath(), e.moveTo(r.x, t.py), e.lineTo(r.x + r.w, t.py), e.stroke(), e.setLineDash([]);
338
+ }
339
+ for (let t of s) e.fillStyle = "rgba(0,0,0,0.65)", e.beginPath(), e.arc(t.px, t.py, i.pointRadius + 1.5, 0, Math.PI * 2), e.fill(), e.fillStyle = t.color, e.beginPath(), e.arc(t.px, t.py, i.pointRadius, 0, Math.PI * 2), e.fill();
340
+ let d = (e) => c(e), f = `${i.fontSize}px ${i.fontFamily}`, p = `600 ${i.fontSize + 1}px ${i.fontFamily}`, g = i.fontSize + 6;
341
+ e.font = f;
342
+ let _ = Math.max(...s.map((t) => e.measureText(t.label).width));
343
+ e.font = p;
344
+ let v = Math.max(...s.map((t) => e.measureText(d(t.yVal)).width));
345
+ e.font = f;
346
+ let y = e.measureText("x").width;
347
+ e.font = p;
348
+ let b = e.measureText(d(u)).width, x = Math.max(0, _, y), S = Math.max(v, b), C = 36 + x + 8 + S, w = g + 4, T = 20 + w + 2 + s.length * g, E = l + 14;
349
+ E + C > o && (E = Math.max(2, l - C - 14));
350
+ let D = a.y - T - 10;
351
+ D < 2 && (D = a.y + 10), D + T > r.y + r.h && (D = Math.max(2, a.y - T - 10)), e.fillStyle = "rgba(10,12,14,0.70)", e.beginPath(), m(e, E, D, C, T, 6), e.fill(), e.strokeStyle = "rgba(255,255,255,0.08)", e.lineWidth = .8, e.beginPath(), m(e, E, D, C, T, 6), e.stroke();
352
+ let O = D + 10;
353
+ e.fillStyle = i.textColor, e.globalAlpha = .5, e.font = f, e.fillText("x", E + 10 + 8 + 8, O + g - 4), e.globalAlpha = 1, e.font = p, e.textAlign = "right", e.fillStyle = "rgba(255,255,255,0.85)", e.fillText(d(u), E + C - 10, O + g - 4);
354
+ let k = D + 10 + w + 1;
355
+ e.strokeStyle = "rgba(255,255,255,0.07)", e.lineWidth = 1, e.beginPath(), e.moveTo(E + 10, k), e.lineTo(E + C - 10, k), e.stroke();
356
+ for (let t = 0; t < s.length; t++) {
357
+ let n = s[t], r = D + 10 + w + 2 + t * g;
358
+ e.fillStyle = n.color, e.beginPath(), e.arc(E + 10 + 4, r + g / 2, 4, 0, Math.PI * 2), e.fill(), e.font = f, e.textAlign = "left", e.fillStyle = "rgba(255,255,255,0.55)", e.fillText(n.label, E + 10 + 8 + 8, r + g - 4), e.font = p, e.textAlign = "right", e.fillStyle = "rgba(255,255,255,0.90)", e.fillText(d(n.yVal), E + C - 10, r + g - 4);
359
+ }
360
+ e.textAlign = "left", e.globalAlpha = 1;
361
+ }
362
+ //#endregion
363
+ //#region src/render/legend.ts
364
+ function _(e, t, n, r) {
365
+ if (t.length < 2) return;
366
+ e.font = `${r.fontSize}px ${r.fontFamily}`;
367
+ let i = t.map((t) => ({
368
+ config: t,
369
+ width: 14 + e.measureText(t.name).width
370
+ })), a = i.reduce((e, t) => e + t.width + (e > 0 ? 16 : 0), 0), o = Math.max(...i.map((e) => e.width)), s = a <= n.w - 16, c, l;
371
+ s ? (c = a + 20, l = r.fontSize + 14) : (c = o + 20, l = i.length * (r.fontSize + 6) + 14);
372
+ let u = n.x + n.w - c - 8, d = n.y + 8;
373
+ if (e.fillStyle = "rgba(10,12,14,0.70)", e.beginPath(), m(e, u, d, c, l, 6), e.fill(), e.strokeStyle = "rgba(255,255,255,0.08)", e.lineWidth = .7, e.beginPath(), m(e, u, d, c, l, 6), e.stroke(), e.textAlign = "left", e.textBaseline = "middle", s) {
374
+ let t = u + 10;
375
+ for (let n = 0; n < i.length; n++) {
376
+ n > 0 && (t += 16);
377
+ let r = i[n], a = d + l / 2;
378
+ e.fillStyle = r.config.color, e.beginPath(), e.arc(t + 4, a, 4, 0, Math.PI * 2), e.fill(), e.fillStyle = "rgba(255,255,255,0.65)", e.fillText(r.config.name, t + 8 + 6, a), t += r.width;
379
+ }
380
+ } else {
381
+ e.textBaseline = "top";
382
+ for (let t = 0; t < i.length; t++) {
383
+ let n = i[t], a = d + 7 + t * (r.fontSize + 6);
384
+ e.fillStyle = n.config.color, e.beginPath(), e.arc(u + 10 + 4, a + r.fontSize / 2, 4, 0, Math.PI * 2), e.fill(), e.fillStyle = "rgba(255,255,255,0.65)", e.fillText(n.config.name, u + 10 + 8 + 6, a);
385
+ }
386
+ }
387
+ e.textAlign = "left", e.textBaseline = "top";
388
+ }
389
+ //#endregion
390
+ //#region src/render/stacked-band.ts
391
+ function v(e, t, n, r, i) {
392
+ let a = t[0].count;
393
+ if (a === 0) return;
394
+ let o = t[0], { xArr: s, cap: c } = o, l = i.xMax - i.xMin, u = i.yMax - i.yMin, d = l > 0 ? r.w / l : 0, f = r.x - i.xMin * d, p = u > 0 ? r.h / u : 0, m = r.y + r.h + i.yMin * p, h = r.y + r.h, g = r.y, _ = (e) => e < g ? g : e > h ? h : e, v = (e) => _(m - e * p), x = [], S = new Float64Array(a);
395
+ for (let e = 0; e < t.length; e++) {
396
+ let n = t[e], r = n.head, i = n.cap - n.head;
397
+ for (let e = 0; e < a; e++) S[e] += n.yArr[r], --i === 0 ? (r = 0, i = n.cap) : r++;
398
+ x.push(new Float64Array(S));
399
+ }
400
+ e.lineJoin = "round", a > r.w * 2 ? b(e, x, n, s, o.head, c, f, d, v, h) : y(e, x, n, s, o.head, c, a, f, d, v, h);
401
+ }
402
+ function y(e, t, n, r, i, a, o, s, c, l, u) {
403
+ let d = new Float64Array(o), f = i, p = a - i;
404
+ for (let e = 0; e < o; e++) d[e] = s + r[f] * c, --p === 0 ? (f = 0, p = a) : f++;
405
+ for (let r = 0; r < t.length; r++) {
406
+ let i = t[r], a = n[r];
407
+ e.beginPath(), e.fillStyle = a.fillColor, a.fillOpacity < 1 && (e.globalAlpha = a.fillOpacity), e.moveTo(d[0], l(i[0]));
408
+ for (let t = 1; t < o; t++) e.lineTo(d[t], l(i[t]));
409
+ if (r === 0) e.lineTo(d[o - 1], u), e.lineTo(d[0], u);
410
+ else {
411
+ let n = t[r - 1];
412
+ for (let t = o - 1; t >= 0; t--) e.lineTo(d[t], l(n[t]));
413
+ }
414
+ e.closePath(), e.fill(), e.globalAlpha = 1, e.beginPath(), e.strokeStyle = a.lineColor, e.lineWidth = a.lineWidth, e.lineCap = "round", e.moveTo(d[0], l(i[0]));
415
+ for (let t = 1; t < o; t++) e.lineTo(d[t], l(i[t]));
416
+ e.stroke();
417
+ }
418
+ }
419
+ function b(e, t, n, r, i, a, o, s, c, l) {
420
+ let u = t[0].length, d = new Int32Array(u);
421
+ {
422
+ let e = i, t = a - i;
423
+ for (let n = 0; n < u; n++) d[n] = o + r[e] * s | 0, --t === 0 ? (e = 0, t = a) : e++;
424
+ }
425
+ let f = t.map((e) => {
426
+ let t = [], n = [], r = [], i = -1, a = 0, o = 0;
427
+ for (let s = 0; s < u; s++) {
428
+ let l = d[s], u = c(e[s]);
429
+ l === i ? (u < a && (a = u), u > o && (o = u)) : (i >= 0 && (t.push(i + .5), n.push(a), r.push(o)), i = l, a = o = u);
430
+ }
431
+ return i >= 0 && (t.push(i + .5), n.push(a), r.push(o)), {
432
+ cx: t,
433
+ top: n,
434
+ bot: r
435
+ };
436
+ });
437
+ for (let t = 0; t < f.length; t++) {
438
+ let r = f[t], i = r.cx.length;
439
+ if (i === 0) continue;
440
+ let a = n[t];
441
+ e.beginPath(), e.fillStyle = a.fillColor, a.fillOpacity < 1 && (e.globalAlpha = a.fillOpacity), e.moveTo(r.cx[0], r.top[0]);
442
+ for (let t = 0; t < i; t++) e.lineTo(r.cx[t], r.top[t]), e.lineTo(r.cx[t], r.bot[t]);
443
+ if (t === 0) e.lineTo(r.cx[i - 1], l), e.lineTo(r.cx[0], l);
444
+ else {
445
+ let n = f[t - 1];
446
+ for (let t = n.cx.length - 1; t >= 0; t--) e.lineTo(n.cx[t], n.bot[t]), e.lineTo(n.cx[t], n.top[t]);
447
+ }
448
+ e.closePath(), e.fill(), e.globalAlpha = 1, e.beginPath(), e.strokeStyle = a.lineColor, e.lineWidth = a.lineWidth, e.lineCap = "round", e.moveTo(r.cx[0], r.top[0]);
449
+ for (let t = 0; t < i; t++) e.lineTo(r.cx[t], r.top[t]), e.lineTo(r.cx[t], r.bot[t]);
450
+ e.stroke();
451
+ }
452
+ }
453
+ //#endregion
454
+ //#region src/charts/chart-base.ts
455
+ var x = class {
456
+ opts;
457
+ surface;
458
+ stores;
459
+ seriesConfigs;
460
+ gridDomainLeft = {
461
+ xMin: 0,
462
+ xMax: 0,
463
+ yMin: 0,
464
+ yMax: 0
465
+ };
466
+ gridDomainRight = {
467
+ xMin: 0,
468
+ xMax: 0,
469
+ yMin: 0,
470
+ yMax: 0
471
+ };
472
+ gridPinned = !1;
473
+ hasRightAxis = !1;
474
+ stackGroupsAll;
475
+ stackGroupsByAxis;
476
+ dirty = !1;
477
+ cursorX = -1;
478
+ cursorY = -1;
479
+ showCrosshair = !1;
480
+ autoDraw;
481
+ rafScheduled = 0;
482
+ suspendCount = 0;
483
+ syncTargets = /* @__PURE__ */ new Set();
484
+ resizeObserver = null;
485
+ destroyed = !1;
486
+ liveRegion = null;
487
+ handleResize = () => this.onResize();
488
+ handleMouseMove = (e) => this.onMouseMove(e);
489
+ handleMouseLeave = () => this.onMouseLeave();
490
+ handleKeyDown = (e) => this.onKeyDown(e);
491
+ constructor(t, n) {
492
+ if (this.opts = {
493
+ ...e,
494
+ ...n
495
+ }, this.autoDraw = this.opts.autoDraw, this.seriesConfigs = this.opts.series.length > 0 ? this.opts.series : [{
496
+ name: "Series 0",
497
+ color: this.opts.lineColor
498
+ }], this.validateOpts(), this.surface = new i(t), this.stores = this.seriesConfigs.map(() => new r()), this.hasRightAxis = this.seriesConfigs.some((e) => e.yAxis === "right"), this.stackGroupsAll = this.computeAllStackGroups(), this.stackGroupsByAxis = {
499
+ left: this.computeStackGroupsOnAxis("left"),
500
+ right: this.computeStackGroupsOnAxis("right")
501
+ }, n?.maxPoints != null && n.maxPoints > 0) for (let e of this.stores) e.initRing(n.maxPoints);
502
+ (this.opts.yMin !== 0 || this.opts.yMax !== 0) && (this.gridDomainLeft.yMin = this.opts.yMin, this.gridDomainLeft.yMax = this.opts.yMax, this.gridDomainRight.yMin = this.opts.yMin, this.gridDomainRight.yMax = this.opts.yMax, this.gridPinned = !0), this.dirty = !0, this.attachEvents(), this.applySystemTheme(), this.ensureLiveRegion();
503
+ }
504
+ validateOpts() {
505
+ this.opts.maxPoints < 0 && (console.warn(`[goro-charts] maxPoints must be >= 0, got ${this.opts.maxPoints}. Using 0.`), this.opts.maxPoints = 0), this.opts.fontSize < 6 && console.warn(`[goro-charts] fontSize ${this.opts.fontSize} is very small. Minimum recommended: 6.`);
506
+ let e = this.opts.padding;
507
+ e.some((e) => e < 0) && (console.warn(`[goro-charts] padding values must be >= 0, got [${e}]. Clamping to 0.`), this.opts.padding = e.map((e) => Math.max(0, e))), this.opts.yMin > 0 && this.opts.yMax > 0 && this.opts.yMin >= this.opts.yMax && (console.warn(`[goro-charts] yMin (${this.opts.yMin}) must be < yMax (${this.opts.yMax}). Swapping.`), [this.opts.yMin, this.opts.yMax] = [this.opts.yMax, this.opts.yMin]);
508
+ for (let e = 0; e < this.seriesConfigs.length; e++) {
509
+ let t = this.seriesConfigs[e];
510
+ (!t.name || t.name.trim() === "") && (console.warn(`[goro-charts] series[${e}] name is empty. Using "Series ${e}".`), this.seriesConfigs[e] = {
511
+ ...t,
512
+ name: `Series ${e}`
513
+ }), t.yAxis && t.yAxis !== "left" && t.yAxis !== "right" && (console.warn(`[goro-charts] series[${e}] has invalid yAxis "${t.yAxis}". Using "left".`), this.seriesConfigs[e] = {
514
+ ...t,
515
+ yAxis: "left"
516
+ });
517
+ }
518
+ }
519
+ applySystemTheme() {
520
+ try {
521
+ window.matchMedia("(prefers-reduced-motion: reduce)").matches && (this.autoDraw = !1), window.matchMedia("(prefers-contrast: more)").matches && (this.opts.gridColor === "rgba(255,255,255,0.08)" && (this.opts.gridColor = "rgba(255,255,255,0.25)"), this.opts.textColor === "rgba(255,255,255,0.5)" && (this.opts.textColor = "rgba(255,255,255,0.8)")), window.matchMedia("(forced-colors: active)").matches && (this.opts.textColor = "CanvasText", this.opts.bgColor = "Canvas", this.opts.gridColor = "GrayText", this.opts.axisColor = "GrayText", this.opts.crosshairColor = "GrayText");
522
+ } catch {}
523
+ }
524
+ ensureLiveRegion() {
525
+ if (!this.liveRegion) try {
526
+ this.liveRegion = document.createElement("div"), this.liveRegion.setAttribute("aria-live", "polite"), this.liveRegion.setAttribute("aria-atomic", "true"), this.liveRegion.style.cssText = "position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;", this.surface.canvas.parentElement?.appendChild(this.liveRegion);
527
+ } catch {}
528
+ }
529
+ updateAriaLabel() {
530
+ let e = this.stores.map((e, t) => ({
531
+ config: this.seriesConfigs[t],
532
+ count: e.count,
533
+ last: e.lastValue
534
+ })).filter((e) => e.count > 0), t;
535
+ t = e.length === 0 ? "Chart: no data" : `Chart: ${e.map((e) => `${e.config.name} ${c(e.last)}`).join(", ")}`, this.surface.canvas.setAttribute("aria-label", t);
536
+ }
537
+ onKeyDown(e) {
538
+ if (document.activeElement !== this.surface.canvas) return;
539
+ let t = e.shiftKey ? 10 : 1, n = this.plotRect();
540
+ switch (e.key) {
541
+ case "ArrowLeft":
542
+ e.preventDefault(), this.cursorX = Math.max(n.x, this.cursorX - t), this.showCrosshair = !0, this.draw(), this.notifySyncCrosshair();
543
+ break;
544
+ case "ArrowRight":
545
+ e.preventDefault(), this.cursorX = Math.min(n.x + n.w, this.cursorX + t), this.showCrosshair = !0, this.draw(), this.notifySyncCrosshair();
546
+ break;
547
+ case "Escape":
548
+ e.preventDefault(), this.showCrosshair = !1, this.draw(), this.notifySyncCrosshairLeave();
549
+ break;
550
+ }
551
+ }
552
+ notifySyncCrosshair() {
553
+ let e = this.surface.canvas.getBoundingClientRect().left + this.cursorX;
554
+ for (let t of this.syncTargets) t.injectCursor(e);
555
+ }
556
+ notifySyncCrosshairLeave() {
557
+ for (let e of this.syncTargets) e.injectCursorLeave();
558
+ }
559
+ setData(e, t, n) {
560
+ this.destroyed || (this.storeAt(e).setData(t, n), this.gridPinned = !1, this.invalidate());
561
+ }
562
+ append(e, t, n) {
563
+ this.destroyed || (this.storeAt(e).append(t, n), this.invalidate());
564
+ }
565
+ appendBatch(e, t, n) {
566
+ this.destroyed || (this.storeAt(e).appendBatch(t, n), this.invalidate());
567
+ }
568
+ setMaxPoints(e) {
569
+ if (!this.destroyed) {
570
+ for (let t of this.stores) t.setMaxPoints(e);
571
+ this.invalidate();
572
+ }
573
+ }
574
+ clear() {
575
+ if (!this.destroyed) {
576
+ for (let e of this.stores) e.clear();
577
+ this.gridPinned = !1, this.invalidate();
578
+ }
579
+ }
580
+ get seriesCount() {
581
+ return this.destroyed ? 0 : this.stores.length;
582
+ }
583
+ get renderedPointCount() {
584
+ return this.destroyed ? 0 : this.stores.reduce((e, t) => e + t.count, 0);
585
+ }
586
+ pointCount(e) {
587
+ return this.destroyed ? 0 : this.stores[e].count;
588
+ }
589
+ extentMin(e) {
590
+ return this.destroyed ? NaN : this.stores[e].yMin;
591
+ }
592
+ extentMax(e) {
593
+ return this.destroyed ? NaN : this.stores[e].yMax;
594
+ }
595
+ lastValue(e) {
596
+ return this.destroyed ? NaN : this.stores[e].lastValue;
597
+ }
598
+ suspendDraw() {
599
+ this.destroyed || this.suspendCount++;
600
+ }
601
+ resumeDraw() {
602
+ this.destroyed || (this.suspendCount > 0 && this.suspendCount--, this.suspendCount === 0 && this.dirty && this.invalidate());
603
+ }
604
+ toImage() {
605
+ return this.destroyed ? "" : this.surface.canvas.toDataURL("image/png");
606
+ }
607
+ sync(e) {
608
+ this.destroyed || (this.syncTargets.add(e), e.syncTargets.add(this));
609
+ }
610
+ onHover;
611
+ draw() {
612
+ if (this.destroyed || !this.dirty && !this.showCrosshair) return;
613
+ let { cssW: e, cssH: t } = this.surface;
614
+ if (e <= 0 || t <= 0) return;
615
+ let n = this.plotRect();
616
+ if (!(n.w <= 0 || n.h <= 0)) {
617
+ if (this.dirty && (this.renderStatic(n), this.updateAriaLabel()), this.surface.blit(), this.showCrosshair) {
618
+ let { groups: t } = this.detectAllStackGroups(), r = /* @__PURE__ */ new Map();
619
+ for (let [, e] of t) {
620
+ if (e.length < 2) continue;
621
+ let t = this.accumulateStackGroup(e);
622
+ if (t) for (let n of e) r.set(n, new Float64Array(t));
623
+ }
624
+ let i = this.stores.map((e, t) => {
625
+ let n = this.seriesConfigs[t], i = (n.yAxis ?? "left") === "right" ? this.gridDomainRight : this.gridDomainLeft, a = i.yMin, o = i.yMax;
626
+ n.yMin != null && (a = n.yMin), n.yMax != null && (o = n.yMax);
627
+ let s = r.get(t);
628
+ return Object.assign(Object.create(Object.getPrototypeOf(e)), e, {
629
+ xMin: i.xMin,
630
+ xMax: i.xMax,
631
+ yMin: a,
632
+ yMax: o,
633
+ ...s ? { yArr: s } : {}
634
+ });
635
+ });
636
+ if (this.onHover || this.liveRegion) {
637
+ let e = h(i, this.seriesConfigs, n, this.cursorX);
638
+ this.onHover && e.length > 0 && this.onHover(e), this.liveRegion && (this.liveRegion.textContent = e.length > 0 ? e.map((e) => `${e.label}: ${c(e.yVal)}`).join(", ") : "");
639
+ }
640
+ g(this.surface.ctx, i, this.seriesConfigs, n, this.opts, {
641
+ x: this.cursorX,
642
+ y: this.cursorY
643
+ }, e);
644
+ }
645
+ !this.showCrosshair && this.liveRegion && (this.liveRegion.textContent = ""), this.dirty = !1;
646
+ }
647
+ }
648
+ destroy() {
649
+ this.destroyed || (this.destroyed = !0, this.rafScheduled &&= (cancelAnimationFrame(this.rafScheduled), 0), this.resizeObserver?.disconnect(), this.resizeObserver = null, this.surface.canvas.removeEventListener("mousemove", this.handleMouseMove), this.surface.canvas.removeEventListener("mouseleave", this.handleMouseLeave), this.surface.canvas.removeEventListener("keydown", this.handleKeyDown), this.liveRegion?.remove(), this.liveRegion = null, this.surface.dispose(), this.stores = []);
650
+ }
651
+ renderStatic(e) {
652
+ let t = this.surface.offscreenCtx(), { cssW: n, cssH: r } = this.surface;
653
+ if (t.clearRect(0, 0, n, r), t.fillStyle = this.opts.bgColor, t.fillRect(0, 0, n, r), this.stores.every((e) => e.count === 0)) return;
654
+ this.updateGridDomain(), f(t, this.gridDomainLeft, e, this.opts), p(t, this.gridDomainLeft, e, this.opts), this.hasRightAxis && p(t, this.gridDomainRight, e, this.opts, "right");
655
+ let { groups: i, stacked: a } = this.detectAllStackGroups();
656
+ for (let n = 0; n < this.stores.length; n++) {
657
+ if (a.has(n)) continue;
658
+ let r = this.stores[n];
659
+ r.count !== 0 && this.renderOne(t, n, r, r.yArr, e);
660
+ }
661
+ for (let [, n] of i) {
662
+ if (n.length < 2) {
663
+ for (let r of n) {
664
+ let n = this.stores[r];
665
+ n.count > 0 && this.renderOne(t, r, n, n.yArr, e);
666
+ }
667
+ continue;
668
+ }
669
+ let r = [], i = [];
670
+ for (let e of n) {
671
+ let t = this.stores[e];
672
+ if (t.count === 0) continue;
673
+ let n = this.seriesConfigs[e];
674
+ r.push(t), i.push({
675
+ lineColor: n.color,
676
+ lineWidth: n.lineWidth ?? this.opts.lineWidth,
677
+ fillColor: n.fillColor ?? this.opts.fillColor,
678
+ fillOpacity: n.fillOpacity ?? this.opts.fillOpacity
679
+ });
680
+ }
681
+ if (r.length < 2) {
682
+ for (let i = 0; i < r.length; i++) this.renderOne(t, n[i], r[i], r[i].yArr, e);
683
+ continue;
684
+ }
685
+ v(t, r, i, e, (this.seriesConfigs[n[0]].yAxis ?? "left") === "right" ? this.gridDomainRight : this.gridDomainLeft);
686
+ }
687
+ _(t, this.seriesConfigs, e, this.opts);
688
+ }
689
+ renderOne(e, t, n, r, i) {
690
+ let a = this.seriesConfigs[t], o = {
691
+ ...this.opts,
692
+ lineColor: a.color,
693
+ lineWidth: a.lineWidth ?? this.opts.lineWidth,
694
+ fillColor: a.fillColor ?? this.opts.fillColor,
695
+ fillOpacity: a.fillOpacity ?? this.opts.fillOpacity
696
+ };
697
+ a.dash && e.setLineDash(a.dash);
698
+ let s = (a.yAxis ?? "left") === "right" ? this.gridDomainRight : this.gridDomainLeft, c = s.yMin, l = s.yMax;
699
+ a.yMin != null && (c = a.yMin), a.yMax != null && (l = a.yMax);
700
+ let u = Object.assign(Object.create(Object.getPrototypeOf(n)), n, {
701
+ xMin: s.xMin,
702
+ xMax: s.xMax,
703
+ yArr: r,
704
+ yMin: c,
705
+ yMax: l
706
+ });
707
+ this.renderSeries(e, u, i, o), a.dash && e.setLineDash([]);
708
+ }
709
+ detectStackGroupsOnAxis(e) {
710
+ return this.stackGroupsByAxis[e];
711
+ }
712
+ computeStackGroupsOnAxis(e) {
713
+ let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Set();
714
+ for (let n = 0; n < this.stores.length; n++) {
715
+ if ((this.seriesConfigs[n].yAxis ?? "left") !== e) continue;
716
+ let r = this.seriesConfigs[n].stack;
717
+ if (r) {
718
+ let e = t.get(r);
719
+ e || (e = [], t.set(r, e)), e.push(n);
720
+ }
721
+ }
722
+ for (let e of t.values()) if (e.length >= 2) for (let t of e) n.add(t);
723
+ return {
724
+ groups: t,
725
+ stacked: n
726
+ };
727
+ }
728
+ detectAllStackGroups() {
729
+ return this.stackGroupsAll;
730
+ }
731
+ computeAllStackGroups() {
732
+ let e = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Set();
733
+ for (let t = 0; t < this.stores.length; t++) {
734
+ let n = this.seriesConfigs[t].stack;
735
+ if (n) {
736
+ let r = e.get(n);
737
+ r || (r = [], e.set(n, r)), r.push(t);
738
+ }
739
+ }
740
+ for (let n of e.values()) if (n.length >= 2) for (let e of n) t.add(e);
741
+ return {
742
+ groups: e,
743
+ stacked: t
744
+ };
745
+ }
746
+ accumulateStackGroup(e) {
747
+ let t = this.stores[e[0]].count;
748
+ if (t === 0) return null;
749
+ let n = new Float64Array(t);
750
+ for (let r of e) {
751
+ let e = this.stores[r], i = e.head, a = e.cap - e.head;
752
+ for (let r = 0; r < t; r++) n[r] += e.yArr[i], --a === 0 ? (i = 0, a = e.cap) : i++;
753
+ }
754
+ return n;
755
+ }
756
+ updateGridDomain() {
757
+ if (this.stores.every((e) => e.count === 0)) return;
758
+ let e = this.opts.yMin, t = this.opts.yMax, n = e !== 0 || t !== 0, r = this.stores.some((e) => e.isRing), i = () => {
759
+ n && (e !== 0 && (this.gridDomainLeft.yMin = e, this.gridDomainRight.yMin = e), t !== 0 && (this.gridDomainLeft.yMax = t, this.gridDomainRight.yMax = t));
760
+ };
761
+ if (r && !n) {
762
+ this.initDomain(this.gridDomainLeft, "left", .05), this.hasRightAxis && this.initDomain(this.gridDomainRight, "right", .05), this.refreshXDomain(), this.gridPinned = !0;
763
+ return;
764
+ }
765
+ if (!this.gridPinned) {
766
+ this.initDomain(this.gridDomainLeft, "left"), this.hasRightAxis && this.initDomain(this.gridDomainRight, "right"), i(), this.refreshXDomain(), this.gridPinned = !0;
767
+ return;
768
+ }
769
+ this.refreshXDomain(), !n && (this.expandDomain(this.gridDomainLeft, "left"), this.hasRightAxis && this.expandDomain(this.gridDomainRight, "right"));
770
+ }
771
+ initDomain(e, t, n = 0) {
772
+ e.xMin = Infinity, e.xMax = -Infinity, e.yMin = Infinity, e.yMax = -Infinity;
773
+ let { groups: r, stacked: i } = this.detectStackGroupsOnAxis(t);
774
+ for (let [, t] of r) {
775
+ if (t.length < 2) continue;
776
+ let n = this.accumulateStackGroup(t);
777
+ if (!n) continue;
778
+ let r = Infinity, i = -Infinity;
779
+ for (let n of t) {
780
+ let t = this.stores[n];
781
+ t.xMin < e.xMin && (e.xMin = t.xMin), t.xMax > e.xMax && (e.xMax = t.xMax);
782
+ }
783
+ for (let e = 0; e < n.length; e++) n[e] < r && (r = n[e]), n[e] > i && (i = n[e]);
784
+ r < e.yMin && (e.yMin = r), i > e.yMax && (e.yMax = i);
785
+ }
786
+ for (let n = 0; n < this.stores.length; n++) {
787
+ if (i.has(n)) continue;
788
+ let r = this.stores[n];
789
+ r.count !== 0 && (this.seriesConfigs[n].yAxis ?? "left") === t && (r.xMin < e.xMin && (e.xMin = r.xMin), r.xMax > e.xMax && (e.xMax = r.xMax), r.yMin < e.yMin && (e.yMin = r.yMin), r.yMax > e.yMax && (e.yMax = r.yMax));
790
+ }
791
+ if (n > 0 && e.yMax > e.yMin) {
792
+ let t = (e.yMax - e.yMin) * n;
793
+ e.yMin -= t, e.yMax += t;
794
+ }
795
+ }
796
+ expandDomain(e, t) {
797
+ let n = e.yMax - e.yMin || 1, { groups: r, stacked: i } = this.detectStackGroupsOnAxis(t), a = !1;
798
+ for (let [, t] of r) {
799
+ if (t.length < 2) continue;
800
+ let r = this.accumulateStackGroup(t);
801
+ if (!r) continue;
802
+ let i = Infinity, o = -Infinity;
803
+ for (let e = 0; e < r.length; e++) r[e] < i && (i = r[e]), r[e] > o && (o = r[e]);
804
+ i < e.yMin && (e.yMin = i - n * .1, a = !0), o > e.yMax && (e.yMax = o + n * .1, a = !0);
805
+ }
806
+ for (let r = 0; r < this.stores.length; r++) {
807
+ if (i.has(r)) continue;
808
+ let o = this.stores[r];
809
+ o.count !== 0 && (this.seriesConfigs[r].yAxis ?? "left") === t && (o.yMin < e.yMin && (e.yMin = o.yMin - n * .1, a = !0), o.yMax > e.yMax && (e.yMax = o.yMax + n * .1, a = !0));
810
+ }
811
+ if (a) {
812
+ e.xMin = Infinity, e.xMax = -Infinity;
813
+ for (let n = 0; n < this.stores.length; n++) {
814
+ let r = this.stores[n];
815
+ r.count !== 0 && (this.seriesConfigs[n].yAxis ?? "left") === t && (r.xMin < e.xMin && (e.xMin = r.xMin), r.xMax > e.xMax && (e.xMax = r.xMax));
816
+ }
817
+ }
818
+ }
819
+ refreshXDomain() {
820
+ let e = Infinity, t = -Infinity;
821
+ for (let n of this.stores) n.count !== 0 && (n.xMin < e && (e = n.xMin), n.xMax > t && (t = n.xMax));
822
+ e <= t && (this.gridDomainLeft.xMin = e, this.gridDomainLeft.xMax = t, this.gridDomainRight.xMin = e, this.gridDomainRight.xMax = t);
823
+ }
824
+ plotRect() {
825
+ let [e, t, n, r] = this.opts.padding;
826
+ return {
827
+ x: r,
828
+ y: e,
829
+ w: this.surface.cssW - r - t,
830
+ h: this.surface.cssH - e - n
831
+ };
832
+ }
833
+ invalidate() {
834
+ this.dirty = !0, !(!this.autoDraw || this.suspendCount > 0) && (this.rafScheduled ||= requestAnimationFrame(() => {
835
+ this.rafScheduled = 0, this.draw();
836
+ }));
837
+ }
838
+ storeAt(e) {
839
+ let t = this.stores[e];
840
+ if (!t) throw Error(`series index ${e} out of range (${this.stores.length} series)`);
841
+ return t;
842
+ }
843
+ injectCursor(e) {
844
+ let t = this.surface.canvas.getBoundingClientRect();
845
+ this.cursorX = e - t.left, this.showCrosshair = !0, this.draw();
846
+ }
847
+ injectCursorLeave() {
848
+ this.showCrosshair = !1, this.draw();
849
+ }
850
+ attachEvents() {
851
+ this.resizeObserver = new ResizeObserver(this.handleResize), this.resizeObserver.observe(this.surface.canvas), this.surface.canvas.addEventListener("mousemove", this.handleMouseMove), this.surface.canvas.addEventListener("mouseleave", this.handleMouseLeave), this.surface.canvas.addEventListener("keydown", this.handleKeyDown);
852
+ }
853
+ onResize() {
854
+ this.surface.measure() && (this.dirty = !0, this.draw());
855
+ }
856
+ onMouseMove(e) {
857
+ let t = this.surface.canvas.getBoundingClientRect();
858
+ this.cursorX = e.clientX - t.left, this.cursorY = e.clientY - t.top, this.showCrosshair = !0, this.draw(), this.notifySyncCrosshair();
859
+ }
860
+ onMouseLeave() {
861
+ this.showCrosshair = !1, this.draw(), this.notifySyncCrosshairLeave();
862
+ }
863
+ };
864
+ //#endregion
865
+ //#region src/render/line.ts
866
+ function S(e, t, n, r) {
867
+ let { xArr: i, yArr: a, count: o, cap: s } = t;
868
+ if (o === 0) return;
869
+ e.strokeStyle = r.lineColor, e.lineWidth = r.lineWidth, e.lineJoin = "round", e.lineCap = "round", e.beginPath();
870
+ let c = t.xMax - t.xMin, l = t.yMax - t.yMin, u = c > 0 ? n.w / c : 0, d = n.x - t.xMin * u, f = l > 0 ? n.h / l : 0, p = n.y + n.h + t.yMin * f, m = t.head, h = s - t.head;
871
+ if (o > n.w * 2) {
872
+ let t = -1, n = 0, r = 0, c = 0, l = 0, g = !1, _ = (t) => {
873
+ e.lineTo(t, c), e.lineTo(t, n), e.lineTo(t, r), e.lineTo(t, l);
874
+ };
875
+ for (let v = 0; v < o; v++) {
876
+ let o = d + i[m] * u | 0, v = p - a[m] * f;
877
+ o === t ? (v < n && (n = v), v > r && (r = v), l = v) : (g ? _(t + .5) : (e.moveTo(o + .5, v), g = !0), t = o, n = v, r = v, c = v, l = v), --h === 0 ? (m = 0, h = s) : m++;
878
+ }
879
+ g && _(t + .5);
880
+ } else {
881
+ e.moveTo(d + i[m] * u, p - a[m] * f), --h === 0 ? (m = 0, h = s) : m++;
882
+ for (let t = 1; t < o; t++) e.lineTo(d + i[m] * u, p - a[m] * f), --h === 0 ? (m = 0, h = s) : m++;
883
+ }
884
+ e.stroke();
885
+ }
886
+ //#endregion
887
+ //#region src/charts/line-chart.ts
888
+ var C = class extends x {
889
+ renderSeries(e, t, n, r) {
890
+ S(e, t, n, r);
891
+ }
892
+ };
893
+ //#endregion
894
+ //#region src/render/area.ts
895
+ function w(e, t, n, r) {
896
+ let { xArr: i, yArr: a, count: o, cap: s } = t;
897
+ if (o === 0) return;
898
+ let c = t.xMax - t.xMin, l = t.yMax - t.yMin, u = c > 0 ? n.w / c : 0, d = n.x - t.xMin * u, f = l > 0 ? n.h / l : 0, p = n.y + n.h + t.yMin * f, m = n.y + n.h, h = t.head, g = s - t.head;
899
+ if (e.lineJoin = "round", o > n.w * 2) {
900
+ let t = [], n = -1, c = 0, l = 0, _ = 0, v = 0;
901
+ for (let e = 0; e < o; e++) {
902
+ let e = d + i[h] * u | 0, r = p - a[h] * f;
903
+ e === n ? (r < c && (c = r), r > l && (l = r), v = r) : (n >= 0 && t.push([
904
+ n + .5,
905
+ _,
906
+ c,
907
+ l,
908
+ v
909
+ ]), n = e, c = l = _ = v = r), --g === 0 ? (h = 0, g = s) : h++;
910
+ }
911
+ if (n >= 0 && t.push([
912
+ n + .5,
913
+ _,
914
+ c,
915
+ l,
916
+ v
917
+ ]), t.length === 0) return;
918
+ let y = t[0], b = t[t.length - 1];
919
+ e.beginPath(), e.moveTo(y[0], y[1]);
920
+ for (let n = 0; n < t.length; n++) {
921
+ let [, r, i, a, o] = t[n];
922
+ e.lineTo(t[n][0], r), e.lineTo(t[n][0], i), e.lineTo(t[n][0], a), e.lineTo(t[n][0], o);
923
+ }
924
+ e.lineTo(b[0], m), e.lineTo(y[0], m), e.closePath(), e.fillStyle = r.fillColor, r.fillOpacity < 1 && (e.globalAlpha = r.fillOpacity), e.fill(), e.globalAlpha = 1, e.beginPath(), e.strokeStyle = r.lineColor, e.lineWidth = r.lineWidth, e.lineCap = "round", e.moveTo(y[0], y[1]);
925
+ for (let n = 0; n < t.length; n++) {
926
+ let [, r, i, a, o] = t[n];
927
+ e.lineTo(t[n][0], r), e.lineTo(t[n][0], i), e.lineTo(t[n][0], a), e.lineTo(t[n][0], o);
928
+ }
929
+ e.stroke();
930
+ } else {
931
+ let n = Array(o);
932
+ h = t.head, g = s - t.head;
933
+ for (let e = 0; e < o; e++) n[e] = [d + i[h] * u, p - a[h] * f], --g === 0 ? (h = 0, g = s) : h++;
934
+ let c = n[0][0], l = n[o - 1][0];
935
+ e.beginPath(), e.moveTo(n[0][0], n[0][1]);
936
+ for (let t = 1; t < o; t++) e.lineTo(n[t][0], n[t][1]);
937
+ e.lineTo(l, m), e.lineTo(c, m), e.closePath(), e.fillStyle = r.fillColor, r.fillOpacity < 1 && (e.globalAlpha = r.fillOpacity), e.fill(), e.globalAlpha = 1, e.beginPath(), e.strokeStyle = r.lineColor, e.lineWidth = r.lineWidth, e.lineCap = "round", e.moveTo(n[0][0], n[0][1]);
938
+ for (let t = 1; t < o; t++) e.lineTo(n[t][0], n[t][1]);
939
+ e.stroke();
940
+ }
941
+ }
942
+ //#endregion
943
+ //#region src/charts/area-chart.ts
944
+ var T = class extends x {
945
+ renderSeries(e, t, n, r) {
946
+ w(e, t, n, r);
947
+ }
948
+ };
949
+ //#endregion
950
+ //#region src/render/scatter.ts
951
+ function E(e, t, n) {
952
+ let r = e + t;
953
+ return r >= n ? r - n : r;
954
+ }
955
+ function D(e, t, n, r) {
956
+ let { xArr: i, yArr: a, count: o, cap: s } = t;
957
+ if (o === 0) return;
958
+ let c = t.xMax - t.xMin, l = t.yMax - t.yMin, u = c > 0 ? n.w / c : 0, d = n.x - t.xMin * u, f = l > 0 ? n.h / l : 0, p = n.y + n.h + t.yMin * f, m = r.maxDots, h = o > m ? Math.max(1, Math.floor(o / m)) : 1, g = r.pointRadius, _ = t.head;
959
+ e.fillStyle = r.lineColor, e.beginPath();
960
+ for (let t = 0; t < o; t += h) {
961
+ let t = d + i[_] * u, n = p - a[_] * f;
962
+ e.moveTo(t + g, n), e.arc(t, n, g, 0, Math.PI * 2), _ = E(_, h, s);
963
+ }
964
+ e.fill();
965
+ }
966
+ //#endregion
967
+ //#region src/charts/scatter-chart.ts
968
+ var O = class extends x {
969
+ renderSeries(e, t, n, r) {
970
+ D(e, t, n, r);
971
+ }
972
+ }, k = {
973
+ gridColor: "rgba(255,255,255,0.08)",
974
+ axisColor: "rgba(255,255,255,0.25)",
975
+ textColor: "rgba(255,255,255,0.5)",
976
+ crosshairColor: "rgba(255,255,255,0.3)",
977
+ pointColor: "#4ea8ff",
978
+ bgColor: "#111"
979
+ }, A = {
980
+ gridColor: "rgba(0,0,0,0.08)",
981
+ axisColor: "rgba(0,0,0,0.18)",
982
+ textColor: "rgba(0,0,0,0.55)",
983
+ crosshairColor: "rgba(0,0,0,0.18)",
984
+ pointColor: "#2563eb",
985
+ bgColor: "#fff"
986
+ };
987
+ //#endregion
988
+ export { T as AreaChart, k as DARK, A as LIGHT, C as LineChart, O as ScatterChart };
989
+
990
+ //# sourceMappingURL=goro-charts.js.map