react-native-livechart 3.3.0 → 3.5.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 (56) hide show
  1. package/README.md +5 -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/ThresholdLineOverlay.d.ts +34 -0
  9. package/dist/components/ThresholdLineOverlay.d.ts.map +1 -0
  10. package/dist/components/XAxisOverlay.d.ts.map +1 -1
  11. package/dist/constants.d.ts +4 -0
  12. package/dist/constants.d.ts.map +1 -1
  13. package/dist/core/resolveConfig.d.ts +55 -1
  14. package/dist/core/resolveConfig.d.ts.map +1 -1
  15. package/dist/hooks/crosshairShared.d.ts +110 -0
  16. package/dist/hooks/crosshairShared.d.ts.map +1 -1
  17. package/dist/hooks/useChartPaths.d.ts +5 -1
  18. package/dist/hooks/useChartPaths.d.ts.map +1 -1
  19. package/dist/hooks/useCrosshair.d.ts +14 -2
  20. package/dist/hooks/useCrosshair.d.ts.map +1 -1
  21. package/dist/hooks/useMarkers.d.ts +2 -0
  22. package/dist/hooks/useMarkers.d.ts.map +1 -1
  23. package/dist/hooks/useReferenceLine.d.ts +36 -3
  24. package/dist/hooks/useReferenceLine.d.ts.map +1 -1
  25. package/dist/hooks/useReferenceLinePress.d.ts +23 -0
  26. package/dist/hooks/useReferenceLinePress.d.ts.map +1 -0
  27. package/dist/hooks/useThreshold.d.ts +22 -0
  28. package/dist/hooks/useThreshold.d.ts.map +1 -0
  29. package/dist/index.d.ts +1 -1
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/math/referenceLines.d.ts +23 -0
  32. package/dist/math/referenceLines.d.ts.map +1 -1
  33. package/dist/math/threshold.d.ts +25 -0
  34. package/dist/math/threshold.d.ts.map +1 -0
  35. package/dist/types.d.ts +190 -6
  36. package/dist/types.d.ts.map +1 -1
  37. package/package.json +1 -1
  38. package/src/components/LiveChart.tsx +362 -61
  39. package/src/components/LiveChartSeries.tsx +39 -2
  40. package/src/components/ReferenceLineOverlay.tsx +121 -94
  41. package/src/components/ScrubActionOverlay.tsx +187 -0
  42. package/src/components/ThresholdLineOverlay.tsx +172 -0
  43. package/src/components/XAxisOverlay.tsx +2 -1
  44. package/src/constants.ts +5 -0
  45. package/src/core/resolveConfig.ts +102 -0
  46. package/src/hooks/crosshairShared.ts +293 -0
  47. package/src/hooks/useChartPaths.ts +25 -1
  48. package/src/hooks/useCrosshair.ts +340 -6
  49. package/src/hooks/useMarkers.ts +18 -2
  50. package/src/hooks/useReferenceLine.ts +259 -14
  51. package/src/hooks/useReferenceLinePress.ts +92 -0
  52. package/src/hooks/useThreshold.ts +63 -0
  53. package/src/index.ts +5 -0
  54. package/src/math/referenceLines.ts +55 -0
  55. package/src/math/threshold.ts +59 -0
  56. package/src/types.ts +195 -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
@@ -201,6 +241,61 @@ export interface LineConfig {
201
241
  colors?: string[];
202
242
  }
203
243
 
