@octane-xplat/charts 0.0.1 → 0.11.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 (47) hide show
  1. package/LICENSE +21 -0
  2. package/dist/macos/Chart.macos.tsrx.js +351 -0
  3. package/dist/macos/core/axes.js +146 -0
  4. package/dist/macos/core/hit.js +131 -0
  5. package/dist/macos/core/marks.js +262 -0
  6. package/dist/macos/core/scales.js +99 -0
  7. package/dist/macos/core/scene.js +120 -0
  8. package/dist/macos/core/svg.js +40 -0
  9. package/dist/macos/index.js +2 -0
  10. package/dist/macos/octane-client-build.json +8 -0
  11. package/dist/macos/svg-image.macos.js +14 -0
  12. package/dist/native/Chart.tsrx.js +340 -0
  13. package/dist/native/core/axes.js +146 -0
  14. package/dist/native/core/hit.js +131 -0
  15. package/dist/native/core/marks.js +262 -0
  16. package/dist/native/core/scales.js +99 -0
  17. package/dist/native/core/scene.js +120 -0
  18. package/dist/native/core/svg.js +40 -0
  19. package/dist/native/index.js +2 -0
  20. package/dist/native/octane-client-build.json +8 -0
  21. package/dist/web/Chart.web.tsrx.js +488 -0
  22. package/dist/web/core/axes.js +146 -0
  23. package/dist/web/core/hit.js +131 -0
  24. package/dist/web/core/marks.js +262 -0
  25. package/dist/web/core/scales.js +99 -0
  26. package/dist/web/core/scene.js +120 -0
  27. package/dist/web/core/svg.js +40 -0
  28. package/dist/web/index.js +2 -0
  29. package/dist/web/octane-client-build.json +8 -0
  30. package/package.json +86 -3
  31. package/src/Chart.macos.tsrx +134 -0
  32. package/src/Chart.tsrx +174 -0
  33. package/src/Chart.web.tsrx +215 -0
  34. package/src/core/axes.ts +211 -0
  35. package/src/core/hit.ts +201 -0
  36. package/src/core/marks.ts +380 -0
  37. package/src/core/scales.ts +168 -0
  38. package/src/core/scene.ts +145 -0
  39. package/src/core/svg.ts +84 -0
  40. package/src/index.macos.ts +12 -0
  41. package/src/index.ts +12 -0
  42. package/src/index.web.ts +12 -0
  43. package/src/props.ts +90 -0
  44. package/src/svg-image.macos.ts +34 -0
  45. package/types/index.d.ts +17 -0
  46. package/types/props.d.ts +83 -0
  47. package/README.md +0 -4
