@ledgerhq/lumen-ui-react-visualization 0.1.21 → 0.1.22

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.
@@ -1,4 +1,4 @@
1
- import { useContext as e, createContext as n, useMemo as r } from "react";
1
+ import { createContext as n, useContext as e, useMemo as r } from "react";
2
2
  const o = n(void 0), s = () => e(o)?.clipPathAttr, c = () => {
3
3
  const t = e(o);
4
4
  return r(() => t?.getPointRevealStyle(), [t]);
@@ -1,4 +1,4 @@
1
1
  import { PointLabelProps, PointProps } from './types';
2
2
  export declare function PointLabel({ style, textAnchor, dominantBaseline, ...props }: Readonly<PointLabelProps>): import("react/jsx-runtime").JSX.Element;
3
- export declare function Point({ dataX, dataY, color, label, LabelComponent, labelPosition, hidePoint, showLabelArrow, size, onClick, magnetic, }: Readonly<PointProps>): import("react/jsx-runtime").JSX.Element | null;
3
+ export declare function Point({ dataX, dataY, color, label, LabelComponent, labelPosition, hidePoint, showLabelArrow, size, onClick, magnetic, labelAlignment, }: Readonly<PointProps>): import("react/jsx-runtime").JSX.Element | null;
4
4
  //# sourceMappingURL=Point.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Point.d.ts","sourceRoot":"","sources":["../../../../src/lib/Components/Point/Point.tsx"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAS3D,wBAAgB,UAAU,CAAC,EACzB,KAAK,EACL,UAAqB,EACrB,gBAAyB,EACzB,GAAG,KAAK,EACT,EAAE,QAAQ,CAAC,eAAe,CAAC,2CAe3B;AAED,wBAAgB,KAAK,CAAC,EACpB,KAAK,EACL,KAAK,EACL,KAAK,EACL,KAAK,EACL,cAAc,EACd,aAAqB,EACrB,SAAiB,EACjB,cAAqB,EACrB,IAAmB,EACnB,OAAO,EACP,QAAgB,GACjB,EAAE,QAAQ,CAAC,UAAU,CAAC,kDAmEtB"}
1
+ {"version":3,"file":"Point.d.ts","sourceRoot":"","sources":["../../../../src/lib/Components/Point/Point.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAEV,eAAe,EAEf,UAAU,EACX,MAAM,SAAS,CAAC;AAIjB,wBAAgB,UAAU,CAAC,EACzB,KAAK,EACL,UAAqB,EACrB,gBAAyB,EACzB,GAAG,KAAK,EACT,EAAE,QAAQ,CAAC,eAAe,CAAC,2CAe3B;AA+BD,wBAAgB,KAAK,CAAC,EACpB,KAAK,EACL,KAAK,EACL,KAAK,EACL,KAAK,EACL,cAAc,EACd,aAAqB,EACrB,SAAiB,EACjB,cAAqB,EACrB,IAAmB,EACnB,OAAO,EACP,QAAgB,EAChB,cAAuB,GACxB,EAAE,QAAQ,CAAC,UAAU,CAAC,kDA2DtB"}
@@ -1,94 +1,122 @@
1
- import { jsxs as k, jsx as n } from "react/jsx-runtime";
2
- import { useMemo as E } from "react";
3
- import { projectPoint as M } from "../../utils/scales/scales.js";
4
- import { STROKE_WIDTH as R, DEFAULT_SIZE as T } from "./constants.js";
5
- import { useMagneticRegistration as z, isWithinBounds as D, resolveLabel as F, buildArrowPoints as I, computeLabelY as Y } from "./utils.js";
6
- import { useCartesianChartContext as _ } from "../CartesianChart/context/cartesianChartContext.js";
7
- import { useMagneticPointsContext as B } from "./pointContext/magneticPointsContext.js";
8
- import { usePointReveal as H } from "../CartesianChart/RevealAnimation/context.js";
9
- import { cssVar as e } from "../../../libs/design-core/dist/lib/cssVar/cssVar.js";
10
- function K({
11
- style: o,
12
- textAnchor: r = "middle",
13
- dominantBaseline: i = "auto",
14
- ...s
1
+ import { jsxs as A, jsx as n } from "react/jsx-runtime";
2
+ import { DEFAULT_SIZE as E, LABEL_FONT_SIZE as P, STROKE_WIDTH as S } from "./constants.js";
3
+ import { usePointGeometry as T } from "./usePointGeometry.js";
4
+ import { resolveLabel as k, computeLabelGeometry as _, buildArrowPoints as w } from "./utils.js";
5
+ import { cssVar as l } from "../../../libs/design-core/dist/lib/cssVar/cssVar.js";
6
+ function F({
7
+ style: t,
8
+ textAnchor: e = "middle",
9
+ dominantBaseline: o = "auto",
10
+ ...r
15
11
  }) {
16
12
  return /* @__PURE__ */ n(
17
13
  "text",
18
14
  {
19
- textAnchor: r,
20
- dominantBaseline: i,
15
+ textAnchor: e,
16
+ dominantBaseline: o,
21
17
  style: {
22
- fill: e("var(--text-base)"),
23
- fontSize: e("var(--font-style-body-4-size)"),
24
- fontWeight: e("var(--font-style-body-4-weight-medium)"),
25
- fontFamily: e("var(--font-family-font)"),
26
- ...o
18
+ fill: l("var(--text-base)"),
19
+ fontSize: P,
20
+ fontWeight: l("var(--font-style-body-4-weight-medium)"),
21
+ fontFamily: l("var(--font-family-font)"),
22
+ ...t
27
23
  },
28
- ...s
24
+ ...r
29
25
  }
30
26
  );
31
27
  }
32
- function $({
33
- dataX: o,
34
- dataY: r,
35
- color: i,
36
- label: s,
37
- LabelComponent: p,
38
- labelPosition: m = "top",
39
- hidePoint: y = !1,
40
- showLabelArrow: x = !0,
41
- size: g = T,
42
- onClick: u,
43
- magnetic: v = !1
28
+ function G({ x: t, y: e, size: o, color: r }) {
29
+ const u = o / 2, a = r ?? l("var(--background-muted-strong)");
30
+ return /* @__PURE__ */ n(
31
+ "circle",
32
+ {
33
+ "data-testid": "point-circle",
34
+ cx: t,
35
+ cy: e,
36
+ r: u,
37
+ style: {
38
+ fill: a,
39
+ stroke: l("var(--background-canvas)")
40
+ },
41
+ strokeWidth: S
42
+ }
43
+ );
44
+ }
45
+ function I({ x: t, y: e, size: o, position: r }) {
46
+ return /* @__PURE__ */ n(
47
+ "polygon",
48
+ {
49
+ "data-testid": "point-arrow",
50
+ points: w(t, e, o / 2, r),
51
+ style: { fill: l("var(--text-base)") }
52
+ }
53
+ );
54
+ }
55
+ function Z({
56
+ dataX: t,
57
+ dataY: e,
58
+ color: o,
59
+ label: r,
60
+ LabelComponent: u,
61
+ labelPosition: a = "top",
62
+ hidePoint: d = !1,
63
+ showLabelArrow: m = !0,
64
+ size: f = E,
65
+ onClick: x,
66
+ magnetic: p = !1,
67
+ labelAlignment: b = "auto"
44
68
  }) {
45
- const { getXScale: b, getYScale: h, getXAxisConfig: S, drawingArea: L } = _(), w = B();
46
- z(v, o, S, w);
47
- const l = b(), a = h(), c = g / 2, A = i ?? e("var(--background-muted-strong)"), t = E(() => {
48
- if (!(!l || !a))
49
- return M(o, r, l, a);
50
- }, [o, r, l, a]), C = H();
51
- if (!t || !D(t.x, t.y, L))
69
+ const { pixel: i, drawingArea: v, revealStyle: g, isVisible: L } = T({
70
+ dataX: t,
71
+ dataY: e,
72
+ magnetic: p
73
+ });
74
+ if (!L || !i)
52
75
  return null;
53
- const f = F(s, o), P = f != null, d = x && P, W = Y(t.y, c, m, d), j = p ?? K;
54
- return /* @__PURE__ */ k(
76
+ const s = k(r, t), y = s !== void 0, c = y ? _({
77
+ text: s,
78
+ pixelX: i.x,
79
+ pixelY: i.y,
80
+ size: f,
81
+ labelPosition: a,
82
+ showLabelArrow: m,
83
+ area: v,
84
+ alignment: b
85
+ }) : null, h = u ?? F;
86
+ return /* @__PURE__ */ A(
55
87
  "g",
56
88
  {
57
89
  "data-testid": "point-group",
58
- onClick: u,
90
+ onClick: x,
59
91
  style: {
60
- ...C,
61
- ...u ? { cursor: "pointer" } : void 0
92
+ ...g,
93
+ ...x ? { cursor: "pointer" } : void 0
62
94
  },
63
95
  children: [
64
- !y && /* @__PURE__ */ n(
65
- "circle",
96
+ !d && /* @__PURE__ */ n(G, { x: i.x, y: i.y, size: f, color: o }),
97
+ y && m && /* @__PURE__ */ n(
98
+ I,
66
99
  {
67
- "data-testid": "point-circle",
68
- cx: t.x,
69
- cy: t.y,
70
- r: c,
71
- style: {
72
- fill: A,
73
- stroke: e("var(--background-canvas)")
74
- },
75
- strokeWidth: R
100
+ x: i.x,
101
+ y: i.y,
102
+ size: f,
103
+ position: a
76
104
  }
77
105
  ),
78
- d && /* @__PURE__ */ n(
79
- "polygon",
106
+ s != null && c && /* @__PURE__ */ n(
107
+ h,
80
108
  {
81
- "data-testid": "point-arrow",
82
- points: I(t.x, t.y, c, m),
83
- style: { fill: e("var(--text-base)") }
109
+ x: c.x,
110
+ y: c.y,
111
+ textAnchor: c.textAnchor,
112
+ children: s
84
113
  }
85
- ),
86
- f != null && /* @__PURE__ */ n(j, { x: t.x, y: W, children: f })
114
+ )
87
115
  ]
88
116
  }
89
117
  );
90
118
  }
91
119
  export {
92
- $ as Point,
93
- K as PointLabel
120
+ Z as Point,
121
+ F as PointLabel
94
122
  };
@@ -4,4 +4,6 @@ export declare const ARROW_WIDTH = 6;
4
4
  export declare const ARROW_HEIGHT = 4;
5
5
  export declare const GAP = 4;
6
6
  export declare const LABEL_FONT_SIZE = 10;
7
+ /** Approximate width of a character in the label font, as a ratio of the font size. */
8
+ export declare const LABEL_CHAR_WIDTH_RATIO = 0.6;
7
9
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../src/lib/Components/Point/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY,KAAK,CAAC;AAC/B,eAAO,MAAM,YAAY,IAAI,CAAC;AAC9B,eAAO,MAAM,WAAW,IAAI,CAAC;AAC7B,eAAO,MAAM,YAAY,IAAI,CAAC;AAC9B,eAAO,MAAM,GAAG,IAAI,CAAC;AACrB,eAAO,MAAM,eAAe,KAAK,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../src/lib/Components/Point/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY,KAAK,CAAC;AAC/B,eAAO,MAAM,YAAY,IAAI,CAAC;AAC9B,eAAO,MAAM,WAAW,IAAI,CAAC;AAC7B,eAAO,MAAM,YAAY,IAAI,CAAC;AAC9B,eAAO,MAAM,GAAG,IAAI,CAAC;AACrB,eAAO,MAAM,eAAe,KAAK,CAAC;AAClC,uFAAuF;AACvF,eAAO,MAAM,sBAAsB,MAAM,CAAC"}
@@ -1,9 +1,10 @@
1
- const o = 10, t = 2, c = 6, n = 4, s = 4, E = 10;
1
+ const _ = 10, o = 2, t = 6, A = 4, T = 4, c = 10, n = 0.6;
2
2
  export {
3
- n as ARROW_HEIGHT,
4
- c as ARROW_WIDTH,
5
- o as DEFAULT_SIZE,
6
- s as GAP,
7
- E as LABEL_FONT_SIZE,
8
- t as STROKE_WIDTH
3
+ A as ARROW_HEIGHT,
4
+ t as ARROW_WIDTH,
5
+ _ as DEFAULT_SIZE,
6
+ T as GAP,
7
+ n as LABEL_CHAR_WIDTH_RATIO,
8
+ c as LABEL_FONT_SIZE,
9
+ o as STROKE_WIDTH
9
10
  };
@@ -5,6 +5,28 @@ export type PointLabelProps = {
5
5
  children: string;
6
6
  } & Omit<SVGProps<SVGTextElement>, 'x' | 'y' | 'children'>;
7
7
  export type PointLabelComponent = ComponentType<PointLabelProps>;
8
+ /**
9
+ * Horizontal alignment strategy for a point's label.
10
+ *
11
+ * - `'auto'`: keep the label inside the drawing area, anchoring it to the
12
+ * nearest edge when it would overflow.
13
+ * - `'center'`: always centre the label on the point.
14
+ */
15
+ export type LabelAlignment = 'center' | 'auto';
16
+ /**
17
+ * Pixel position and styling inputs shared by the point's rendered glyphs. Each
18
+ * glyph picks the subset it needs and derives its own pixel geometry (e.g.
19
+ * radius from `size`).
20
+ */
21
+ type PointGlyphProps = {
22
+ x: number;
23
+ y: number;
24
+ size: number;
25
+ color?: string;
26
+ position: 'top' | 'bottom';
27
+ };
28
+ export type PointMarkerProps = Pick<PointGlyphProps, 'x' | 'y' | 'size' | 'color'>;
29
+ export type PointArrowProps = Pick<PointGlyphProps, 'x' | 'y' | 'size' | 'position'>;
8
30
  export type PointProps = {
9
31
  /**
10
32
  * X coordinate in data space (index or explicit value).
@@ -74,5 +96,15 @@ export type PointProps = {
74
96
  * @default false
75
97
  */
76
98
  magnetic?: boolean;
99
+ /**
100
+ * Horizontal alignment of the label relative to the chart's drawing area.
101
+ * With `'auto'`, a label that would overflow the left/right edge is anchored
102
+ * to that edge and grows inward instead of being clipped, while the arrow
103
+ * keeps pointing at the exact data point. Use `'center'` to always centre the
104
+ * label on the point.
105
+ * @default 'auto'
106
+ */
107
+ labelAlignment?: LabelAlignment;
77
108
  };
109
+ export {};
78
110
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/lib/Components/Point/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEjE,MAAM,MAAM,eAAe,GAAG;IAC5B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,QAAQ,EAAE,MAAM,CAAC;CAClB,GAAG,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,GAAG,GAAG,GAAG,GAAG,UAAU,CAAC,CAAC;AAE3D,MAAM,MAAM,mBAAmB,GAAG,aAAa,CAAC,eAAe,CAAC,CAAC;AAEjE,MAAM,MAAM,UAAU,GAAG;IACvB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAC,CAAC;IACjD;;;;;OAKG;IACH,cAAc,CAAC,EAAE,mBAAmB,CAAC;IACrC;;;OAGG;IACH,aAAa,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC;IACjC;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;OAEG;IACH,OAAO,CAAC,EAAE,CA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EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAC,CAAC;IACjD;;;;;OAKG;IACH,cAAc,CAAC,EAAE,mBAAmB,CAAC;IACrC;;;OAGG;IACH,aAAa,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC;IACjC;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;IACnD;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;;;;OAOG;IACH,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC,CAAC"}
@@ -0,0 +1,33 @@
1
+ import { CSSProperties } from 'react';
2
+ import { DrawingArea } from '../../utils/types';
3
+ import { BaseAxisProps } from '../Axis';
4
+ import { MagneticPointsContextValue } from './pointContext/magneticPointsContext';
5
+ type Pixel = {
6
+ x: number;
7
+ y: number;
8
+ };
9
+ type UsePointGeometryParams = {
10
+ dataX: number;
11
+ dataY: number;
12
+ magnetic: boolean;
13
+ };
14
+ type PointGeometry = {
15
+ pixel: Pixel | undefined;
16
+ drawingArea: DrawingArea;
17
+ revealStyle: CSSProperties | undefined;
18
+ isVisible: boolean;
19
+ };
20
+ /**
21
+ * Resolves a point's chart geometry and behaviour: projects its data
22
+ * coordinates to pixels, registers it as a magnetic snap target when enabled,
23
+ * exposes the reveal-animation style, and reports whether it falls inside the
24
+ * drawing area.
25
+ */
26
+ export declare const usePointGeometry: ({ dataX, dataY, magnetic, }: UsePointGeometryParams) => PointGeometry;
27
+ /**
28
+ * Registers/unregisters a data index as a magnetic snap target
29
+ * when the Point has `magnetic` enabled.
30
+ */
31
+ export declare const useMagneticRegistration: (magnetic: boolean, dataX: number, getXAxisConfig: () => BaseAxisProps | undefined, { register, unregister }: MagneticPointsContextValue) => void;
32
+ export {};
33
+ //# sourceMappingURL=usePointGeometry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePointGeometry.d.ts","sourceRoot":"","sources":["../../../../src/lib/Components/Point/usePointGeometry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAsB,MAAM,OAAO,CAAC;AAG/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAI7C,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAGvF,KAAK,KAAK,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEtC,KAAK,sBAAsB,GAAG;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,KAAK,aAAa,GAAG;IACnB,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC;IACzB,WAAW,EAAE,WAAW,CAAC;IACzB,WAAW,EAAE,aAAa,GAAG,SAAS,CAAC;IACvC,SAAS,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAI,6BAI9B,sBAAsB,KAAG,aAqB3B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,uBAAuB,GAClC,UAAU,OAAO,EACjB,OAAO,MAAM,EACb,gBAAgB,MAAM,aAAa,GAAG,SAAS,EAC/C,0BAA0B,0BAA0B,KACnD,IAQF,CAAC"}
@@ -0,0 +1,30 @@
1
+ import { useMemo as x, useEffect as a } from "react";
2
+ import { projectPoint as v } from "../../utils/scales/scales.js";
3
+ import { isWithinBounds as C, resolveDataXToIndex as S } from "./utils.js";
4
+ import { useCartesianChartContext as g } from "../CartesianChart/context/cartesianChartContext.js";
5
+ import { useMagneticPointsContext as y } from "./pointContext/magneticPointsContext.js";
6
+ import { usePointReveal as P } from "../CartesianChart/RevealAnimation/context.js";
7
+ const A = ({
8
+ dataX: t,
9
+ dataY: e,
10
+ magnetic: n
11
+ }) => {
12
+ const { getXScale: r, getYScale: i, getXAxisConfig: o, drawingArea: u } = g(), f = y();
13
+ d(n, t, o, f);
14
+ const c = r(), m = i(), s = x(() => {
15
+ if (!(!c || !m))
16
+ return v(t, e, c, m);
17
+ }, [t, e, c, m]), l = P(), p = s !== void 0 && C(s.x, s.y, u);
18
+ return { pixel: s, drawingArea: u, revealStyle: l, isVisible: p };
19
+ }, d = (t, e, n, { register: r, unregister: i }) => {
20
+ a(() => {
21
+ if (!t) return;
22
+ const o = S(e, n());
23
+ if (o !== void 0)
24
+ return r(o), () => i(o);
25
+ }, [t, e, n, r, i]);
26
+ };
27
+ export {
28
+ d as useMagneticRegistration,
29
+ A as usePointGeometry
30
+ };
@@ -1,6 +1,7 @@
1
1
  import { DrawingArea } from '../../utils/types';
2
2
  import { BaseAxisProps } from '../Axis';
3
- import { MagneticPointsContextValue } from './pointContext/magneticPointsContext';
3
+ import { LabelAlignment } from './types';
4
+ export type LabelTextAnchor = 'start' | 'middle' | 'end';
4
5
  export declare const isWithinBounds: (px: number, py: number, area: DrawingArea) => boolean;
5
6
  /**
6
7
  * Builds the three SVG points of the arrow triangle.
@@ -15,12 +16,36 @@ export declare const buildArrowPoints: (cx: number, cy: number, radius: number,
15
16
  export declare const resolveLabel: (label: string | ((dataIndex: number) => string) | undefined, dataX: number) => string | undefined;
16
17
  export declare const resolveDataXToIndex: (dataX: number, axisConfig: BaseAxisProps | undefined) => number | undefined;
17
18
  /**
18
- * Registers/unregisters a data index as a magnetic snap target
19
- * when the Point has `magnetic` enabled.
19
+ * Computes the label's horizontal placement, keeping it inside the drawing area
20
+ * near the left/right edges. Centred on the point when it fits; otherwise
21
+ * anchored to the edge and aligned with the arrow's outer vertex (offset by half
22
+ * the arrow width from the point, when an arrow is rendered).
20
23
  */
21
- export declare const useMagneticRegistration: (magnetic: boolean, dataX: number, getXAxisConfig: () => BaseAxisProps | undefined, { register, unregister }: MagneticPointsContextValue) => void;
24
+ export declare const computeLabelX: (pixelX: number, label: string, area: DrawingArea, alignment: LabelAlignment, hasArrow: boolean) => {
25
+ x: number;
26
+ textAnchor: LabelTextAnchor;
27
+ };
22
28
  /**
23
29
  * Computes the vertical position of the label text baseline.
24
30
  */
25
31
  export declare const computeLabelY: (pixelY: number, radius: number, labelPosition: "top" | "bottom", renderArrow: boolean) => number;
32
+ /**
33
+ * Computes where a point's label is drawn: the (optionally clamped) horizontal
34
+ * placement and the vertical baseline. Label content is resolved separately via
35
+ * {@link resolveLabel}.
36
+ */
37
+ export declare const computeLabelGeometry: ({ text, pixelX, pixelY, size, labelPosition, showLabelArrow, area, alignment, }: {
38
+ text: string;
39
+ pixelX: number;
40
+ pixelY: number;
41
+ size: number;
42
+ labelPosition: "top" | "bottom";
43
+ showLabelArrow: boolean;
44
+ area: DrawingArea;
45
+ alignment: LabelAlignment;
46
+ }) => {
47
+ x: number;
48
+ y: number;
49
+ textAnchor: LabelTextAnchor;
50
+ };
26
51
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/lib/Components/Point/utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAEvF,eAAO,MAAM,cAAc,GACzB,IAAI,MAAM,EACV,IAAI,MAAM,EACV,MAAM,WAAW,KAChB,OAIyB,CAAC;AAE7B;;;;;GAK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AAG,QAAQ,KACzB,MAYF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY,GACvB,OAAO,MAAM,GAAG,CAAC,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAC,GAAG,SAAS,EAC3D,OAAO,MAAM,KACZ,MAAM,GAAG,SAGX,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAC9B,OAAO,MAAM,EACb,YAAY,aAAa,GAAG,SAAS,KACpC,MAAM,GAAG,SAMX,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,aAAa,GACxB,QAAQ,MAAM,EACd,OAAO,MAAM,EACb,MAAM,WAAW,EACjB,WAAW,cAAc,EACzB,UAAU,OAAO,KAChB;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,eAAe,CAAA;CAgB1C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa,GACxB,QAAQ,MAAM,EACd,QAAQ,MAAM,EACd,eAAe,KAAK,GAAG,QAAQ,EAC/B,aAAa,OAAO,KACnB,MAMF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,GAAI,iFASlC;IACD,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,KAAK,GAAG,QAAQ,CAAC;IAChC,cAAc,EAAE,OAAO,CAAC;IACxB,IAAI,EAAE,WAAW,CAAC;IAClB,SAAS,EAAE,cAAc,CAAC;CAC3B,KAAG;IACF,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,UAAU,EAAE,eAAe,CAAC;CAY7B,CAAC"}
@@ -1,38 +1,54 @@
1
- import { useEffect as d } from "react";
2
- import { GAP as i, LABEL_FONT_SIZE as p, ARROW_HEIGHT as f, ARROW_WIDTH as v } from "./constants.js";
3
- const R = (t, n, o) => t >= o.x && t <= o.x + o.width && n >= o.y && n <= o.y + o.height, W = (t, n, o, r) => {
4
- const s = v / 2;
1
+ import { GAP as i, LABEL_FONT_SIZE as h, LABEL_CHAR_WIDTH_RATIO as x, ARROW_WIDTH as A, ARROW_HEIGHT as d } from "./constants.js";
2
+ const _ = (t, o, n) => t >= n.x && t <= n.x + n.width && o >= n.y && o <= n.y + n.height, I = (t, o, n, r) => {
3
+ const e = A / 2;
5
4
  if (r === "top") {
6
- const c = n - o - i, $ = c - f;
7
- return `${t},${c} ${t - s},${$} ${t + s},${$}`;
5
+ const f = o - n - i, u = f - d;
6
+ return `${t},${f} ${t - e},${u} ${t + e},${u}`;
8
7
  }
9
- const e = n + o + i, u = e + f;
10
- return `${t},${e} ${t - s},${u} ${t + s},${u}`;
11
- }, b = (t, n) => {
12
- const o = typeof t == "function" ? t(n) : t;
13
- return o === "" ? void 0 : o;
14
- }, h = (t, n) => {
15
- const o = n?.data;
16
- if (!o || typeof o[0] != "number") return t;
17
- const r = o.indexOf(t);
8
+ const s = o + n + i, c = s + d;
9
+ return `${t},${s} ${t - e},${c} ${t + e},${c}`;
10
+ }, R = (t, o) => {
11
+ const n = typeof t == "function" ? t(o) : t;
12
+ return n === "" ? void 0 : n;
13
+ }, T = (t, o) => {
14
+ const n = o?.data;
15
+ if (!n || typeof n[0] != "number") return t;
16
+ const r = n.indexOf(t);
18
17
  if (r !== -1)
19
18
  return r;
20
- }, A = (t, n, o, { register: r, unregister: s }) => {
21
- d(() => {
22
- if (!t) return;
23
- const e = h(n, o());
24
- if (e !== void 0)
25
- return r(e), () => s(e);
26
- }, [t, n, o, r, s]);
27
- }, E = (t, n, o, r) => {
28
- const s = r ? f + i : i;
29
- return o === "top" ? t - n - s - i : t + n + s + i + p;
19
+ }, L = (t, o, n, r, e) => {
20
+ if (r === "center")
21
+ return { x: t, textAnchor: "middle" };
22
+ const s = o.length * h * x / 2, c = e ? A / 2 : 0;
23
+ return t - s < n.x ? { x: t - c, textAnchor: "start" } : t + s > n.x + n.width ? { x: t + c, textAnchor: "end" } : { x: t, textAnchor: "middle" };
24
+ }, O = (t, o, n, r) => {
25
+ const e = r ? d + i : i;
26
+ return n === "top" ? t - o - e - i : t + o + e + i + h;
27
+ }, b = ({
28
+ text: t,
29
+ pixelX: o,
30
+ pixelY: n,
31
+ size: r,
32
+ labelPosition: e,
33
+ showLabelArrow: s,
34
+ area: c,
35
+ alignment: f
36
+ }) => {
37
+ const { x: u, textAnchor: $ } = L(
38
+ o,
39
+ t,
40
+ c,
41
+ f,
42
+ s
43
+ ), m = O(n, r / 2, e, s);
44
+ return { x: u, y: m, textAnchor: $ };
30
45
  };
31
46
  export {
32
- W as buildArrowPoints,
33
- E as computeLabelY,
34
- R as isWithinBounds,
35
- h as resolveDataXToIndex,
36
- b as resolveLabel,
37
- A as useMagneticRegistration
47
+ I as buildArrowPoints,
48
+ b as computeLabelGeometry,
49
+ L as computeLabelX,
50
+ O as computeLabelY,
51
+ _ as isWithinBounds,
52
+ T as resolveDataXToIndex,
53
+ R as resolveLabel
38
54
  };
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ledgerhq/lumen-ui-react-visualization",
3
- "version": "0.1.20",
3
+ "version": "0.1.21",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "keywords": [
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "peerDependencies": {
36
36
  "@ledgerhq/lumen-design-core": "0.1.17",
37
- "@ledgerhq/lumen-ui-react": "0.1.41",
37
+ "@ledgerhq/lumen-ui-react": "0.1.42",
38
38
  "class-variance-authority": "^0.7.1",
39
39
  "clsx": "^2.1.1",
40
40
  "react": "^18.0.0 || ^19.0.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ledgerhq/lumen-ui-react-visualization",
3
- "version": "0.1.21",
3
+ "version": "0.1.22",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "keywords": [
@@ -33,8 +33,8 @@
33
33
  ]
34
34
  },
35
35
  "peerDependencies": {
36
- "@ledgerhq/lumen-design-core": "0.1.17",
37
- "@ledgerhq/lumen-ui-react": "0.1.42",
36
+ "@ledgerhq/lumen-design-core": "0.1.18",
37
+ "@ledgerhq/lumen-ui-react": "0.1.43",
38
38
  "class-variance-authority": "^0.7.1",
39
39
  "clsx": "^2.1.1",
40
40
  "react": "^18.0.0 || ^19.0.0",
@@ -42,7 +42,7 @@
42
42
  "tailwind-merge": "^2.6.0"
43
43
  },
44
44
  "dependencies": {
45
- "@ledgerhq/lumen-utils-shared": "0.1.5",
45
+ "@ledgerhq/lumen-utils-shared": "0.1.6",
46
46
  "d3-array": "^3.2.4",
47
47
  "d3-scale": "^4.0.2",
48
48
  "d3-shape": "^3.2.0"