@vroomchart/react 0.2.0 → 0.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.
- package/dist/index.d.ts +125 -13
- package/dist/index.js +765 -49
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -94,6 +94,10 @@ type VroomTheme = {
|
|
|
94
94
|
crosshair?: VroomColor;
|
|
95
95
|
/** Crosshair target — the hollow ring/dot at the intersection. */
|
|
96
96
|
crosshairTarget?: VroomColor;
|
|
97
|
+
/** Line-chart-mode close polyline color. Defaults to a neutral foreground. */
|
|
98
|
+
lineColor?: VroomColor;
|
|
99
|
+
/** Line-chart-mode polyline stroke width in px. Defaults to 1.5. */
|
|
100
|
+
lineWidth?: number;
|
|
97
101
|
};
|
|
98
102
|
/** A time window over the candle data, as Unix epoch milliseconds. */
|
|
99
103
|
type VisibleRange = {
|
|
@@ -108,8 +112,15 @@ type VisibleRange = {
|
|
|
108
112
|
* 'draw' — left-clicks place drawing points; panning/zooming are suppressed.
|
|
109
113
|
*/
|
|
110
114
|
type ChartMode = 'pan' | 'draw';
|
|
115
|
+
/**
|
|
116
|
+
* How the price series is drawn.
|
|
117
|
+
* 'candles' — default: candlestick bodies + wicks.
|
|
118
|
+
* 'line' — a single polyline through each candle's close. Volume, indicators,
|
|
119
|
+
* overlays, crosshair, and drawings still render.
|
|
120
|
+
*/
|
|
121
|
+
type ChartType = 'candles' | 'line';
|
|
111
122
|
/** Active drawing tool while in `draw` mode. `null` draws nothing. */
|
|
112
|
-
type DrawTool = null | 'line';
|
|
123
|
+
type DrawTool = null | 'line' | 'box' | 'pencil';
|
|
113
124
|
/** A drawing anchor in data space, so it stays glued to the candles on pan/zoom. */
|
|
114
125
|
type DrawPoint = {
|
|
115
126
|
/** Anchor time as Unix epoch milliseconds (not snapped to a candle slot). */
|
|
@@ -117,23 +128,81 @@ type DrawPoint = {
|
|
|
117
128
|
/** Anchor price. */
|
|
118
129
|
price: number;
|
|
119
130
|
};
|
|
120
|
-
/**
|
|
121
|
-
|
|
122
|
-
* persisted annotations; the chart appends a new one (via `onDrawingComplete`)
|
|
123
|
-
* each time the user finishes drawing. For now only the `'line'` (two-point
|
|
124
|
-
* trendline) type exists.
|
|
125
|
-
*/
|
|
126
|
-
type Drawing = {
|
|
131
|
+
/** Fields shared by every drawing type. */
|
|
132
|
+
type DrawingBase = {
|
|
127
133
|
/** Stable unique id (the chart generates one for drawings it creates). */
|
|
128
134
|
id: string;
|
|
129
|
-
|
|
130
|
-
/** The two endpoints, in data space. */
|
|
131
|
-
points: [DrawPoint, DrawPoint];
|
|
132
|
-
/** Line color (hex string or packed ARGB number). Default solid blue. */
|
|
135
|
+
/** Stroke color (hex string or packed ARGB number). Default solid blue. */
|
|
133
136
|
color?: VroomColor;
|
|
134
137
|
/** Stroke width in px. Default 2. */
|
|
135
138
|
width?: number;
|
|
136
139
|
};
|
|
140
|
+
/** A two-point trendline from `points[0]` to `points[1]`. */
|
|
141
|
+
type LineDrawing = DrawingBase & {
|
|
142
|
+
type: 'line';
|
|
143
|
+
/** The two endpoints, in data space. */
|
|
144
|
+
points: [DrawPoint, DrawPoint];
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* An axis-aligned rectangle whose two opposite corners are `points[0]` and
|
|
148
|
+
* `points[1]` (the other two corners are derived).
|
|
149
|
+
*/
|
|
150
|
+
type BoxDrawing = DrawingBase & {
|
|
151
|
+
type: 'box';
|
|
152
|
+
/** Two opposite corners, in data space. */
|
|
153
|
+
points: [DrawPoint, DrawPoint];
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* A freehand pencil stroke: an open path through `points`, in order. Unlike the
|
|
157
|
+
* other tools a stroke has a variable number of points, and once committed it
|
|
158
|
+
* can only be translated — never reshaped.
|
|
159
|
+
*/
|
|
160
|
+
type PencilDrawing = DrawingBase & {
|
|
161
|
+
type: 'pencil';
|
|
162
|
+
/** The path's points in draw order (at least 2), in data space. */
|
|
163
|
+
points: DrawPoint[];
|
|
164
|
+
};
|
|
165
|
+
/**
|
|
166
|
+
* A committed drawing. Pass an array of these via the `drawings` prop to render
|
|
167
|
+
* persisted annotations; the chart appends a new one (via `onDrawingComplete`)
|
|
168
|
+
* each time the user finishes drawing.
|
|
169
|
+
*
|
|
170
|
+
* This is a discriminated union on `type` — narrow on it before reading
|
|
171
|
+
* `points[1]`, since a `'pencil'` stroke has a variable-length array while
|
|
172
|
+
* `'line'` and `'box'` are always exactly two points.
|
|
173
|
+
*/
|
|
174
|
+
type Drawing = LineDrawing | BoxDrawing | PencilDrawing;
|
|
175
|
+
/**
|
|
176
|
+
* Storage adapter for **managed** drawing persistence. Provide it via the
|
|
177
|
+
* `drawingStore` prop and the chart owns the drawings array itself — loading and
|
|
178
|
+
* saving through this adapter instead of you wiring the controlled `drawings`
|
|
179
|
+
* prop + `onDrawing*` callbacks.
|
|
180
|
+
*
|
|
181
|
+
* The adapter is an **opaque string key-value store** — the chart serializes
|
|
182
|
+
* drawings into a **versioned envelope** (`{ v, drawings }`) and hands you the
|
|
183
|
+
* string; you just persist bytes. Because the library owns the schema and
|
|
184
|
+
* migrates old payloads on load, adding drawing tools or persisted fields later
|
|
185
|
+
* never changes this interface — your adapter is written once.
|
|
186
|
+
*
|
|
187
|
+
* `marketId` is the chart's `seriesKey`, so drawings are bucketed per market:
|
|
188
|
+
* they persist across timeframe changes (same key) but not across markets. Both
|
|
189
|
+
* methods may be async (localStorage is sync; AsyncStorage / MMKV / a REST
|
|
190
|
+
* backend are async). The chart debounces `save`. Consumers that only handle a
|
|
191
|
+
* single market can ignore `marketId`.
|
|
192
|
+
*/
|
|
193
|
+
type DrawingStore = {
|
|
194
|
+
/**
|
|
195
|
+
* Return the raw string previously handed to `save` for `marketId`, or
|
|
196
|
+
* `null`/`undefined`/`''` if nothing is stored. Sync or async.
|
|
197
|
+
*/
|
|
198
|
+
load: (marketId: string) => string | null | undefined | Promise<string | null | undefined>;
|
|
199
|
+
/**
|
|
200
|
+
* Persist the opaque `data` string for `marketId`. Sync or async; the chart
|
|
201
|
+
* debounces calls. The string is a versioned envelope owned by the library —
|
|
202
|
+
* store it verbatim, don't parse or reshape it.
|
|
203
|
+
*/
|
|
204
|
+
save: (marketId: string, data: string) => void | Promise<void>;
|
|
205
|
+
};
|
|
137
206
|
/** RSI indicator config. Rendered in a pane below the candles when enabled. */
|
|
138
207
|
type RSIConfig = {
|
|
139
208
|
enabled?: boolean;
|
|
@@ -267,6 +336,18 @@ type VroomChartCoreProps = {
|
|
|
267
336
|
* devices of different widths.
|
|
268
337
|
*/
|
|
269
338
|
defaultCandleWidth?: number;
|
|
339
|
+
/**
|
|
340
|
+
* Price-series render style. `'candles'` (default) draws candlesticks;
|
|
341
|
+
* `'line'` draws a polyline through each candle's close (style it with
|
|
342
|
+
* `theme.lineColor` / `theme.lineWidth`). All other layers are unaffected.
|
|
343
|
+
*/
|
|
344
|
+
chartType?: ChartType;
|
|
345
|
+
/**
|
|
346
|
+
* Duration (ms) of the animated candle↔line transition when `chartType`
|
|
347
|
+
* changes. Default ~300. `0` snaps instantly. Ignored (snaps) when the OS
|
|
348
|
+
* requests reduced motion, which instead uses a plain cross-fade.
|
|
349
|
+
*/
|
|
350
|
+
transitionMs?: number;
|
|
270
351
|
theme?: VroomTheme;
|
|
271
352
|
/** RSI indicator (pane below the candles). Omit/disable to hide it. */
|
|
272
353
|
rsi?: RSIConfig;
|
|
@@ -308,10 +389,30 @@ type VroomChartCoreProps = {
|
|
|
308
389
|
* Committed drawings to render, anchored to data so they track the candles on
|
|
309
390
|
* pan/zoom. This is a controlled prop: append the value the chart hands you in
|
|
310
391
|
* `onDrawingComplete` to persist it.
|
|
392
|
+
*
|
|
393
|
+
* Ignored when `drawingStore` is set (the chart then owns the array itself).
|
|
311
394
|
*/
|
|
312
395
|
drawings?: Drawing[];
|
|
396
|
+
/**
|
|
397
|
+
* Opt into **managed** drawing persistence: the chart owns the drawings array
|
|
398
|
+
* internally and loads/saves it through this adapter, keyed by `seriesKey`.
|
|
399
|
+
* When set, `drawings` and the `onDrawing*` callbacks are ignored. Web only.
|
|
400
|
+
* Requires `seriesKey` — without one, drawings work in-session but aren't saved.
|
|
401
|
+
*/
|
|
402
|
+
drawingStore?: DrawingStore;
|
|
313
403
|
/** Fired with the finished drawing when the user completes one. */
|
|
314
404
|
onDrawingComplete?: (drawing: Drawing) => void;
|
|
405
|
+
/**
|
|
406
|
+
* Fired after the user drags a selected line's endpoint handle. The payload is
|
|
407
|
+
* the same drawing (same `id`) with updated `points`; apply it to your
|
|
408
|
+
* controlled `drawings` state (replace by id). Web only.
|
|
409
|
+
*/
|
|
410
|
+
onDrawingChange?: (drawing: Drawing) => void;
|
|
411
|
+
/**
|
|
412
|
+
* Fired when the user deletes the selected line (Backspace/Delete). Remove the
|
|
413
|
+
* drawing with this `id` from your controlled `drawings` state. Web only.
|
|
414
|
+
*/
|
|
415
|
+
onDrawingDelete?: (id: string) => void;
|
|
315
416
|
/**
|
|
316
417
|
* Fired when the chart wants the mode changed — e.g. it requests `'pan'` after
|
|
317
418
|
* the user clicks away from a just-drawn line. Since `mode` is controlled, the
|
|
@@ -372,4 +473,15 @@ declare function classifyTransition(prev: Candle[] | null, next: Candle[], serie
|
|
|
372
473
|
*/
|
|
373
474
|
declare function timeframeWindow(oldWindow: VisibleRange, oldStepMs: number, oldLastMs: number, newStepMs: number, newLastMs: number): VisibleRange;
|
|
374
475
|
|
|
375
|
-
|
|
476
|
+
/** Current envelope schema version. Bump when the persisted shape changes. */
|
|
477
|
+
declare const DRAWINGS_VERSION = 1;
|
|
478
|
+
/** Wrap the current drawings in a versioned envelope and stringify. */
|
|
479
|
+
declare function serializeDrawings(drawings: Drawing[]): string;
|
|
480
|
+
/**
|
|
481
|
+
* Parse a stored string back into drawings, migrating older envelopes and
|
|
482
|
+
* dropping anything malformed or of an unknown drawing `type`. Never throws —
|
|
483
|
+
* returns `[]` for null/empty/garbage input.
|
|
484
|
+
*/
|
|
485
|
+
declare function deserializeDrawings(raw: string | null | undefined): Drawing[];
|
|
486
|
+
|
|
487
|
+
export { type Candle, type ChartMode, type ChartType, type CrosshairEvent, DRAWINGS_VERSION, type DataTransition, type DrawPoint, type DrawTool, type Drawing, type DrawingStore, type LiquidityBand, type LiquidityConfig, type MACDConfig, type MASource, type MovingAverageOverlay, type RSIConfig, type VWAPConfig, type VisibleRange, VroomChart, type VroomChartProps, type VroomColor, type VroomTheme, classifyTransition, deserializeDrawings, inferStepMs, serializeDrawings, timeframeWindow };
|