@wick-charts/vue 0.5.1 → 0.6.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 (80) hide show
  1. package/README.md +18 -3
  2. package/dist/BarSeries.vue.js +26 -20
  3. package/dist/CandlestickSeries.vue.js +30 -24
  4. package/dist/ChartContainer.vue.js +88 -65
  5. package/dist/HeatmapSeries.vue.js +40 -0
  6. package/dist/HeatmapSeries.vue2.js +4 -0
  7. package/dist/LineSeries.vue.js +26 -20
  8. package/dist/PieSeries.vue.js +24 -18
  9. package/dist/core/dist/animation/animator.js +21 -21
  10. package/dist/core/dist/animation/config.js +114 -87
  11. package/dist/core/dist/animation/easing.js +3 -1
  12. package/dist/core/dist/animation/intro-wave.js +68 -0
  13. package/dist/core/dist/axis/dom-labels.js +13 -14
  14. package/dist/core/dist/chart/badge-animator.js +56 -0
  15. package/dist/core/dist/chart/edge-indicators.js +28 -13
  16. package/dist/core/dist/chart/last-value.js +18 -17
  17. package/dist/core/dist/chart/y-target.js +13 -12
  18. package/dist/core/dist/chart.js +679 -452
  19. package/dist/core/dist/components/annotation-chip.js +28 -0
  20. package/dist/core/dist/components/edge-indicator.js +58 -26
  21. package/dist/core/dist/components/loading-indicator.js +46 -0
  22. package/dist/core/dist/components/marker.js +49 -31
  23. package/dist/core/dist/components/reference-line.js +27 -36
  24. package/dist/core/dist/components/time-region.js +30 -28
  25. package/dist/core/dist/data/store.js +38 -19
  26. package/dist/core/dist/data/sync.js +60 -38
  27. package/dist/core/dist/heatmap-tooltip.js +16 -0
  28. package/dist/core/dist/interactions/handler.js +67 -43
  29. package/dist/core/dist/perf/perf-hud.js +5 -5
  30. package/dist/core/dist/scales/x-scale.js +85 -37
  31. package/dist/core/dist/scales/y-scale.js +38 -27
  32. package/dist/core/dist/series/bar-intro.js +18 -0
  33. package/dist/core/dist/series/bar.js +337 -205
  34. package/dist/core/dist/series/base-multi-layer.js +224 -96
  35. package/dist/core/dist/series/candlestick-intro.js +57 -0
  36. package/dist/core/dist/series/candlestick.js +454 -276
  37. package/dist/core/dist/series/heatmap.js +387 -0
  38. package/dist/core/dist/series/line-intro.js +85 -0
  39. package/dist/core/dist/series/line.js +590 -282
  40. package/dist/core/dist/series/painters/builtins.js +2 -2
  41. package/dist/core/dist/series/pie.js +396 -259
  42. package/dist/core/dist/series/register-builtins.js +8 -7
  43. package/dist/core/dist/series/types.js +6 -0
  44. package/dist/core/dist/series/wave-intro.js +26 -0
  45. package/dist/core/dist/theme/create.js +69 -63
  46. package/dist/core/dist/theme/themes/mint-breeze.js +2 -2
  47. package/dist/core/dist/theme/themes/sand-dune.js +2 -2
  48. package/dist/core/dist/utils/color.js +109 -34
  49. package/dist/core/dist/utils/deep-equal.js +18 -0
  50. package/dist/core/dist/utils/time.js +25 -19
  51. package/dist/index.d.ts +1405 -123
  52. package/dist/index.js +177 -130
  53. package/dist/ui/Crosshair.vue.js +20 -21
  54. package/dist/ui/HeatmapTooltip.vue.js +96 -0
  55. package/dist/ui/HeatmapTooltip.vue2.js +4 -0
  56. package/dist/ui/InfoBar.vue.js +46 -47
  57. package/dist/ui/Legend.vue.js +80 -79
  58. package/dist/ui/PieLegend.vue.js +5 -5
  59. package/dist/ui/PieTooltip.vue.js +77 -67
  60. package/dist/ui/Tooltip.vue.js +60 -60
  61. package/dist/ui/YAxis.vue.js +2 -2
  62. package/dist/ui/YLabel.vue.js +94 -61
  63. package/package.json +2 -2
  64. package/src/BarSeries.vue +23 -7
  65. package/src/CandlestickSeries.vue +23 -7
  66. package/src/ChartContainer.vue +134 -12
  67. package/src/HeatmapSeries.vue +69 -0
  68. package/src/LineSeries.vue +23 -7
  69. package/src/PieSeries.vue +22 -6
  70. package/src/index.ts +84 -3
  71. package/src/ui/Crosshair.vue +1 -2
  72. package/src/ui/HeatmapTooltip.vue +144 -0
  73. package/src/ui/InfoBar.vue +1 -2
  74. package/src/ui/Legend.vue +13 -0
  75. package/src/ui/Marker.vue +1 -1
  76. package/src/ui/PieTooltip.vue +10 -0
  77. package/src/ui/ReferenceLine.vue +2 -2
  78. package/src/ui/TimeRegion.vue +2 -2
  79. package/src/ui/Tooltip.vue +2 -2
  80. package/src/ui/YLabel.vue +123 -8
