react-native-livechart 3.3.0 → 3.4.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 (44) hide show
  1. package/README.md +4 -1
  2. package/dist/components/LiveChart.d.ts.map +1 -1
  3. package/dist/components/LiveChartSeries.d.ts.map +1 -1
  4. package/dist/components/ReferenceLineOverlay.d.ts +10 -3
  5. package/dist/components/ReferenceLineOverlay.d.ts.map +1 -1
  6. package/dist/components/ScrubActionOverlay.d.ts +32 -0
  7. package/dist/components/ScrubActionOverlay.d.ts.map +1 -0
  8. package/dist/components/XAxisOverlay.d.ts.map +1 -1
  9. package/dist/constants.d.ts +4 -0
  10. package/dist/constants.d.ts.map +1 -1
  11. package/dist/core/resolveConfig.d.ts +23 -1
  12. package/dist/core/resolveConfig.d.ts.map +1 -1
  13. package/dist/hooks/crosshairShared.d.ts +110 -0
  14. package/dist/hooks/crosshairShared.d.ts.map +1 -1
  15. package/dist/hooks/useCrosshair.d.ts +14 -2
  16. package/dist/hooks/useCrosshair.d.ts.map +1 -1
  17. package/dist/hooks/useMarkers.d.ts +2 -0
  18. package/dist/hooks/useMarkers.d.ts.map +1 -1
  19. package/dist/hooks/useReferenceLine.d.ts +36 -3
  20. package/dist/hooks/useReferenceLine.d.ts.map +1 -1
  21. package/dist/hooks/useReferenceLinePress.d.ts +23 -0
  22. package/dist/hooks/useReferenceLinePress.d.ts.map +1 -0
  23. package/dist/index.d.ts +1 -1
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/math/referenceLines.d.ts +23 -0
  26. package/dist/math/referenceLines.d.ts.map +1 -1
  27. package/dist/types.d.ts +131 -6
  28. package/dist/types.d.ts.map +1 -1
  29. package/package.json +1 -1
  30. package/src/components/LiveChart.tsx +165 -21
  31. package/src/components/LiveChartSeries.tsx +39 -2
  32. package/src/components/ReferenceLineOverlay.tsx +121 -94
  33. package/src/components/ScrubActionOverlay.tsx +187 -0
  34. package/src/components/XAxisOverlay.tsx +2 -1
  35. package/src/constants.ts +5 -0
  36. package/src/core/resolveConfig.ts +40 -0
  37. package/src/hooks/crosshairShared.ts +293 -0
  38. package/src/hooks/useCrosshair.ts +340 -6
  39. package/src/hooks/useMarkers.ts +18 -2
  40. package/src/hooks/useReferenceLine.ts +259 -14
  41. package/src/hooks/useReferenceLinePress.ts +92 -0
  42. package/src/index.ts +3 -0
  43. package/src/math/referenceLines.ts +55 -0
  44. package/src/types.ts +134 -6
