react-native-livechart 3.12.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/dist/components/BadgeOverlay.d.ts +9 -1
  2. package/dist/components/BadgeOverlay.d.ts.map +1 -1
  3. package/dist/components/ChartOverlayLayer.d.ts +19 -0
  4. package/dist/components/ChartOverlayLayer.d.ts.map +1 -0
  5. package/dist/components/CustomMarkerOverlay.d.ts +16 -6
  6. package/dist/components/CustomMarkerOverlay.d.ts.map +1 -1
  7. package/dist/components/CustomReferenceLineOverlay.d.ts +36 -0
  8. package/dist/components/CustomReferenceLineOverlay.d.ts.map +1 -0
  9. package/dist/components/CustomTooltipOverlay.d.ts +5 -2
  10. package/dist/components/CustomTooltipOverlay.d.ts.map +1 -1
  11. package/dist/components/DotOverlay.d.ts +7 -1
  12. package/dist/components/DotOverlay.d.ts.map +1 -1
  13. package/dist/components/LiveChart.d.ts.map +1 -1
  14. package/dist/components/LiveChartSeries.d.ts.map +1 -1
  15. package/dist/components/MarkerOverlay.d.ts +6 -3
  16. package/dist/components/MarkerOverlay.d.ts.map +1 -1
  17. package/dist/components/MultiSeriesDots.d.ts +4 -1
  18. package/dist/components/MultiSeriesDots.d.ts.map +1 -1
  19. package/dist/components/ReferenceLineGroupOverlay.d.ts +27 -0
  20. package/dist/components/ReferenceLineGroupOverlay.d.ts.map +1 -0
  21. package/dist/components/ReferenceLineOverlay.d.ts +25 -2
  22. package/dist/components/ReferenceLineOverlay.d.ts.map +1 -1
  23. package/dist/components/XAxisOverlay.d.ts +7 -1
  24. package/dist/components/XAxisOverlay.d.ts.map +1 -1
  25. package/dist/components/YAxisOverlay.d.ts +12 -1
  26. package/dist/components/YAxisOverlay.d.ts.map +1 -1
  27. package/dist/constants.d.ts +7 -0
  28. package/dist/constants.d.ts.map +1 -1
  29. package/dist/core/liveChartEngineTick.d.ts +29 -0
  30. package/dist/core/liveChartEngineTick.d.ts.map +1 -1
  31. package/dist/core/liveChartSeriesEngineTick.d.ts +18 -0
  32. package/dist/core/liveChartSeriesEngineTick.d.ts.map +1 -1
  33. package/dist/core/resolveConfig.d.ts +56 -2
  34. package/dist/core/resolveConfig.d.ts.map +1 -1
  35. package/dist/core/useLiveChartEngine.d.ts +58 -7
  36. package/dist/core/useLiveChartEngine.d.ts.map +1 -1
  37. package/dist/core/useLiveChartSeriesEngine.d.ts +8 -2
  38. package/dist/core/useLiveChartSeriesEngine.d.ts.map +1 -1
  39. package/dist/draw/grid.d.ts.map +1 -1
  40. package/dist/draw/markerAtlas.d.ts +20 -2
  41. package/dist/draw/markerAtlas.d.ts.map +1 -1
  42. package/dist/draw/volume.d.ts +25 -0
  43. package/dist/draw/volume.d.ts.map +1 -0
  44. package/dist/hooks/crosshairShared.d.ts +12 -6
  45. package/dist/hooks/crosshairShared.d.ts.map +1 -1
  46. package/dist/hooks/overlayScale.d.ts +22 -0
  47. package/dist/hooks/overlayScale.d.ts.map +1 -0
  48. package/dist/hooks/resolveChartLayout.d.ts +9 -0
  49. package/dist/hooks/resolveChartLayout.d.ts.map +1 -1
  50. package/dist/hooks/useBadge.d.ts +22 -1
  51. package/dist/hooks/useBadge.d.ts.map +1 -1
  52. package/dist/hooks/useCandlePaths.d.ts +6 -0
  53. package/dist/hooks/useCandlePaths.d.ts.map +1 -1
  54. package/dist/hooks/useChartOverlayContext.d.ts +45 -0
  55. package/dist/hooks/useChartOverlayContext.d.ts.map +1 -0
  56. package/dist/hooks/useChartPaths.d.ts +8 -1
  57. package/dist/hooks/useChartPaths.d.ts.map +1 -1
  58. package/dist/hooks/useCrosshair.d.ts +9 -2
  59. package/dist/hooks/useCrosshair.d.ts.map +1 -1
  60. package/dist/hooks/useLiveDot.d.ts +6 -1
  61. package/dist/hooks/useLiveDot.d.ts.map +1 -1
  62. package/dist/hooks/useMarkers.d.ts +9 -4
  63. package/dist/hooks/useMarkers.d.ts.map +1 -1
  64. package/dist/hooks/usePanScroll.d.ts +82 -0
  65. package/dist/hooks/usePanScroll.d.ts.map +1 -0
  66. package/dist/hooks/usePinchZoom.d.ts +74 -0
  67. package/dist/hooks/usePinchZoom.d.ts.map +1 -0
  68. package/dist/hooks/useReferenceDrag.d.ts +24 -0
  69. package/dist/hooks/useReferenceDrag.d.ts.map +1 -0
  70. package/dist/hooks/useReferenceLine.d.ts +23 -4
  71. package/dist/hooks/useReferenceLine.d.ts.map +1 -1
  72. package/dist/hooks/useReferenceLinePress.d.ts +5 -1
  73. package/dist/hooks/useReferenceLinePress.d.ts.map +1 -1
  74. package/dist/hooks/useVisibleRange.d.ts +39 -0
  75. package/dist/hooks/useVisibleRange.d.ts.map +1 -0
  76. package/dist/index.d.ts +2 -1
  77. package/dist/index.d.ts.map +1 -1
  78. package/dist/math/markerCluster.d.ts +47 -0
  79. package/dist/math/markerCluster.d.ts.map +1 -0
  80. package/dist/math/markers.d.ts +10 -0
  81. package/dist/math/markers.d.ts.map +1 -1
  82. package/dist/math/referenceDrag.d.ts +24 -0
  83. package/dist/math/referenceDrag.d.ts.map +1 -0
  84. package/dist/math/referenceGroup.d.ts +31 -0
  85. package/dist/math/referenceGroup.d.ts.map +1 -0
  86. package/dist/math/referenceLines.d.ts +33 -7
  87. package/dist/math/referenceLines.d.ts.map +1 -1
  88. package/dist/types.d.ts +505 -21
  89. package/dist/types.d.ts.map +1 -1
  90. package/package.json +1 -1
  91. package/src/components/BadgeOverlay.tsx +26 -1
  92. package/src/components/ChartOverlayLayer.tsx +32 -0
  93. package/src/components/CustomMarkerOverlay.tsx +150 -57
  94. package/src/components/CustomReferenceLineOverlay.tsx +250 -0
  95. package/src/components/CustomTooltipOverlay.tsx +27 -7
  96. package/src/components/DotOverlay.tsx +9 -0
  97. package/src/components/LiveChart.tsx +549 -32
  98. package/src/components/LiveChartSeries.tsx +110 -5
  99. package/src/components/MarkerOverlay.tsx +92 -6
  100. package/src/components/MultiSeriesDots.tsx +12 -3
  101. package/src/components/ReferenceLineGroupOverlay.tsx +207 -0
  102. package/src/components/ReferenceLineOverlay.tsx +105 -32
  103. package/src/components/XAxisOverlay.tsx +9 -2
  104. package/src/components/YAxisOverlay.tsx +48 -26
  105. package/src/constants.ts +10 -0
  106. package/src/core/liveChartEngineTick.ts +81 -8
  107. package/src/core/liveChartSeriesEngineTick.ts +50 -9
  108. package/src/core/resolveConfig.ts +122 -1
  109. package/src/core/useLiveChartEngine.ts +103 -10
  110. package/src/core/useLiveChartSeriesEngine.ts +26 -3
  111. package/src/draw/grid.ts +13 -1
  112. package/src/draw/markerAtlas.ts +117 -3
  113. package/src/draw/volume.ts +190 -0
  114. package/src/hooks/crosshairShared.ts +37 -9
  115. package/src/hooks/overlayScale.ts +59 -0
  116. package/src/hooks/resolveChartLayout.ts +33 -0
  117. package/src/hooks/useBadge.ts +89 -21
  118. package/src/hooks/useCandlePaths.ts +104 -7
  119. package/src/hooks/useChartOverlayContext.ts +93 -0
  120. package/src/hooks/useChartPaths.ts +14 -1
  121. package/src/hooks/useCrosshair.ts +29 -2
  122. package/src/hooks/useLiveDot.ts +16 -5
  123. package/src/hooks/useMarkers.ts +39 -11
  124. package/src/hooks/usePanScroll.ts +253 -0
  125. package/src/hooks/usePinchZoom.ts +189 -0
  126. package/src/hooks/useReferenceDrag.ts +254 -0
  127. package/src/hooks/useReferenceLine.ts +56 -9
  128. package/src/hooks/useReferenceLinePress.ts +16 -2
  129. package/src/hooks/useVisibleRange.ts +119 -0
  130. package/src/index.ts +17 -1
  131. package/src/math/markerCluster.ts +214 -0
  132. package/src/math/markers.ts +35 -3
  133. package/src/math/referenceDrag.ts +66 -0
  134. package/src/math/referenceGroup.ts +65 -0
  135. package/src/math/referenceLines.ts +76 -19
  136. package/src/types.ts +525 -21
