react-native-vroom-chart 0.5.0 → 0.7.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 (58) hide show
  1. package/android/CMakeLists.txt +143 -0
  2. package/android/README.md +60 -5
  3. package/android/build.gradle +115 -0
  4. package/android/src/main/AndroidManifest.xml +2 -0
  5. package/android/src/main/cpp/VroomChartJni.cpp +24 -0
  6. package/android/src/main/java/com/vroom/chart/VroomChartModule.kt +31 -0
  7. package/android/src/main/java/com/vroom/chart/VroomChartPackage.kt +31 -0
  8. package/cpp/VroomChartHostObject.cpp +368 -33
  9. package/cpp/VroomJsiInstaller.cpp +11 -1
  10. package/cpp/VroomSkiaContext.cpp +15 -7
  11. package/cpp/_core_include/vroom/vroom_chart.h +250 -22
  12. package/cpp/_core_src/bollinger.h +1 -1
  13. package/cpp/_core_src/candles.cpp +138 -41
  14. package/cpp/_core_src/candles.h +11 -1
  15. package/cpp/_core_src/chart.cpp +98 -40
  16. package/cpp/_core_src/chart.h +82 -20
  17. package/cpp/_core_src/chart_facade.cpp +297 -66
  18. package/cpp/_core_src/gradient.cpp +46 -0
  19. package/cpp/_core_src/gradient.h +31 -0
  20. package/cpp/_core_src/labels.cpp +49 -16
  21. package/cpp/_core_src/labels.h +33 -4
  22. package/cpp/_core_src/liquidity.cpp +3 -37
  23. package/cpp/_core_src/ma_overlay.cpp +174 -12
  24. package/cpp/_core_src/ma_overlay.h +55 -3
  25. package/cpp/_core_src/macd.cpp +13 -42
  26. package/cpp/_core_src/macd.h +11 -8
  27. package/cpp/_core_src/macd_pane.cpp +57 -27
  28. package/cpp/_core_src/price_line_layout.cpp +87 -0
  29. package/cpp/_core_src/price_line_layout.h +80 -0
  30. package/cpp/_core_src/price_lines.cpp +428 -0
  31. package/cpp/_core_src/price_lines.h +56 -0
  32. package/cpp/_core_src/rsi.cpp +4 -18
  33. package/cpp/_core_src/rsi.h +6 -6
  34. package/cpp/_core_src/rsi_pane.cpp +34 -19
  35. package/cpp/_core_src/series_ma.cpp +64 -0
  36. package/cpp/_core_src/series_ma.h +30 -0
  37. package/cpp/_core_src/style_inherit.h +35 -0
  38. package/cpp/_core_src/theme.cpp +2 -1
  39. package/cpp/_core_src/viewport.cpp +36 -12
  40. package/cpp/_core_src/viewport.h +50 -0
  41. package/cpp/_core_src/volume.cpp +33 -8
  42. package/cpp/_core_src/volume.h +12 -1
  43. package/cpp/_core_src/volume_anim.cpp +32 -0
  44. package/cpp/_core_src/volume_anim.h +41 -0
  45. package/lib/index.d.mts +261 -25
  46. package/lib/index.d.ts +261 -25
  47. package/lib/index.js +252 -36
  48. package/lib/index.js.map +1 -1
  49. package/lib/index.mjs +252 -36
  50. package/lib/index.mjs.map +1 -1
  51. package/package.json +5 -4
  52. package/src/VroomChart.tsx +162 -11
  53. package/src/easing.ts +40 -0
  54. package/src/index.ts +5 -0
  55. package/src/jsi.d.ts +124 -20
  56. package/src/theme.ts +1 -0
  57. package/src/types.ts +5 -0
  58. package/src/useChartCore.ts +166 -28
