-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.ts
More file actions
261 lines (224 loc) · 6.92 KB
/
Copy pathtypes.ts
File metadata and controls
261 lines (224 loc) · 6.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
import type { StyleProp, ViewStyle } from 'react-native'
import type { SkFont } from '@shopify/react-native-skia'
export interface NativelinePoint {
time: number // unix seconds — points MUST be ordered ascending by time (caller contract; not sorted internally)
value: number
}
export type Momentum = 'up' | 'down' | 'flat'
export type ThemeMode = 'light' | 'dark'
export type WindowStyle = 'default' | 'rounded' | 'text'
export type BadgeVariant = 'default' | 'minimal'
/**
* Viewport mode — the one real addition over liveline.
* - 'live' : the X axis is anchored to the wall clock and the window trails
* `now` (Date.now()), scrolling continuously. Identical to liveline.
* - 'static' : the X axis is a fixed domain (from `domain`, or auto-fit to the
* data extent). It does NOT scroll with the clock — but value/range
* lerps, entrance morphs, scrub, and updates still animate. This is
* "unlive motion": it animates, it just doesn't chase real time.
*/
export type Viewport = 'live' | 'static'
/** Explicit X range (unix seconds) for the static viewport. */
export interface Domain {
from: number
to: number
}
export interface ReferenceLine {
value: number
label?: string
}
export interface HoverPoint {
time: number
value: number
x: number
y: number
}
export interface Padding {
top?: number
right?: number
bottom?: number
left?: number
}
export interface WindowOption {
label: string
secs: number
}
export interface OrderbookData {
bids: [number, number][] // [price, size][]
asks: [number, number][] // [price, size][]
}
export interface DegenOptions {
/** Multiplier for particle count and size (default 1) */
scale?: number
/** Show particles on down-momentum swings (default false) */
downMomentum?: boolean
}
export interface NativelineSeries {
id: string
data: NativelinePoint[] // MUST be ordered ascending by time (caller contract; not sorted internally)
value: number
color: string
label?: string
}
export interface CandlePoint {
time: number // unix seconds — candle open time
open: number
high: number
low: number
close: number
}
/**
* Optional per-part font overrides. If omitted, the component builds system
* fonts via matchFont (family from `labelFontFamily`). Each part can be
* customized independently.
*/
export interface NativelineFonts {
/** Grid / time-axis / reference / series labels (~11px). */
label?: SkFont
/** Scrub crosshair tooltip (~13px). */
tooltip?: SkFont
/** The value badge at the live tip (~11px × badgeScale). */
badge?: SkFont
/** The large `showValue` overlay (~20px). Its family/size/weight are read from this font. */
value?: SkFont
}
export interface NativelineProps {
data: NativelinePoint[]
value: number
// Multi-series mode — when provided, overrides data/value/color
series?: NativelineSeries[]
// Viewport (live vs. static) --------------------------------------------
viewport?: Viewport // default 'live'
domain?: Domain // static viewport X range; omitted => auto-fit to data extent
// Appearance
theme?: ThemeMode
color?: string
/** Actual container background (any CSS color). Aligns the chart's fade/outline
* math (orderbook labels, grid label fades) to it, so they don't leave a dark
* halo when the Canvas sits on a card that isn't the theme's default bg. */
background?: string
// Time
window?: number // (live) trailing window in seconds; default 30
// Feature flags
grid?: boolean
/** Show the time (x-axis) labels. Default true; set false for compact cards. */
xAxis?: boolean
/** Show the value (y-axis) labels. Default true; grid lines stay — only the
* right-edge numbers are hidden. (For no lines either, use grid={false}.) */
yAxis?: boolean
badge?: boolean
momentum?: boolean | Momentum
fill?: boolean
loading?: boolean
paused?: boolean
emptyText?: string
scrub?: boolean
exaggerate?: boolean
showValue?: boolean
valueMomentumColor?: boolean
degen?: boolean | DegenOptions
badgeTail?: boolean
// Time window buttons
windows?: WindowOption[]
onWindowChange?: (secs: number) => void
windowStyle?: WindowStyle
// Badge
badgeVariant?: BadgeVariant
/** Scale the value badge (font + padding). Default 1; e.g. 0.8 = smaller. */
badgeScale?: number
/** Color the badge by momentum (green/red). Default true. Set false to use
* the accent `color` instead — useful when `color` already encodes direction. */
badgeMomentumColor?: boolean
// Crosshair
tooltipY?: number
tooltipOutline?: boolean
// Orderbook
orderbook?: OrderbookData
// Optional
referenceLine?: ReferenceLine
formatValue?: (v: number) => string
formatTime?: (t: number) => string
/** Time formatter for the scrub crosshair tooltip. Falls back to `formatTime`.
* Lets the hover label be range-aware (date on wide ranges, time intraday)
* independently of the compact axis labels. */
formatHoverTime?: (t: number) => string
lerpSpeed?: number
padding?: Padding
onHover?: (point: HoverPoint | null) => void
pulse?: boolean
lineWidth?: number
// Candlestick mode
mode?: 'line' | 'candle'
candles?: CandlePoint[]
candleWidth?: number
liveCandle?: CandlePoint
lineMode?: boolean
lineData?: NativelinePoint[]
lineValue?: number
onModeChange?: (mode: 'line' | 'candle') => void
onSeriesToggle?: (id: string, visible: boolean) => void
seriesToggleCompact?: boolean
/** Render the built-in multi-series show/hide chips. Default true. Set false
* when the host supplies its own legend/toggle UI. */
seriesToggle?: boolean
// React Native specifics
fonts?: NativelineFonts
labelFontFamily?: string // system monospace family override (e.g. 'Menlo')
style?: StyleProp<ViewStyle>
}
export interface NativelinePalette {
// Line
line: string
lineWidth: number
// Fill gradient
fillTop: string
fillBottom: string
// Grid
gridLine: string
gridLabel: string
// Dot
dotUp: string
dotDown: string
dotFlat: string
glowUp: string
glowDown: string
glowFlat: string
// Badge
badgeOuterBg: string
badgeOuterShadow: string
badgeBg: string
badgeText: string
// Dash line
dashLine: string
// Reference line
refLine: string
refLabel: string
// Time axis
timeLabel: string
// Crosshair
crosshairLine: string
tooltipBg: string
tooltipText: string
tooltipBorder: string
// Background (for color fading — labels fade toward bg instead of alpha)
bgRgb: [number, number, number]
}
/**
* Per-frame projection, baked by the engine and read by the draw layer.
* `toX`/`toY` are worklet closures. `valRange = (max - min) || 0.001` is the
* sole divide-by-zero guard.
*/
export interface ChartLayout {
w: number
h: number
pad: Required<Padding>
chartW: number
chartH: number
leftEdge: number
rightEdge: number
minVal: number
maxVal: number
valRange: number
toX: (t: number) => number
toY: (v: number) => number
}