244
+ /**
245
+ * Color the line above vs. below a live threshold value — green above, red below
246
+ * by default. The threshold is **always** a `SharedValue` so it can track a live
247
+ * benchmark (break-even / average cost, VWAP, previous close, a peg) on the UI
248
+ * thread without re-rendering. Drives a hard-split line stroke and, optionally, a
249
+ * tinted profit/loss fill band and a dashed marker line at the threshold.
250
+ *
251
+ * The split stroke supersedes `LineConfig.color`/`colors` and segment recoloring
252
+ * for the main line while a threshold is set.
253
+ */
254
+ export interface ThresholdConfig {
255
+ /**
256
+ * The split value, in Y-axis (price) units. A `SharedValue` — update it with
257
+ * `.set()` and the split tracks live on the UI thread (break-even, VWAP, the
258
+ * previous close, a peg, …).
259
+ */
260
+ value: SharedValue<number>;
261
+ /** Stroke color where the line is at/above `value`. Default: palette up-green (`candleUp`). */
262
+ aboveColor?: string;
263
+ /** Stroke color where the line is below `value`. Default: palette down-red (`candleDown`). */
264
+ belowColor?: string;
265
+ /**
266
+ * Tint the area between the line and `value` (the profit/loss band) toward the
267
+ * above/below colors. Independent of the baseline `gradient` fill — set
268
+ * `gradient={false}` for the threshold band alone. Default `false`.
269
+ */
270
+ fill?: boolean;
271
+ /**
272
+ * Dashed marker line + optional gutter label at the threshold. `true` → a dashed
273
+ * line in the palette reference color; object → styled; omit/`false` → none.
274
+ * Default off.
275
+ */
276
+ line?: boolean | ThresholdLineConfig;
277
+ }
278
+
279
+ /** Dashed marker line drawn at a {@link ThresholdConfig} value. */
280
+ export interface ThresholdLineConfig {
281
+ /** Label text, e.g. `"Break-even"`. */
282
+ label?: string;
283
+ /**
284
+ * Label side. `"left"` sits just inside the plot at the line's left edge —
285
+ * clear of the y-axis labels and the live badge; `"right"` uses the right
286
+ * gutter like a legacy reference line (may overlap y-axis labels). Default `"left"`.
287
+ */
288
+ labelPosition?: "left" | "right";
289
+ /** Line + label color. Defaults to palette `refLine` / `refLabel`. */
290
+ color?: string;
291
+ /** Dash pattern `[dashLength, gapLength]` in pixels. Default `[4, 4]`. */
292
+ intervals?: [number, number];
293
+ /** Line thickness in pixels. Default `1`. */
294
+ strokeWidth?: number;
295
+ /** Append the formatted threshold value to the label. Default `false`. */
296
+ showValue?: boolean;
297
+ }
298
+
204
299
  /** Area fill gradient beneath the chart line. */
