@wick-charts/vue 0.4.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. package/README.md +5 -3
  2. package/dist/BarSeries.vue.js +44 -0
  3. package/dist/BarSeries.vue2.js +4 -0
  4. package/dist/CandlestickSeries.vue.js +45 -0
  5. package/dist/CandlestickSeries.vue2.js +4 -0
  6. package/dist/ChartContainer.vue.js +168 -0
  7. package/dist/ChartContainer.vue2.js +4 -0
  8. package/dist/LineSeries.vue.js +44 -0
  9. package/dist/LineSeries.vue2.js +4 -0
  10. package/dist/PieSeries.vue.js +34 -0
  11. package/dist/PieSeries.vue2.js +4 -0
  12. package/dist/composables.js +44 -0
  13. package/dist/context.js +25 -0
  14. package/dist/core/dist/animation/animator.js +72 -0
  15. package/dist/core/dist/animation/config.js +145 -0
  16. package/dist/core/dist/animation/easing.js +4 -0
  17. package/dist/core/dist/animation/scalar-spring.js +57 -0
  18. package/dist/core/dist/animation/spring.js +11 -0
  19. package/dist/core/dist/animation/time.js +19 -0
  20. package/dist/core/dist/animation/viewport-engine.js +174 -0
  21. package/dist/core/dist/animation/visible-range-spring.js +64 -0
  22. package/dist/core/dist/animation/y-range-hermite.js +72 -0
  23. package/dist/core/dist/animation/y-range-snap.js +31 -0
  24. package/dist/core/dist/animation/y-range-spring.js +59 -0
  25. package/dist/core/dist/axis/dom-labels.js +60 -0
  26. package/dist/core/dist/canvas-manager.js +109 -0
  27. package/dist/core/dist/chart/edge-indicators.js +26 -0
  28. package/dist/core/dist/chart/fit-to-data.js +9 -0
  29. package/dist/core/dist/chart/last-value.js +31 -0
  30. package/dist/core/dist/chart/options.js +35 -0
  31. package/dist/core/dist/chart/pan-zoom-math.js +66 -0
  32. package/dist/core/dist/chart/streaming-cadence.js +70 -0
  33. package/dist/core/dist/chart/streaming-target.js +22 -0
  34. package/dist/core/dist/chart/viewport-padding.js +6 -0
  35. package/dist/core/dist/chart/y-target.js +24 -0
  36. package/dist/core/dist/chart.js +1495 -0
  37. package/dist/core/dist/components/crosshair.js +9 -0
  38. package/dist/core/dist/components/edge-indicator.js +36 -0
  39. package/dist/core/dist/components/grid.js +22 -0
  40. package/dist/core/dist/components/marker.js +41 -0
  41. package/dist/core/dist/components/reference-line.js +48 -0
  42. package/dist/core/dist/components/time-region.js +35 -0
  43. package/dist/core/dist/data/decimation.js +54 -0
  44. package/dist/core/dist/data/store.js +76 -0
  45. package/dist/core/dist/data/sync.js +47 -0
  46. package/dist/core/dist/events.js +19 -0
  47. package/dist/core/dist/interactions/handler.js +84 -0
  48. package/dist/core/dist/interactions/pan.js +26 -0
  49. package/dist/core/dist/interactions/zoom.js +21 -0
  50. package/dist/core/dist/navigator/controller.js +374 -0
  51. package/dist/core/dist/navigator/decimate.js +44 -0
  52. package/dist/core/dist/navigator/interactions.js +28 -0
  53. package/dist/core/dist/navigator/render.js +68 -0
  54. package/dist/core/dist/perf/counting-context.js +19 -0
  55. package/dist/core/dist/perf/perf-hud.js +453 -0
  56. package/dist/core/dist/perf/perf-monitor.js +132 -0
  57. package/dist/core/dist/render-scheduler.js +31 -0
  58. package/dist/core/dist/scales/tick-tracker.js +110 -0
  59. package/dist/core/dist/scales/x-scale.js +145 -0
  60. package/dist/core/dist/scales/y-scale.js +156 -0
  61. package/dist/core/dist/series/bar.js +341 -0
  62. package/dist/core/dist/series/base-multi-layer.js +438 -0
  63. package/dist/core/dist/series/candlestick.js +481 -0
  64. package/dist/core/dist/series/definition.js +11 -0
  65. package/dist/core/dist/series/line.js +446 -0
  66. package/dist/core/dist/series/painters/builtins.js +36 -0
  67. package/dist/core/dist/series/painters/canvas-path.js +79 -0
  68. package/dist/core/dist/series/painters/resolve.js +32 -0
  69. package/dist/core/dist/series/pie.js +545 -0
  70. package/dist/core/dist/series/register-builtins.js +11 -0
  71. package/dist/core/dist/series/stack-math.js +17 -0
  72. package/dist/core/dist/snapshots.js +107 -0
  73. package/dist/core/dist/theme/create.js +176 -0
  74. package/dist/core/dist/theme/resolve.js +14 -0
  75. package/dist/core/dist/theme/themes/andromeda.js +33 -0
  76. package/dist/core/dist/theme/themes/ayu-mirage.js +33 -0
  77. package/dist/core/dist/theme/themes/catppuccin.js +33 -0
  78. package/dist/core/dist/theme/themes/dracula.js +35 -0
  79. package/dist/core/dist/theme/themes/github-light.js +34 -0
  80. package/dist/core/dist/theme/themes/gruvbox.js +33 -0
  81. package/dist/core/dist/theme/themes/handwritten.js +101 -0
  82. package/dist/core/dist/theme/themes/high-contrast.js +33 -0
  83. package/dist/core/dist/theme/themes/lavender-mist.js +33 -0
  84. package/dist/core/dist/theme/themes/light-pink.js +34 -0
  85. package/dist/core/dist/theme/themes/material-palenight.js +33 -0
  86. package/dist/core/dist/theme/themes/minimal-light.js +34 -0
  87. package/dist/core/dist/theme/themes/mint-breeze.js +33 -0
  88. package/dist/core/dist/theme/themes/monokai-pro.js +33 -0
  89. package/dist/core/dist/theme/themes/night-owl.js +35 -0
  90. package/dist/core/dist/theme/themes/one-dark-pro.js +33 -0
  91. package/dist/core/dist/theme/themes/panda.js +33 -0
  92. package/dist/core/dist/theme/themes/peach-cream.js +33 -0
  93. package/dist/core/dist/theme/themes/quiet-light.js +37 -0
  94. package/dist/core/dist/theme/themes/rose-pine-dawn.js +33 -0
  95. package/dist/core/dist/theme/themes/sand-dune.js +33 -0
  96. package/dist/core/dist/theme/themes/solarized-light.js +34 -0
  97. package/dist/core/dist/tooltip-position.js +10 -0
  98. package/dist/core/dist/utils/color.js +37 -0
  99. package/dist/core/dist/utils/format.js +29 -0
  100. package/dist/core/dist/utils/math.js +26 -0
  101. package/dist/core/dist/utils/poisoned-data-reporter.js +15 -0
  102. package/dist/core/dist/utils/time.js +41 -0
  103. package/dist/index.d.ts +1096 -63
  104. package/dist/index.js +142 -7754
  105. package/dist/ui/Crosshair.vue.js +53 -0
  106. package/dist/ui/Crosshair.vue2.js +4 -0
  107. package/dist/ui/InfoBar.vue.js +143 -0
  108. package/dist/ui/InfoBar.vue2.js +4 -0
  109. package/dist/ui/Legend.vue.js +212 -0
  110. package/dist/ui/Legend.vue2.js +4 -0
  111. package/dist/ui/Marker.vue.js +47 -0
  112. package/dist/ui/Marker.vue2.js +4 -0
  113. package/dist/ui/Navigator.vue.js +58 -0
  114. package/dist/ui/Navigator.vue2.js +4 -0
  115. package/dist/ui/NumberFlow.vue.js +69 -0
  116. package/dist/ui/NumberFlow.vue2.js +4 -0
  117. package/dist/ui/PieLegend.vue.js +132 -0
  118. package/dist/ui/PieLegend.vue2.js +4 -0
  119. package/dist/ui/PieTooltip.vue.js +135 -0
  120. package/dist/ui/PieTooltip.vue2.js +4 -0
  121. package/dist/ui/ReferenceLine.vue.js +44 -0
  122. package/dist/ui/ReferenceLine.vue2.js +4 -0
  123. package/dist/ui/TimeAxis.vue.js +43 -0
  124. package/dist/ui/TimeAxis.vue2.js +4 -0
  125. package/dist/ui/TimeRegion.vue.js +41 -0
  126. package/dist/ui/TimeRegion.vue2.js +4 -0
  127. package/dist/ui/Title.vue.js +54 -0
  128. package/dist/ui/Title.vue2.js +4 -0
  129. package/dist/ui/Tooltip.vue.js +195 -0
  130. package/dist/ui/Tooltip.vue2.js +4 -0
  131. package/dist/ui/YAxis.vue.js +42 -0
  132. package/dist/ui/YAxis.vue2.js +4 -0
  133. package/dist/ui/YLabel.vue.js +105 -0
  134. package/dist/ui/YLabel.vue2.js +4 -0
  135. package/package.json +2 -2
  136. package/src/BarSeries.vue +12 -13
  137. package/src/CandlestickSeries.vue +17 -6
  138. package/src/LineSeries.vue +12 -13
  139. package/src/PieSeries.vue +2 -1
  140. package/src/composables.ts +12 -2
  141. package/src/index.ts +42 -0
  142. package/src/ui/Crosshair.vue +28 -3
  143. package/src/ui/Legend.vue +1 -2
  144. package/src/ui/Marker.vue +62 -0
  145. package/src/ui/ReferenceLine.vue +58 -0
  146. package/src/ui/TimeRegion.vue +54 -0