package/src/types.ts CHANGED
@@ -79,6 +79,15 @@ export interface ReferenceLine {
79
79
  strokeWidth?: number;
80
80
  /** Dash pattern as `[dashLength, gapLength]` in pixels (line stroke + band border). */
81
81
  intervals?: [number, number];
82
+ /**
83
+ * Span the **full chart width** — edge to edge through the Y-axis gutter, not
84
+ * clipped at the plot's right edge — so the line/band visually connects to its
85
+ * value on the axis (like a price tag). Only the line/band extends; any
86
+ * `label`/`badge` stays anchored inside the plot. For a Form-A line with a
87
+ * `badge`, the full-width line replaces the dashed connector. No effect on a
88
+ * vertical time band. Default `false` (stops at the plot edge). Form A / B.
89
+ */
90
+ fullWidth?: boolean;
82
91
  /** Line / band color override. Defaults to palette `refLine`. */
83
92
  color?: string;
84
93
  /** Fill opacity for a value / time band (0–1). Default `0.16`. */
@@ -126,6 +135,86 @@ export interface ReferenceLine {
126
135
  badgeBorderColor?: string;
127
136
  /** Badge pill corner radius in pixels. Default `5`. (Fallback for `badge.radius`.) */
128
137
  badgeRadius?: number;
138
+
139
+ // ── Draggable (Form A only) ───────────────────────────────────────────────
140
+ /**
141
+ * Make this Form-A line **draggable** along the Y-axis — grab its handle / badge
142
+ * and drag to set a new value (a working-order price, alert level, or target).
143
+ * The line tracks the finger on the UI thread; {@link onChange} / {@link onCommit}
144
+ * report the value to JS. The line is *uncontrolled* by default (it stays where
145
+ * you drop it); pair `onCommit` with writing the value back into `value` to make
146
+ * it controlled. No effect on bands / time bands. Default `false`.
147
+ */
148
+ draggable?: boolean;
149
+ /**
150
+ * Snap the dragged value to this increment (e.g. `0.01` for cents, `0.5` for a
151
+ * tick size) so drops land on round levels. Omit for free dragging. Applies only
152
+ * while {@link draggable}.
153
+ */
154
+ snap?: number;
155
+ /**
156
+ * Hard-clamp the draggable value to `[min, max]` in Y-axis units — the line
157
+ * can't be dragged past either end. Omit for unbounded (clamped only to the
158
+ * visible range). Reaching a bound fires {@link onDragOut}. Applies only while
159
+ * {@link draggable}.
160
+ */
161
+ bounds?: [number, number];
162
+ /**
163
+ * Fired on the JS thread *while* dragging, each time the (snapped, clamped)
164
+ * value changes. De-duplicated to value changes — not every frame. Form-A
165
+ * draggable only.
166
+ */
167
+ onChange?: (value: number) => void;
168
+ /**
169
+ * Fired once on the JS thread when the drag ends (finger up), with the final
170
+ * (snapped, clamped) value. Pair with a controlled `value` to persist the move.
171
+ * Form-A draggable only.
172
+ */
173
+ onCommit?: (value: number) => void;
174
+ /**
175
+ * Fired on the JS thread when the line's value crosses **into** its watched
176
+ * interval — the visible Y-range, or {@link bounds} when set. Triggers from
177
+ * dragging *or* the axis rescaling under a fixed value (e.g. a target scrolling
178
+ * back into view). Edge-triggered: once per crossing. Form-A only.
179
+ */
180
+ onDragIn?: (value: number) => void;
181
+ /**
182
+ * Fired on the JS thread when the line's value crosses **out of** its watched
183
+ * interval (the visible Y-range, or {@link bounds}) — dragged/scrolled off-screen
184
+ * or pinned at a bound. Edge-triggered: once per crossing. Form-A only.
185
+ */
186
+ onDragOut?: (value: number) => void;
187
+ }
188
+
189
+ /**
190
+ * Shared **style & shape** knobs for every badge pill — the value `badge`
191
+ * ({@link BadgeConfig}), reference-line badges ({@link ReferenceLineBadgeConfig}),
192
+ * and the grouping count pill. Each badge interface extends this and adds its own
193
+ * anchor (`position`) / content fields. Unset values fall back to that badge's own
194
+ * defaults (documented on each interface). One source of truth so every badge is
195
+ * configured identically.
196
+ */
197
+ export interface BadgeStyleConfig {
198
+ /** Pill background color. */
199
+ background?: string;
200
+ /** Pill border color. */
201
+ borderColor?: string;
202
+ /** Border stroke width in pixels. Default `1`. */
203
+ borderWidth?: number;
204
+ /** Pill corner radius in pixels. */
205
+ radius?: number;
206
+ /** Label / icon text color override. */
207
+ textColor?: string;
208
+ /** Badge font size in pixels. Falls back to the chart `font`. */
209
+ fontSize?: number;
210
+ /** Badge font family. Falls back to the chart `font`. */
211
+ fontFamily?: string;
212
+ /** Badge font weight. Falls back to the chart `font`. */
213
+ fontWeight?: FontWeight;
214
+ /** Nudge the whole badge horizontally from its anchor, in pixels. Default `0`. */
215
+ offsetX?: number;
216
+ /** Nudge the whole badge vertically from its anchor, in pixels. Default `0`. */
217
+ offsetY?: number;
129
218
  }
130
219
 
131
220
  /**
@@ -133,10 +222,20 @@ export interface ReferenceLine {
133
222
  * price alert, or target tag. The badge sits at the line's value (pinned to
134
223
  * `position`) with a dashed connector to the opposite edge, and pins to the
135
224
  * nearest edge with a chevron once the value scrolls off-screen.
225
+ *
226
+ * Extends {@link BadgeStyleConfig} for the style/shape knobs. Their reference-line
227
+ * fallbacks: `background` → `badgeBackground` → theme `tooltipBg`; `borderColor` →
228
+ * `badgeBorderColor` → the line `color`; `radius` → `badgeRadius` → `5`; `textColor`
229
+ * → `labelColor` → the line `color` → theme `refLabel`; the `font*` knobs → the
230
+ * chart `font`.
136
231
  */
137
- export interface ReferenceLineBadgeConfig {
138
- /** Which plot edge the badge pins to. Default `"left"`. */
139
- position?: "left" | "right";
232
+ export interface ReferenceLineBadgeConfig extends BadgeStyleConfig {
233
+ /**
234
+ * Where the badge pins horizontally. `"left"` / `"right"` pin to that plot edge
235
+ * with a dashed connector running to the opposite edge; `"center"` floats the
236
+ * pill centered in the plot at the line's value (no connector). Default `"left"`.
237
+ */
238
+ position?: "left" | "center" | "right";
140
239
  /**
141
240
  * Leading glyph drawn in the badge — rendered with the chart font, so pass an
142
241
  * emoji-capable font (via the chart `font` prop) for emoji. Like `Marker.icon`.
@@ -147,12 +246,71 @@ export interface ReferenceLineBadgeConfig {
147
246
  * Default `true`. Set `false` for an **icon-only** badge.
148
247
  */
149
248
  text?: boolean;
150
- /** Pill background. Falls back to `badgeBackground`, then theme `tooltipBg`. */
151
- background?: string;
152
- /** Pill border color. Falls back to `badgeBorderColor`, then the line `color`. */
153
- borderColor?: string;
154
- /** Pill corner radius in pixels. Falls back to `badgeRadius`, then `5`. */
249
+ }
250
+
251
+ /**
252
+ * Context passed to a custom {@link LiveChartProps.renderReferenceLine}. The chart
253
+ * floats the element you return over the canvas and pins it to the line's value on
254
+ * the UI thread (vertically centered on the line, horizontally at the badge /
255
+ * label position) — so it tracks the rescaling axis and any drag smoothly without
256
+ * JS re-renders, just like {@link TooltipRenderProps}. Replaces the built-in pill
257
+ * badge / gutter label for that line; return `null`/`undefined` to keep the
258
+ * built-in. Bind the SharedValues to animated text (e.g. an animated `TextInput`)
259
+ * for the value to update on the UI thread too.
260
+ */
261
+ export interface ReferenceLineRenderProps {
262
+ /** The reference line being rendered. */
263
+ line: ReferenceLine;
264
+ /** Its index in the `referenceLines` array. */
265
+ index: number;
266
+ /** Live Y-axis value of the line — tracks dragging when {@link ReferenceLine.draggable}. */
267
+ value: SharedValue<number>;
268
+ /** The value formatted with the chart's `formatValue` (computed UI-side). */
269
+ valueStr: SharedValue<string>;
270
+ /** Canvas Y pixel of the line, recomputed each frame (`-1` when not laid out). */
271
+ y: SharedValue<number>;
272
+ /** Whether the value currently sits within the visible plot range. */
273
+ inRange: SharedValue<boolean>;
274
+ /**
275
+ * Which visible edge the value is pinned to when off-screen: `"above"` (past the
276
+ * top), `"below"` (past the bottom), or `"in"`. Use it to flip a directional
277
+ * chevron on a custom off-axis handle.
278
+ */
279
+ edge: SharedValue<"above" | "in" | "below">;
280
+ /** Whether this line is currently being dragged. */
281
+ dragging: SharedValue<boolean>;
282
+ }
283
+
284
+ /**
285
+ * Grouping behavior for reference lines (single-series). When enabled, Form-A
286
+ * lines whose handles fall within {@link ReferenceLineGroupingConfig.radius} px of
287
+ * each other collapse into a single count handle, so a cluster of nearby orders /
288
+ * alerts reads as one tag instead of an unreadable pile. Pass `true` for defaults
289
+ * or an object to tune the proximity radius.
290
+ */
291
+ export interface ReferenceLineGroupingConfig {
292
+ /**
293
+ * Collapse lines whose value-Y positions are within this many px of each other.
294
+ * Default `18`.
295
+ */
155
296
  radius?: number;
297
+ /**
298
+ * Styling for the collapsed **count pill** — the same style/shape config as a
299
+ * reference-line badge ({@link ReferenceLineBadgeConfig}): `position`
300
+ * (`"left"` / `"center"` / `"right"`), `icon` (a leading glyph before the count),
301
+ * `background`, `borderColor`, `borderWidth`, `radius` (corner radius),
302
+ * `textColor`, `fontSize` / `fontFamily` / `fontWeight`, and `offsetX` / `offsetY`.
303
+ * Omit for the theme defaults (left-pinned, `tooltipBg` fill, `refLine` border,
304
+ * `refLabel` text). The badge's `text: false` hides the count for an icon-only pill.
305
+ */
306
+ badge?: ReferenceLineBadgeConfig;
307
+ /**
308
+ * Format the collapsed count for the pill label, e.g. `n => \`×${n}\`` or
309
+ * `n => \`${n} orders\``. Default `String(n)` (the bare count). **Must be a
310
+ * worklet** (add the `"worklet"` directive) — it runs on the UI thread each
311
+ * frame, like the chart's `formatValue`. A plain JS closure throws.
312
+ */
313
+ format?: (count: number) => string;
156
314
  }
157
315
 
158
316
  /**
@@ -356,22 +514,67 @@ export interface AreaDotsConfig {
356
514
  opacity?: number;
357
515
  }
358
516
 
359
- /** Value badge pill configuration. */
360
- export interface BadgeConfig {
517
+ /**
518
+ * Value badge pill configuration. Extends {@link BadgeStyleConfig} for the
519
+ * style/shape knobs (`background`, `borderColor` / `borderWidth`, `radius`,
520
+ * `textColor`, `font*`, `offsetX/Y`). Value-badge specifics: `radius` defaults to a
521
+ * full capsule (clamped to `[0, pillHeight / 2]`); `borderColor` unset → no border;
522
+ * `textColor` unset → the `variant` / theme rule.
523
+ */
524
+ export interface BadgeConfig extends BadgeStyleConfig {
361
525
  /** Visual style of the badge pill. Default `"default"`. */
362
526
  variant?: BadgeVariant;
363
527
  /** Show the pointed tail toward the live dot. Default `true`. */
364
528
  tail?: boolean;
365
- /** Badge background color override. */
366
- background?: string;
367
529
  /** Which side of the chart the badge appears on. Default `"right"`. */
368
530
  position?: "right" | "left";
531
+ /**
532
+ * When the chart is scrolled back (see `timeScroll`), move the live-price
533
+ * indicators — the badge, the value line, and the live dot — to the price at
534
+ * the visible window's right edge instead of the live price, so they track the
535
+ * last visible price as you pan. Default `false`.
536
+ *
537
+ * @experimental
538
+ */
539
+ followViewEdge?: boolean;
540
+ }
541
+
542
+ /**
543
+ * Volume-bar configuration (candle mode only — see {@link LiveChartProps.volume}).
544
+ * Bars are drawn in a reserved band below the candles; the candle/price plot
545
+ * shrinks by {@link maxHeight} to make room (the x-axis stays at the bottom).
546
+ * Each bar's height is its candle's `volume` normalized to the largest visible
547
+ * volume, so the tallest visible bar fills the band.
548
+ */
549
+ export interface VolumeConfig {
550
+ /** Bar color for up (close ≥ open) candles. Default: `palette.candleUp`. */
551
+ upColor?: string;
552
+ /** Bar color for down (close < open) candles. Default: `palette.candleDown`. */
553
+ downColor?: string;
554
+ /**
555
+ * Height (px) of the reserved band — the tallest a bar can be. Reserved out of
556
+ * the plot below the candles. Default `48`.
557
+ */
558
+ maxHeight?: number;
559
+ /** Corner radius (px) of bar tops. `0` = sharp. Default `2`. */
560
+ radius?: number;
561
+ /** Opacity (0..1) applied to the whole band. Default `0.6`. */
562
+ opacity?: number;
369
563
  }
370
564
 
371
565
  /** Y-axis grid configuration. */
372
566
  export interface YAxisConfig {
373
567
  /** Minimum pixel gap between grid lines. Default `36`. */
374
568
  minGap?: number;
569
+ /**
570
+ * Float the price axis over a full-width plot instead of reserving a right
571
+ * gutter for it. The line/candles run all the way to the right edge, and the
572
+ * price labels (and the live-value badge) float on top — so the chart isn't
573
+ * cut off short of the edge, especially while time-scrolling. Default `false`.
574
+ *
575
+ * @experimental
576
+ */
577
+ float?: boolean;
375
578
  }
376
579
 
377
580
  /**
@@ -480,11 +683,13 @@ export interface ScrubConfig {
480
683
  * Where the tooltip pill sits relative to the vertical scrub line.
481
684
  * `"side"` (default) offsets it to the right of the line and flips left near
482
685
  * the right edge. `"top"` / `"bottom"` center it horizontally over the line,
483
- * clamped into the plot and pinned to the plot's top or bottom. This also
484
- * drives a custom {@link LiveChartProps.renderTooltip} so it gets the same
485
- * placement for free.
686
+ * clamped into the plot and pinned to the plot's top or bottom. `"point"`
687
+ * centers it over the line and floats it just above the scrub dot, flipping
688
+ * below the dot when there isn't room above (single-series line mode; candle
689
+ * mode keeps its top-pinned OHLC stack). This also drives a custom
690
+ * {@link LiveChartProps.renderTooltip} so it gets the same placement for free.
486
691
  */
487
- tooltipPlacement?: "side" | "top" | "bottom";
692
+ tooltipPlacement?: "side" | "top" | "bottom" | "point";
488
693
  /**
489
694
  * Gap in px between the tooltip and the plot edge it's pinned to — the top for
490
695
  * `"side"`/`"top"`, the bottom for `"bottom"`. Applies to the built-in pill and
@@ -626,6 +831,92 @@ export interface TooltipRenderProps {
626
831
  candle: SharedValue<CandlePoint | null>;
627
832
  }
628
833
 
834
+ /** Inner plot rectangle in canvas pixels (a snapshot field of {@link ChartScale}). */
835
+ export interface ChartPlotRect {
836
+ /** Inner plot left edge (`padding.left`). */
837
+ left: number;
838
+ /** Inner plot top edge (`padding.top`). */
839
+ top: number;
840
+ /** Inner plot right edge (`canvasWidth - padding.right`). */
841
+ right: number;
842
+ /** Inner plot bottom edge (`canvasHeight - padding.bottom`). */
843
+ bottom: number;
844
+ /** Full canvas width. */
845
+ width: number;
846
+ /** Full canvas height. */
847
+ height: number;
848
+ }
849
+
850
+ /**
851
+ * A snapshot of the chart's live scale — the value range, time window, and plot
852
+ * rect at one frame. Carried by {@link ChartOverlayContext.scale} (a `SharedValue`
853
+ * recomputed each frame) and consumed by the pure mapping functions. Reading
854
+ * `scale.get()` inside your worklet is what subscribes the overlay to per-frame
855
+ * updates, so it tracks the chart as it scrolls and rescales.
856
+ */
857
+ export interface ChartScale {
858
+ /** Live Y-axis lower bound (price at the plot bottom). */
859
+ min: number;
860
+ /** Live Y-axis upper bound (price at the plot top). */
861
+ max: number;
862
+ /** Visible time window in seconds. */
863
+ window: number;
864
+ /** Right-edge timestamp (unix seconds) — "now". */
865
+ now: number;
866
+ /** Inner plot rectangle in canvas px. */
867
+ plot: ChartPlotRect;
868
+ }
869
+
870
+ /**
871
+ * The price↔pixel / time↔pixel bridge handed to a custom
872
+ * {@link LiveChartProps.renderOverlay}.
873
+ *
874
+ * **Easiest path — the `usePriceY` / `useTimeX` hooks.** They project a price / time
875
+ * to a `SharedValue<number>` that tracks the live axis for you; just read it in
876
+ * your `useAnimatedStyle` like any SharedValue:
877
+ *
878
+ * ```tsx
879
+ * function PriceLevel({ ctx, price }) {
880
+ * const y = usePriceY(ctx, price); // reactive — tracks the rescaling axis
881
+ * const style = useAnimatedStyle(() => ({ transform: [{ translateY: y.get() }] }));
882
+ * return <Animated.View style={style} />;
883
+ * }
884
+ * ```
885
+ *
886
+ * **Manual path — {@link scale} + the pure mappings.** For one-off math (e.g. a
887
+ * gesture handler) or when you want everything in one worklet, read `scale.get()`
888
+ * inside your worklet — that read subscribes it to the per-frame scale — then pass
889
+ * the snapshot to the pure mappings (`priceToY` / `yToPrice` / `timeToX` /
890
+ * `xToTime`). The mappings do **not** read `scale` themselves, so they only reflect
891
+ * the chart live when you feed them `scale.get()`:
892
+ *
893
+ * ```tsx
894
+ * const style = useAnimatedStyle(() => {
895
+ * const s = scale.get(); // subscribe to the live scale
896
+ * const y = priceToY(142.5, s); // project a price to its pixel
897
+ * return { transform: [{ translateY: y }] };
898
+ * });
899
+ * ```
900
+ */
901
+ export interface ChartOverlayContext {
902
+ /**
903
+ * The live {@link ChartScale} snapshot, recomputed each frame. Read `.get()`
904
+ * inside your worklet to subscribe it to chart updates.
905
+ */
906
+ scale: SharedValue<ChartScale>;
907
+ /** Maps a price (Y-axis value) → canvas Y px for a {@link ChartScale}. Worklet. -1 when not laid out. */
908
+ priceToY: (price: number, scale: ChartScale) => number;
909
+ /**
910
+ * Inverse of {@link priceToY}: canvas Y px → price. Worklet. Clamps to the
911
+ * visible range; `null` when not laid out.
912
+ */
913
+ yToPrice: (y: number, scale: ChartScale) => number | null;
914
+ /** Maps a unix-seconds timestamp → canvas X px for a {@link ChartScale}. Worklet. -1 when not laid out. */
915
+ timeToX: (time: number, scale: ChartScale) => number;
916
+ /** Inverse of {@link timeToX}: canvas X px → unix-seconds timestamp. Worklet. */
917
+ xToTime: (x: number, scale: ChartScale) => number;
918
+ }
919
+
629
920
  /** Outer ring drawn around the built-in selection dot (the subtle halo). */
630
921
  export interface SelectionDotRingConfig {
631
922
  /** Ring color. Defaults to the dot color. */
@@ -783,14 +1074,60 @@ export interface Marker {
783
1074
  pill?: boolean;
784
1075
  /** Icon / image box size in px (icon font size or image width+height). Default `16`. */
785
1076
  size?: number;
786
- /** Pass-through payload surfaced on `onMarkerHover`. */
1077
+ /**
1078
+ * Sit the glyph above / below its anchor instead of centered on it. Default
1079
+ * `"center"` (on the line/value, today's behavior). Also the stack direction
1080
+ * when `markerCluster: "stacked"` — e.g. buys `"below"`, sells `"above"`.
1081
+ */
1082
+ side?: MarkerSide;
1083
+ /** Pass-through payload surfaced on `onMarkerPress`. */
787
1084
  data?: unknown;
788
1085
  }
789
1086
 
790
- /** Payload for `onMarkerHover` the marker and its screen position. */
791
- export interface MarkerHoverEvent {
1087
+ /** Where a marker glyph sits relative to its anchor (and the stack direction). */
1088
+ export type MarkerSide = "above" | "below" | "center";
1089
+
1090
+ /**
1091
+ * Object form of {@link LiveChartProps.markerCluster} for tuning the stacked
1092
+ * collision behavior. Passing this object implies `mode: "stacked"` unless you
1093
+ * set `mode` explicitly.
1094
+ */
1095
+ export interface MarkerClusterConfig {
1096
+ /** Defaults to `"stacked"` when this object form is used. */
1097
+ mode?: "anchored" | "stacked";
1098
+ /**
1099
+ * How much adjacent co-located glyphs overlap when fanned, `0` (just touching)
1100
+ * to `1` (fully stacked). Default `0.75`. The on-screen overlap is approximate
1101
+ * (the fan step is estimated from the glyph size, not its exact pixels).
1102
+ */
1103
+ overlap?: number;
1104
+ /** Collapse a co-located run to a single count badge once it exceeds this many.
1105
+ * Default `5`. */
1106
+ maxBeforeGroup?: number;
1107
+ }
1108
+
1109
+ /** Context passed to `renderMarker` alongside the marker (cluster / position state). */
1110
+ export interface MarkerRenderContext {
1111
+ /** Index of the marker in the `markers` array. */
1112
+ index: number;
1113
+ /** `true` when this marker is the representative of a collapsed cluster. */
1114
+ isGrouped: boolean;
1115
+ /** Number of markers in the collapsed cluster (`0` when not grouped). */
1116
+ groupCount: number;
1117
+ /** Resolved side the glyph is drawn on. */
1118
+ side: MarkerSide;
1119
+ }
1120
+
1121
+ /** Payload for `onMarkerPress` — the marker and its screen position. */
1122
+ export interface MarkerPressEvent {
792
1123
  marker: Marker;
793
1124
  point: { x: number; y: number };
1125
+ /** Index of the pressed marker in the `markers` array. */
1126
+ index: number;
1127
+ /** `true` when the press landed on a collapsed cluster (count badge). */
1128
+ isGrouped: boolean;
1129
+ /** The cluster's markers when `isGrouped`, so the consumer can list them. */
1130
+ members?: Marker[];
794
1131
  }
795
1132
 
796
1133
  /** Particle burst + screen shake on momentum swings ("degen mode"). */
@@ -1001,6 +1338,13 @@ export interface CandlePoint {
1001
1338
  low: number;
1002
1339
  /** Closing price. */
1003
1340
  close: number;
1341
+ /**
1342
+ * Traded volume in the bucket. Drives the optional volume bars
1343
+ * (see {@link LiveChartProps.volume}); bar heights are normalized to the
1344
+ * largest visible volume, so only relative values matter. Omitted candles
1345
+ * contribute no bar. Ignored when `volume` is off or in line mode.
1346
+ */
1347
+ volume?: number;
1004
1348
  }
1005
1349
 
1006
1350
  // ── Metrics (sizing & motion tokens) ─────────────────────────────────────────
@@ -1048,6 +1392,10 @@ export interface CandleMetrics {
1048
1392
  maxBodyPx: number;
1049
1393
  /** Body width as a fraction of the per-candle slot width (0–1). Default `0.8`. */
1050
1394
  bodyWidthRatio: number;
1395
+ /** Corner radius (px) of candle bodies. `0` = sharp corners. Default `0`. */
1396
+ bodyRadius: number;
1397
+ /** Wick (high–low line) stroke width in px. Default `1`. */
1398
+ wickWidth: number;
1051
1399
  }
1052
1400
 
1053
1401
  /** Grid-line and axis-label fade animation speeds. */
@@ -1091,6 +1439,61 @@ export interface LiveChartMetricsOverride {
1091
1439
 
1092
1440
  // ── Component Props ──────────────────────────────────────────────────────────
1093
1441
 
1442
+ /**
1443
+ * Time-scroll activation (see {@link LiveChartCoreProps.timeScroll}).
1444
+ *
1445
+ * @experimental Prototype — gesture model and API may change.
1446
+ */
1447
+ export interface TimeScrollConfig {
1448
+ /**
1449
+ * Which gesture pans the timeline:
1450
+ * - `"holdToScrub"` (default) — a one-finger drag anywhere scrolls; scrub
1451
+ * moves to press-and-hold (Rainbow-style). See {@link scrubHoldMs} for the
1452
+ * hold duration.
1453
+ * - `"axisDrag"` — a one-finger drag starting in the bottom X-axis band
1454
+ * ("grab the time ruler"); the plot area stays free for one-finger scrub.
1455
+ */
1456
+ gesture?: "holdToScrub" | "axisDrag";
1457
+ /**
1458
+ * `holdToScrub` only: press-and-hold duration (ms) before scrub engages, so a
1459
+ * quicker one-finger drag scrolls instead. Higher = more deliberate scrub and
1460
+ * fewer accidental scrubs while scrolling. Falls back to `scrub.panGestureDelay`
1461
+ * if set, otherwise `500`.
1462
+ */
1463
+ scrubHoldMs?: number;
1464
+ }
1465
+
1466
+ /**
1467
+ * Pinch-to-zoom the visible time window (see {@link LiveChartCoreProps.zoom}).
1468
+ *
1469
+ * @experimental Prototype — gesture model and API may change.
1470
+ */
1471
+ export interface ZoomConfig {
1472
+ /**
1473
+ * Tightest visible window in seconds (max zoom-in). Default `timeWindow / 8`.
1474
+ */
1475
+ minTimeWindow?: number;
1476
+ /**
1477
+ * Widest visible window in seconds (max zoom-out). Defaults to the full data
1478
+ * span (you can zoom out to all retained history), never below `timeWindow`.
1479
+ */
1480
+ maxTimeWindow?: number;
1481
+ }
1482
+
1483
+ /**
1484
+ * The visible time range reported by {@link LiveChartCoreProps.onVisibleRangeChange}.
1485
+ *
1486
+ * @experimental
1487
+ */
1488
+ export interface VisibleRange {
1489
+ /** Left-edge time of the visible window (unix seconds). */
1490
+ startSec: number;
1491
+ /** Right-edge time of the visible window (unix seconds). */
1492
+ endSec: number;
1493
+ /** True when the window is at the live edge (not scrolled back / paused). */
1494
+ following: boolean;
1495
+ }
1496
+
1094
1497
  /** Props shared between `LiveChart` and `LiveChartSeries`. */
1095
1498
  export interface LiveChartCoreProps {
1096
1499
  /** Color scheme. Default `"dark"`. */
@@ -1168,9 +1571,19 @@ export interface LiveChartCoreProps {
1168
1571
  */
1169
1572
  markers?: SharedValue<Marker[]>;
1170
1573
  /** Fires when a marker is tapped; `null` when a tap misses every marker. */
1171
- onMarkerHover?: (event: MarkerHoverEvent | null) => void;
1574
+ onMarkerPress?: (event: MarkerPressEvent | null) => void;
1172
1575
  /** Tap hit-test radius in px. Default `16` (≈ 44px touch target with the glyph). */
1173
1576
  markerHitRadius?: number;
1577
+ /**
1578
+ * Collision handling for co-located markers. `"anchored"` (default) keeps
1579
+ * today's behavior — glyphs draw at their anchor and overlap. `"stacked"` fans
1580
+ * co-located markers apart horizontally (overlapping, left-over-right) along
1581
+ * their {@link Marker.side}, collapsing a cluster into a single count-badge
1582
+ * marker once it exceeds {@link MarkerClusterConfig.maxBeforeGroup}. Grouping is
1583
+ * recomputed per frame, so a cluster fans back out as you zoom/scroll in. Pass a
1584
+ * {@link MarkerClusterConfig} object to tune the `overlap` and group threshold.
1585
+ */
1586
+ markerCluster?: "anchored" | "stacked" | MarkerClusterConfig;
1174
1587
  /**
1175
1588
  * Render a marker as a custom **React Native** element instead of a built-in
1176
1589
  * Skia glyph — e.g. an `expo-blur` glass badge or any non-Skia view that the
@@ -1183,8 +1596,15 @@ export interface LiveChartCoreProps {
1183
1596
  * each custom marker is its own animated view + projection, whereas built-in
1184
1597
  * glyphs batch into a single draw call. Custom-rendered markers skip the atlas
1185
1598
  * glyph entirely (no double-draw).
1599
+ *
1600
+ * The second argument carries cluster / position state (see
1601
+ * {@link MarkerRenderContext}) — e.g. render a distinct collapsed look when
1602
+ * `ctx.isGrouped` (showing `ctx.groupCount`).
1186
1603
  */
1187
- renderMarker?: (marker: Marker) => ReactElement | null | undefined;
1604
+ renderMarker?: (
1605
+ marker: Marker,
1606
+ ctx: MarkerRenderContext,
1607
+ ) => ReactElement | null | undefined;
1188
1608
  /**
1189
1609
  * Render a fully custom scrub tooltip as a **React Native** element instead of
1190
1610
  * the built-in pill — the same idea as `renderMarker`. The chart floats the
@@ -1226,6 +1646,31 @@ export interface LiveChartCoreProps {
1226
1646
  * and `timeWindow = maxT - minT` to fill the canvas edge-to-edge with historical data.
1227
1647
  */
1228
1648
  nowOverride?: number;
1649
+ /**
1650
+ * Enable horizontal time-scrolling: drag (or fling) to pan back through history.
1651
+ * The chart stops auto-scrolling while panned and resumes once you reach the
1652
+ * live edge again. One-finger plot-area scrub is unchanged. Requires retained
1653
+ * history in `data` / `candles` to scroll into.
1654
+ *
1655
+ * `true` uses the default drag-to-scroll gesture (`"holdToScrub"`); pass a
1656
+ * {@link TimeScrollConfig} to pick the activation (`"holdToScrub"` or
1657
+ * `"axisDrag"`). Default `false`.
1658
+ *
1659
+ * @experimental Prototype — gesture model and API may change.
1660
+ */
1661
+ timeScroll?: boolean | TimeScrollConfig;
1662
+ /**
1663
+ * Pinch-to-zoom the visible time window. Two-finger pinch in/out narrows or
1664
+ * widens the window, anchored at the focal point between your fingers. Composes
1665
+ * with `timeScroll` (zoom level and scroll position are independent). Seed extra
1666
+ * history in `data` / `candles` to have room to zoom out into.
1667
+ *
1668
+ * `true` uses sensible default bounds; pass a {@link ZoomConfig} to set
1669
+ * `minTimeWindow` / `maxTimeWindow`. Default `false`.
1670
+ *
1671
+ * @experimental Prototype — gesture model and API may change.
1672
+ */
1673
+ zoom?: boolean | ZoomConfig;
1229
1674
  /** Accessibility label for the chart container. */
1230
1675
  accessibilityLabel?: string;
1231
1676
  /** Accessibility role for the chart container. Default `"image"`. */
@@ -1242,6 +1687,22 @@ export interface LiveChartCoreProps {
1242
1687
  onGestureStart?: () => void;
1243
1688
  /** Called once when the user stops scrubbing/panning the chart. */
1244
1689
  onGestureEnd?: () => void;
1690
+ /**
1691
+ * Called as the visible time window changes (throttled to ~1 Hz), with the
1692
+ * window's edges in unix seconds and whether the chart is at the live edge.
1693
+ * Useful for paging data sources alongside `timeScroll` / `zoom`.
1694
+ *
1695
+ * @experimental
1696
+ */
1697
+ onVisibleRangeChange?: (range: VisibleRange) => void;
1698
+ /**
1699
+ * Called once when the visible window's left edge comes within one
1700
+ * window-width of the earliest retained data — the cue to lazily load older
1701
+ * history. Re-arms after the edge moves back out.
1702
+ *
1703
+ * @experimental
1704
+ */
1705
+ onReachStart?: () => void;
1245
1706
  /**
1246
1707
  * Fade out chart content on the left (destination-out style). `true` = defaults, `false` = off,
1247
1708
  * or pass `LeftEdgeFadeConfig`. Default `true`.
@@ -1324,6 +1785,19 @@ export interface LiveChartProps extends LiveChartCoreProps {
1324
1785
  * in a list. Pulse/scrub/degen and the entry animation are disabled. Frame the data
1325
1786
  * with `timeWindow` + `nowOverride` (see the historical-data-fill pattern). */
1326
1787
  static?: boolean;
1788
+ /**
1789
+ * Render a custom overlay floated over the chart canvas, handed a price↔pixel /
1790
+ * time↔pixel {@link ChartOverlayContext} so it can track the auto-rescaling axis
1791
+ * on the UI thread. Return any React Native view tree (e.g. order / avg-entry /
1792
+ * liquidation price tags) and position its pieces with the context's worklet
1793
+ * mappings inside `useAnimatedStyle`; return `null`/`undefined` for no overlay.
1794
+ *
1795
+ * The returned tree is mounted as an RN sibling of the `<Canvas>` (like
1796
+ * `renderMarker` / `renderTooltip`), full-bleed with `pointerEvents="box-none"`
1797
+ * so empty areas still scrub while an interactive leaf can receive touches.
1798
+ * Single-series only.
1799
+ */
1800
+ renderOverlay?: (ctx: ChartOverlayContext) => ReactElement | null | undefined;
1327
1801
  /** Called when the user scrubs the crosshair. `null` when scrub ends. */
1328
1802
  onScrub?: (point: ScrubPoint | null) => void;
1329
1803
  /**
@@ -1349,6 +1823,36 @@ export interface LiveChartProps extends LiveChartCoreProps {
1349
1823
  * routed here, not to reticle placement). Single-series only.
1350
1824
  */
1351
1825
  onReferenceLinePress?: (line: ReferenceLine, index: number) => void;
1826
+ /**
1827
+ * Render a reference line's tag as a custom **React Native** element instead of
1828
+ * the built-in Skia pill / gutter label — the same model as `renderMarker` /
1829
+ * `renderTooltip`. The chart floats the returned element over the canvas and
1830
+ * pins it to the line's value on the UI thread (see {@link ReferenceLineRenderProps}),
1831
+ * so it tracks the rescaling axis and any drag without JS re-renders. Called per
1832
+ * Form-A line; return `null`/`undefined` to keep that line's built-in tag. Works
1833
+ * with `badge: false` too (replace the plain gutter label). Single-series only.
1834
+ */
1835
+ renderReferenceLine?: (
1836
+ ctx: ReferenceLineRenderProps,
1837
+ ) => ReactElement | null | undefined;
1838
+ /**
1839
+ * Collapse Form-A reference lines whose handles sit near the same value into a
1840
+ * single count handle (e.g. a stack of working orders at adjacent prices reads
1841
+ * as one "×3" tag). `true` = defaults, `false`/omitted = off, or pass a
1842
+ * {@link ReferenceLineGroupingConfig} to tune the proximity radius. Lines a
1843
+ * {@link LiveChartProps.renderReferenceLine} owns are excluded (their custom tag
1844
+ * draws itself), so the count reflects only collapsed built-in tags. Single-series
1845
+ * only. Default off.
1846
+ */
1847
+ referenceLineGrouping?: boolean | ReferenceLineGroupingConfig;
1848
+ /**
1849
+ * Volume bars below the candles (candle mode only). `true` = defaults,
1850
+ * `false`/omitted = off, or pass a {@link VolumeConfig} for colors, band
1851
+ * height, rounding, and opacity. The candle/price plot shrinks by the band
1852
+ * height to make room; the x-axis stays pinned to the bottom. Reads each
1853
+ * candle's `CandlePoint.volume`. Ignored in line mode. Default off.
1854
+ */
1855
+ volume?: boolean | VolumeConfig;
1352
1856
  /**
1353
1857
  * Called on the JS thread when degen chart shake starts (momentum swing with shake enabled).
1354
1858
  * Not called when `degen` is off or `DegenOptions.shake` is `false`.