@@ -0,0 +1,28 @@
1
+ import { isLightColor as m, hexToRgba as T } from "../utils/color.js";
2
+ const y = 7, b = 3.5, v = 5, w = 4.5, B = 6, C = 0.92, M = 0.12, S = 0.6, Y = "rgba(15, 20, 35, 0.1)", A = "rgba(0, 0, 0, 0.4)", L = 3, k = 1;
3
+ function E(o) {
4
+ const { context: t, theme: i, label: s, hpr: r, vpr: c } = o;
5
+ return t.font = f(i, r), {
6
+ width: t.measureText(s).width + y * r * 2,
7
+ height: i.yLabel.fontSize * r + b * c * 2
8
+ };
9
+ }
10
+ function X(o) {
11
+ const { context: t, theme: i, color: s, label: r, x: c, y: l, width: e, height: a, hpr: n, vpr: h, tail: d } = o;
12
+ H({ context: t, x: c, y: l, width: e, height: a, hpr: n, tail: d }), t.save(), t.shadowColor = m(i.background) ? Y : A, t.shadowBlur = L * n, t.shadowOffsetY = k * h, t.fillStyle = T(i.background, C), t.fill(), t.restore(), t.fillStyle = T(s, M), t.fill(), t.strokeStyle = T(s, S), t.lineWidth = Math.max(1, Math.round(n)), t.stroke(), t.font = f(i, n), t.textAlign = "center", t.textBaseline = "middle", t.fillStyle = i.tooltip.textColor, t.fillText(r, c + e / 2, l + a / 2);
13
+ }
14
+ function f(o, t) {
15
+ return `500 ${o.yLabel.fontSize * t}px ${o.typography.fontFamily}`;
16
+ }
17
+ function H({ context: o, x: t, y: i, width: s, height: r, hpr: c, tail: l }) {
18
+ const e = Math.min(v * c, s / 2, r / 2), a = t + s, n = i + r, h = w * c, d = t + e + h, x = a - e - h, p = l === void 0 ? 0 : I(l.tipX, d, x), u = l !== void 0 && l.tipY < i, g = l !== void 0 && l.tipY > n;
19
+ o.beginPath(), o.moveTo(t + e, i), l !== void 0 && u && (o.lineTo(p - h, i), o.lineTo(l.tipX, l.tipY), o.lineTo(p + h, i)), o.lineTo(a - e, i), o.arcTo(a, i, a, i + e, e), o.lineTo(a, n - e), o.arcTo(a, n, a - e, n, e), l !== void 0 && g && (o.lineTo(p + h, n), o.lineTo(l.tipX, l.tipY), o.lineTo(p - h, n)), o.lineTo(t + e, n), o.arcTo(t, n, t, n - e, e), o.lineTo(t, i + e), o.arcTo(t, i, t + e, i, e), o.closePath();
20
+ }
21
+ function I(o, t, i) {
22
+ return t > i ? (t + i) / 2 : Math.max(t, Math.min(i, o));
23
+ }
24
+ export {
25
+ B as CHIP_TAIL_HEIGHT_MEDIA,
26
+ X as drawChip,
27
+ E as measureChip
28
+ };
@@ -1,36 +1,68 @@
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);
1
+ function $(t) {
2
+ const { state: i } = t;
3
+ if (i === "idle" || i === "has-more") return;
4
+ const a = t.timeScale.timeToX(t.boundaryTime);
5
+ if (Number.isFinite(a)) {
6
+ if (i === "loading") {
7
+ t.customIndicator ? S(t, a, t.customIndicator) : y(t, a);
8
8
  return;
9
9
  }
10
- e === "no-data" && T(i, o);
10
+ i === "no-data" && R(t, a);
11
11
  }
12
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();
13
+ function S({
14
+ scope: t,
15
+ theme: i,
16
+ chartMediaWidth: a,
17
+ chartMediaHeight: n,
18
+ side: l,
19
+ now: e,
20
+ resolveEdgeAnchor: o,
21
+ resolveEdgeBarSpacing: s,
22
+ reportPlaceholders: c
23
+ }, h, g) {
24
+ const { context: r, horizontalPixelRatio: d, verticalPixelRatio: m } = t, x = Math.min(150, a), f = l === "right" ? h : h - x;
25
+ r.save(), r.beginPath(), r.rect(
26
+ f * d,
27
+ 0,
28
+ x * d,
29
+ n * m
30
+ ), r.clip(), r.translate(f * d, 0);
31
+ const u = o?.() ?? null, P = s?.() ?? void 0;
32
+ g({
33
+ scope: t,
34
+ theme: i,
35
+ chartMediaWidth: x,
36
+ chartMediaHeight: n,
37
+ now: e,
38
+ side: l,
39
+ edgeValueY: u?.valueY,
40
+ seriesKind: u?.seriesKind,
41
+ barSpacing: P,
42
+ reportPlaceholders: c
43
+ }), r.restore();
44
+ }
45
+ function y({ scope: t, theme: i, chartMediaHeight: a, side: n, now: l }, e) {
46
+ const { context: o, horizontalPixelRatio: s, verticalPixelRatio: c } = t, h = 3 * s, g = 8 * s, r = 24 * s, d = e * s, m = n === "right" ? d + r : d - r, x = a / 2 * c, f = l % 900 / 900, u = Math.floor(f * 3), P = M(i.axis.textColor ?? "#787b86", 0.3), b = i.axis.textColor ?? "#787b86";
47
+ o.save();
48
+ for (let p = 0; p < 3; p++) {
49
+ const v = (p - 1) * g, I = m + v;
50
+ o.beginPath(), o.arc(I, x, h, 0, Math.PI * 2), o.fillStyle = p === u ? b : P, o.fill();
19
51
  }
20
- a.restore();
52
+ o.restore();
21
53
  }
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();
54
+ function R({ scope: t, theme: i, chartMediaHeight: a, side: n }, l) {
55
+ const { context: e, horizontalPixelRatio: o, verticalPixelRatio: s } = t, c = Math.round(l * o) + 0.5;
56
+ e.save(), e.strokeStyle = M(i.axis.textColor ?? "#787b86", 0.6), e.lineWidth = 1, e.setLineDash([4 * o, 4 * o]), e.beginPath(), e.moveTo(c, 0), e.lineTo(c, a * s), e.stroke(), e.setLineDash([]);
57
+ const h = 10 * o, g = n === "right" ? c - h : c + h, r = 18 * s;
58
+ e.fillStyle = i.axis.textColor ?? "#787b86", e.font = `${11 * o}px ${i.typography.fontFamily}`, e.textAlign = n === "right" ? "right" : "left", e.textBaseline = "top", e.fillText("No more data", g, r), e.restore();
27
59
  }
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})`;
60
+ function M(t, i) {
61
+ const a = /^#([0-9a-f]{6})$/i.exec(t.trim());
62
+ if (!a) return t;
63
+ const n = parseInt(a[1].slice(0, 2), 16), l = parseInt(a[1].slice(2, 4), 16), e = parseInt(a[1].slice(4, 6), 16);
64
+ return `rgba(${n}, ${l}, ${e}, ${i})`;
33
65
  }
34
66
  export {
35
- v as renderEdgeIndicator
67
+ $ as renderEdgeIndicator
36
68
  };
@@ -0,0 +1,46 @@
1
+ import { hexToRgba as d } from "../utils/color.js";
2
+ const F = 6, J = 24, K = 0.55, u = 5, z = 1400, g = 35, O = ({
3
+ scope: E,
4
+ theme: G,
5
+ chartMediaWidth: h,
6
+ chartMediaHeight: H,
7
+ now: I,
8
+ side: W,
9
+ edgeValueY: X,
10
+ barSpacing: p,
11
+ seriesKind: b,
12
+ reportPlaceholders: v
13
+ }) => {
14
+ const { context: o, horizontalPixelRatio: a, verticalPixelRatio: e } = E, l = G.axis.textColor ?? "#787b86", w = X ?? H / 2, m = W === "right", i = p && p > 4 ? p : J, T = Math.max(3, i * K), _ = b === void 0 || b === "candlestick", k = Math.min(H * 0.22, 34), A = Math.max(3, Math.min(F, Math.floor(h / i)));
15
+ o.save();
16
+ const y = [];
17
+ for (let t = 0; t < A; t++) {
18
+ const f = m ? i * 0.7 + t * i : h - i * 0.7 - t * i, x = Math.sin(t * 1.1 + 0.6) * 0.4, M = t === 0 ? w : w + x * k * 1.4, r = Math.max(6, k * (0.5 + 0.5 * Math.abs(Math.cos(t * 0.8))));
19
+ y.push({ x: f, y: M, halfHeight: r, width: T });
20
+ const s = f * a, R = T * a, n = (M - r) * e, S = r * 2 * e;
21
+ o.fillStyle = d(l, 0.16), o.fillRect(s - R / 2, n, R, S), _ && (o.strokeStyle = d(l, 0.12), o.lineWidth = Math.max(1, a), o.beginPath(), o.moveTo(s, n - u * e), o.lineTo(s, n), o.moveTo(s, n + S), o.lineTo(s, n + S + u * e), o.stroke());
22
+ }
23
+ v !== void 0 && v(
24
+ y.map((t) => ({
25
+ offsetX: m ? t.x : h - t.x,
26
+ y: t.y,
27
+ halfHeight: t.halfHeight,
28
+ width: t.width
29
+ }))
30
+ );
31
+ const B = h + g * 2, P = I % z / z * B - g, C = m ? P : h - P, c = o.createLinearGradient(
32
+ (C - g) * a,
33
+ 0,
34
+ (C + g) * a,
35
+ 0
36
+ );
37
+ c.addColorStop(0, d(l, 0)), c.addColorStop(0.5, d(l, 0.35)), c.addColorStop(1, d(l, 0)), o.fillStyle = c;
38
+ for (const t of y) {
39
+ const f = t.x * a, x = t.width * a, M = (t.y - t.halfHeight) * e, r = t.halfHeight * 2 * e;
40
+ o.fillRect(f - x / 2, M, x, r);
41
+ }
42
+ o.restore();
43
+ };
44
+ export {
45
+ O as skeletonLoadingIndicator
46
+ };
@@ -1,41 +1,59 @@
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();
1
+ import { hexToRgba as g } from "../utils/color.js";
2
+ import { measureChip as I, drawChip as T, CHIP_TAIL_HEIGHT_MEDIA as S } from "./annotation-chip.js";
3
+ const y = 4, H = 5, k = 9, W = 3, C = 4;
4
+ function Y(e) {
5
+ const { scope: a, timeScale: r, yScale: l, theme: s, marker: t, phase: n, plotWidth: o, plotHeight: p } = e, { context: h, horizontalPixelRatio: i, verticalPixelRatio: d } = a, c = r.timeToBitmapX(t.time), b = l.valueToBitmapY(t.value);
6
+ if (!Number.isFinite(c) || !Number.isFinite(b)) return;
7
+ const m = y * i, f = t.shape === "arrow-up" || t.shape === "arrow-down", x = t.label !== void 0 && t.label !== "";
8
+ h.save(), t.pulse && R({ context: h, bx: c, by: b, color: t.color, radius: m, hpr: i, phase: n }), f && x || _({ context: h, bx: c, by: b, color: t.color, radius: m, hpr: i, vpr: d, shape: t.shape }), t.label !== void 0 && t.label !== "" && A({
9
+ context: h,
10
+ bx: c,
11
+ by: b,
12
+ color: t.color,
13
+ theme: s,
14
+ hpr: i,
15
+ vpr: d,
16
+ label: t.label,
17
+ shape: t.shape,
18
+ plotWidth: o,
19
+ plotHeight: p
20
+ }), h.restore();
9
21
  }
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();
22
+ function R({ context: e, bx: a, by: r, color: l, radius: s, hpr: t, phase: n }) {
23
+ const o = 0.4 + 0.6 * Math.abs(Math.sin(n * 2 * Math.PI)), p = s + 4 * t * o;
24
+ e.beginPath(), e.arc(a, r, p, 0, Math.PI * 2), e.fillStyle = g(l, o * 0.3), e.fill();
13
25
  }
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();
26
+ function _({ context: e, bx: a, by: r, color: l, radius: s, hpr: t, vpr: n, shape: o }) {
27
+ if (o === "dot") {
28
+ e.beginPath(), e.arc(a, r, s, 0, Math.PI * 2), e.fillStyle = l, e.fill();
17
29
  return;
18
30
  }
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();
31
+ if (o === "circle") {
32
+ e.beginPath(), e.arc(a, r, s, 0, Math.PI * 2), e.strokeStyle = l, e.lineWidth = Math.max(1, Math.round(1.5 * t)), e.stroke();
21
33
  return;
22
34
  }
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();
35
+ const p = H * t, h = k * n, i = o === "arrow-down" ? -1 : 1;
36
+ e.beginPath(), e.moveTo(a, r), e.lineTo(a - p, r + i * h), e.lineTo(a + p, r + i * h), e.closePath(), e.fillStyle = l, e.fill();
25
37
  }
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
+ function A(e) {
39
+ const { context: a, bx: r, by: l, color: s, theme: t, hpr: n, vpr: o, label: p, shape: h, plotWidth: i, plotHeight: d } = e, { width: c, height: b } = I({ context: a, theme: t, label: p, hpr: n, vpr: o }), m = S * o, f = C * n, x = h === "arrow-up" || h === "arrow-down" ? 0 : (y + W) * o, v = x + m + b;
40
+ let u = h !== "arrow-up";
41
+ u && l - v < 0 && (u = !1), !u && l + v > d && (u = !0);
42
+ const w = u ? l - x : l + x, M = u ? w - m - b : w + m, P = Math.max(f, Math.min(r - c / 2, i - c - f));
43
+ T({
44
+ context: a,
45
+ theme: t,
46
+ color: s,
47
+ label: p,
48
+ x: P,
49
+ y: M,
50
+ width: c,
51
+ height: b,
52
+ hpr: n,
53
+ vpr: o,
54
+ tail: { tipX: r, tipY: w }
55
+ });
38
56
  }
39
57
  export {
40
- B as renderMarker
58
+ Y as renderMarker
41
59
  };
@@ -1,48 +1,39 @@
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();
1
+ import { measureChip as T, drawChip as b } from "./annotation-chip.js";
2
+ const v = 4, x = 6;
3
+ function S(c) {
4
+ const { scope: m, timeScale: r, yScale: d, theme: p, line: o, plotWidth: a, plotHeight: h } = c, { context: e, horizontalPixelRatio: n, verticalPixelRatio: s } = m;
5
+ if (e.save(), e.strokeStyle = o.color, o.style === "dashed" && e.setLineDash([v * n, v * n]), o.orientation === "horizontal") {
6
+ const t = d.valueToBitmapY(o.coord);
7
+ if (!Number.isFinite(t) || t < 0 || t > h) {
8
+ e.restore();
9
9
  return;
10
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();
11
+ const l = Math.max(1, Math.round(o.width * s)), i = Math.round(t) + (l % 2 === 1 ? 0.5 : 0);
12
+ e.lineWidth = l, e.beginPath(), e.moveTo(0, i), e.lineTo(a, i), e.stroke();
13
13
  } else {
14
- const o = l.timeToBitmapX(e.coord);
15
- if (!Number.isFinite(o) || o < 0 || o > r) {
16
- t.restore();
14
+ const t = r.timeToBitmapX(o.coord);
15
+ if (!Number.isFinite(t) || t < 0 || t > a) {
16
+ e.restore();
17
17
  return;
18
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();
19
+ const l = Math.max(1, Math.round(o.width * n)), i = Math.round(t) + (l % 2 === 1 ? 0.5 : 0);
20
+ e.lineWidth = l, e.beginPath(), e.moveTo(i, 0), e.lineTo(i, h), e.stroke();
21
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();
22
+ e.setLineDash([]), o.label !== void 0 && M({ context: e, theme: p, line: o, timeScale: r, yScale: d, plotWidth: a, hpr: n, vpr: s }), e.restore();
23
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;
24
+ function M({ context: c, theme: m, line: r, timeScale: d, yScale: p, plotWidth: o, hpr: a, vpr: h }) {
25
+ const e = r.label;
26
+ if (e === void 0) return;
27
+ const { width: n, height: s } = T({ context: c, theme: m, label: e, hpr: a, vpr: h }), t = x * a, l = x * h;
28
+ let i, u;
29
+ if (r.orientation === "horizontal")
30
+ i = t, u = p.valueToBitmapY(r.coord) - s / 2;
33
31
  else {
34
- const v = m.timeToBitmapX(l.coord);
35
- u = Math.min(v + n, e - y - n), p = s;
32
+ const f = d.timeToBitmapX(r.coord);
33
+ i = Math.min(f + t, o - n - t), u = l;
36
34
  }
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);
35
+ b({ context: c, theme: m, color: r.color, label: e, x: i, y: u, width: n, height: s, hpr: a, vpr: h });
45
36
  }
46
37
  export {
47
- R as renderReferenceLine
38
+ S as renderReferenceLine
48
39
  };
@@ -1,35 +1,37 @@
1
- import { fillRoundedRect as d } from "../series/painters/canvas-path.js";
2
1
  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());
2
+ import { measureChip as b, drawChip as v } from "./annotation-chip.js";
3
+ const d = 0.5, f = 6;
4
+ function w(t) {
5
+ const { scope: i, timeScale: l, theme: n, region: e, plotWidth: r, plotHeight: a } = t, { context: o, horizontalPixelRatio: m, verticalPixelRatio: u } = i, c = l.timeToBitmapX(e.from), s = e.to === null ? r : l.timeToBitmapX(e.to);
6
+ if (!Number.isFinite(c) || !Number.isFinite(s)) return;
7
+ const h = Math.max(0, Math.min(c, s)), p = Math.min(r, Math.max(c, s));
8
+ p <= 0 || h >= r || p <= h || (o.save(), o.fillStyle = e.fill, o.fillRect(h, 0, p - h, a), o.globalAlpha = d, o.strokeStyle = e.color, o.lineWidth = Math.max(1, Math.round(m)), x(o, c, r, a), e.to !== null && x(o, s, r, a), o.globalAlpha = 1, e.label && M({ context: o, theme: n, region: e, left: h, hpr: m, vpr: u }), o.restore());
9
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());
10
+ function x(t, i, l, n) {
11
+ i < 0 || i > l || (t.beginPath(), t.moveTo(i, 0), t.lineTo(i, n), t.stroke());
12
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);
13
+ function M({ context: t, theme: i, region: l, left: n, hpr: e, vpr: r }) {
14
+ const a = l.label;
15
+ if (a === void 0) return;
16
+ const { width: o, height: m } = b({ context: t, theme: i, label: a, hpr: e, vpr: r });
17
+ v({
18
+ context: t,
19
+ theme: i,
20
+ color: l.color,
21
+ label: a,
22
+ x: n + f * e,
23
+ y: f * r,
24
+ width: o,
25
+ height: m,
26
+ hpr: e,
27
+ vpr: r
28
+ });
27
29
  }
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 };
30
+ function C(t, i) {
31
+ const l = t.color ?? i.axis.textColor, n = t.fill ?? g(l, 0.08);
32
+ return { color: l, fill: n };
31
33
  }
32
34
  export {
33
- $ as renderTimeRegion,
34
- A as resolveTimeRegionColors
35
+ w as renderTimeRegion,
36
+ C as resolveTimeRegionColors
35
37
  };
@@ -1,10 +1,15 @@
1
- import { EventEmitter as l } from "../events.js";
1
+ import { EventEmitter as d } from "../events.js";
2
2
  import { binarySearch as n } from "../utils/math.js";
3
- class g extends l {
3
+ class u extends d {
4
4
  data = [];
5
5
  _visible = !0;
6
6
  cachedRange = null;
7
7
  cachedResult = [];
8
+ // Dev-only, warn-once-per-instance: these two conditions are almost always
9
+ // a persistent bug in the caller's feed (not a one-off), so a per-call
10
+ // warning would just spam the console on every tick.
11
+ warnedUnsorted = !1;
12
+ warnedOutOfOrderAppend = !1;
8
13
  setVisible(t) {
9
14
  this._visible = t;
10
15
  }
@@ -12,17 +17,21 @@ class g extends l {
12
17
  return this._visible;
13
18
  }
14
19
  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;
20
+ let a = !0;
21
+ for (let e = 1; e < t.length; e++)
22
+ if (t[e].time < t[e - 1].time) {
23
+ a = !1;
19
24
  break;
20
25
  }
21
- this.data = e ? t.slice() : [...t].sort((a, i) => a.time - i.time), this.cachedRange = null, this.emit("update");
26
+ !a && process.env.NODE_ENV !== "production" && !this.warnedUnsorted && (this.warnedUnsorted = !0, console.warn(
27
+ "[wick-charts] data is not sorted by time — re-sorting on every setData() call is wasted work. Sort your feed by `time` ascending before passing it in."
28
+ )), this.data = a ? t.slice() : [...t].sort((e, i) => e.time - i.time), this.cachedRange = null, this.emit("update");
22
29
  }
23
30
  append(t) {
24
31
  if (this.data.length > 0 && t.time <= this.data[this.data.length - 1].time) {
25
- this.updateLast(t);
32
+ process.env.NODE_ENV !== "production" && !this.warnedOutOfOrderAppend && (this.warnedOutOfOrderAppend = !0, console.warn(
33
+ `[wick-charts] append() received time ${t.time}, not after the last point's time ${this.data[this.data.length - 1].time} — treating it as an overwrite of the last point instead of a new one. If you meant to append, check your feed for out-of-order or duplicate timestamps.`
34
+ )), this.updateLast(t);
26
35
  return;
