react-native-vroom-chart 0.1.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 (66) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +27 -0
  3. package/android/README.md +7 -0
  4. package/cpp/README.md +11 -0
  5. package/cpp/VroomChartHostObject.cpp +458 -0
  6. package/cpp/VroomChartHostObject.h +36 -0
  7. package/cpp/VroomJsiInstaller.cpp +69 -0
  8. package/cpp/VroomJsiInstaller.h +10 -0
  9. package/cpp/VroomSkiaContext.cpp +25 -0
  10. package/cpp/VroomSkiaContext.h +30 -0
  11. package/cpp/_core_include/vroom/vroom_chart.h +195 -0
  12. package/cpp/_core_src/candles.cpp +74 -0
  13. package/cpp/_core_src/candles.h +34 -0
  14. package/cpp/_core_src/chart.cpp +317 -0
  15. package/cpp/_core_src/chart.h +167 -0
  16. package/cpp/_core_src/chart_facade.cpp +570 -0
  17. package/cpp/_core_src/chart_internal.h +30 -0
  18. package/cpp/_core_src/crosshair.cpp +65 -0
  19. package/cpp/_core_src/crosshair.h +32 -0
  20. package/cpp/_core_src/fonts.cpp +22 -0
  21. package/cpp/_core_src/fonts.h +25 -0
  22. package/cpp/_core_src/labels.cpp +340 -0
  23. package/cpp/_core_src/labels.h +85 -0
  24. package/cpp/_core_src/ma.cpp +53 -0
  25. package/cpp/_core_src/ma.h +39 -0
  26. package/cpp/_core_src/ma_overlay.cpp +73 -0
  27. package/cpp/_core_src/ma_overlay.h +42 -0
  28. package/cpp/_core_src/macd.cpp +68 -0
  29. package/cpp/_core_src/macd.h +29 -0
  30. package/cpp/_core_src/macd_pane.cpp +199 -0
  31. package/cpp/_core_src/macd_pane.h +41 -0
  32. package/cpp/_core_src/price_indicator.cpp +106 -0
  33. package/cpp/_core_src/price_indicator.h +29 -0
  34. package/cpp/_core_src/rsi.cpp +70 -0
  35. package/cpp/_core_src/rsi.h +32 -0
  36. package/cpp/_core_src/rsi_pane.cpp +167 -0
  37. package/cpp/_core_src/rsi_pane.h +39 -0
  38. package/cpp/_core_src/theme.cpp +41 -0
  39. package/cpp/_core_src/theme.h +23 -0
  40. package/cpp/_core_src/ticks.cpp +49 -0
  41. package/cpp/_core_src/ticks.h +30 -0
  42. package/cpp/_core_src/viewport.cpp +141 -0
  43. package/cpp/_core_src/viewport.h +100 -0
  44. package/cpp/_core_src/volume.cpp +70 -0
  45. package/cpp/_core_src/volume.h +34 -0
  46. package/cpp/_core_src/vwap.cpp +51 -0
  47. package/cpp/_core_src/vwap.h +27 -0
  48. package/ios/README.md +7 -0
  49. package/ios/VroomChartModule.h +11 -0
  50. package/ios/VroomChartModule.mm +44 -0
  51. package/lib/index.d.mts +185 -0
  52. package/lib/index.d.ts +185 -0
  53. package/lib/index.js +429 -0
  54. package/lib/index.js.map +1 -0
  55. package/lib/index.mjs +396 -0
  56. package/lib/index.mjs.map +1 -0
  57. package/package.json +75 -0
  58. package/react-native-vroom-chart.podspec +79 -0
  59. package/src/NativeVroomChart.ts +12 -0
  60. package/src/VroomChart.tsx +382 -0
  61. package/src/index.ts +14 -0
  62. package/src/jsi.d.ts +128 -0
  63. package/src/packCandles.ts +24 -0
  64. package/src/theme.ts +43 -0
  65. package/src/types.ts +27 -0
  66. package/src/useChartCore.ts +135 -0