205
300
  export interface GradientConfig {
206
301
  /** Opacity at the top of the gradient (near the line). Default `0.35`. */
@@ -293,6 +388,71 @@ export interface ScrubConfig {
293
388
  panGestureDelay?: number;
294
389
  }
295
390
 
391
+ /**
392
+ * Scrub-action ("order ticket") mode for the single-series `LiveChart` (line and
393
+ * candle). Tap to drop a locked crosshair, drag to fine-tune a **price level**,
394
+ * then press the right-gutter action badge to fire {@link LiveChartProps.onScrubAction}.
395
+ *
396
+ * The reported price is the value at the reticle's **Y position** (a free price
397
+ * level you choose — the inverse of the value→pixel mapping), NOT the line/candle
398
+ * value at the reticle's X. That matches how a limit price works (a horizontal
399
+ * level) and the crosshair badge in pro charting tools. Opt-in (default off).
400
+ */
401
+ export interface ScrubActionConfig {
402
+ /** Glyph drawn in the action badge (rendered as chart text, like `Marker.icon`). Default `"+"`. */
403
+ icon?: string;
404
+ /** Action-badge background color. Defaults to the accent / badge color. */
405
+ background?: string;
406
+ /** Action-badge icon + price text color. Defaults to the badge text color. */
407
+ iconColor?: string;
408
+ /** Horizontal level-line color. Defaults to `palette.crosshairLine`. */
409
+ lineColor?: string;
410
+ /**
411
+ * Show the price readout inside the action badge. Default `true`. Set `false`
412
+ * for an **icon-only** pill (mirrors {@link ReferenceLineBadgeConfig.text}).
413
+ */
414
+ text?: boolean;
415
+ /**
416
+ * Show a date/time pill where the reticle's vertical line meets the x-axis,
417
+ * formatted by the chart's `formatTime`. Off by default — for order entry the
418
+ * reticle's X (time) is incidental to a price *level*; enable it when the time
419
+ * under the reticle is meaningful (annotations, time-relevant actions, or a full
420
+ * crosshair readout). Reuses `background` / `iconColor`. Default `false`.
421
+ */
422
+ timeBadge?: boolean;
423
+ /**
424
+ * Round the reported price to this increment (e.g. `0.01` for cents, `0.5` for
425
+ * a tick size) so the badge reads round numbers. Omit for the raw value.
426
+ */
427
+ snap?: number;
428
+ /**
429
+ * A tap on empty plot (outside the reticle + action badge) dismisses the lock
430
+ * instead of moving it. Default `false` (an empty-plot tap re-places the reticle).
431
+ */
432
+ dismissOnTapOutside?: boolean;
433
+ }
434
+
435
+ /**
436
+ * Payload for {@link LiveChartProps.onScrubAction} — the chosen price **level**
437
+ * (from the locked reticle's Y), not the line value at that time.
438
+ *
439
+ * The library asserts no buy/sell semantics: derive the side from `price` versus
440
+ * your own current price (`price < last` is the usual buy-below / sell-above
441
+ * convention, but stop orders invert it).
442
+ */
443
+ export interface ScrubActionPoint {
444
+ /** Chosen price level — the value at the reticle Y, optionally `snap`-rounded. */
445
+ price: number;
446
+ /** Unix timestamp in seconds at the reticle X. */
447
+ time: number;
448
+ /** Canvas X coordinate of the reticle. */
449
+ x: number;
450
+ /** Canvas Y coordinate of the reticle. */
451
+ y: number;
452
+ /** In candle mode, the OHLC data of the candle under the reticle X (context only). */
453
+ candle?: CandlePoint;
454
+ }
455
+
296
456
  /**
297
457
  * Props passed to a custom {@link SelectionDotConfig.component} — the dot drawn
298
458
  * at the scrub intersection while scrubbing. All positional inputs are
@@ -929,6 +1089,12 @@ export interface LiveChartProps extends LiveChartCoreProps {
929
1089
  * `mutedColors`). Optional dashed `divider` + `label` mark a segment's edge.
930
1090
  */
931
1091
  segments?: ChartSegment[];
1092
+ /**
1093
+ * Color the line above vs. below a live threshold value (break-even / average
1094
+ * cost, VWAP, previous close, a peg). Always a `SharedValue` so the split tracks
1095
+ * live on the UI thread. See {@link ThresholdConfig}.
1096
+ */
1097
+ threshold?: ThresholdConfig;
932
1098
  /** Render the live value as a large text overlay in the top-left. Default `false`. */
933
1099
  showValue?: boolean;
934
1100
  /** Tint the `showValue` text by momentum (green up / red down). Default `false`. */
@@ -962,6 +1128,29 @@ export interface LiveChartProps extends LiveChartCoreProps {
962
1128
  static?: boolean;
963
1129
  /** Called when the user scrubs the crosshair. `null` when scrub ends. */
964
1130
  onScrub?: (point: ScrubPoint | null) => void;
1131
+ /**
1132
+ * Scrub-action ("order ticket") mode: tap to drop a locked crosshair, drag to
1133
+ * fine-tune a **price level**, then press the right-gutter action badge to fire
1134
+ * {@link onScrubAction}. `true` = defaults, `false`/omitted = off, or pass
1135
+ * {@link ScrubActionConfig}. Coexists with `scrub`/`onScrub`. Default off.
1136
+ */
1137
+ scrubAction?: boolean | ScrubActionConfig;
1138
+ /**
1139
+ * Called on the JS thread when the user presses the scrub-action badge. The
1140
+ * payload's `price` is the value at the locked reticle's Y (a chosen price
1141
+ * level), not the line value at that time. See {@link ScrubActionPoint}.
1142
+ */
1143
+ onScrubAction?: (point: ScrubActionPoint) => void;
1144
+ /**
1145
+ * Called on the JS thread when the user taps a reference line's **badge** — the
1146
+ * pill tag drawn for a working order / alert / target (a `ReferenceLine` with a
1147
+ * {@link ReferenceLine.badge}). Receives the tapped line and its index in the
1148
+ * `referenceLines` array, e.g. to open a cancel/edit sheet for that order. Only
1149
+ * badge-tagged Form-A (value) lines are pressable — a plain line has no discrete
1150
+ * hit target. Coexists with `scrub`/`scrubAction`/`markers` (a tap on a badge is
1151
+ * routed here, not to reticle placement). Single-series only.
1152
+ */
1153
+ onReferenceLinePress?: (line: ReferenceLine, index: number) => void;
965
1154
  /**
966
1155
  * Called on the JS thread when degen chart shake starts (momentum swing with shake enabled).
967
1156
  * Not called when `degen` is off or `DegenOptions.shake` is `false`.