@@ -0,0 +1,9 @@
1
+ function d(r, s, l, x) {
2
+ const { context: t, bitmapSize: e, horizontalPixelRatio: o, verticalPixelRatio: c } = r, a = Math.max(1, Math.round(c)), i = Math.max(1, Math.round(o));
3
+ t.strokeStyle = x.crosshair.color, t.lineWidth = Math.max(a, i), t.setLineDash([4 * o, 4 * o]);
4
+ const h = Math.round(s) + (i % 2 === 1 ? 0.5 : 0), n = Math.round(l) + (a % 2 === 1 ? 0.5 : 0);
5
+ t.beginPath(), t.moveTo(h, 0), t.lineTo(h, e.height), t.moveTo(0, n), t.lineTo(e.width, n), t.stroke(), t.setLineDash([]);
6
+ }
7
+ export {
8
+ d as renderCrosshair
9
+ };
@@ -0,0 +1,36 @@
1
+ function v(i) {
2
+ const { state: e } = i;
3
+ if (e === "idle" || e === "has-more") return;
4
+ const o = i.timeScale.timeToX(i.boundaryTime);
5
+ if (Number.isFinite(o)) {
6
+ if (e === "loading") {
7
+ M(i, o);
8
+ return;
9
+ }
10
+ e === "no-data" && T(i, o);
11
+ }
12
+ }
13
+ function M({ scope: i, theme: e, chartMediaHeight: o, side: n, now: s }, t) {
14
+ const { context: a, horizontalPixelRatio: r, verticalPixelRatio: l } = i, c = 3 * r, f = 8 * r, h = 24 * r, d = t * r, u = n === "right" ? d + h : d - h, m = o / 2 * l, b = s % 900 / 900, p = Math.floor(b * 3), P = g(e.axis.textColor ?? "#787b86", 0.3), y = e.axis.textColor ?? "#787b86";
15
+ a.save();
16
+ for (let x = 0; x < 3; x++) {
17
+ const $ = (x - 1) * f, I = u + $;
18
+ a.beginPath(), a.arc(I, m, c, 0, Math.PI * 2), a.fillStyle = x === p ? y : P, a.fill();
19
+ }
20
+ a.restore();
21
+ }
22
+ function T({ scope: i, theme: e, chartMediaHeight: o, side: n }, s) {
23
+ const { context: t, horizontalPixelRatio: a, verticalPixelRatio: r } = i, l = Math.round(s * a) + 0.5;
24
+ t.save(), t.strokeStyle = g(e.axis.textColor ?? "#787b86", 0.6), t.lineWidth = 1, t.setLineDash([4 * a, 4 * a]), t.beginPath(), t.moveTo(l, 0), t.lineTo(l, o * r), t.stroke(), t.setLineDash([]);
25
+ const c = 10 * a, f = n === "right" ? l - c : l + c, h = 18 * r;
26
+ t.fillStyle = e.axis.textColor ?? "#787b86", t.font = `${11 * a}px ${e.typography.fontFamily}`, t.textAlign = n === "right" ? "right" : "left", t.textBaseline = "top", t.fillText("No more data", f, h), t.restore();
27
+ }
28
+ function g(i, e) {
29
+ const o = /^#([0-9a-f]{6})$/i.exec(i.trim());
30
+ if (!o) return i;
31
+ const n = parseInt(o[1].slice(0, 2), 16), s = parseInt(o[1].slice(2, 4), 16), t = parseInt(o[1].slice(4, 6), 16);
32
+ return `rgba(${n}, ${s}, ${t}, ${e})`;
33
+ }
34
+ export {
35
+ v as renderEdgeIndicator
36
+ };
@@ -0,0 +1,22 @@
1
+ function T({ scope: c, timeScale: h, yScale: d, theme: a, yTicks: m, timeTicks: p }) {
2
+ const { context: t, bitmapSize: s, horizontalPixelRatio: e, verticalPixelRatio: u } = c;
3
+ t.save(), t.strokeStyle = a.grid.color, a.grid.style === "dashed" ? t.setLineDash([4 * e, 4 * e]) : a.grid.style === "dotted" && t.setLineDash([1 * e, 3 * e]);
4
+ const l = Math.max(1, Math.round(u)), g = l % 2 === 1 ? 0.5 : 0;
5
+ t.lineWidth = l;
6
+ for (const { value: n, opacity: o } of m.entries) {
7
+ if (o <= 0.01) continue;
8
+ const i = Math.round(d.valueToBitmapY(n)) + g;
9
+ t.globalAlpha = o, t.beginPath(), t.moveTo(0, i), t.lineTo(s.width, i), t.stroke();
10
+ }
11
+ const r = Math.max(1, Math.round(e)), y = r % 2 === 1 ? 0.5 : 0;
12
+ t.lineWidth = r;
13
+ for (const { value: n, opacity: o } of p.entries) {
14
+ if (o <= 0.01) continue;
15
+ const i = Math.round(h.timeToBitmapX(n)) + y;
16
+ t.globalAlpha = o, t.beginPath(), t.moveTo(i, 0), t.lineTo(i, s.height), t.stroke();
17
+ }
18
+ t.restore();
19
+ }
20
+ export {
21
+ T as renderGrid
22
+ };
@@ -0,0 +1,41 @@
1
+ import { fillRoundedRect as d } from "../series/painters/canvas-path.js";
2
+ import { hexToRgba as P } from "../utils/color.js";
3
+ const f = 4, x = 5, g = 9, v = 6, M = 6, S = 3;
4
+ function B(t) {
5
+ const { scope: i, timeScale: o, yScale: c, theme: l, marker: e, phase: s } = t, { context: r, horizontalPixelRatio: a, verticalPixelRatio: h } = i, n = o.timeToBitmapX(e.time), p = c.valueToBitmapY(e.value);
6
+ if (!Number.isFinite(n) || !Number.isFinite(p)) return;
7
+ const b = f * a;
8
+ r.save(), e.pulse && T({ context: r, bx: n, by: p, color: e.color, radius: b, hpr: a, phase: s }), w({ context: r, bx: n, by: p, color: e.color, radius: b, hpr: a, vpr: h, shape: e.shape }), e.label && R({ context: r, bx: n, by: p, color: e.color, theme: l, hpr: a, vpr: h, label: e.label, shape: e.shape }), r.restore();
9
+ }
10
+ function T({ context: t, bx: i, by: o, color: c, radius: l, hpr: e, phase: s }) {
11
+ const r = 0.4 + 0.6 * Math.abs(Math.sin(s * 2 * Math.PI)), a = l + 4 * e * r;
12
+ t.beginPath(), t.arc(i, o, a, 0, Math.PI * 2), t.fillStyle = P(c, r * 0.3), t.fill();
13
+ }
14
+ function w({ context: t, bx: i, by: o, color: c, radius: l, hpr: e, vpr: s, shape: r }) {
15
+ if (r === "dot") {
16
+ t.beginPath(), t.arc(i, o, l, 0, Math.PI * 2), t.fillStyle = c, t.fill();
17
+ return;
18
+ }
19
+ if (r === "circle") {
20
+ t.beginPath(), t.arc(i, o, l, 0, Math.PI * 2), t.strokeStyle = c, t.lineWidth = Math.max(1, Math.round(1.5 * e)), t.stroke();
21
+ return;
22
+ }
23
+ const a = x * e, h = g * s, n = r === "arrow-down" ? -1 : 1;
24
+ t.beginPath(), t.moveTo(i, o), t.lineTo(i - a, o + n * h), t.lineTo(i + a, o + n * h), t.closePath(), t.fillStyle = c, t.fill();
25
+ }
26
+ function R({ context: t, bx: i, by: o, color: c, theme: l, hpr: e, vpr: s, label: r, shape: a }) {
27
+ const h = l.yLabel.fontSize * e;
28
+ t.font = `${h}px ${l.typography.fontFamily}`, t.textAlign = "left", t.textBaseline = "middle";
29
+ const n = M * e, p = S * s, b = v * e, m = a === "arrow-down" || a === "arrow-up" ? x * e : f * e, y = t.measureText(r).width, u = i + m + b + n;
30
+ t.fillStyle = c, d(t, {
31
+ x: u - n,
32
+ y: o - h / 2 - p,
33
+ width: y + n * 2,
34
+ height: h + p * 2,
35
+ radius: 3 * e,
36
+ corners: { tl: !0, tr: !0, br: !0, bl: !0 }
37
+ }), t.fillStyle = l.yLabel.textColor, t.fillText(r, u, o);
38
+ }
39
+ export {
40
+ B as renderMarker
41
+ };
@@ -0,0 +1,48 @@
1
+ import { fillRoundedRect as S } from "../series/painters/canvas-path.js";
2
+ const b = 4, T = 6, M = 6, g = 3;
3
+ function R(i) {
4
+ const { scope: h, timeScale: l, yScale: m, theme: f, line: e, plotWidth: r, plotHeight: c } = i, { context: t, horizontalPixelRatio: a, verticalPixelRatio: d } = h;
5
+ if (t.save(), t.strokeStyle = e.color, e.style === "dashed" && t.setLineDash([b * a, b * a]), e.orientation === "horizontal") {
6
+ const o = m.valueToBitmapY(e.coord);
7
+ if (!Number.isFinite(o) || o < 0 || o > c) {
8
+ t.restore();
9
+ return;
10
+ }
11
+ const n = Math.max(1, Math.round(e.width * d)), s = Math.round(o) + (n % 2 === 1 ? 0.5 : 0);
12
+ t.lineWidth = n, t.beginPath(), t.moveTo(0, s), t.lineTo(r, s), t.stroke();
13
+ } else {
14
+ const o = l.timeToBitmapX(e.coord);
15
+ if (!Number.isFinite(o) || o < 0 || o > r) {
16
+ t.restore();
17
+ return;
18
+ }
19
+ const n = Math.max(1, Math.round(e.width * a)), s = Math.round(o) + (n % 2 === 1 ? 0.5 : 0);
20
+ t.lineWidth = n, t.beginPath(), t.moveTo(s, 0), t.lineTo(s, c), t.stroke();
21
+ }
22
+ t.setLineDash([]), e.label !== void 0 && L({ context: t, theme: f, line: e, timeScale: l, yScale: m, plotWidth: r, hpr: a, vpr: d }), t.restore();
23
+ }
24
+ function L({ context: i, theme: h, line: l, timeScale: m, yScale: f, plotWidth: e, hpr: r, vpr: c }) {
25
+ const t = l.label;
26
+ if (t === void 0) return;
27
+ const a = h.yLabel.fontSize * r;
28
+ i.font = `${a}px ${h.typography.fontFamily}`, i.textAlign = "left", i.textBaseline = "middle";
29
+ const d = M * r, o = g * c, n = T * r, s = T * c, y = i.measureText(t).width + d * 2, x = a + o * 2;
30
+ let u, p;
31
+ if (l.orientation === "horizontal")
32
+ u = n, p = f.valueToBitmapY(l.coord) - x / 2;
33
+ else {
34
+ const v = m.timeToBitmapX(l.coord);
35
+ u = Math.min(v + n, e - y - n), p = s;
36
+ }
37
+ i.fillStyle = l.color, S(i, {
38
+ x: u,
39
+ y: p,
40
+ width: y,
41
+ height: x,
42
+ radius: 3 * r,
43
+ corners: { tl: !0, tr: !0, br: !0, bl: !0 }
44
+ }), i.fillStyle = h.yLabel.textColor, i.fillText(t, u + d, p + x / 2);
45
+ }
46
+ export {
47
+ R as renderReferenceLine
48
+ };
@@ -0,0 +1,35 @@
1
+ import { fillRoundedRect as d } from "../series/painters/canvas-path.js";
2
+ import { hexToRgba as g } from "../utils/color.js";
3
+ const y = 0.5, p = 6, T = 6, R = 3;
4
+ function $(e) {
5
+ const { scope: l, timeScale: i, theme: a, region: o, plotWidth: r, plotHeight: m } = e, { context: t, horizontalPixelRatio: h, verticalPixelRatio: u } = l, s = i.timeToBitmapX(o.from), c = o.to === null ? r : i.timeToBitmapX(o.to);
6
+ if (!Number.isFinite(s) || !Number.isFinite(c)) return;
7
+ const n = Math.max(0, Math.min(s, c)), f = Math.min(r, Math.max(s, c));
8
+ f <= 0 || n >= r || f <= n || (t.save(), t.fillStyle = o.fill, t.fillRect(n, 0, f - n, m), t.globalAlpha = y, t.strokeStyle = o.color, t.lineWidth = Math.max(1, Math.round(h)), b(t, s, r, m), o.to !== null && b(t, c, r, m), t.globalAlpha = 1, o.label && v({ context: t, theme: a, region: o, left: n, hpr: h, vpr: u }), t.restore());
9
+ }
10
+ function b(e, l, i, a) {
11
+ l < 0 || l > i || (e.beginPath(), e.moveTo(l, 0), e.lineTo(l, a), e.stroke());
12
+ }
13
+ function v({ context: e, theme: l, region: i, left: a, hpr: o, vpr: r }) {
14
+ const m = i.label;
15
+ if (m === void 0) return;
16
+ const t = l.yLabel.fontSize * o;
17
+ e.font = `${t}px ${l.typography.fontFamily}`, e.textAlign = "left", e.textBaseline = "middle";
18
+ const h = T * o, u = R * r, s = p * o, c = e.measureText(m).width, n = a + s, f = p * r, x = t + u * 2;
19
+ e.fillStyle = i.color, d(e, {
20
+ x: n,
21
+ y: f,
22
+ width: c + h * 2,
23
+ height: x,
24
+ radius: 3 * o,
25
+ corners: { tl: !0, tr: !0, br: !0, bl: !0 }
26
+ }), e.fillStyle = l.yLabel.textColor, e.fillText(m, n + h, f + x / 2);
27
+ }
28
+ function A(e, l) {
29
+ const i = e.color ?? l.axis.textColor, a = e.fill ?? g(i, 0.08);
30
+ return { color: i, fill: a };
31
+ }
32
+ export {
33
+ $ as renderTimeRegion,
34
+ A as resolveTimeRegionColors
35
+ };
@@ -0,0 +1,54 @@
1
+ function D(t, o) {
2
+ return t.length <= o ? t : x(
3
+ t,
4
+ o,
5
+ (l) => l.time,
6
+ (l) => l.value
7
+ );
8
+ }
9
+ function L(t, o) {
10
+ if (t.length <= o) return t;
11
+ const l = Math.ceil(t.length / o), c = [];
12
+ for (let h = 0; h < t.length; h += l) {
13
+ const s = Math.min(h + l, t.length);
14
+ let r = -1 / 0, a = 1 / 0, f = 0;
15
+ for (let n = h; n < s; n++)
16
+ t[n].high > r && (r = t[n].high), t[n].low < a && (a = t[n].low), f += t[n].volume ?? 0;
17
+ c.push({
18
+ time: t[h].time,
19
+ open: t[h].open,
20
+ high: r,
21
+ low: a,
22
+ close: t[s - 1].close,
23
+ volume: f
24
+ });
25
+ }
26
+ return c;
27
+ }
28
+ function x(t, o, l, c) {
29
+ if (o >= t.length || o < 3) return t;
30
+ const h = [t[0]], s = (t.length - 2) / (o - 2);
31
+ let r = 0;
32
+ for (let a = 0; a < o - 2; a++) {
33
+ const f = Math.floor((a + 1) * s) + 1, n = Math.min(Math.floor((a + 2) * s) + 1, t.length - 1);
34
+ let u = 0, g = 0;
35
+ const M = n, p = Math.min(Math.floor((a + 3) * s) + 1, t.length), e = p - M;
36
+ if (e > 0) {
37
+ for (let i = M; i < p; i++)
38
+ u += l(t[i]), g += c(t[i]);
39
+ u /= e, g /= e;
40
+ }
41
+ let v = -1, m = f;
42
+ const w = l(t[r]), b = c(t[r]);
43
+ for (let i = f; i < n; i++) {
44
+ const d = Math.abs((w - u) * (c(t[i]) - b) - (w - l(t[i])) * (g - b));
45
+ d > v && (v = d, m = i);
46
+ }
47
+ h.push(t[m]), r = m;
48
+ }
49
+ return h.push(t[t.length - 1]), h;
50
+ }
51
+ export {
52
+ D as decimateLineData,
53
+ L as decimateOHLCData
54
+ };
@@ -0,0 +1,76 @@
1
+ import { EventEmitter as l } from "../events.js";
2
+ import { binarySearch as n } from "../utils/math.js";
3
+ class g extends l {
4
+ data = [];
5
+ _visible = !0;
6
+ cachedRange = null;
7
+ cachedResult = [];
8
+ setVisible(t) {
9
+ this._visible = t;
10
+ }
11
+ isVisible() {
12
+ return this._visible;
13
+ }
14
+ setData(t) {
15
+ let e = !0;
16
+ for (let a = 1; a < t.length; a++)
17
+ if (t[a].time < t[a - 1].time) {
18
+ e = !1;
19
+ break;
20
+ }
21
+ this.data = e ? t.slice() : [...t].sort((a, i) => a.time - i.time), this.cachedRange = null, this.emit("update");
22
+ }
23
+ append(t) {
24
+ if (this.data.length > 0 && t.time <= this.data[this.data.length - 1].time) {
25
+ this.updateLast(t);
26
+ return;
27
+ }
28
+ this.data.push(t), this.cachedRange = null, this.emit("update");
29
+ }
30
+ updateLast(t) {
31
+ this.data.length !== 0 && (this.data[this.data.length - 1] = t, this.cachedRange = null, this.emit("update"));
32
+ }
33
+ trimStart(t) {
34
+ if (!(t <= 0 || this.data.length === 0)) {
35
+ if (t >= this.data.length) {
36
+ this.data = [], this.cachedRange = null, this.emit("update");
37
+ return;
38
+ }
39
+ this.data = this.data.slice(t), this.cachedRange = null, this.emit("update");
40
+ }
41
+ }
42
+ getAll() {
43
+ return this.data;
44
+ }
45
+ getVisibleData(t, e) {
46
+ if (this.data.length === 0) return [];
47
+ if (this.cachedRange && this.cachedRange.from === t && this.cachedRange.to === e) return this.cachedResult;
48
+ const a = Math.max(0, n(this.data, t, (h) => h.time) - 1), i = Math.min(this.data.length, n(this.data, e, (h) => h.time) + 1);
49
+ return this.cachedResult = this.data.slice(a, i), this.cachedRange = { from: t, to: e }, this.cachedResult;
50
+ }
51
+ first() {
52
+ return this.data[0];
53
+ }
54
+ last() {
55
+ return this.data[this.data.length - 1];
56
+ }
57
+ get length() {
58
+ return this.data.length;
59
+ }
60
+ isEmpty() {
61
+ return this.data.length === 0;
62
+ }
63
+ findNearest(t, e) {
64
+ if (this.data.length === 0) return null;
65
+ const a = n(this.data, t, (s) => s.time);
66
+ let i = null, h = e;
67
+ for (let s = Math.max(0, a - 1); s <= Math.min(this.data.length - 1, a + 1); s++) {
68
+ const d = Math.abs(this.data[s].time - t);
69
+ d <= h && (h = d, i = this.data[s]);
70
+ }
71
+ return i;
72
+ }
73
+ }
74
+ export {
75
+ g as TimeSeriesStore
76
+ };
@@ -0,0 +1,47 @@
1
+ import { normalizeTime as h } from "../utils/time.js";
2
+ const y = { len: 0, firstTime: null, lastTime: null }, d = 20;
3
+ function f(a) {
4
+ return typeof a == "object" && a !== null && !Array.isArray(a) && Array.isArray(a.data);
5
+ }
6
+ function p(a) {
7
+ if (!Array.isArray(a)) return [a];
8
+ if (a.length === 0) return [{ data: [] }];
9
+ const r = a[0];
10
+ return Array.isArray(r) || f(r) ? a.map((t) => Array.isArray(t) ? { data: t } : t) : [{ data: a }];
11
+ }
12
+ function A(a) {
13
+ const { chart: r, id: t } = a, e = p(a.data), l = e.length > 1 ? e.map((n, i) => n.label ?? `Series ${i + 1}`) : [e[0].label];
14
+ r.setSeriesLabels(t, l), r.setLayerColors(
15
+ t,
16
+ e.map((n) => n.color)
17
+ );
18
+ const s = [];
19
+ return r.batch(() => {
20
+ for (let n = 0; n < e.length; n++)
21
+ s[n] = T({
22
+ chart: r,
23
+ id: t,
24
+ data: e[n].data,
25
+ prev: a.prev[n] ?? y,
26
+ layerIndex: n
27
+ });
28
+ }), s;
29
+ }
30
+ function T(a) {
31
+ const { chart: r, id: t, data: e, prev: l, layerIndex: s } = a;
32
+ if (e.length === 0)
33
+ return r.setSeriesData(t, [], s), { len: 0, firstTime: null, lastTime: null };
34
+ const n = h(e[0].time), i = h(e[e.length - 1].time), c = l.firstTime !== null && l.firstTime !== n, u = e.length - l.len, m = l.lastTime !== null && l.lastTime !== i;
35
+ return c && u === 0 && m ? r.batch(() => {
36
+ r.appendData(t, e[e.length - 1], s), r.keepLast(t, e.length, s);
37
+ }) : l.len === 0 || e.length < l.len || u > d || c ? r.setSeriesData(t, e, s) : e.length === l.len ? r.updateData(t, e[e.length - 1], s) : r.batch(() => {
38
+ for (let o = l.len; o < e.length; o++)
39
+ r.appendData(t, e[o], s);
40
+ }), { len: e.length, firstTime: n, lastTime: i };
41
+ }
42
+ export {
43
+ y as EMPTY_SYNC_STATE,
44
+ A as syncLayers,
45
+ T as syncSeriesLayer,
46
+ p as toLayers
47
+ };
@@ -0,0 +1,19 @@
1
+ class l {
2
+ listeners = /* @__PURE__ */ new Map();
3
+ on(e, s) {
4
+ let t = this.listeners.get(e);
5
+ t || (t = /* @__PURE__ */ new Set(), this.listeners.set(e, t)), t.add(s);
6
+ }
7
+ off(e, s) {
8
+ this.listeners.get(e)?.delete(s);
9
+ }
10
+ emit(e, ...s) {
11
+ this.listeners.get(e)?.forEach((t) => t(...s));
12
+ }
13
+ removeAllListeners() {
14
+ this.listeners.clear();
15
+ }
16
+ }
17
+ export {
18
+ l as EventEmitter
19
+ };
@@ -0,0 +1,84 @@
1
+ import { EventEmitter as c } from "../events.js";
2
+ import { clamp as u } from "../utils/math.js";
3
+ import { PanHandler as l } from "./pan.js";
4
+ import { ZoomHandler as r } from "./zoom.js";
5
+ function i(n, t) {
6
+ const e = n.clientX - t.clientX, s = n.clientY - t.clientY;
7
+ return Math.hypot(e, s);
8
+ }
9
+ class M extends c {
10
+ zoom;
11
+ pan;
12
+ canvas;
13
+ timeScale;
14
+ yScale;
15
+ target;
16
+ constructor(t, e, s, o) {
17
+ super(), this.canvas = t, this.target = e, this.timeScale = s, this.yScale = o, this.zoom = new r(e, s), this.pan = new l(e, s, t), t.style.cursor = "crosshair", t.style.touchAction = "none", t.addEventListener("wheel", this.onWheel, { passive: !1 }), t.addEventListener("mousedown", this.onMouseDown), t.addEventListener("mousemove", this.onMouseMove), t.addEventListener("mouseup", this.onMouseUp), t.addEventListener("mouseleave", this.onMouseLeave), t.addEventListener("dblclick", this.onDblClick), t.addEventListener("touchstart", this.onTouchStart, { passive: !1 }), t.addEventListener("touchmove", this.onTouchMove, { passive: !1 }), t.addEventListener("touchend", this.onTouchEnd), t.addEventListener("touchcancel", this.onTouchCancel);
18
+ }
19
+ onWheel = (t) => {
20
+ this.zoom.handleWheel(t);
21
+ };
22
+ onMouseDown = (t) => {
23
+ this.zoom.cancelPendingRebound(), this.pan.handleMouseDown(t);
24
+ };
25
+ onMouseMove = (t) => {
26
+ this.pan.isDragging() && this.pan.handleMouseMove(t), this.emitCrosshair(t.offsetX, t.offsetY);
27
+ };
28
+ onMouseUp = () => {
29
+ this.pan.handleMouseUp();
30
+ };
31
+ onMouseLeave = () => {
32
+ this.pan.handleMouseUp(), this.emit("crosshairMove", null);
33
+ };
34
+ onDblClick = () => {
35
+ };
36
+ // Touch handling
37
+ lastTouchDist = 0;
38
+ touchCount = 0;
39
+ onTouchStart = (t) => {
40
+ t.preventDefault(), this.zoom.cancelPendingRebound(), this.touchCount = t.touches.length, t.touches.length === 1 ? this.pan.handleMouseDown({
41
+ button: 0,
42
+ clientX: t.touches[0].clientX
43
+ }) : t.touches.length === 2 && (this.lastTouchDist = i(t.touches[0], t.touches[1]));
44
+ };
45
+ onTouchMove = (t) => {
46
+ if (t.preventDefault(), t.touches.length === 1 && this.touchCount === 1)
47
+ this.pan.handleMouseMove({
48
+ clientX: t.touches[0].clientX
49
+ });
50
+ else if (t.touches.length === 2) {
51
+ const e = i(t.touches[0], t.touches[1]), s = (t.touches[0].clientX + t.touches[1].clientX) / 2, o = this.canvas.getBoundingClientRect();
52
+ if (e > 0 && this.lastTouchDist > 0) {
53
+ const h = u(this.lastTouchDist / e, 0.1, 10), a = this.timeScale.xToTime(s - o.left);
54
+ this.target.zoomAt(a, h, this.timeScale.getMediaWidth());
55
+ }
56
+ this.lastTouchDist = e;
57
+ }
58
+ };
59
+ onTouchEnd = (t) => {
60
+ if (t.touches.length === 0) {
61
+ this.pan.handleMouseUp(), this.touchCount = 0, this.lastTouchDist = 0, this.emit("crosshairMove", null);
62
+ return;
63
+ }
64
+ t.touches.length === 1 && (this.touchCount = 1, this.lastTouchDist = 0, this.pan.handleMouseDown({ button: 0, clientX: t.touches[0].clientX }));
65
+ };
66
+ onTouchCancel = () => {
67
+ this.pan.handleMouseUp(), this.touchCount = 0, this.lastTouchDist = 0, this.emit("crosshairMove", null);
68
+ };
69
+ emitCrosshair(t, e) {
70
+ const s = this.timeScale.xToTime(t), o = this.yScale.yToValue(e);
71
+ this.emit("crosshairMove", {
72
+ mediaX: t,
73
+ mediaY: e,
74
+ time: s,
75
+ y: o
76
+ });
77
+ }
78
+ destroy() {
79
+ this.zoom.cancelPendingRebound(), this.canvas.removeEventListener("wheel", this.onWheel), this.canvas.removeEventListener("mousedown", this.onMouseDown), this.canvas.removeEventListener("mousemove", this.onMouseMove), this.canvas.removeEventListener("mouseup", this.onMouseUp), this.canvas.removeEventListener("mouseleave", this.onMouseLeave), this.canvas.removeEventListener("dblclick", this.onDblClick), this.canvas.removeEventListener("touchstart", this.onTouchStart), this.canvas.removeEventListener("touchmove", this.onTouchMove), this.canvas.removeEventListener("touchend", this.onTouchEnd), this.canvas.removeEventListener("touchcancel", this.onTouchCancel), this.removeAllListeners();
80
+ }
81
+ }
82
+ export {
83
+ M as InteractionHandler
84
+ };
@@ -0,0 +1,26 @@
1
+ class e {
2
+ constructor(t, s, i) {
3
+ this.target = t, this.timeScale = s, this.canvas = i;
4
+ }
5
+ dragging = !1;
6
+ lastX = 0;
7
+ handleMouseDown(t) {
8
+ t.button === 0 && (this.dragging = !0, this.lastX = t.clientX, this.canvas.style.cursor = "grabbing");
9
+ }
10
+ handleMouseMove(t) {
11
+ if (!this.dragging) return;
12
+ const s = t.clientX - this.lastX;
13
+ this.lastX = t.clientX;
14
+ const i = this.timeScale.pixelDeltaToTimeDelta(-s);
15
+ this.target.pan(i, this.timeScale.getMediaWidth());
16
+ }
17
+ handleMouseUp() {
18
+ this.dragging && (this.dragging = !1, this.canvas.style.cursor = "crosshair");
19
+ }
20
+ isDragging() {
21
+ return this.dragging;
22
+ }
23
+ }
24
+ export {
25
+ e as PanHandler
26
+ };
@@ -0,0 +1,21 @@
1
+ class s {
2
+ constructor(e, a) {
3
+ this.target = e, this.timeScale = a;
4
+ }
5
+ handleWheel(e) {
6
+ e.preventDefault();
7
+ const a = l(e.deltaY, e.deltaMode), i = Math.exp(a * 5e-3), n = this.timeScale.getMediaWidth(), o = Math.min(e.offsetX, n), h = this.timeScale.xToTime(o);
8
+ this.target.zoomAt(h, i, n);
9
+ }
10
+ /** Kept for API parity with InteractionHandler.destroy. Phase 2 step 2
11
+ * removed the wheel-idle rebound timer alongside the rest of the
12
+ * rebound feature; this is now a no-op. */
13
+ cancelPendingRebound() {
14
+ }
15
+ }
16
+ function l(t, e) {
17
+ return e === WheelEvent.DOM_DELTA_LINE ? t * 8 : e === WheelEvent.DOM_DELTA_PAGE ? t * 24 : t;
18
+ }
19
+ export {
20
+ s as ZoomHandler
21
+ };