@@ -0,0 +1,167 @@
1
+ // Internal definition of `struct VroomChart` — the central state bag for a
2
+ // single chart instance. Lives in this internal header so the various
3
+ // rendering / facade modules (chart.cpp, chart_facade.cpp, labels.cpp,
4
+ // candles.cpp, …) can all see the same layout.
5
+ //
6
+ // The public C API in `vroom/vroom_chart.h` keeps `VroomChart` opaque, so
7
+ // consumers never include this header.
8
+
9
+ #pragma once
10
+
11
+ #include <chrono>
12
+ #include <vector>
13
+
14
+ #include "vroom/vroom_chart.h"
15
+
16
+ #pragma clang diagnostic push
17
+ #pragma clang diagnostic ignored "-Wdocumentation"
18
+ #include "include/core/SkPicture.h" // SkPicture must be complete so the
19
+ // sk_sp<SkPicture> field's destructor
20
+ // is callable wherever VroomChart is.
21
+ #include "include/core/SkRefCnt.h"
22
+ #pragma clang diagnostic pop
23
+
24
+ #include "labels.h"
25
+ #include "theme.h"
26
+ #include "viewport.h"
27
+
28
+ class SkCanvas;
29
+
30
+ struct VroomChart {
31
+ // --- bridge / lifecycle -------------------------------------------------
32
+ VroomCallbacks cb{};
33
+ void* user_ctx = nullptr;
34
+
35
+ // --- data ---------------------------------------------------------------
36
+ std::vector<VroomCandle> candles;
37
+
38
+ // Inferred from the gap between consecutive candles when data is loaded.
39
+ // Each candle occupies a fixed pixel slot of (duration / window) × width
40
+ // so the visual size is stable as the user pans / scrolls into "future"
41
+ // empty space past the latest candle.
42
+ int64_t candle_duration_ms = 60'000;
43
+
44
+ // --- layout -------------------------------------------------------------
45
+ float width_px = 0.f;
46
+ float height_px = 0.f;
47
+ float px_ratio = 1.f;
48
+
49
+ // 0/0 = uninitialized; set_candles defaults to last ~60 candles.
50
+ int64_t visible_start_ms = 0;
51
+ int64_t visible_end_ms = 0;
52
+
53
+ // Cached y-axis width in pixels, sized to fit the widest formatted price
54
+ // label. 0 = uncomputed; layout() falls back to a width ratio.
55
+ float axis_width_px = 0.f;
56
+
57
+ // --- price bounds (y-axis state) ---------------------------------------
58
+ // Persistent across pans (panning preserves the price scale). Mutated
59
+ // only by pinch zoom, axis drags, vertical drag-translate.
60
+ vroom::PriceBounds price_bounds{0.0, 1.0};
61
+ bool price_bounds_initialized = false;
62
+
63
+ // --- crosshair (not yet drawn) -----------------------------------------
64
+ bool crosshair_active = false;
65
+ float crosshair_x_px = 0.f;
66
+ float crosshair_y_px = 0.f;
67
+
68
+ // --- indicators ---------------------------------------------------------
69
+ // RSI, drawn in a pane below the candles. rsi_cache is aligned to `candles`
70
+ // (one value per candle, NaN where undefined) and recomputed lazily by
71
+ // ensure_rsi() when rsi_dirty (set on any data or config change).
72
+ bool rsi_enabled = false;
73
+ int rsi_period = 14;
74
+ double rsi_upper = 70.0; // overbought band
75
+ double rsi_lower = 30.0; // oversold band
76
+ bool rsi_ma_enabled = true; // RSI-based moving average (trendline)
77
+ int rsi_ma_period = 14;
78
+ std::vector<double> rsi_cache; // RSI per candle (NaN where undefined)
79
+ std::vector<double> rsi_ma_cache; // SMA of rsi_cache (empty if MA off)
80
+ bool rsi_dirty = true;
81
+
82
+ // MACD, drawn in its own pane. Caches aligned to `candles` (NaN warmup).
83
+ bool macd_enabled = false;
84
+ int macd_fast = 12;
85
+ int macd_slow = 26;
86
+ int macd_signal = 9;
87
+ std::vector<double> macd_cache;
88
+ std::vector<double> macd_signal_cache;
89
+ std::vector<double> macd_hist_cache;
90
+ bool macd_dirty = true;
91
+
92
+ // Stacking order for the indicator panes: each indicator gets the next
93
+ // sequence number on its off->on transition, so the most recently enabled
94
+ // pane sorts last (bottom). -1 = not currently enabled.
95
+ int rsi_order = -1;
96
+ int macd_order = -1;
97
+ int pane_seq = 0;
98
+
99
+ // Moving-average overlay lines (SMA/EMA) drawn on the price pane. Not panes
100
+ // — they don't reserve indicator_area_h. overlay_caches[i] is the computed
101
+ // series for overlays[i], aligned to `candles` (NaN warmup).
102
+ std::vector<VroomOverlay> overlays;
103
+ std::vector<std::vector<double>> overlay_caches;
104
+ bool overlays_dirty = true;
105
+
106
+ // VWAP overlay (session anchor, configurable reset time). Single line on the
107
+ // price pane; vwap_breaks marks session resets so the line lifts the pen.
108
+ bool vwap_enabled = false;
109
+ int vwap_reset_offset_min = 0; // session boundary offset from UTC midnight
110
+ uint32_t vwap_color = 0xff00bcd4; // cyan
111
+ float vwap_width = 1.5f;
112
+ std::vector<double> vwap_cache;
113
+ std::vector<unsigned char> vwap_breaks;
114
+ bool vwap_dirty = true;
115
+
116
+ // --- theme --------------------------------------------------------------
117
+ vroom::Theme theme;
118
+
119
+ // --- picture cache ------------------------------------------------------
120
+ sk_sp<SkPicture> chart_picture;
121
+ bool chart_dirty = true;
122
+
123
+ // --- label fade animation ----------------------------------------------
124
+ std::vector<vroom::labels::YLabelFade> y_fades;
125
+ std::vector<vroom::labels::XLabelFade> x_fades;
126
+ std::chrono::steady_clock::time_point last_anim_tick{};
127
+ bool anim_started = false;
128
+
129
+ // dt of the current rebuild — populated by rebuild_chart_picture and
130
+ // consumed by the label-fade updaters. Public so the labels namespace
131
+ // can read it without a getter.
132
+ float last_dt_seconds = 0.f;
133
+
134
+ // --- methods ------------------------------------------------------------
135
+ VroomChart();
136
+
137
+ // Marks the chart_picture dirty and fires the on_redraw_requested
138
+ // callback (if any).
139
+ void mark_dirty();
140
+
141
+ // Builds a Layout snapshot for the current geometry / theme / axis sizing.
142
+ vroom::Layout layout() const;
143
+
144
+ // Recomputes rsi_cache (over the full candle series) when rsi_dirty and
145
+ // RSI is enabled. No-op otherwise.
146
+ void ensure_rsi();
147
+
148
+ // Recomputes the MACD caches when macd_dirty and MACD is enabled.
149
+ void ensure_macd();
150
+
151
+ // Recomputes overlay_caches (one per overlay line) when overlays_dirty.
152
+ void ensure_overlays();
153
+
154
+ // Recomputes the VWAP cache when vwap_dirty and VWAP is enabled.
155
+ void ensure_vwap();
156
+
157
+ // The main drawing pass. Calls into the labels and candles modules.
158
+ void draw_chart(SkCanvas* canvas);
159
+
160
+ // Re-records `chart_picture` by invoking draw_chart on a fresh
161
+ // SkPictureRecorder. Also computes `last_dt_seconds` for fade animation.
162
+ void rebuild_chart_picture();
163
+
164
+ // True if any axis label is mid-fade. Used by the JS-side animation loop
165
+ // to know when to keep ticking.
166
+ bool is_animating_now() const;
167
+ };