package/src/types.ts CHANGED
@@ -100,21 +100,61 @@ export interface ReferenceLine {
100
100
  */
101
101
  excludeFromRange?: boolean;
102
102
  /**
103
- * When a Form-A `value` falls outside the visible plot, render a pinned edge
104
- * badge with a directional chevron instead of culling the off-screen line.
103
+ * Render the Form-A value as a **pill badge** an icon and/or text tag pinned
104
+ * to a plot edge at the line's value, with a dashed connector running to the
105
+ * opposite edge (instead of a plain gutter label that collides with the Y-axis
106
+ * ticks). Auto-pins to the nearest edge with a directional chevron once the
107
+ * value scrolls off-screen. Ideal for working orders, price alerts, and targets.
108
+ *
109
+ * `true` = defaults (left-pinned, the line's label/value), or a
110
+ * {@link ReferenceLineBadgeConfig} for an `icon`, `text` toggle (icon-only), and
111
+ * `position`. Supersedes the legacy `offAxisBadge`. Default off.
112
+ */
113
+ badge?: boolean | ReferenceLineBadgeConfig;
114
+ /**
115
+ * Legacy: when a Form-A `value` falls outside the visible plot, render a pinned
116
+ * edge badge with a directional chevron instead of culling the off-screen line.
117
+ * Prefer {@link badge} (which also shows the tag in-range and supports an icon).
105
118
  * Typically paired with `excludeFromRange`. Default `false`.
106
119
  */
107
120
  offAxisBadge?: boolean;
108
- /** Localized word shown in the off-axis badge (e.g. "Target"). Falls back to `label`. */
121
+ /** Localized word shown in the legacy off-axis badge (e.g. "Target"). Falls back to `label`. */
109
122
  offAxisBadgeLabel?: string;
110
- /** Off-axis badge pill background. Default: theme `tooltipBg`. */
123
+ /** Badge pill background. Default: theme `tooltipBg`. (Fallback for `badge.background`.) */
111
124
  badgeBackground?: string;
112
- /** Off-axis badge pill border color. Default: the line `color`. */
125
+ /** Badge pill border color. Default: the line `color`. (Fallback for `badge.borderColor`.) */
113
126
  badgeBorderColor?: string;
114
- /** Off-axis badge pill corner radius in pixels. Default `5`. */
127
+ /** Badge pill corner radius in pixels. Default `5`. (Fallback for `badge.radius`.) */
115
128
  badgeRadius?: number;
116
129
  }
117
130
 