package/lib/index.d.ts CHANGED
@@ -82,7 +82,12 @@ type VroomTheme = {
82
82
  candleRadius?: number;
83
83
  /** Round the wick end caps. Defaults to false. */
84
84
  wickRoundCap?: boolean;
85
- /** Corner radius (px) of the *top* of volume bars. Defaults to 0 (square). */
85
+ /**
86
+ * Corner radius (px) of the *top* of volume bars. Defaults to 0 (square).
87
+ *
88
+ * @deprecated Use `volume.radius`, which sits with the rest of the volume
89
+ * styling. This still applies when `volume.radius` is omitted.
90
+ */
86
91
  volumeRadius?: number;
87
92
  /** Gridlines. */
88
93
  grid?: VroomColor;
@@ -92,10 +97,16 @@ type VroomTheme = {
92
97
  crosshair?: VroomColor;
93
98
  /** Crosshair target — the hollow ring/dot at the intersection. */
94
99
  crosshairTarget?: VroomColor;
95
- /** Line-chart-mode close polyline color. Defaults to a neutral foreground. */
100
+ /** Line-chart-mode close polyline color. Defaults to violet, matching the RSI line. */
96
101
  lineColor?: VroomColor;
97
102
  /** Line-chart-mode polyline stroke width in px. Defaults to 1.5. */
98
103
  lineWidth?: number;
104
+ /**
105
+ * Opacity of the gradient filled beneath the line-chart polyline, at its
106
+ * strongest point. The fill uses `lineColor` and ramps to fully transparent at
107
+ * the bottom of the price pane. Defaults to 0.28; set to 0 to disable the fill.
108
+ */
109
+ lineGradientOpacity?: number;
99
110
  };
100
111
  /** A time window over the candle data, as Unix epoch milliseconds. */
101
112
  type VisibleRange = {
@@ -117,6 +128,11 @@ type ChartMode = 'pan' | 'draw';
117
128
  * overlays, crosshair, and drawings still render.
118
129
  */
119
130
  type ChartType = 'candles' | 'line';
131
+ /**
132
+ * Easing curve for animated transitions (candle↔line and interval switches).
133
+ * Defaults to `'ease-in-out'`.
134
+ */
135
+ type TransitionEasing = 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out';
120
136
  /** Active drawing tool while in `draw` mode. `null` draws nothing. */
121
137
  type DrawTool = null | 'line' | 'box' | 'pencil';
122
138
  /** A drawing anchor in data space, so it stays glued to the candles on pan/zoom. */
@@ -226,8 +242,21 @@ type UndoRedoControls = {
226
242
  */
227
243
  clearHistory: () => void;
228
244
  };
229
- /** RSI indicator config. Rendered in a pane below the candles when enabled. */
245
+ /** Price source for a moving average. */
246
+ type MASource = 'close' | 'open' | 'high' | 'low' | 'hl2' | 'hlc3' | 'ohlc4';
247
+ /** Averaging used by a moving average: simple or exponential. */
248
+ type MAKind = 'sma' | 'ema';
249
+ /**
250
+ * RSI indicator config. Rendered in a pane below the candles when enabled: the
251
+ * RSI line, an optional moving-average trendline over it, and two dashed rules
252
+ * at the overbought and oversold levels.
253
+ *
254
+ * RSI reads closes only — Wilder's definition is built on close-to-close
255
+ * change — so unlike the moving-average, Bollinger, and MACD configs it takes
256
+ * no {@link MASource}.
257
+ */
230
258
  type RSIConfig = {
259
+ /** Draw the pane. Default false. */
231
260
  enabled?: boolean;
232
261
  /** Lookback period in candle counts. Default 14, clamped to >= 2. */
233
262
  period?: number;
@@ -235,23 +264,37 @@ type RSIConfig = {
235
264
  upperBand?: number;
236
265
  /** Oversold band level (0..100). Default 30. */
237
266
  lowerBand?: number;
238
- /** Show the RSI-based moving-average trendline. Default true. */
239
- maEnabled?: boolean;
240
267
  /** Trendline (MA of RSI) length. Default 14, clamped to >= 1. */
241
268
  maPeriod?: number;
269
+ /** Averaging used for the trendline ({@link MAKind}). Default 'sma'. */
270
+ maType?: MAKind;
271
+ /** Draw the moving-average trendline. Default true. */
272
+ maVisible?: boolean;
273
+ /** RSI line color (hex string or packed ARGB number). Default violet. */
274
+ lineColor?: string | number;
275
+ /** RSI line stroke width in px. Default 1.5. */
276
+ lineWidth?: number;
277
+ /** Draw the RSI line. Default true. */
278
+ lineVisible?: boolean;
279
+ /** Trendline color. Default amber. */
280
+ maColor?: string | number;
281
+ /** Trendline stroke width in px. Default 1.5. */
282
+ maWidth?: number;
283
+ /** Color of both dashed band rules. Default gray. */
284
+ bandColor?: string | number;
285
+ /** Draw the overbought/oversold rules. Default true. */
286
+ bandsVisible?: boolean;
242
287
  };
243
- /** Price source for a moving average. */
244
- type MASource = 'close' | 'open' | 'high' | 'low' | 'hl2' | 'hlc3' | 'ohlc4';
245
288
  /**
246
289
  * A moving-average overlay line drawn on the price pane. Provide an array of
247
290
  * these via `movingAverages` to render a ribbon of SMA/EMA lines.
248
291
  */
249
292
  type MovingAverageOverlay = {
250
- /** 'sma' (simple) or 'ema' (exponential). */
251
- kind: 'sma' | 'ema';
293
+ /** Averaging for this line ({@link MAKind}). */
294
+ maType: MAKind;
252
295
  /** Lookback in candles. */
253
- length: number;
254
- /** Price source. Default 'close'. */
296
+ period: number;
297
+ /** Price source ({@link MASource}). Default 'close'. */
255
298
  source?: MASource;
256
299
  /** Line color (hex string or packed ARGB number). */
257
300
  color?: string | number;
@@ -263,6 +306,7 @@ type MovingAverageOverlay = {
263
306
  * pane, resetting each session.
264
307
  */
265
308
  type VWAPConfig = {
309
+ /** Draw the line. Default false. */
266
310
  enabled?: boolean;
267
311
  /** Session reset offset from UTC midnight, in minutes (default 0). */
268
312
  resetMinutes?: number;
@@ -278,18 +322,20 @@ type VWAPConfig = {
278
322
  * fill between the bands. No pane is reserved.
279
323
  */
280
324
  type BollingerBandsConfig = {
325
+ /** Draw the bands. Default false. */
281
326
  enabled?: boolean;
282
327
  /** Lookback in candles. Default 20, clamped to >= 1. */
283
328
  period?: number;
284
329
  /** Standard-deviation multiplier. Default 2. */
285
330
  stdDev?: number;
286
- /** Price source. Default 'close'. */
331
+ /** Price source ({@link MASource}). Default 'close'. */
287
332
  source?: MASource;
288
333
  /**
289
- * Basis (middle) line type. Default 'sma'. The stdev always uses the
290
- * window's arithmetic mean, even with an EMA basis (TradingView semantics).
334
+ * Averaging for the basis (middle) line ({@link MAKind}). Default 'sma'. The
335
+ * stdev always uses the window's arithmetic mean, even with an EMA basis
336
+ * (the standard semantics).
291
337
  */
292
- basis?: 'sma' | 'ema';
338
+ maType?: MAKind;
293
339
  /** Upper band color (hex string or packed ARGB number). Default blue. */
294
340
  upperColor?: string | number;
295
341
  /** Upper band stroke width in px. Default 1. */
@@ -302,11 +348,40 @@ type BollingerBandsConfig = {
302
348
  lowerColor?: string | number;
303
349
  /** Lower band stroke width in px. Default 1. */
304
350
  lowerWidth?: number;
305
- /** Translucent fill between the bands. Default true. */
306
- fill?: boolean;
351
+ /** Draw the translucent fill between the bands. Default true. */
352
+ fillVisible?: boolean;
307
353
  /** Fill opacity 0..1, applied to the upper band color. Default 0.1. */
308
354
  fillOpacity?: number;
309
355
  };
356
+ /**
357
+ * Volume bar config. One bottom-anchored bar per candle on the price pane,
358
+ * drawn under the candles and sharing their x position and body width.
359
+ *
360
+ * Unlike the other indicator configs the bars are on by default, so omitting
361
+ * this prop leaves the chart looking as it always has.
362
+ */
363
+ type VolumeConfig = {
364
+ /** Draw the bars. Default true. */
365
+ enabled?: boolean;
366
+ /** Bar opacity 0..1 (1 = opaque). Default 0.5, so bars read quieter than the candles. */
367
+ opacity?: number;
368
+ /**
369
+ * Height of the tallest bar as a fraction of the price pane, 0..1.
370
+ * Default 0.2.
371
+ *
372
+ * This is a ceiling rather than a reserved strip: raising it lets the bars
373
+ * reach further up over the candles rather than compressing them, matching
374
+ * the conventional volume overlay. Heights always auto-fit the loudest volume
375
+ * in view, so the tallest bar sits exactly at the ceiling.
376
+ */
377
+ height?: number;
378
+ /** Corner radius (px) of the *top* of each bar. Defaults to `theme.volumeRadius`, else 0 (square). */
379
+ radius?: number;
380
+ /** Up-bar color (hex string or packed ARGB number). Defaults to `theme.accentBull`. */
381
+ upColor?: string | number;
382
+ /** Down-bar color (hex string or packed ARGB number). Defaults to `theme.accentBear`. */
383
+ downColor?: string | number;
384
+ };
310
385
  /**
311
386
  * A single resting-liquidity band: a price interval carrying a total order size
312
387
  * on one side of the book. Consolidate raw L2 levels into these buckets before
@@ -352,15 +427,137 @@ type LiquidityConfig = {
352
427
  * `widthPx` and `widthFrac * paneWidth` is used. */
353
428
  widthFrac?: number;
354
429
  };
355
- /** MACD indicator config. Rendered in its own pane below the candles. */
430
+ /**
431
+ * A consumer-supplied horizontal status line at a fixed price — the primitive
432
+ * behind resting limit orders, take-profits, stop-losses and liquidation levels.
433
+ *
434
+ * Renders as a line across the price pane ending in a label group (a `text` pill
435
+ * plus an optional solid-filled `quantity` pill and an optional close button),
436
+ * with a price badge in the y-axis strip.
437
+ *
438
+ * Interaction is opt-in and callback-gated: the line is only draggable when
439
+ * `draggable` is set, and the close button only renders when you pass
440
+ * `onPriceLineClose`. Dragging is a *preview* — the chart never mutates
441
+ * the price you gave it, so a move your backend rejects reverts on its own
442
+ * simply by leaving your `priceLines` state unchanged.
443
+ */
444
+ type PriceLine = {
445
+ /** Stable unique id, echoed back by every callback. */
446
+ id: string;
447
+ /** Where the line sits on the price scale. */
448
+ price: number;
449
+ /** Body label — render whatever you like (e.g. `'Limit Buy @ 13.79'`). */
450
+ text?: string;
451
+ /**
452
+ * Trailing segment, drawn as a solid-filled pill with white text so size reads
453
+ * at a glance (e.g. `'x 5.206'`). Omit to hide it.
454
+ */
455
+ quantity?: string;
456
+ /** Line, border, body text and close-icon color. Defaults to a soft red. */
457
+ color?: VroomColor;
458
+ /** Stroke width in px. Default 1. */
459
+ width?: number;
460
+ /** Line style. Default `'dotted'`, matching the current-price indicator. */
461
+ lineStyle?: 'solid' | 'dotted' | 'dashed';
462
+ /**
463
+ * Let the user drag this line vertically to a new price. Default false.
464
+ * Pair with `onPriceLineDragEnd` to commit the move.
465
+ */
466
+ draggable?: boolean;
467
+ /**
468
+ * Show the close button on this line. Defaults to true, but the button only
469
+ * ever renders if you also pass `onPriceLineClose` — set this to false to opt a
470
+ * single line out (e.g. a liquidation level the user can't dismiss).
471
+ */
472
+ closable?: boolean;
473
+ /** Extend the line to the pane's left edge. Default true. */
474
+ extendLeft?: boolean;
475
+ /** Show the price badge in the y-axis strip. Default true. */
476
+ axisLabel?: boolean;
477
+ };
478
+ /** Shared layout/style for every price line, passed via `priceLinesStyle`. */
479
+ type PriceLinesStyle = {
480
+ /**
481
+ * Translucent fill behind the body and close-button pills, so the label reads
482
+ * over candles without hiding them. Defaults to a dark translucent grey.
483
+ */
484
+ bodyBackground?: VroomColor;
485
+ /** Label font size in px. Defaults to the axis font size. */
486
+ fontSize?: number;
487
+ /**
488
+ * How far in from the price axis the label group sits, as a fraction of pane
489
+ * width (0 = flush against the axis, 0.5 = at the pane's midpoint). Only
490
+ * applies when `align` is `'right'`. Default 0.
491
+ */
492
+ inset?: number;
493
+ /** Where the label group sits horizontally. Default `'right'`. */
494
+ align?: 'left' | 'center' | 'right';
495
+ /**
496
+ * How much the hovered line or close button brightens, as a channel
497
+ * multiplier. 1 disables the highlight. Default 1.25. Web only — touch
498
+ * platforms have no hover state.
499
+ */
500
+ hoverBoost?: number;
501
+ };
502
+ /**
503
+ * MACD indicator config. Rendered in its own pane below the candles: the gap
504
+ * between a fast and a slow moving average, a signal line smoothing that gap,
505
+ * and a histogram of the distance between the two.
506
+ *
507
+ * Every style field is optional and falls back to the stock look, so an
508
+ * untouched config renders exactly as it always has.
509
+ */
356
510
  type MACDConfig = {
511
+ /** Draw the pane. Default false. */
357
512
  enabled?: boolean;
358
- /** Fast EMA length. Default 12. */
513
+ /** Fast moving-average length. Default 12. */
359
514
  fast?: number;
360
- /** Slow EMA length (forced > fast). Default 26. */
515
+ /** Slow moving-average length (forced > fast). Default 26. */
361
516
  slow?: number;
362
- /** Signal-line EMA length. Default 9. */
517
+ /** Signal-line length. Default 9. */
363
518
  signal?: number;
519
+ /** Price source for the fast/slow legs ({@link MASource}). Default 'close'. */
520
+ source?: MASource;
521
+ /** Averaging used for the fast and slow legs ({@link MAKind}). Default 'ema'. */
522
+ maType?: MAKind;
523
+ /** Averaging applied to the MACD series for the signal line. Default 'ema'. */
524
+ signalMaType?: MAKind;
525
+ /** MACD line color (hex string or packed ARGB number). Default blue. */
526
+ lineColor?: string | number;
527
+ /** MACD line stroke width in px. Default 1.5. */
528
+ lineWidth?: number;
529
+ /** Draw the MACD line. Default true. */
530
+ lineVisible?: boolean;
531
+ /** Signal line color. Default orange. */
532
+ signalColor?: string | number;
533
+ /** Signal line stroke width in px. Default 1.5. */
534
+ signalWidth?: number;
535
+ /** Draw the signal line. Default true. */
536
+ signalVisible?: boolean;
537
+ /** Draw the histogram bars. Default true. */
538
+ histogramVisible?: boolean;
539
+ /**
540
+ * Bars above zero that are still growing away from it. Defaults to
541
+ * `theme.accentBull`. Set all four histogram colors alike for a flat,
542
+ * single-color histogram.
543
+ */
544
+ histogramUpColor?: string | number;
545
+ /**
546
+ * Bars above zero that are falling back toward it, i.e. momentum easing.
547
+ * Defaults to `histogramUpColor` at half opacity.
548
+ */
549
+ histogramUpFadingColor?: string | number;
550
+ /** Bars below zero still growing away from it. Defaults to `theme.accentBear`. */
551
+ histogramDownColor?: string | number;
552
+ /**
553
+ * Bars below zero rising back toward it. Defaults to `histogramDownColor` at
554
+ * half opacity.
555
+ */
556
+ histogramDownFadingColor?: string | number;
557
+ /** Zero-reference line color. Default gray. */
558
+ zeroLineColor?: string | number;
559
+ /** Draw the zero-reference line. Default true. */
560
+ zeroLineVisible?: boolean;
364
561
  };
365
562
  /**
366
563
  * Platform-agnostic props shared by every vroom chart component. Each platform
@@ -402,11 +599,17 @@ type VroomChartCoreProps = {
402
599
  */
403
600
  chartType?: ChartType;
404
601
  /**
405
- * Duration (ms) of the animated candle↔line transition when `chartType`
406
- * changes. Default ~300. `0` snaps instantly. Ignored (snaps) when the OS
407
- * requests reduced motion, which instead uses a plain cross-fade.
602
+ * Duration (ms) of the animated transitions: the candle↔line switch when
603
+ * `chartType` changes, and the candle reshape when the `candles` array is
604
+ * swapped for a different interval of the same asset. Default ~300. `0` snaps
605
+ * instantly. Ignored (snaps) when the OS requests reduced motion, which
606
+ * instead uses a plain cross-fade.
408
607
  */
409
608
  transitionMs?: number;
609
+ /**
610
+ * Easing curve applied to those transitions. Default `'ease-in-out'`.
611
+ */
612
+ transitionEasing?: TransitionEasing;
410
613
  theme?: VroomTheme;
411
614
  /** RSI indicator (pane below the candles). Omit/disable to hide it. */
412
615
  rsi?: RSIConfig;
@@ -418,8 +621,41 @@ type VroomChartCoreProps = {
418
621
  vwap?: VWAPConfig;
419
622
  /** Bollinger Bands overlay (three lines + fill on the price pane). */
420
623
  bollingerBands?: BollingerBandsConfig;
624
+ /** Volume bars under the candles. On by default; disable or restyle them here. */
625
+ volume?: VolumeConfig;
421
626
  /** Resting-order / order-book liquidity bands drawn behind the candles. */
422
627
  liquidity?: LiquidityConfig;
628
+ /**
629
+ * Horizontal status lines at consumer-supplied prices (resting orders, TP/SL,
630
+ * liquidation levels), each with a text label and an optional close button.
631
+ *
632
+ * This is a controlled prop: the chart renders exactly what you pass and never
633
+ * mutates it. A drag paints a live preview and reports the new price through
634
+ * `onPriceLineDragEnd`; the line only actually moves once you update this
635
+ * array, so a rejected move needs no explicit rollback.
636
+ */
637
+ priceLines?: PriceLine[];
638
+ /** Shared layout/style for every entry in `priceLines`. */
639
+ priceLinesStyle?: PriceLinesStyle;
640
+ /**
641
+ * Fired continuously while a draggable price line is being dragged, with the
642
+ * price under the pointer. Use it for a live readout (e.g. an order ticket);
643
+ * wait for `onPriceLineDragEnd` to commit.
644
+ */
645
+ onPriceLineDrag?: (id: string, price: number) => void;
646
+ /**
647
+ * Fired once when the user drops a dragged price line. Submit the new price to
648
+ * your backend here, then update `priceLines` on success — the line snaps back
649
+ * on its own if you don't. Dragging is cancelled (and this never fires) if the
650
+ * user presses Escape.
651
+ */
652
+ onPriceLineDragEnd?: (id: string, price: number) => void;
653
+ /**
654
+ * Fired when the user activates a price line's close button. Passing this
655
+ * handler is what makes the button render at all; individual lines opt out with
656
+ * `closable: false`.
657
+ */
658
+ onPriceLineClose?: (id: string) => void;
423
659
  /**
424
660
  * Pixels the crosshair dot / horizontal line sit *above* the touch point so
425
661
  * they aren't hidden under the thumb. The vertical line stays centered on the
@@ -547,4 +783,4 @@ declare global {
547
783
  */
548
784
  declare function VroomChart(props: VroomChartProps): React.JSX.Element;
549
785
 
550
- export { type BollingerBandsConfig, type Candle, type ChartType, type CrosshairEvent, type MACDConfig, type MASource, type MovingAverageOverlay, type RSIConfig, type VWAPConfig, type VisibleRange, VroomChart, type VroomChartProps, type VroomColor, type VroomTheme };
786
+ export { type BollingerBandsConfig, type Candle, type ChartType, type CrosshairEvent, type MACDConfig, type MAKind, type MASource, type MovingAverageOverlay, type PriceLine, type PriceLinesStyle, type RSIConfig, type TransitionEasing, type VWAPConfig, type VisibleRange, type VolumeConfig, VroomChart, type VroomChartProps, type VroomColor, type VroomTheme };