@@ -0,0 +1,340 @@
1
+ import { computeScene } from "./core/scene.js";
2
+ import { createScrub, hitLabel } from "./core/hit.js";
3
+ import { defineUniversalComponent, hookSlots, universalIf, universalPlan, universalValue, useMemo, useRef, useState, withSlot } from "@nativescript-community/octane";
4
+ import { AccessibilityRole, Color } from "@nativescript/core";
5
+ import { useMeasure } from "@octane-xplat/ui";
6
+ //#region src/Chart.tsrx
7
+ var _hs$ = /* @__PURE__ */ hookSlots(7);
8
+ var _h$0 = /* @__PURE__ */ Symbol(_hs$);
9
+ var _h$1 = /* @__PURE__ */ Symbol(_hs$ + 1);
10
+ var _h$2 = /* @__PURE__ */ Symbol(_hs$ + 2);
11
+ var _h$3 = /* @__PURE__ */ Symbol(_hs$ + 3);
12
+ var _h$4 = /* @__PURE__ */ Symbol(_hs$ + 4);
13
+ var _h$5 = /* @__PURE__ */ Symbol(_hs$ + 5);
14
+ var _h$6 = /* @__PURE__ */ Symbol(_hs$ + 6);
15
+ var __octaneUniversalPlan0 = universalPlan("nativescript", {
16
+ "kind": "host",
17
+ "type": "flexboxlayout",
18
+ "props": {
19
+ "flexDirection": "row",
20
+ "alignItems": "center"
21
+ },
22
+ "bindings": [["style", 0]],
23
+ "children": [{
24
+ "kind": "host",
25
+ "type": "contentview",
26
+ "bindings": [["style", 1]]
27
+ }, {
28
+ "kind": "host",
29
+ "type": "label",
30
+ "bindings": [["text", 2], ["style", 3]]
31
+ }]
32
+ });
33
+ var __octaneUniversalPlan1 = universalPlan("nativescript", {
34
+ "kind": "host",
35
+ "type": "flexboxlayout",
36
+ "props": {
37
+ "flexDirection": "row",
38
+ "flexWrap": "wrap"
39
+ },
40
+ "bindings": [["style", 0]],
41
+ "children": [{
42
+ "kind": "slot",
43
+ "slot": 1
44
+ }]
45
+ });
46
+ var __octaneUniversalPlan2 = universalPlan("nativescript", {
47
+ "kind": "host",
48
+ "type": "label",
49
+ "bindings": [
50
+ ["left", 0],
51
+ ["top", 1],
52
+ ["width", 2],
53
+ ["text", 3],
54
+ ["textAlignment", 4],
55
+ ["style", 5]
56
+ ]
57
+ });
58
+ var __octaneUniversalPlan3 = universalPlan("nativescript", {
59
+ "kind": "host",
60
+ "type": "contentview",
61
+ "props": { "width": 1 },
62
+ "bindings": [
63
+ ["left", 0],
64
+ ["top", 1],
65
+ ["height", 2],
66
+ ["backgroundColor", 3]
67
+ ]
68
+ });
69
+ var __octaneUniversalPlan4 = universalPlan("nativescript", {
70
+ "kind": "host",
71
+ "type": "contentview",
72
+ "props": {
73
+ "width": 8,
74
+ "height": 8,
75
+ "borderRadius": 4
76
+ },
77
+ "bindings": [
78
+ ["left", 0],
79
+ ["top", 1],
80
+ ["backgroundColor", 2]
81
+ ]
82
+ });
83
+ var __octaneUniversalPlan5 = universalPlan("nativescript", {
84
+ "kind": "host",
85
+ "type": "flexboxlayout",
86
+ "props": {
87
+ "borderRadius": 4,
88
+ "paddingTop": 2,
89
+ "paddingBottom": 2,
90
+ "paddingLeft": 6,
91
+ "paddingRight": 6
92
+ },
93
+ "bindings": [
94
+ ["left", 0],
95
+ ["top", 1],
96
+ ["backgroundColor", 2]
97
+ ],
98
+ "children": [{
99
+ "kind": "host",
100
+ "type": "label",
101
+ "bindings": [
102
+ ["text", 3],
103
+ ["color", 4],
104
+ ["style", 5]
105
+ ]
106
+ }]
107
+ });
108
+ var __octaneUniversalPlan6 = universalPlan("nativescript", {
109
+ "kind": "host",
110
+ "type": "flexboxlayout",
111
+ "props": {
112
+ "flexDirection": "row",
113
+ "alignItems": "center"
114
+ },
115
+ "bindings": [["style", 0]],
116
+ "children": [{
117
+ "kind": "host",
118
+ "type": "contentview",
119
+ "bindings": [["style", 1]]
120
+ }, {
121
+ "kind": "host",
122
+ "type": "label",
123
+ "bindings": [["text", 2], ["style", 3]]
124
+ }]
125
+ });
126
+ var __octaneUniversalPlan7 = universalPlan("nativescript", {
127
+ "kind": "host",
128
+ "type": "flexboxlayout",
129
+ "props": {
130
+ "flexDirection": "row",
131
+ "flexWrap": "wrap"
132
+ },
133
+ "bindings": [["style", 0]],
134
+ "children": [{
135
+ "kind": "slot",
136
+ "slot": 1
137
+ }]
138
+ });
139
+ var __octaneUniversalPlan8 = universalPlan("nativescript", {
140
+ "kind": "host",
141
+ "type": "flexboxlayout",
142
+ "bindings": [
143
+ ["id", 0],
144
+ ["className", 1],
145
+ ["style", 2],
146
+ ["accessible", 3],
147
+ ["accessibilityRole", 4],
148
+ ["accessibilityLabel", 5]
149
+ ],
150
+ "children": [
151
+ {
152
+ "kind": "slot",
153
+ "slot": 6
154
+ },
155
+ {
156
+ "kind": "host",
157
+ "type": "gridlayout",
158
+ "bindings": [["ref", 7], ["style", 8]],
159
+ "children": [{
160
+ "kind": "host",
161
+ "type": "svgview",
162
+ "props": { "stretch": "aspectFit" },
163
+ "bindings": [["src", 9], ["style", 10]]
164
+ }, {
165
+ "kind": "host",
166
+ "type": "absolutelayout",
167
+ "bindings": [
168
+ ["id", 11],
169
+ ["style", 12],
170
+ ["isUserInteractionEnabled", 13],
171
+ ["onTouch", 14],
172
+ ["onTap", 15]
173
+ ],
174
+ "children": [
175
+ {
176
+ "kind": "slot",
177
+ "slot": 16
178
+ },
179
+ {
180
+ "kind": "slot",
181
+ "slot": 17
182
+ },
183
+ {
184
+ "kind": "slot",
185
+ "slot": 18
186
+ },
187
+ {
188
+ "kind": "slot",
189
+ "slot": 19
190
+ }
191
+ ]
192
+ }]
193
+ },
194
+ {
195
+ "kind": "slot",
196
+ "slot": 20
197
+ }
198
+ ]
199
+ });
200
+ var EMPTY_SVG = "<svg xmlns=\"http://www.w3.org/2000/svg\"/>";
201
+ var TIP_ESTIMATE_CHAR = 6.2;
202
+ var Chart = defineUniversalComponent("nativescript", function Chart(props) {
203
+ const measure = withSlot(_h$0, useMeasure);
204
+ const [cursor, setCursor] = useState(null, _h$1);
205
+ const sceneRef = useRef(null, _h$2);
206
+ const propsRef = useRef(props, _h$3);
207
+ propsRef.current = props;
208
+ const bounds = measure.bounds;
209
+ const w = props.width ?? bounds?.width ?? 0;
210
+ const h = props.height ?? (props.aspectRatio && w > 0 ? w / props.aspectRatio : bounds?.height && bounds.height > 0 ? bounds.height : w > 0 ? w / 1.6 : 0);
211
+ const scene = useMemo(() => w > 0 && h > 0 ? computeScene(propsRef.current, w, h) : null, [
212
+ props.type,
213
+ props.data,
214
+ props.margin,
215
+ props.stacked,
216
+ props.innerRadiusRatio,
217
+ props.xAxis,
218
+ props.yAxis,
219
+ w,
220
+ h
221
+ ], _h$4);
222
+ sceneRef.current = scene;
223
+ const interactive = !!(props.onPress || props.onScrub || props.tooltip || props.crosshair);
224
+ const onTouch = useMemo(() => {
225
+ const scrub = createScrub(() => sceneRef.current, () => propsRef.current, setCursor);
226
+ return (e) => {
227
+ scrub(e.action, e.getX(), e.getY());
228
+ };
229
+ }, [], _h$5);
230
+ const onTap = useMemo(() => {
231
+ const scrub = createScrub(() => sceneRef.current, () => propsRef.current, setCursor);
232
+ return (e) => {
233
+ const size = e.object?.getActualSize?.();
234
+ scrub("tap", e.getX?.() ?? (size ? size.width / 2 : 0), e.getY?.() ?? (size ? size.height / 2 : 0));
235
+ };
236
+ }, [], _h$6);
237
+ const legend = props.legend === true ? "bottom" : props.legend;
238
+ const plot = scene?.plot;
239
+ const dotColor = cursor && scene ? scene.pie ? scene.pie.slices.find((s) => s.series === cursor.series && s.index === cursor.index)?.color : scene.series[cursor.series]?.color : void 0;
240
+ const tipText = cursor && scene ? hitLabel(scene, cursor) : null;
241
+ const tipWidth = tipText ? tipText.length * TIP_ESTIMATE_CHAR + 14 : 0;
242
+ const tipLeft = cursor && scene ? Math.min(Math.max(0, cursor.px - tipWidth / 2), Math.max(0, scene.width - tipWidth)) : 0;
243
+ const tipTop = cursor ? cursor.py - 30 : 0;
244
+ return universalValue(__octaneUniversalPlan8, [
245
+ props.id,
246
+ props.className,
247
+ {
248
+ flexDirection: "column",
249
+ ...props.style
250
+ },
251
+ props.accessibilityLabel != null,
252
+ AccessibilityRole.Image,
253
+ props.accessibilityLabel,
254
+ universalIf(legend === "top" && scene, () => {
255
+ return universalValue(__octaneUniversalPlan1, [{ paddingBottom: 4 }, scene.legend.map((item) => universalValue(__octaneUniversalPlan0, [
256
+ { marginRight: 12 },
257
+ {
258
+ width: 10,
259
+ height: 10,
260
+ borderRadius: 2,
261
+ backgroundColor: new Color(item.color),
262
+ marginRight: 4
263
+ },
264
+ item.text,
265
+ { fontSize: 11 }
266
+ ]))]);
267
+ }),
268
+ measure.ref,
269
+ {
270
+ width: props.width,
271
+ height: props.height ?? (props.aspectRatio && w > 0 ? w / props.aspectRatio : void 0),
272
+ flexGrow: 1
273
+ },
274
+ scene?.markup ?? EMPTY_SVG,
275
+ {
276
+ width: w,
277
+ height: h
278
+ },
279
+ props.id ? props.id + "-overlay" : void 0,
280
+ {
281
+ width: w,
282
+ height: h
283
+ },
284
+ interactive,
285
+ interactive ? onTouch : void 0,
286
+ interactive ? onTap : void 0,
287
+ scene?.labels.map((l) => universalValue(__octaneUniversalPlan2, [
288
+ l.x,
289
+ l.y,
290
+ l.width,
291
+ l.text,
292
+ l.align === "center" ? "center" : l.align === "end" ? "right" : "left",
293
+ {
294
+ fontSize: 10,
295
+ opacity: .7
296
+ }
297
+ ])),
298
+ universalIf(cursor && props.crosshair && !scene?.pie && plot, () => {
299
+ return universalValue(__octaneUniversalPlan3, [
300
+ cursor.px - .5,
301
+ plot.y,
302
+ plot.height,
303
+ new Color("#8a8a8a")
304
+ ]);
305
+ }),
306
+ universalIf(cursor && (props.crosshair || props.tooltip), () => {
307
+ return universalValue(__octaneUniversalPlan4, [
308
+ cursor.px - 4,
309
+ cursor.py - 4,
310
+ new Color(dotColor ?? "#4e79a7")
311
+ ]);
312
+ }),
313
+ universalIf(cursor && props.tooltip && tipText, () => {
314
+ return universalValue(__octaneUniversalPlan5, [
315
+ tipLeft,
316
+ tipTop < 0 ? cursor.py + 12 : tipTop,
317
+ new Color("rgba(20,20,20,0.88)"),
318
+ tipText,
319
+ new Color("#ffffff"),
320
+ { fontSize: 11 }
321
+ ]);
322
+ }),
323
+ universalIf(legend === "bottom" && scene, () => {
324
+ return universalValue(__octaneUniversalPlan7, [{ paddingTop: 4 }, scene.legend.map((item) => universalValue(__octaneUniversalPlan6, [
325
+ { marginRight: 12 },
326
+ {
327
+ width: 10,
328
+ height: 10,
329
+ borderRadius: 2,
330
+ backgroundColor: new Color(item.color),
331
+ marginRight: 4
332
+ },
333
+ item.text,
334
+ { fontSize: 11 }
335
+ ]))]);
336
+ })
337
+ ]);
338
+ }, { "module": "@nativescript-community/octane" });
339
+ //#endregion
340
+ export { Chart };
@@ -0,0 +1,146 @@
1
+ import { xCenter } from "./scales.js";
2
+ import { format } from "d3-format";
3
+ import { timeFormat } from "d3-time-format";
4
+ //#region src/core/axes.ts
5
+ var AXIS_COLOR = "#9aa3ad";
6
+ var GRID_COLOR = "#9aa3ad";
7
+ var GRID_OPACITY = .22;
8
+ var si = format("~s");
9
+ var plain = format("~g");
10
+ var day = timeFormat("%b %d");
11
+ /** Default tick label formatting — SI suffixes for big magnitudes, plain
12
+ * significant digits otherwise, short month-day for dates. */
13
+ function defaultFormat(value) {
14
+ if (value instanceof Date) return day(value);
15
+ if (typeof value === "number") return Math.abs(value) >= 1e3 ? si(value) : plain(value);
16
+ return String(value);
17
+ }
18
+ /** Cap categorical label count so boxes don't collide — keep every nth. */
19
+ function thinDomain(domain, plotWidth) {
20
+ const maxLabels = Math.max(2, Math.floor(plotWidth / 56));
21
+ if (domain.length <= maxLabels) return domain;
22
+ const step = Math.ceil(domain.length / maxLabels);
23
+ return domain.filter((_, i) => i % step === 0);
24
+ }
25
+ function xAxisModel(kind, scale, spec, plot) {
26
+ const labels = spec?.labels !== false;
27
+ const stubs = spec?.ticks !== false;
28
+ const grid = spec?.grid === true;
29
+ const fmt = spec?.format ?? defaultFormat;
30
+ const frame = [{
31
+ kind: "line",
32
+ x1: plot.x,
33
+ y1: plot.y + plot.height,
34
+ x2: plot.x + plot.width,
35
+ y2: plot.y + plot.height,
36
+ stroke: AXIS_COLOR,
37
+ strokeWidth: 1
38
+ }];
39
+ const gridMarks = [];
40
+ const out = [];
41
+ let values;
42
+ let format = fmt;
43
+ if (kind === "band" || kind === "point") values = thinDomain(scale.domain(), plot.width);
44
+ else {
45
+ const continuous = scale;
46
+ const count = spec?.tickCount ?? 6;
47
+ values = continuous.ticks(count);
48
+ if (!spec?.format && kind === "time") {
49
+ const tf = continuous.tickFormat(count);
50
+ format = (v) => tf(v);
51
+ }
52
+ }
53
+ for (const v of values) {
54
+ const px = plot.x + xCenter(kind, scale, v);
55
+ if (stubs) frame.push({
56
+ kind: "line",
57
+ x1: px,
58
+ y1: plot.y + plot.height,
59
+ x2: px,
60
+ y2: plot.y + plot.height + 4,
61
+ stroke: AXIS_COLOR,
62
+ strokeWidth: 1
63
+ });
64
+ if (grid) gridMarks.push({
65
+ kind: "line",
66
+ x1: px,
67
+ y1: plot.y,
68
+ x2: px,
69
+ y2: plot.y + plot.height,
70
+ stroke: GRID_COLOR,
71
+ strokeOpacity: GRID_OPACITY,
72
+ strokeWidth: 1
73
+ });
74
+ if (labels) {
75
+ const width = Math.min(72, plot.width / Math.max(1, values.length));
76
+ const boxX = Math.min(Math.max(0, px - width / 2), Math.max(0, plot.x + plot.width + 8 - width));
77
+ out.push({
78
+ x: boxX,
79
+ y: plot.y + plot.height + 6,
80
+ width,
81
+ align: "center",
82
+ text: format(v),
83
+ axis: "x"
84
+ });
85
+ }
86
+ }
87
+ return {
88
+ labels: out,
89
+ frame,
90
+ grid: gridMarks
91
+ };
92
+ }
93
+ function yAxisModel(scale, spec, plot) {
94
+ const labels = spec?.labels !== false;
95
+ const stubs = spec?.ticks !== false;
96
+ const grid = spec?.grid === true;
97
+ const fmt = spec?.format ?? defaultFormat;
98
+ const frame = [{
99
+ kind: "line",
100
+ x1: plot.x,
101
+ y1: plot.y,
102
+ x2: plot.x,
103
+ y2: plot.y + plot.height,
104
+ stroke: AXIS_COLOR,
105
+ strokeWidth: 1
106
+ }];
107
+ const gridMarks = [];
108
+ const out = [];
109
+ for (const v of scale.ticks(spec?.tickCount ?? 5)) {
110
+ const py = plot.y + scale(v);
111
+ if (stubs) frame.push({
112
+ kind: "line",
113
+ x1: plot.x - 4,
114
+ y1: py,
115
+ x2: plot.x,
116
+ y2: py,
117
+ stroke: AXIS_COLOR,
118
+ strokeWidth: 1
119
+ });
120
+ if (grid) gridMarks.push({
121
+ kind: "line",
122
+ x1: plot.x,
123
+ y1: py,
124
+ x2: plot.x + plot.width,
125
+ y2: py,
126
+ stroke: GRID_COLOR,
127
+ strokeOpacity: GRID_OPACITY,
128
+ strokeWidth: 1
129
+ });
130
+ if (labels) out.push({
131
+ x: 0,
132
+ y: py - 6,
133
+ width: Math.max(0, plot.x - 8),
134
+ align: "end",
135
+ text: fmt(v),
136
+ axis: "y"
137
+ });
138
+ }
139
+ return {
140
+ labels: out,
141
+ frame,
142
+ grid: gridMarks
143
+ };
144
+ }
145
+ //#endregion
146
+ export { defaultFormat, xAxisModel, yAxisModel };
@@ -0,0 +1,131 @@
1
+ import { defaultFormat } from "./axes.js";
2
+ /** Map a chart-space pointer position to the nearest datum. Cartesian charts
3
+ * snap to the nearest x group, then pick the closest point inside it —
4
+ * scatter gates on pointer distance instead of always snapping. Pie hits
5
+ * resolve by ring + angle. Coordinates outside the plot (+slop) miss. */
6
+ function hitTest(scene, x, y, slop = 24) {
7
+ if (scene.pie) return pieHit(scene, x, y, slop);
8
+ const { plot, points } = scene;
9
+ if (!points.length) return null;
10
+ if (x < plot.x - slop || x > plot.x + plot.width + slop || y < plot.y - slop || y > plot.y + plot.height + slop) return null;
11
+ const centers = /* @__PURE__ */ new Map();
12
+ for (const p of points) {
13
+ const cur = centers.get(p.key);
14
+ centers.set(p.key, cur === void 0 ? p.cx : (cur + p.cx) / 2);
15
+ }
16
+ let key = null;
17
+ let keyDist = Infinity;
18
+ for (const [k, cx] of centers) {
19
+ const d = Math.abs(cx - x);
20
+ if (d < keyDist) {
21
+ keyDist = d;
22
+ key = k;
23
+ }
24
+ }
25
+ if (key === null) return null;
26
+ let best = null;
27
+ let bestDist = Infinity;
28
+ for (const p of points) {
29
+ if (p.key !== key) continue;
30
+ const d = Math.hypot(p.cx - x, p.cy - y);
31
+ if (d < bestDist) {
32
+ bestDist = d;
33
+ best = {
34
+ series: p.series,
35
+ index: p.index,
36
+ x: p.x,
37
+ y: p.y,
38
+ px: p.cx,
39
+ py: p.cy
40
+ };
41
+ }
42
+ }
43
+ if (best && scene.type === "scatter" && bestDist > slop) return null;
44
+ return best;
45
+ }
46
+ function pieHit(scene, x, y, slop) {
47
+ const pie = scene.pie;
48
+ const dx = x - pie.cx;
49
+ const dy = y - pie.cy;
50
+ const r = Math.hypot(dx, dy);
51
+ if (r < pie.rInner - slop || r > pie.rOuter + slop) return null;
52
+ const angle = (Math.atan2(dx, -dy) + Math.PI * 2) % (Math.PI * 2);
53
+ const slice = pie.slices.find((s) => angle >= s.startAngle && angle < s.endAngle);
54
+ if (!slice) return null;
55
+ return {
56
+ series: slice.series,
57
+ index: slice.index,
58
+ x: slice.label,
59
+ y: slice.value,
60
+ px: slice.cx,
61
+ py: slice.cy
62
+ };
63
+ }
64
+ /** Shared gesture → cursor state machine. Both leaves normalize their pointer
65
+ * source (DOM pointer/click events, NS `touch`+`tap`) to phases and call
66
+ * this; hit math stays identical across targets. `move` while pressed
67
+ * scrubs and fires `onScrub`; `hover` (web-only, unpressed move) moves the
68
+ * cursor without scrubbing; `up` ends the scrub and persists the cursor;
69
+ * `tap` is a completed press — fires `onPress` and updates the cursor;
70
+ * `cancel`/`leave` clear. `onPress` lives only on `tap` so NS's tap
71
+ * recognizer and the web click both reach it exactly once. */
72
+ function createScrub(getScene, getProps, setCursor) {
73
+ let downAt = null;
74
+ return (phase, x, y) => {
75
+ const scene = getScene();
76
+ const props = getProps();
77
+ const showCursor = props.tooltip === true || props.crosshair === true;
78
+ switch (phase) {
79
+ case "down": {
80
+ downAt = {
81
+ x,
82
+ y,
83
+ t: Date.now()
84
+ };
85
+ const hit = scene && showCursor ? hitTest(scene, x, y) : null;
86
+ setCursor(hit);
87
+ if (hit) props.onScrub?.(hit);
88
+ break;
89
+ }
90
+ case "move": {
91
+ if (!downAt) break;
92
+ const hit = scene && showCursor ? hitTest(scene, x, y) : null;
93
+ setCursor(hit);
94
+ props.onScrub?.(hit);
95
+ break;
96
+ }
97
+ case "hover":
98
+ if (downAt) break;
99
+ setCursor(scene && showCursor ? hitTest(scene, x, y) : null);
100
+ break;
101
+ case "up":
102
+ downAt = null;
103
+ setCursor(scene ? hitTest(scene, x, y) : null);
104
+ props.onScrub?.(null);
105
+ break;
106
+ case "tap": {
107
+ downAt = null;
108
+ const hit = scene ? hitTest(scene, x, y) : null;
109
+ setCursor(hit);
110
+ if (hit) props.onPress?.(hit);
111
+ break;
112
+ }
113
+ case "cancel":
114
+ case "leave":
115
+ downAt = null;
116
+ setCursor(null);
117
+ props.onScrub?.(null);
118
+ }
119
+ };
120
+ }
121
+ /** Tooltip body for a hit — series name + formatted y for cartesian charts,
122
+ * slice label + value for pie. */
123
+ function hitLabel(scene, hit) {
124
+ if (scene.pie) {
125
+ const slice = scene.pie.slices.find((s) => s.series === hit.series && s.index === hit.index);
126
+ return slice ? `${slice.label}: ${defaultFormat(slice.value)}` : defaultFormat(hit.y);
127
+ }
128
+ return `${scene.series[hit.series]?.name ?? String(hit.series)}: ${defaultFormat(hit.y)}`;
129
+ }
130
+ //#endregion
131
+ export { createScrub, hitLabel, hitTest };