131
+ /**
132
+ * Pill-badge presentation for a Form-A {@link ReferenceLine} — a working order,
133
+ * price alert, or target tag. The badge sits at the line's value (pinned to
134
+ * `position`) with a dashed connector to the opposite edge, and pins to the
135
+ * nearest edge with a chevron once the value scrolls off-screen.
136
+ */
137
+ export interface ReferenceLineBadgeConfig {
138
+ /** Which plot edge the badge pins to. Default `"left"`. */
139
+ position?: "left" | "right";
140
+ /**
141
+ * Leading glyph drawn in the badge — rendered with the chart font, so pass an
142
+ * emoji-capable font (via the chart `font` prop) for emoji. Like `Marker.icon`.
143
+ */
144
+ icon?: string;
145
+ /**
146
+ * Show the text label (the line's `label`, plus the value when `showValue`).
147
+ * Default `true`. Set `false` for an **icon-only** badge.
148
+ */
149
+ 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`. */
155
+ radius?: number;
156
+ }
157
+
118
158
  /**
119
159
  * A time-range segment of the chart — e.g. a pre-market / regular / after-hours
120
160
  * session — distinguished with a **scrub-focus** interaction (Robinhood-style
@@ -293,6 +333,71 @@ export interface ScrubConfig {
293
333
  panGestureDelay?: number;
294
334
  }
295
335
 
336
+ /**
337
+ * Scrub-action ("order ticket") mode for the single-series `LiveChart` (line and
338
+ * candle). Tap to drop a locked crosshair, drag to fine-tune a **price level**,
339
+ * then press the right-gutter action badge to fire {@link LiveChartProps.onScrubAction}.
340
+ *
341
+ * The reported price is the value at the reticle's **Y position** (a free price
342
+ * level you choose — the inverse of the value→pixel mapping), NOT the line/candle
343
+ * value at the reticle's X. That matches how a limit price works (a horizontal
344
+ * level) and the crosshair badge in pro charting tools. Opt-in (default off).
345
+ */
346
+ export interface ScrubActionConfig {
347
+ /** Glyph drawn in the action badge (rendered as chart text, like `Marker.icon`). Default `"+"`. */
348
+ icon?: string;
349
+ /** Action-badge background color. Defaults to the accent / badge color. */
350
+ background?: string;
351
+ /** Action-badge icon + price text color. Defaults to the badge text color. */
352
+ iconColor?: string;
353
+ /** Horizontal level-line color. Defaults to `palette.crosshairLine`. */
354
+ lineColor?: string;
355
+ /**
356
+ * Show the price readout inside the action badge. Default `true`. Set `false`
357
+ * for an **icon-only** pill (mirrors {@link ReferenceLineBadgeConfig.text}).
358
+ */
359
+ text?: boolean;
360
+ /**
361
+ * Show a date/time pill where the reticle's vertical line meets the x-axis,
362
+ * formatted by the chart's `formatTime`. Off by default — for order entry the
363
+ * reticle's X (time) is incidental to a price *level*; enable it when the time
364
+ * under the reticle is meaningful (annotations, time-relevant actions, or a full
365
+ * crosshair readout). Reuses `background` / `iconColor`. Default `false`.
366
+ */
367
+ timeBadge?: boolean;
368
+ /**
369
+ * Round the reported price to this increment (e.g. `0.01` for cents, `0.5` for
370
+ * a tick size) so the badge reads round numbers. Omit for the raw value.
371
+ */
372
+ snap?: number;
373
+ /**
374
+ * A tap on empty plot (outside the reticle + action badge) dismisses the lock
375
+ * instead of moving it. Default `false` (an empty-plot tap re-places the reticle).
376
+ */
377
+ dismissOnTapOutside?: boolean;
378
+ }
379
+
380
+ /**
381
+ * Payload for {@link LiveChartProps.onScrubAction} — the chosen price **level**
382
+ * (from the locked reticle's Y), not the line value at that time.
383
+ *
384
+ * The library asserts no buy/sell semantics: derive the side from `price` versus
385
+ * your own current price (`price < last` is the usual buy-below / sell-above
386
+ * convention, but stop orders invert it).
387
+ */
388
+ export interface ScrubActionPoint {
389
+ /** Chosen price level — the value at the reticle Y, optionally `snap`-rounded. */
390
+ price: number;
391
+ /** Unix timestamp in seconds at the reticle X. */
392
+ time: number;
393
+ /** Canvas X coordinate of the reticle. */
394
+ x: number;
395
+ /** Canvas Y coordinate of the reticle. */
396
+ y: number;
397
+ /** In candle mode, the OHLC data of the candle under the reticle X (context only). */
398
+ candle?: CandlePoint;
399
+ }
400
+
296
401
  /**
297
402
  * Props passed to a custom {@link SelectionDotConfig.component} — the dot drawn
298
403
  * at the scrub intersection while scrubbing. All positional inputs are
@@ -962,6 +1067,29 @@ export interface LiveChartProps extends LiveChartCoreProps {
962
1067
  static?: boolean;
963
1068
  /** Called when the user scrubs the crosshair. `null` when scrub ends. */
964
1069
  onScrub?: (point: ScrubPoint | null) => void;
1070
+ /**
1071
+ * Scrub-action ("order ticket") mode: tap to drop a locked crosshair, drag to
1072
+ * fine-tune a **price level**, then press the right-gutter action badge to fire
1073
+ * {@link onScrubAction}. `true` = defaults, `false`/omitted = off, or pass
1074
+ * {@link ScrubActionConfig}. Coexists with `scrub`/`onScrub`. Default off.
1075
+ */
1076
+ scrubAction?: boolean | ScrubActionConfig;
1077
+ /**
1078
+ * Called on the JS thread when the user presses the scrub-action badge. The
1079
+ * payload's `price` is the value at the locked reticle's Y (a chosen price
1080
+ * level), not the line value at that time. See {@link ScrubActionPoint}.
1081
+ */
1082
+ onScrubAction?: (point: ScrubActionPoint) => void;
1083
+ /**
1084
+ * Called on the JS thread when the user taps a reference line's **badge** — the
1085
+ * pill tag drawn for a working order / alert / target (a `ReferenceLine` with a
1086
+ * {@link ReferenceLine.badge}). Receives the tapped line and its index in the
1087
+ * `referenceLines` array, e.g. to open a cancel/edit sheet for that order. Only
1088
+ * badge-tagged Form-A (value) lines are pressable — a plain line has no discrete
1089
+ * hit target. Coexists with `scrub`/`scrubAction`/`markers` (a tap on a badge is
1090
+ * routed here, not to reticle placement). Single-series only.
1091
+ */
1092
+ onReferenceLinePress?: (line: ReferenceLine, index: number) => void;
965
1093
  /**
966
1094
  * Called on the JS thread when degen chart shake starts (momentum swing with shake enabled).
967
1095
  * Not called when `degen` is off or `DegenOptions.shake` is `false`.