27
36
  }
28
37
  this.data.push(t), this.cachedRange = null, this.emit("update");
@@ -30,6 +39,16 @@ class g extends l {
30
39
  updateLast(t) {
31
40
  this.data.length !== 0 && (this.data[this.data.length - 1] = t, this.cachedRange = null, this.emit("update"));
32
41
  }
42
+ /**
43
+ * Insert older points at the front of the buffer (history prepend). The
44
+ * caller guarantees `points` are sorted ascending and all strictly before
45
+ * the current first point — the sync reconciler only routes here after
46
+ * proving the untouched suffix matches the previous data, so the boundary
47
+ * is already validated and no re-sort is needed here. No-op on empty input.
48
+ */
49
+ prepend(t) {
50
+ t.length !== 0 && (this.data = t.concat(this.data), this.cachedRange = null, this.emit("update"));
51
+ }
33
52
  trimStart(t) {
34
53
  if (!(t <= 0 || this.data.length === 0)) {
35
54
  if (t >= this.data.length) {
@@ -42,11 +61,11 @@ class g extends l {
42
61
  getAll() {
43
62
  return this.data;
44
63
  }
45
- getVisibleData(t, e) {
64
+ getVisibleData(t, a) {
46
65
  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;
66
+ if (this.cachedRange && this.cachedRange.from === t && this.cachedRange.to === a) return this.cachedResult;
67
+ const e = Math.max(0, n(this.data, t, (s) => s.time) - 1), i = Math.min(this.data.length, n(this.data, a, (s) => s.time) + 1);
68
+ return this.cachedResult = this.data.slice(e, i), this.cachedRange = { from: t, to: a }, this.cachedResult;
50
69
  }
51
70
  first() {
52
71
  return this.data[0];
@@ -60,17 +79,17 @@ class g extends l {
60
79
  isEmpty() {
61
80
  return this.data.length === 0;
62
81
  }
63
- findNearest(t, e) {
82
+ findNearest(t, a) {
64
83
  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]);
84
+ const e = n(this.data, t, (h) => h.time);
85
+ let i = null, s = a;
86
+ for (let h = Math.max(0, e - 1); h <= Math.min(this.data.length - 1, e + 1); h++) {
87
+ const r = Math.abs(this.data[h].time - t);
88
+ r <= s && (s = r, i = this.data[h]);
70
89
  }
71
90
  return i;
72
91
  }
73
92
  }
74
93
  export {
75
- g as TimeSeriesStore
94
+ u as TimeSeriesStore
76
95
  };