@supersolutions/super-chart-react-native 0.0.0 → 0.17.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/LICENSE +674 -0
- package/README.md +19 -0
- package/dist/LayerControls.d.ts +24 -0
- package/dist/PrecisionGuide.d.ts +11 -0
- package/dist/SuperChart.d.ts +42 -0
- package/dist/avatars.d.ts +7 -0
- package/dist/camera.d.ts +12 -0
- package/dist/drawingShapes.d.ts +12 -0
- package/dist/drawings.d.ts +36 -0
- package/dist/gestures.d.ts +66 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +2023 -0
- package/dist/labels.d.ts +3 -0
- package/dist/markerBuckets.d.ts +13 -0
- package/dist/model.d.ts +31 -0
- package/dist/nativeMotion.d.ts +28 -0
- package/dist/overlays.d.ts +41 -0
- package/dist/overlaysModel.d.ts +50 -0
- package/dist/plot.d.ts +17 -0
- package/dist/precision.d.ts +30 -0
- package/dist/studies.d.ts +3 -0
- package/package.json +55 -3
package/dist/index.js
ADDED
|
@@ -0,0 +1,2023 @@
|
|
|
1
|
+
// packages/bindings/react-native/src/SuperChart.tsx
|
|
2
|
+
import * as React7 from "react";
|
|
3
|
+
import {
|
|
4
|
+
StyleSheet as StyleSheet2,
|
|
5
|
+
Text as Text6,
|
|
6
|
+
useColorScheme,
|
|
7
|
+
useWindowDimensions as useWindowDimensions4,
|
|
8
|
+
View as View2
|
|
9
|
+
} from "react-native";
|
|
10
|
+
import Animated from "react-native-reanimated";
|
|
11
|
+
import { GestureDetector, GestureHandlerRootView } from "react-native-gesture-handler";
|
|
12
|
+
import Svg, { G as G6, Line as Line4, Rect as Rect5, Text as SvgText } from "react-native-svg";
|
|
13
|
+
import {
|
|
14
|
+
buildEngineFrame as buildEngineFrame2,
|
|
15
|
+
clampContinuousViewport as clampContinuousViewport4,
|
|
16
|
+
derivePrecision,
|
|
17
|
+
normalizeBars,
|
|
18
|
+
toHeikinAshi,
|
|
19
|
+
viewportSpan as viewportSpan3,
|
|
20
|
+
zoomContinuousViewport as zoomContinuousViewport2
|
|
21
|
+
} from "@supersolutions/super-chart-core";
|
|
22
|
+
|
|
23
|
+
// packages/bindings/react-native/src/camera.ts
|
|
24
|
+
import { buildEngineFrame } from "@supersolutions/super-chart-core";
|
|
25
|
+
function bufferedFrame(visible, width, height, raw, display, studies, layout) {
|
|
26
|
+
const { viewport } = visible.snapshot;
|
|
27
|
+
const span = viewport.i1 - viewport.i0;
|
|
28
|
+
const extra = span > 0 ? visible.model.geometry.plotWidth : 0;
|
|
29
|
+
if (!extra) return { frame: visible, extra, width };
|
|
30
|
+
const buffer = { i0: viewport.i0 - span, i1: viewport.i1 + span };
|
|
31
|
+
const start = Math.max(0, Math.floor(buffer.i0));
|
|
32
|
+
const snapshot = { ...visible.snapshot, viewport: buffer, dataStart: start, bars: display.slice(start, Math.ceil(buffer.i1) + 1) };
|
|
33
|
+
const paneScales = Object.fromEntries(visible.panes.slice(1).map((pane) => [pane.id, { range: [pane.scale.min, pane.scale.max] }]));
|
|
34
|
+
const primary = visible.panes[0].scale;
|
|
35
|
+
const frame = buildEngineFrame(snapshot, raw, studies, width + 2 * extra, height, {
|
|
36
|
+
...layout,
|
|
37
|
+
axisGutter: width - visible.model.geometry.right,
|
|
38
|
+
paneScales,
|
|
39
|
+
priceScale: { ...layout.priceScale, range: [primary.min, primary.max] }
|
|
40
|
+
}, void 0, raw);
|
|
41
|
+
return { frame, extra, width: width + 2 * extra };
|
|
42
|
+
}
|
|
43
|
+
function dragPriceRange(range, fractionFromLow, delta, height, mode) {
|
|
44
|
+
const log = mode === "log";
|
|
45
|
+
const lo = log ? Math.log(range[0]) : range[0], hi = log ? Math.log(range[1]) : range[1];
|
|
46
|
+
const fraction = Math.max(0, Math.min(1, fractionFromLow));
|
|
47
|
+
const center = lo + fraction * (hi - lo);
|
|
48
|
+
const factor = Math.exp(Math.max(-4, Math.min(4, 2 * delta / Math.max(1, height))));
|
|
49
|
+
const a = center + (lo - center) * factor, b = center + (hi - center) * factor;
|
|
50
|
+
const next = [log ? Math.exp(a) : a, log ? Math.exp(b) : b];
|
|
51
|
+
return Number.isFinite(next[0]) && Number.isFinite(next[1]) && next[0] < next[1] && (!log || next[0] > 0) ? next : range;
|
|
52
|
+
}
|
|
53
|
+
function bufferTranslation(renderedStart, camera, scale, extra) {
|
|
54
|
+
"worklet";
|
|
55
|
+
return Math.max(-extra, Math.min(extra, (renderedStart - camera) * scale));
|
|
56
|
+
}
|
|
57
|
+
function panStartAt(start, delta, pixelsPerBar, maximum) {
|
|
58
|
+
"worklet";
|
|
59
|
+
return Math.max(0, Math.min(maximum, start - delta / pixelsPerBar));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// packages/bindings/react-native/src/nativeMotion.ts
|
|
63
|
+
import * as React from "react";
|
|
64
|
+
import { GestureStateManager, useManualGesture } from "react-native-gesture-handler";
|
|
65
|
+
import { cancelAnimation, useAnimatedReaction, useAnimatedStyle, useSharedValue, withDecay } from "react-native-reanimated";
|
|
66
|
+
import { scheduleOnRN, scheduleOnUI } from "react-native-worklets";
|
|
67
|
+
import { clampContinuousViewport as clampContinuousViewport2 } from "@supersolutions/super-chart-core";
|
|
68
|
+
|
|
69
|
+
// packages/bindings/react-native/src/model.ts
|
|
70
|
+
import {
|
|
71
|
+
clampContinuousViewport,
|
|
72
|
+
defaultViewport,
|
|
73
|
+
nearestBarIndex,
|
|
74
|
+
openingBars,
|
|
75
|
+
viewportSpan
|
|
76
|
+
} from "@supersolutions/super-chart-core";
|
|
77
|
+
|
|
78
|
+
// packages/bindings/react-native/src/studies.ts
|
|
79
|
+
import {
|
|
80
|
+
EngineIndicators
|
|
81
|
+
} from "@supersolutions/super-chart-core";
|
|
82
|
+
function priceSnapshot({ timestamp, open, high, low, close, volume, turnover }) {
|
|
83
|
+
return { timestamp, open, high, low, close, volume, turnover };
|
|
84
|
+
}
|
|
85
|
+
function samePriceBar(a, b) {
|
|
86
|
+
return a.timestamp === b.timestamp && a.open === b.open && a.high === b.high && a.low === b.low && a.close === b.close && a.volume === b.volume && a.turnover === b.turnover;
|
|
87
|
+
}
|
|
88
|
+
function createStudyComputer(specs, showVolume, definitions) {
|
|
89
|
+
const engine = new EngineIndicators();
|
|
90
|
+
for (const definition of definitions ?? []) engine.register(definition);
|
|
91
|
+
for (const spec of specs) engine.add(spec);
|
|
92
|
+
if (showVolume && !specs.some((spec) => spec.name.toUpperCase() === "VOL")) engine.add({ name: "VOL", pane: "overlay" });
|
|
93
|
+
const active = engine.list().filter((item) => item.visible);
|
|
94
|
+
if (!active.length) {
|
|
95
|
+
const empty = [];
|
|
96
|
+
return () => empty;
|
|
97
|
+
}
|
|
98
|
+
const labels = new Map(active.map((item) => [item.id, [item.name, ...item.params].join(" ")]));
|
|
99
|
+
const hasCustom = engine.hasCustom();
|
|
100
|
+
const history = [];
|
|
101
|
+
const previous = [];
|
|
102
|
+
let current;
|
|
103
|
+
let version = 0;
|
|
104
|
+
return (bars) => {
|
|
105
|
+
const sharedLength = Math.min(bars.length, previous.length);
|
|
106
|
+
let from = 0;
|
|
107
|
+
while (from < sharedLength && samePriceBar(previous[from], bars[from])) from++;
|
|
108
|
+
if (!hasCustom && current && from === previous.length && from === bars.length) return current;
|
|
109
|
+
history.length = bars.length;
|
|
110
|
+
for (let i = hasCustom ? 0 : from; i < bars.length; i++) history[i] = hasCustom ? bars[i] : priceSnapshot(bars[i]);
|
|
111
|
+
const tail = bars.length >= previous.length && from >= previous.length - 1;
|
|
112
|
+
engine.invalidate({ kind: tail ? "tail" : "reset", from, length: bars.length, version: ++version });
|
|
113
|
+
const results = engine.compute(history);
|
|
114
|
+
current = results.map((item) => ({
|
|
115
|
+
...item,
|
|
116
|
+
// The core owns mutable row arrays. A pending React render can still read the preceding frame.
|
|
117
|
+
rows: item.rows.slice(),
|
|
118
|
+
pane: item.pane === "separate" ? item.paneId ?? item.id : "price",
|
|
119
|
+
overlay: item.pane === "overlay",
|
|
120
|
+
label: labels.get(item.id)
|
|
121
|
+
}));
|
|
122
|
+
previous.length = bars.length;
|
|
123
|
+
for (let i = from; i < bars.length; i++) previous[i] = hasCustom ? priceSnapshot(bars[i]) : history[i];
|
|
124
|
+
return current;
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// packages/bindings/react-native/src/model.ts
|
|
129
|
+
var LIGHT_THEME = {
|
|
130
|
+
background: "#ffffff",
|
|
131
|
+
text: "#201c30",
|
|
132
|
+
muted: "#706b80",
|
|
133
|
+
grid: "#e8e6ee",
|
|
134
|
+
up: "#087b58",
|
|
135
|
+
down: "#bf384b",
|
|
136
|
+
accent: "#7054cf"
|
|
137
|
+
};
|
|
138
|
+
var DARK_THEME = {
|
|
139
|
+
background: "#13121a",
|
|
140
|
+
text: "#f5f3fb",
|
|
141
|
+
muted: "#aaa5bb",
|
|
142
|
+
grid: "#302c3c",
|
|
143
|
+
up: "#54cd9e",
|
|
144
|
+
down: "#ff8492",
|
|
145
|
+
accent: "#b69aff"
|
|
146
|
+
};
|
|
147
|
+
var CHART_LIMITS = { minBars: 10, maxBars: 480, rightPaddingBars: 2 };
|
|
148
|
+
var DEFAULT_STUDIES = [{ name: "MA", params: [20] }, { name: "EMA", params: [21] }];
|
|
149
|
+
function resolveWindow(bars, anchor, width) {
|
|
150
|
+
if (!anchor) return defaultViewport(bars.length, openingBars(width), CHART_LIMITS);
|
|
151
|
+
const start = anchor.following ? bars.length + CHART_LIMITS.rightPaddingBars - anchor.span : (nearestBarIndex(bars, anchor.time) ?? 0) + anchor.offset;
|
|
152
|
+
return clampContinuousViewport({ i0: start, i1: start + anchor.span - 1 }, bars.length, CHART_LIMITS);
|
|
153
|
+
}
|
|
154
|
+
function windowAnchor(bars, viewport) {
|
|
155
|
+
if (!bars.length) return null;
|
|
156
|
+
const index = Math.min(bars.length - 1, Math.floor(viewport.i0));
|
|
157
|
+
return {
|
|
158
|
+
time: bars[index].timestamp,
|
|
159
|
+
offset: viewport.i0 - index,
|
|
160
|
+
span: viewportSpan(viewport),
|
|
161
|
+
following: viewport.i1 >= bars.length - 1 + CHART_LIMITS.rightPaddingBars - 0.01
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
function snapshotForWindow(bars, viewport, mode) {
|
|
165
|
+
const dataStart = Math.floor(viewport.i0);
|
|
166
|
+
return {
|
|
167
|
+
version: 0,
|
|
168
|
+
viewport,
|
|
169
|
+
dataStart,
|
|
170
|
+
length: bars.length,
|
|
171
|
+
hasMore: false,
|
|
172
|
+
following: viewport.i1 >= bars.length - 1,
|
|
173
|
+
mode: mode === "heikin-ashi" ? mode : "raw",
|
|
174
|
+
bars: bars.slice(dataStart, Math.ceil(viewport.i1) + 1),
|
|
175
|
+
latestBar: bars[bars.length - 1],
|
|
176
|
+
ma20: [],
|
|
177
|
+
ema21: []
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
function periodTimespan(period) {
|
|
181
|
+
const unit = period.trim().replace(/^[\d.\s]+/, "");
|
|
182
|
+
if (unit === "M" || /^mon/i.test(unit)) return "month";
|
|
183
|
+
if (/^[yY]/.test(unit)) return "year";
|
|
184
|
+
if (/^[wW]/.test(unit)) return "week";
|
|
185
|
+
if (/^[dD]/.test(unit)) return "day";
|
|
186
|
+
if (/^[hH]/.test(unit)) return "hour";
|
|
187
|
+
if (/^[sS]/.test(unit)) return "second";
|
|
188
|
+
return "minute";
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// packages/bindings/react-native/src/precision.ts
|
|
192
|
+
function drawingSight(frame, finger, lifted) {
|
|
193
|
+
const g = frame.model.geometry;
|
|
194
|
+
return { x: Math.max(g.left, Math.min(g.right, finger.x)), y: Math.max(g.top, Math.min(g.bottom, finger.y - (lifted ? 40 : 0))) };
|
|
195
|
+
}
|
|
196
|
+
function nearestOHLC(frame, point, radius = 10) {
|
|
197
|
+
const bar = (frame.inspectBar ?? frame.inspect)(point.x)?.displayBar;
|
|
198
|
+
if (!bar) return null;
|
|
199
|
+
let best = null;
|
|
200
|
+
let limit = radius;
|
|
201
|
+
for (const price of [bar.close, bar.open, bar.high, bar.low]) {
|
|
202
|
+
const p = frame.project(bar.timestamp, price);
|
|
203
|
+
if (!p) continue;
|
|
204
|
+
const distance2 = Math.hypot(p.x - point.x, p.y - point.y);
|
|
205
|
+
if (distance2 < limit) {
|
|
206
|
+
best = { ...p, timestamp: bar.timestamp, price };
|
|
207
|
+
limit = distance2;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return best;
|
|
211
|
+
}
|
|
212
|
+
function lensSegment(x, top, bottom, radius, halfWidth) {
|
|
213
|
+
const outsideEdge = Math.abs(x) + halfWidth;
|
|
214
|
+
if (outsideEdge >= radius) return null;
|
|
215
|
+
const extent = Math.sqrt(radius * radius - outsideEdge * outsideEdge);
|
|
216
|
+
const from = Math.max(top, -extent), to = Math.min(bottom, extent);
|
|
217
|
+
return to > from ? { from, to } : null;
|
|
218
|
+
}
|
|
219
|
+
function drawingRegions(item) {
|
|
220
|
+
if (!item || item.locked) return [];
|
|
221
|
+
const regions = [];
|
|
222
|
+
const line = (a, b, tolerance = 14) => {
|
|
223
|
+
regions.push({ line: true, x1: a.x, x2: b.x, y1: a.y, y2: b.y, tolerance });
|
|
224
|
+
};
|
|
225
|
+
const box = (x1, y1, x2, y2) => {
|
|
226
|
+
regions.push({ line: false, x1, y1, x2, y2, tolerance: 14 });
|
|
227
|
+
};
|
|
228
|
+
for (const handle of item.handles) line(handle.point, handle.point);
|
|
229
|
+
for (const p of item.primitives) {
|
|
230
|
+
if (p.kind === "line") line(p.from, p.to);
|
|
231
|
+
else if (p.kind === "rect") box(p.from.x, p.from.y, p.to.x, p.to.y);
|
|
232
|
+
else if (p.kind === "label" || p.kind === "image") box(p.bounds.left, p.bounds.top, p.bounds.right, p.bounds.bottom);
|
|
233
|
+
else if (p.kind === "ellipse") box(p.center.x - p.radiusX, p.center.y - p.radiusY, p.center.x + p.radiusX, p.center.y + p.radiusY);
|
|
234
|
+
else if (p.kind === "stroke") {
|
|
235
|
+
for (let i = 1; i < p.points.length; i++) line(p.points[i - 1], p.points[i], 14 + p.width / 2);
|
|
236
|
+
} else if (p.kind === "polygon" && p.points.length) {
|
|
237
|
+
const xs = p.points.map((v) => v.x), ys = p.points.map((v) => v.y);
|
|
238
|
+
box(Math.min(...xs), Math.min(...ys), Math.max(...xs), Math.max(...ys));
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return regions;
|
|
242
|
+
}
|
|
243
|
+
function mayEditAt(regions, x, y) {
|
|
244
|
+
"worklet";
|
|
245
|
+
for (const r of regions) {
|
|
246
|
+
if (r.line) {
|
|
247
|
+
const dx = r.x2 - r.x1, dy = r.y2 - r.y1;
|
|
248
|
+
const t = Math.max(0, Math.min(1, ((x - r.x1) * dx + (y - r.y1) * dy) / (dx * dx + dy * dy || 1)));
|
|
249
|
+
if (Math.hypot(x - r.x1 - t * dx, y - r.y1 - t * dy) <= r.tolerance) return true;
|
|
250
|
+
} else if (x >= r.x1 - r.tolerance && x <= r.x2 + r.tolerance && y >= r.y1 - r.tolerance && y <= r.y2 + r.tolerance) return true;
|
|
251
|
+
}
|
|
252
|
+
return false;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// packages/bindings/react-native/src/nativeMotion.ts
|
|
256
|
+
function inputEvent(points, changed, shift) {
|
|
257
|
+
const convert = (p) => ({ locationX: p.x + shift, locationY: p.y });
|
|
258
|
+
return { nativeEvent: { ...convert(changed), touches: points.map(convert), changedTouches: [convert(changed)] } };
|
|
259
|
+
}
|
|
260
|
+
function useChartMotion(options) {
|
|
261
|
+
const latest = React.useRef(options);
|
|
262
|
+
latest.current = options;
|
|
263
|
+
const frame = options.frame;
|
|
264
|
+
const start = frame?.snapshot.viewport.i0 ?? 0;
|
|
265
|
+
const span = frame ? Math.max(1, frame.snapshot.viewport.i1 - start) : 1;
|
|
266
|
+
const width = frame?.model.geometry.plotWidth ?? 1;
|
|
267
|
+
const right = frame?.model.geometry.right ?? 0, bottom = frame?.model.geometry.bottom ?? 0;
|
|
268
|
+
const pitch = width / span;
|
|
269
|
+
const maxStart = frame ? clampContinuousViewport2({ i0: frame.snapshot.length, i1: frame.snapshot.length + span }, frame.snapshot.length, CHART_LIMITS).i0 : 0;
|
|
270
|
+
const { mode, drawing, regions, extra } = options;
|
|
271
|
+
const camera = useSharedValue(start), base = useSharedValue(start);
|
|
272
|
+
const phase = useSharedValue("idle"), refilling = useSharedValue(false);
|
|
273
|
+
const downX = useSharedValue(0), downY = useSharedValue(0), origin = useSharedValue(start);
|
|
274
|
+
const lastX = useSharedValue(0), sampleTime = useSharedValue(0), velocity = useSharedValue(0);
|
|
275
|
+
const downTime = useSharedValue(0), finger = useSharedValue(0), claimed = useSharedValue(0);
|
|
276
|
+
const moved = useSharedValue(false), lastAxisTap = useSharedValue(-1e3);
|
|
277
|
+
React.useLayoutEffect(() => {
|
|
278
|
+
scheduleOnUI((rendered) => {
|
|
279
|
+
"worklet";
|
|
280
|
+
base.value = rendered;
|
|
281
|
+
refilling.value = false;
|
|
282
|
+
if (phase.value !== "pan" && phase.value !== "fling" && phase.value !== "pending") camera.value = rendered;
|
|
283
|
+
}, start);
|
|
284
|
+
}, [start, span, width, base, camera, phase, refilling]);
|
|
285
|
+
const commitStart = React.useCallback((left) => {
|
|
286
|
+
const opt = latest.current, view = opt.frame?.snapshot.viewport;
|
|
287
|
+
if (view) opt.commit({ i0: left, i1: left + view.i1 - view.i0 });
|
|
288
|
+
}, []);
|
|
289
|
+
const dispatch = React.useCallback((step, points, changed, left, id) => {
|
|
290
|
+
const { input, frame: frame2 } = latest.current;
|
|
291
|
+
if (!frame2) return;
|
|
292
|
+
const view = frame2.snapshot.viewport;
|
|
293
|
+
const dx = (left - view.i0) * frame2.model.geometry.plotWidth / Math.max(1, view.i1 - view.i0);
|
|
294
|
+
const event = inputEvent(points, changed, dx);
|
|
295
|
+
if (step === "start") {
|
|
296
|
+
if (points.length >= 2) {
|
|
297
|
+
input.pinchAt(points[0], points[1], { i0: left, i1: left + view.i1 - view.i0 });
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
input.handlers.onTouchStart(event);
|
|
301
|
+
if (latest.current.regions.length && !latest.current.drawing) {
|
|
302
|
+
const capture = input.captured();
|
|
303
|
+
scheduleOnUI((session, value) => {
|
|
304
|
+
"worklet";
|
|
305
|
+
if (finger.value === session && claimed.value === -1) claimed.value = value;
|
|
306
|
+
}, id, capture ? 1 : 0);
|
|
307
|
+
}
|
|
308
|
+
} else if (step === "move") input.handlers.onTouchMove(event);
|
|
309
|
+
else input.handlers.onTouchEnd(event);
|
|
310
|
+
}, [finger, claimed]);
|
|
311
|
+
const nativePan = React.useCallback(() => {
|
|
312
|
+
latest.current.navigation?.(true);
|
|
313
|
+
latest.current.input.nativePan();
|
|
314
|
+
}, []);
|
|
315
|
+
const finishPan = React.useCallback((left) => {
|
|
316
|
+
commitStart(left);
|
|
317
|
+
latest.current.navigation?.(false);
|
|
318
|
+
}, [commitStart]);
|
|
319
|
+
const cancel = React.useCallback(() => latest.current.input.cancel(), []);
|
|
320
|
+
const axis = React.useCallback((stage, v) => {
|
|
321
|
+
if (stage === "start") latest.current.axisStart(v);
|
|
322
|
+
else if (stage === "move") latest.current.axisMove(v);
|
|
323
|
+
else latest.current.axisTap();
|
|
324
|
+
}, []);
|
|
325
|
+
useAnimatedReaction(() => ({ left: camera.value, rendered: base.value, phase: phase.value }), (state) => {
|
|
326
|
+
"worklet";
|
|
327
|
+
if ((state.phase === "pan" || state.phase === "fling") && !refilling.value && Math.abs(state.left - state.rendered) > span * 0.55) {
|
|
328
|
+
refilling.value = true;
|
|
329
|
+
scheduleOnRN(commitStart, state.left);
|
|
330
|
+
}
|
|
331
|
+
}, [span]);
|
|
332
|
+
const animatedStyle = useAnimatedStyle(() => {
|
|
333
|
+
"worklet";
|
|
334
|
+
return { transform: [{ translateX: bufferTranslation(start, camera.value, pitch, extra) }] };
|
|
335
|
+
}, [start, pitch, extra]);
|
|
336
|
+
const gesture = useManualGesture({
|
|
337
|
+
enabled: !!frame && mode !== "none",
|
|
338
|
+
shouldCancelWhenOutside: false,
|
|
339
|
+
onTouchesDown: (e) => {
|
|
340
|
+
"worklet";
|
|
341
|
+
const p = e.changedTouches[0];
|
|
342
|
+
if (!p) return;
|
|
343
|
+
if (e.allTouches.length > 1) {
|
|
344
|
+
if (phase.value === "pan" || phase.value === "fling") {
|
|
345
|
+
cancelAnimation(camera);
|
|
346
|
+
scheduleOnRN(finishPan, camera.value);
|
|
347
|
+
}
|
|
348
|
+
phase.value = "pinch";
|
|
349
|
+
GestureStateManager.activate(e.handlerTag);
|
|
350
|
+
scheduleOnRN(dispatch, "start", e.allTouches.map((t) => ({ x: t.x, y: t.y })), { x: p.x, y: p.y }, camera.value, finger.value);
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
if (phase.value === "fling") {
|
|
354
|
+
cancelAnimation(camera);
|
|
355
|
+
scheduleOnRN(finishPan, camera.value);
|
|
356
|
+
}
|
|
357
|
+
finger.value++;
|
|
358
|
+
downX.value = lastX.value = p.x;
|
|
359
|
+
downY.value = p.y;
|
|
360
|
+
origin.value = camera.value;
|
|
361
|
+
downTime.value = sampleTime.value = performance.now();
|
|
362
|
+
velocity.value = 0;
|
|
363
|
+
moved.value = false;
|
|
364
|
+
claimed.value = drawing ? 1 : mayEditAt(regions, p.x + extra + (camera.value - start) * pitch, p.y) ? -1 : 0;
|
|
365
|
+
if (p.x >= right && p.y <= bottom) {
|
|
366
|
+
phase.value = "axis";
|
|
367
|
+
scheduleOnRN(axis, "start", p.y);
|
|
368
|
+
} else {
|
|
369
|
+
phase.value = "pending";
|
|
370
|
+
scheduleOnRN(dispatch, "start", [{ x: p.x, y: p.y }], { x: p.x, y: p.y }, origin.value, finger.value);
|
|
371
|
+
}
|
|
372
|
+
},
|
|
373
|
+
onTouchesMove: (e) => {
|
|
374
|
+
"worklet";
|
|
375
|
+
const p = e.allTouches[0];
|
|
376
|
+
if (!p || phase.value === "ignore" || phase.value === "idle") return;
|
|
377
|
+
const dx = p.x - downX.value, dy = p.y - downY.value;
|
|
378
|
+
if (phase.value === "pinch") {
|
|
379
|
+
if (e.allTouches.length >= 2) scheduleOnRN(dispatch, "move", e.allTouches.map((t) => ({ x: t.x, y: t.y })), { x: p.x, y: p.y }, base.value, finger.value);
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
const now = performance.now();
|
|
383
|
+
if (phase.value === "axis") {
|
|
384
|
+
if (Math.abs(dy) < 4 && !moved.value) return;
|
|
385
|
+
moved.value = true;
|
|
386
|
+
GestureStateManager.activate(e.handlerTag);
|
|
387
|
+
if (now - sampleTime.value >= 32) {
|
|
388
|
+
sampleTime.value = now;
|
|
389
|
+
scheduleOnRN(axis, "move", dy);
|
|
390
|
+
}
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
if (phase.value === "pending") {
|
|
394
|
+
if (Math.max(Math.abs(dx), Math.abs(dy)) < 5) return;
|
|
395
|
+
if (claimed.value < 0) {
|
|
396
|
+
if (now - downTime.value < 80) return;
|
|
397
|
+
claimed.value = 0;
|
|
398
|
+
}
|
|
399
|
+
if (claimed.value || now - downTime.value >= 360) phase.value = "special";
|
|
400
|
+
else if (mode === "scroll" && Math.abs(dy) > Math.abs(dx)) {
|
|
401
|
+
phase.value = "ignore";
|
|
402
|
+
scheduleOnRN(cancel);
|
|
403
|
+
GestureStateManager.fail(e.handlerTag);
|
|
404
|
+
return;
|
|
405
|
+
} else {
|
|
406
|
+
phase.value = "pan";
|
|
407
|
+
scheduleOnRN(nativePan);
|
|
408
|
+
}
|
|
409
|
+
GestureStateManager.activate(e.handlerTag);
|
|
410
|
+
}
|
|
411
|
+
if (phase.value === "special") {
|
|
412
|
+
scheduleOnRN(dispatch, "move", [{ x: p.x, y: p.y }], { x: p.x, y: p.y }, origin.value, finger.value);
|
|
413
|
+
} else if (phase.value === "pan") {
|
|
414
|
+
const interval = Math.max(1, now - sampleTime.value);
|
|
415
|
+
const speed = (p.x - lastX.value) * 1e3 / interval;
|
|
416
|
+
velocity.value = moved.value ? 0.35 * velocity.value + 0.65 * speed : speed;
|
|
417
|
+
sampleTime.value = now;
|
|
418
|
+
lastX.value = p.x;
|
|
419
|
+
moved.value = true;
|
|
420
|
+
camera.value = panStartAt(origin.value, dx, pitch, maxStart);
|
|
421
|
+
}
|
|
422
|
+
},
|
|
423
|
+
onTouchesUp: (e) => {
|
|
424
|
+
"worklet";
|
|
425
|
+
const p = e.changedTouches[0];
|
|
426
|
+
if (!p) return;
|
|
427
|
+
const remaining = e.allTouches.filter((t) => !e.changedTouches.some((c) => c.id === t.id));
|
|
428
|
+
const previous = phase.value;
|
|
429
|
+
if (previous === "pinch") {
|
|
430
|
+
scheduleOnRN(dispatch, "end", remaining.map((t) => ({ x: t.x, y: t.y })), { x: p.x, y: p.y }, base.value, finger.value);
|
|
431
|
+
if (remaining.length) return;
|
|
432
|
+
} else if (previous === "axis") {
|
|
433
|
+
if (moved.value) scheduleOnRN(axis, "move", p.y - downY.value);
|
|
434
|
+
else {
|
|
435
|
+
const now = performance.now();
|
|
436
|
+
if (now - lastAxisTap.value < 320) {
|
|
437
|
+
scheduleOnRN(axis, "reset", 0);
|
|
438
|
+
lastAxisTap.value = -1e3;
|
|
439
|
+
} else lastAxisTap.value = now;
|
|
440
|
+
}
|
|
441
|
+
} else if (previous === "pan") {
|
|
442
|
+
const v = performance.now() - sampleTime.value < 90 ? velocity.value : 0;
|
|
443
|
+
if (Math.abs(v) > 100 && maxStart > 0) {
|
|
444
|
+
phase.value = "fling";
|
|
445
|
+
camera.value = withDecay({ velocity: -v, velocityFactor: 1 / pitch, deceleration: 0.995, clamp: [0, maxStart] }, (finished) => {
|
|
446
|
+
"worklet";
|
|
447
|
+
if (finished) {
|
|
448
|
+
phase.value = "idle";
|
|
449
|
+
scheduleOnRN(finishPan, camera.value);
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
} else scheduleOnRN(finishPan, camera.value);
|
|
453
|
+
} else if (previous === "pending" || previous === "special") {
|
|
454
|
+
scheduleOnRN(dispatch, "end", [], { x: p.x, y: p.y }, origin.value, finger.value);
|
|
455
|
+
}
|
|
456
|
+
if (phase.value !== "fling") phase.value = "idle";
|
|
457
|
+
if (previous !== "ignore") {
|
|
458
|
+
GestureStateManager.activate(e.handlerTag);
|
|
459
|
+
GestureStateManager.deactivate(e.handlerTag);
|
|
460
|
+
}
|
|
461
|
+
},
|
|
462
|
+
onTouchesCancel: () => {
|
|
463
|
+
"worklet";
|
|
464
|
+
if (phase.value === "pan" || phase.value === "fling") {
|
|
465
|
+
cancelAnimation(camera);
|
|
466
|
+
scheduleOnRN(finishPan, camera.value);
|
|
467
|
+
}
|
|
468
|
+
phase.value = "idle";
|
|
469
|
+
scheduleOnRN(cancel);
|
|
470
|
+
},
|
|
471
|
+
onFinalize: (e) => {
|
|
472
|
+
"worklet";
|
|
473
|
+
if (!e.canceled || phase.value === "idle") return;
|
|
474
|
+
if (phase.value === "pan" || phase.value === "fling") {
|
|
475
|
+
cancelAnimation(camera);
|
|
476
|
+
scheduleOnRN(finishPan, camera.value);
|
|
477
|
+
}
|
|
478
|
+
phase.value = "idle";
|
|
479
|
+
scheduleOnRN(cancel);
|
|
480
|
+
}
|
|
481
|
+
});
|
|
482
|
+
React.useEffect(() => () => {
|
|
483
|
+
cancelAnimation(camera);
|
|
484
|
+
cancel();
|
|
485
|
+
}, [camera, cancel]);
|
|
486
|
+
const stop = React.useCallback(() => {
|
|
487
|
+
latest.current.navigation?.(false);
|
|
488
|
+
scheduleOnUI(() => {
|
|
489
|
+
"worklet";
|
|
490
|
+
cancelAnimation(camera);
|
|
491
|
+
phase.value = "idle";
|
|
492
|
+
camera.value = base.value;
|
|
493
|
+
});
|
|
494
|
+
}, [camera, phase, base]);
|
|
495
|
+
return { gesture, animatedStyle, stop };
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
// packages/bindings/react-native/src/PrecisionGuide.tsx
|
|
499
|
+
import { Circle, G, Line, Rect, Text } from "react-native-svg";
|
|
500
|
+
|
|
501
|
+
// packages/bindings/react-native/src/labels.ts
|
|
502
|
+
var formats = /* @__PURE__ */ new Map();
|
|
503
|
+
function formatPrice(value, precision, locale) {
|
|
504
|
+
const digits = Math.max(0, Math.min(12, Math.trunc(precision)));
|
|
505
|
+
const key = (locale ?? "") + ":" + digits;
|
|
506
|
+
let format = formats.get(key);
|
|
507
|
+
if (!format) {
|
|
508
|
+
const options = { useGrouping: true, minimumFractionDigits: digits, maximumFractionDigits: digits };
|
|
509
|
+
try {
|
|
510
|
+
format = new Intl.NumberFormat(locale, options);
|
|
511
|
+
} catch {
|
|
512
|
+
format = new Intl.NumberFormat(void 0, options);
|
|
513
|
+
}
|
|
514
|
+
if (formats.size >= 64) formats.clear();
|
|
515
|
+
formats.set(key, format);
|
|
516
|
+
}
|
|
517
|
+
return format.format(value);
|
|
518
|
+
}
|
|
519
|
+
function formatScaleLabel(raw, locale) {
|
|
520
|
+
const percent = raw.endsWith("%");
|
|
521
|
+
const number = percent ? raw.slice(0, -1) : raw;
|
|
522
|
+
const value = Number(number);
|
|
523
|
+
if (!Number.isFinite(value)) return raw;
|
|
524
|
+
const decimals = number.includes(".") ? number.split(".")[1].length : 0;
|
|
525
|
+
return formatPrice(value, decimals, locale) + (percent ? "%" : "");
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
// packages/bindings/react-native/src/PrecisionGuide.tsx
|
|
529
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
530
|
+
function PrecisionGuide({ frame, point, theme, precision, locale, fontScale }) {
|
|
531
|
+
const g = frame.model.geometry;
|
|
532
|
+
const radius = Math.min(39, g.plotHeight / 3, g.plotWidth / 4);
|
|
533
|
+
const cx = point.x < (g.left + g.right) / 2 ? g.right - radius - 4 : g.left + radius + 4;
|
|
534
|
+
const cy = Math.min(g.bottom - radius, Math.max(g.top + radius + 4, point.y - 54));
|
|
535
|
+
const magnification = 2.2;
|
|
536
|
+
const candles = frame.model.plottedCandles.filter((b) => Math.abs(b.x - point.x) <= radius / magnification + 5);
|
|
537
|
+
const width = Math.max(2, Math.min(13, g.plotWidth / Math.max(1, frame.snapshot.viewport.i1 - frame.snapshot.viewport.i0) * 1.4));
|
|
538
|
+
const y = (screen) => (screen - point.y) * magnification;
|
|
539
|
+
const ink = theme.accent;
|
|
540
|
+
const label = formatPrice(frame.panes[0].scale.value(point.y), precision, locale);
|
|
541
|
+
const font = 11 * fontScale, labelHeight = font + 7;
|
|
542
|
+
const labelWidth = Math.min(g.plotWidth, Math.max(44, label.length * font * 0.66 + 12));
|
|
543
|
+
const labelX = Math.min(g.right - labelWidth, Math.max(g.left, cx - labelWidth / 2));
|
|
544
|
+
const labelY = cy + radius + 2 + labelHeight <= g.bottom ? cy + radius + 2 : Math.max(g.top, cy - radius - labelHeight - 2);
|
|
545
|
+
return /* @__PURE__ */ jsxs(G, { children: [
|
|
546
|
+
/* @__PURE__ */ jsx(Line, { x1: point.x, x2: point.x, y1: g.top, y2: g.bottom, stroke: ink, strokeDasharray: [3, 3] }),
|
|
547
|
+
/* @__PURE__ */ jsx(Line, { x1: g.left, x2: g.right, y1: point.y, y2: point.y, stroke: ink, strokeDasharray: [3, 3] }),
|
|
548
|
+
/* @__PURE__ */ jsx(Circle, { cx: point.x, cy: point.y, r: 3, fill: ink }),
|
|
549
|
+
/* @__PURE__ */ jsx(Circle, { cx, cy, r: radius, fill: theme.background }),
|
|
550
|
+
candles.map((b) => {
|
|
551
|
+
const dx = (b.x - point.x) * magnification, x = cx + dx;
|
|
552
|
+
const color = b.c >= b.o ? theme.up : theme.down;
|
|
553
|
+
const wick = lensSegment(dx, y(b.wickTop), y(b.wickBottom), radius - 1, 0.5);
|
|
554
|
+
const top = y(b.bodyTop);
|
|
555
|
+
const body = lensSegment(dx, top, Math.max(top + 1, y(b.bodyBottom)), radius - 1, width / 2);
|
|
556
|
+
return /* @__PURE__ */ jsxs(G, { children: [
|
|
557
|
+
wick && /* @__PURE__ */ jsx(Line, { x1: x, x2: x, y1: cy + wick.from, y2: cy + wick.to, stroke: color }),
|
|
558
|
+
body && /* @__PURE__ */ jsx(Rect, { x: x - width / 2, y: cy + body.from, width, height: body.to - body.from, fill: color })
|
|
559
|
+
] }, b.index);
|
|
560
|
+
}),
|
|
561
|
+
/* @__PURE__ */ jsx(Circle, { cx, cy, r: radius, stroke: ink, fill: "none", strokeWidth: 1.5 }),
|
|
562
|
+
/* @__PURE__ */ jsx(Line, { x1: cx - 7, x2: cx + 7, y1: cy, y2: cy, stroke: ink }),
|
|
563
|
+
/* @__PURE__ */ jsx(Line, { x1: cx, x2: cx, y1: cy - 7, y2: cy + 7, stroke: ink }),
|
|
564
|
+
/* @__PURE__ */ jsx(Rect, { x: labelX, y: labelY, width: labelWidth, height: labelHeight, rx: 5, fill: theme.background, stroke: ink, strokeWidth: 0.75 }),
|
|
565
|
+
/* @__PURE__ */ jsx(Text, { x: labelX + labelWidth / 2, y: labelY + font + 2, textAnchor: "middle", fontSize: font, fontWeight: "600", fill: theme.text, children: label })
|
|
566
|
+
] });
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
// packages/bindings/react-native/src/gestures.ts
|
|
570
|
+
import * as React2 from "react";
|
|
571
|
+
import {
|
|
572
|
+
clampContinuousViewport as clampContinuousViewport3,
|
|
573
|
+
viewportSpan as viewportSpan2,
|
|
574
|
+
zoomContinuousViewport
|
|
575
|
+
} from "@supersolutions/super-chart-core";
|
|
576
|
+
var pointOf = (e) => ({ x: e.locationX, y: e.locationY });
|
|
577
|
+
var distance = (a, b) => Math.hypot(a.x - b.x, a.y - b.y);
|
|
578
|
+
var midpoint = (a, b) => ({ x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 });
|
|
579
|
+
function useChartGestures(options) {
|
|
580
|
+
const latest = React2.useRef(options);
|
|
581
|
+
latest.current = options;
|
|
582
|
+
return React2.useMemo(() => createChartGestures(() => latest.current), []);
|
|
583
|
+
}
|
|
584
|
+
function createChartGestures(options) {
|
|
585
|
+
let contact = null;
|
|
586
|
+
let hold = null;
|
|
587
|
+
let lastTap = null;
|
|
588
|
+
function clearHold() {
|
|
589
|
+
if (hold !== null) clearTimeout(hold);
|
|
590
|
+
hold = null;
|
|
591
|
+
}
|
|
592
|
+
function cancel() {
|
|
593
|
+
clearHold();
|
|
594
|
+
if (contact?.kind === "layer") options().layers.cancel();
|
|
595
|
+
options().aim?.(null);
|
|
596
|
+
contact = null;
|
|
597
|
+
}
|
|
598
|
+
function pinch(a, b, view) {
|
|
599
|
+
const { frame, layers, inspect } = options();
|
|
600
|
+
if (!frame) return;
|
|
601
|
+
clearHold();
|
|
602
|
+
options().aim?.(null);
|
|
603
|
+
if (contact?.kind === "layer") layers.cancel();
|
|
604
|
+
const start2 = midpoint(a, b);
|
|
605
|
+
inspect(null);
|
|
606
|
+
contact = { kind: "pinch", start: start2, distance: Math.max(2, distance(a, b)), view: view ?? frame.snapshot.viewport };
|
|
607
|
+
}
|
|
608
|
+
function start(e) {
|
|
609
|
+
const { frame, layers, mode, drawing } = options();
|
|
610
|
+
if (!frame || mode === "none") return;
|
|
611
|
+
const { touches } = e.nativeEvent;
|
|
612
|
+
if (touches.length > 1) {
|
|
613
|
+
if (contact?.kind !== "pinch") pinch(pointOf(touches[0]), pointOf(touches[1]));
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
if (contact) return;
|
|
617
|
+
const point = pointOf(touches[0] ?? e.nativeEvent);
|
|
618
|
+
const capturing = layers.begin(point);
|
|
619
|
+
contact = { kind: capturing ? "layer" : "pending", start: point, view: frame.snapshot.viewport, distance: 0 };
|
|
620
|
+
clearHold();
|
|
621
|
+
if (drawing || capturing) options().aim?.(point, false);
|
|
622
|
+
if (!capturing) hold = setTimeout(() => {
|
|
623
|
+
if (contact?.kind !== "pending") return;
|
|
624
|
+
if (drawing && options().aim) {
|
|
625
|
+
contact.kind = "aim";
|
|
626
|
+
options().aim?.(point, true);
|
|
627
|
+
} else {
|
|
628
|
+
contact.kind = "inspect";
|
|
629
|
+
options().inspect(point);
|
|
630
|
+
}
|
|
631
|
+
}, 360);
|
|
632
|
+
}
|
|
633
|
+
function move(e) {
|
|
634
|
+
const { frame, mode, layers, inspect, changeViewport } = options();
|
|
635
|
+
if (!frame || mode === "none") return;
|
|
636
|
+
const { touches } = e.nativeEvent;
|
|
637
|
+
if (!touches.length) return;
|
|
638
|
+
const first = pointOf(touches[0]);
|
|
639
|
+
if (!contact) start(e);
|
|
640
|
+
if (touches.length >= 2 && contact?.kind !== "pinch") pinch(first, pointOf(touches[1]));
|
|
641
|
+
const session = contact;
|
|
642
|
+
if (!session || session.kind === "ignore") return;
|
|
643
|
+
const { geometry } = frame.model;
|
|
644
|
+
const length = frame.snapshot.length;
|
|
645
|
+
if (session.kind === "pinch") {
|
|
646
|
+
if (touches.length < 2) return;
|
|
647
|
+
const second = pointOf(touches[1]), mid = midpoint(first, second);
|
|
648
|
+
const zoomed = zoomContinuousViewport(
|
|
649
|
+
session.view,
|
|
650
|
+
length,
|
|
651
|
+
distance(first, second) / session.distance,
|
|
652
|
+
(session.start.x - geometry.left) / geometry.plotWidth,
|
|
653
|
+
CHART_LIMITS
|
|
654
|
+
);
|
|
655
|
+
const delta2 = (session.start.x - mid.x) * (viewportSpan2(zoomed) - 1) / geometry.plotWidth;
|
|
656
|
+
changeViewport(clampContinuousViewport3({ i0: zoomed.i0 + delta2, i1: zoomed.i1 + delta2 }, length, CHART_LIMITS));
|
|
657
|
+
return;
|
|
658
|
+
}
|
|
659
|
+
if (session.kind === "layer") {
|
|
660
|
+
layers.move(options().aim?.(first, false) ?? first);
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
663
|
+
if (session.kind === "aim") {
|
|
664
|
+
options().aim?.(first, true);
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
667
|
+
if (session.kind === "inspect") {
|
|
668
|
+
inspect(first);
|
|
669
|
+
return;
|
|
670
|
+
}
|
|
671
|
+
if (session.kind === "pending") {
|
|
672
|
+
const dx = Math.abs(first.x - session.start.x), dy = Math.abs(first.y - session.start.y);
|
|
673
|
+
if (Math.max(dx, dy) < 5) return;
|
|
674
|
+
clearHold();
|
|
675
|
+
if (options().drawing && options().aim) {
|
|
676
|
+
session.kind = "aim";
|
|
677
|
+
options().aim?.(first, true);
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
680
|
+
if (mode === "scroll" && dy > dx) {
|
|
681
|
+
session.kind = "ignore";
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
session.kind = "pan";
|
|
685
|
+
inspect(null);
|
|
686
|
+
}
|
|
687
|
+
const delta = (session.start.x - first.x) * (viewportSpan2(session.view) - 1) / geometry.plotWidth;
|
|
688
|
+
changeViewport(clampContinuousViewport3({ i0: session.view.i0 + delta, i1: session.view.i1 + delta }, length, CHART_LIMITS));
|
|
689
|
+
}
|
|
690
|
+
function end(e) {
|
|
691
|
+
const { frame, layers, inspect, onPress, reset, drawing } = options();
|
|
692
|
+
const session = contact;
|
|
693
|
+
if (!session || !frame) {
|
|
694
|
+
cancel();
|
|
695
|
+
return;
|
|
696
|
+
}
|
|
697
|
+
clearHold();
|
|
698
|
+
if (e.nativeEvent.touches.length) {
|
|
699
|
+
if (session.kind === "pinch") session.kind = "ignore";
|
|
700
|
+
return;
|
|
701
|
+
}
|
|
702
|
+
contact = null;
|
|
703
|
+
const point = pointOf(e.nativeEvent.changedTouches[0] ?? e.nativeEvent);
|
|
704
|
+
if (session.kind === "layer") {
|
|
705
|
+
layers.end(options().aim?.(point, false) ?? point);
|
|
706
|
+
options().aim?.(null);
|
|
707
|
+
return;
|
|
708
|
+
}
|
|
709
|
+
if (session.kind === "aim") {
|
|
710
|
+
layers.tap(options().aim?.(point, true) ?? point);
|
|
711
|
+
options().aim?.(null);
|
|
712
|
+
return;
|
|
713
|
+
}
|
|
714
|
+
if (drawing) options().aim?.(null);
|
|
715
|
+
if (session.kind !== "pending" || distance(point, session.start) > 10) return;
|
|
716
|
+
const previous = lastTap;
|
|
717
|
+
if (!drawing && previous && Date.now() - previous.time < 280 && distance(previous.point, point) < 20) {
|
|
718
|
+
lastTap = null;
|
|
719
|
+
reset();
|
|
720
|
+
return;
|
|
721
|
+
}
|
|
722
|
+
if (layers.tap(point)) {
|
|
723
|
+
lastTap = null;
|
|
724
|
+
return;
|
|
725
|
+
}
|
|
726
|
+
lastTap = { time: Date.now(), point };
|
|
727
|
+
inspect(null);
|
|
728
|
+
onPress?.(point, frame);
|
|
729
|
+
}
|
|
730
|
+
function wantsDrag(e) {
|
|
731
|
+
if (options().mode === "none" || !options().frame) return false;
|
|
732
|
+
if (options().mode === "chart" || e.nativeEvent.touches.length > 1) return true;
|
|
733
|
+
if (!contact || contact.kind === "ignore") return false;
|
|
734
|
+
if (contact.kind === "inspect" || contact.kind === "layer") return true;
|
|
735
|
+
const p = pointOf(e.nativeEvent), origin = contact.start;
|
|
736
|
+
return Math.abs(p.x - origin.x) > Math.max(5, Math.abs(p.y - origin.y));
|
|
737
|
+
}
|
|
738
|
+
return {
|
|
739
|
+
cancel,
|
|
740
|
+
pinchAt: pinch,
|
|
741
|
+
captured: () => contact?.kind === "layer",
|
|
742
|
+
nativePan: () => {
|
|
743
|
+
cancel();
|
|
744
|
+
options().inspect(null);
|
|
745
|
+
},
|
|
746
|
+
handlers: {
|
|
747
|
+
onStartShouldSetResponder: (e) => options().frame !== null && (options().mode === "chart" || options().mode === "scroll" && (options().drawing || e.nativeEvent.touches.length > 1)),
|
|
748
|
+
onMoveShouldSetResponder: wantsDrag,
|
|
749
|
+
onResponderTerminationRequest: () => options().mode === "scroll" && (!contact || contact.kind === "pending" || contact.kind === "ignore"),
|
|
750
|
+
onResponderTerminate: cancel,
|
|
751
|
+
onTouchCancel: cancel,
|
|
752
|
+
onTouchStart: start,
|
|
753
|
+
onTouchMove: move,
|
|
754
|
+
onTouchEnd: end
|
|
755
|
+
}
|
|
756
|
+
};
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
// packages/bindings/react-native/src/overlays.tsx
|
|
760
|
+
import { useEffect as useEffect4, useId, useMemo as useMemo3, useState as useState3 } from "react";
|
|
761
|
+
import { Image as NativeImage, useWindowDimensions as useWindowDimensions2 } from "react-native";
|
|
762
|
+
import { Circle as Circle4, ClipPath, Defs, G as G4, Image as Image2, Line as Line2, Path as Path3, Rect as Rect3, Text as Text4 } from "react-native-svg";
|
|
763
|
+
|
|
764
|
+
// packages/bindings/react-native/src/drawings.tsx
|
|
765
|
+
import { useEffect as useEffect2, useMemo as useMemo2, useRef as useRef3, useState, useSyncExternalStore } from "react";
|
|
766
|
+
import { Circle as Circle3, G as G3, Path as Path2 } from "react-native-svg";
|
|
767
|
+
import {
|
|
768
|
+
DrawingStore,
|
|
769
|
+
drawingAnchorCount,
|
|
770
|
+
drawingUsesText,
|
|
771
|
+
hitTestDrawingGeometry,
|
|
772
|
+
isPathDrawing,
|
|
773
|
+
moveDrawingHandle,
|
|
774
|
+
projectDrawing
|
|
775
|
+
} from "@supersolutions/super-chart-core";
|
|
776
|
+
|
|
777
|
+
// packages/bindings/react-native/src/drawingShapes.tsx
|
|
778
|
+
import { useWindowDimensions } from "react-native";
|
|
779
|
+
import { Circle as Circle2, Ellipse, G as G2, Image, Path, Rect as Rect2, Text as Text2 } from "react-native-svg";
|
|
780
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
781
|
+
function linePath(points) {
|
|
782
|
+
return points.map((p, i) => (i === 0 ? "M" : "L") + p.x + " " + p.y).join(" ");
|
|
783
|
+
}
|
|
784
|
+
function DrawingShape({ geometry, selected, ink, surface, precision, locale }) {
|
|
785
|
+
const { fontScale } = useWindowDimensions();
|
|
786
|
+
const style = geometry.style;
|
|
787
|
+
const color = style?.color ?? ink;
|
|
788
|
+
const fill = style?.fillColor ?? color;
|
|
789
|
+
const width = style?.width ?? 1.5;
|
|
790
|
+
const dash = style?.dash === "dashed" ? [width * 4, width * 2] : style?.dash === "dotted" ? [1, width * 2 + 2] : void 0;
|
|
791
|
+
const textColor = style?.textColor ?? color;
|
|
792
|
+
const segments = [];
|
|
793
|
+
const shapes = [];
|
|
794
|
+
const labels = [];
|
|
795
|
+
for (const [i, p] of geometry.primitives.entries()) {
|
|
796
|
+
switch (p.kind) {
|
|
797
|
+
case "line":
|
|
798
|
+
segments.push(linePath([p.from, p.to]));
|
|
799
|
+
break;
|
|
800
|
+
case "rect":
|
|
801
|
+
shapes.push(/* @__PURE__ */ jsx2(Rect2, { x: p.from.x, y: p.from.y, width: p.to.x - p.from.x, height: p.to.y - p.from.y, fill, fillOpacity: style?.fillOpacity ?? 0.12 }, i));
|
|
802
|
+
break;
|
|
803
|
+
case "polygon":
|
|
804
|
+
shapes.push(/* @__PURE__ */ jsx2(Path, { d: linePath(p.points) + " Z", fill, fillOpacity: style?.fillOpacity ?? 0.12 }, i));
|
|
805
|
+
break;
|
|
806
|
+
case "ellipse":
|
|
807
|
+
shapes.push(/* @__PURE__ */ jsx2(Ellipse, { cx: p.center.x, cy: p.center.y, rx: p.radiusX, ry: p.radiusY, fill, fillOpacity: style?.fillOpacity ?? 0.12, stroke: color, strokeWidth: width, strokeDasharray: dash }, i));
|
|
808
|
+
break;
|
|
809
|
+
case "stroke":
|
|
810
|
+
shapes.push(/* @__PURE__ */ jsx2(Path, { d: linePath(p.points), fill: "none", stroke: color, strokeWidth: p.width, strokeOpacity: p.opacity, strokeLinecap: "round", strokeLinejoin: "round" }, i));
|
|
811
|
+
break;
|
|
812
|
+
case "image":
|
|
813
|
+
shapes.push(/* @__PURE__ */ jsx2(Image, { href: { uri: p.source }, x: p.bounds.left, y: p.bounds.top, width: p.bounds.right - p.bounds.left, height: p.bounds.bottom - p.bounds.top, preserveAspectRatio: "xMidYMid meet" }, i));
|
|
814
|
+
break;
|
|
815
|
+
case "text":
|
|
816
|
+
labels.push(/* @__PURE__ */ jsx2(Text2, { x: p.position.x, y: p.position.y, fill: textColor, fontSize: 10 * fontScale, textAnchor: p.align === "right" ? "end" : p.align === "center" ? "middle" : "start", children: p.price === void 0 ? p.text : p.text + " " + formatPrice(p.price, precision, locale) }, i));
|
|
817
|
+
break;
|
|
818
|
+
case "label": {
|
|
819
|
+
const lines = p.price === void 0 ? p.lines : [formatPrice(p.price, precision, locale)];
|
|
820
|
+
labels.push(/* @__PURE__ */ jsxs2(G2, { children: [
|
|
821
|
+
p.boxed && /* @__PURE__ */ jsx2(Rect2, { x: p.bounds.left, y: p.bounds.top, width: p.bounds.right - p.bounds.left, height: Math.max(p.bounds.bottom - p.bounds.top, (8 + lines.length * 14) * fontScale), rx: 3, fill: surface, stroke: color }),
|
|
822
|
+
lines.map((line, index) => /* @__PURE__ */ jsx2(Text2, { x: p.bounds.left + 4, y: p.bounds.top + (12 + index * 14) * fontScale, fontSize: 11 * fontScale, fill: textColor, children: line }, index))
|
|
823
|
+
] }, i));
|
|
824
|
+
break;
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
return /* @__PURE__ */ jsxs2(G2, { children: [
|
|
829
|
+
shapes,
|
|
830
|
+
segments.length > 0 && /* @__PURE__ */ jsx2(Path, { d: segments.join(" "), fill: "none", stroke: color, strokeWidth: width, strokeDasharray: dash, strokeLinecap: "round" }),
|
|
831
|
+
labels,
|
|
832
|
+
selected && !geometry.locked && geometry.handles.map((h) => /* @__PURE__ */ jsx2(Circle2, { cx: h.point.x, cy: h.point.y, r: 5, fill: surface, stroke: color, strokeWidth: 2.5 }, h.anchorIndex))
|
|
833
|
+
] });
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
// packages/bindings/react-native/src/overlaysModel.ts
|
|
837
|
+
import {
|
|
838
|
+
BUILT_IN_ANNOTATION_TEMPLATES,
|
|
839
|
+
clipDrawingLine
|
|
840
|
+
} from "@supersolutions/super-chart-core";
|
|
841
|
+
function contains(bounds, p) {
|
|
842
|
+
return p.x >= bounds.left && p.x <= bounds.right && p.y >= bounds.top && p.y <= bounds.bottom;
|
|
843
|
+
}
|
|
844
|
+
var templates = new Map(BUILT_IN_ANNOTATION_TEMPLATES.map((t) => [t.name, t]));
|
|
845
|
+
function labelBounds(f, scale) {
|
|
846
|
+
const chars = Array.from(f.text);
|
|
847
|
+
const text = chars.length > 26 ? [...chars.slice(0, 25), "\u2026"] : chars;
|
|
848
|
+
const width = text.reduce((n, c) => n + (c.charCodeAt(0) > 255 ? 10 : 6), 0) * scale;
|
|
849
|
+
const left = f.x - (f.align === "right" ? width : f.align === "center" ? width / 2 : 0);
|
|
850
|
+
return { left, right: left + width, top: f.y - 10 * scale, bottom: f.y + 2 * scale };
|
|
851
|
+
}
|
|
852
|
+
function primitivePosition(figures) {
|
|
853
|
+
const shapes = figures.filter((f2) => f2.type !== "text");
|
|
854
|
+
if (shapes.length !== 1) return void 0;
|
|
855
|
+
const f = shapes[0];
|
|
856
|
+
if (f.type === "line") return "line:" + [f.from.x, f.from.y, f.to.x, f.to.y].map(Math.round).join(",");
|
|
857
|
+
if (f.type === "rect") return "rect:" + [f.x, f.y, f.width, f.height].map(Math.round).join(",");
|
|
858
|
+
if (f.type === "marker") return f.shape + ":" + [f.x, f.y, f.size ?? 5].map(Math.round).join(",");
|
|
859
|
+
return void 0;
|
|
860
|
+
}
|
|
861
|
+
function layoutAnnotationLabels(annotations, bounds, fontScale = 1) {
|
|
862
|
+
const hidden = /* @__PURE__ */ new Map();
|
|
863
|
+
const rows = /* @__PURE__ */ new Map();
|
|
864
|
+
const visible = annotations.map((entry) => ({
|
|
865
|
+
...entry,
|
|
866
|
+
figures: entry.figures.filter((f) => {
|
|
867
|
+
if (f.type !== "text") return true;
|
|
868
|
+
const box = labelBounds(f, fontScale);
|
|
869
|
+
if (box.left > bounds.right || box.right < bounds.left || box.top > bounds.bottom || box.bottom < bounds.top) return false;
|
|
870
|
+
const first = Math.floor((box.top - 2) / 16), last = Math.floor((box.bottom + 2) / 16);
|
|
871
|
+
for (let i = first; i <= last; i++) {
|
|
872
|
+
if (rows.get(i)?.some((other) => box.left < other.right + 3 && box.right + 3 > other.left && box.top < other.bottom + 2 && box.bottom + 2 > other.top)) {
|
|
873
|
+
hidden.set(entry.spec.key, entry.spec);
|
|
874
|
+
return false;
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
for (let i = first; i <= last; i++) {
|
|
878
|
+
const row = rows.get(i);
|
|
879
|
+
if (row) row.push(box);
|
|
880
|
+
else rows.set(i, [box]);
|
|
881
|
+
}
|
|
882
|
+
return true;
|
|
883
|
+
})
|
|
884
|
+
}));
|
|
885
|
+
const occupied = /* @__PURE__ */ new Map();
|
|
886
|
+
for (const entry of visible) {
|
|
887
|
+
const key = primitivePosition(entry.figures);
|
|
888
|
+
if (!key || !annotationPosition(entry, bounds)) continue;
|
|
889
|
+
const previous = occupied.get(key);
|
|
890
|
+
if (previous && !entry.figures.some((f) => f.type === "text")) hidden.set(entry.spec.key, entry.spec);
|
|
891
|
+
else {
|
|
892
|
+
if (previous && !previous.figures.some((f) => f.type === "text")) hidden.set(previous.spec.key, previous.spec);
|
|
893
|
+
occupied.set(key, entry);
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
return { visible, hidden: [...hidden.values()] };
|
|
897
|
+
}
|
|
898
|
+
function projectAnnotation(frame, spec, palette, locale, bounds = frame.model.geometry, precision = frame.pricePrecision ?? 2) {
|
|
899
|
+
const tone = spec.tone ?? "accent", color = spec.color ?? palette[tone];
|
|
900
|
+
const template = templates.get(spec.kind);
|
|
901
|
+
const count = template?.anchors ?? (spec.kind === "zone" ? 2 : 1);
|
|
902
|
+
if (!Array.isArray(spec.anchors) || spec.anchors.length < count) return null;
|
|
903
|
+
const anchors = [];
|
|
904
|
+
for (const anchor of spec.anchors.slice(0, count)) {
|
|
905
|
+
if (!anchor || !Number.isFinite(anchor.time)) return null;
|
|
906
|
+
const price = anchor.price ?? (template?.priceless ? frame.snapshot.bars[0]?.close : void 0);
|
|
907
|
+
if (price === void 0 || !Number.isFinite(price)) return null;
|
|
908
|
+
const point = frame.project(anchor.time, price);
|
|
909
|
+
if (!point || !Number.isFinite(point.x) || !Number.isFinite(point.y)) return null;
|
|
910
|
+
anchors.push({ ...point, time: anchor.time, price });
|
|
911
|
+
}
|
|
912
|
+
const [a, b] = anchors;
|
|
913
|
+
let figures;
|
|
914
|
+
if (template) {
|
|
915
|
+
figures = template.create({ anchors, bounds, tone, color, text: spec.text, params: spec.params ?? {}, project: frame.project, formatPrice: (p) => formatPrice(p, precision, locale) });
|
|
916
|
+
} else {
|
|
917
|
+
const result = [];
|
|
918
|
+
let label;
|
|
919
|
+
if (spec.kind === "level") {
|
|
920
|
+
if (a.y < bounds.top || a.y > bounds.bottom) return null;
|
|
921
|
+
result.push({ type: "line", from: { x: bounds.left, y: a.y }, to: { x: bounds.right, y: a.y } });
|
|
922
|
+
label = { x: bounds.left + 5, y: a.y - 4 };
|
|
923
|
+
} else if (spec.kind === "zone") {
|
|
924
|
+
const x = Math.max(bounds.left, Math.min(a.x, b.x)), right = Math.min(bounds.right, Math.max(a.x, b.x));
|
|
925
|
+
const y = Math.max(bounds.top, Math.min(a.y, b.y)), bottom = Math.min(bounds.bottom, Math.max(a.y, b.y));
|
|
926
|
+
if (x > right || y > bottom) return null;
|
|
927
|
+
result.push({ type: "rect", x, y, width: right - x, height: bottom - y, fillOpacity: 0.12 });
|
|
928
|
+
label = { x: x + 4, y: y + 11 };
|
|
929
|
+
} else if (spec.kind === "marker") {
|
|
930
|
+
if (!contains(bounds, a)) return null;
|
|
931
|
+
result.push({ type: "marker", ...a, shape: "diamond" });
|
|
932
|
+
label = { x: a.x + 7, y: a.y - 4 };
|
|
933
|
+
} else return null;
|
|
934
|
+
if (spec.text) result.push({ type: "text", ...label, text: spec.text });
|
|
935
|
+
figures = result;
|
|
936
|
+
}
|
|
937
|
+
const clipped = [];
|
|
938
|
+
for (const figure of figures) {
|
|
939
|
+
if (figure.type === "line") {
|
|
940
|
+
const line = clipDrawingLine(figure.from, figure.to, bounds, figure.extend === "right", figure.extend === "both");
|
|
941
|
+
if (line) clipped.push({ ...figure, from: line.from, to: line.to });
|
|
942
|
+
} else clipped.push(figure);
|
|
943
|
+
}
|
|
944
|
+
return { spec, figures: clipped, color };
|
|
945
|
+
}
|
|
946
|
+
function segmentDistance(p, a, b) {
|
|
947
|
+
const dx = b.x - a.x, dy = b.y - a.y;
|
|
948
|
+
const ratio = Math.max(0, Math.min(1, ((p.x - a.x) * dx + (p.y - a.y) * dy) / (dx * dx + dy * dy || 1)));
|
|
949
|
+
return Math.hypot(p.x - a.x - ratio * dx, p.y - a.y - ratio * dy);
|
|
950
|
+
}
|
|
951
|
+
function hitsAnnotation(annotation, p, fontScale = 1) {
|
|
952
|
+
return annotation.figures.some((f) => {
|
|
953
|
+
switch (f.type) {
|
|
954
|
+
case "line":
|
|
955
|
+
return segmentDistance(p, f.from, f.to) < 12;
|
|
956
|
+
case "polyline":
|
|
957
|
+
return f.points.some((b, i) => i > 0 && segmentDistance(p, f.points[i - 1], b) < 12);
|
|
958
|
+
case "marker":
|
|
959
|
+
return Math.hypot(p.x - f.x, p.y - f.y) <= 20;
|
|
960
|
+
case "rect":
|
|
961
|
+
return p.x >= f.x - 5 && p.x <= f.x + f.width + 5 && p.y >= f.y - 5 && p.y <= f.y + f.height + 5;
|
|
962
|
+
case "text": {
|
|
963
|
+
const box = labelBounds(f, fontScale);
|
|
964
|
+
return p.x >= box.left - 4 && p.x <= box.right + 4 && p.y >= box.top - 4 && p.y <= box.bottom + 4;
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
});
|
|
968
|
+
}
|
|
969
|
+
function annotationPosition(entry, bounds) {
|
|
970
|
+
const center = (x, y) => ({ x: Math.max(bounds.left, Math.min(x, bounds.right)), y: Math.max(bounds.top, Math.min(y, bounds.bottom)) });
|
|
971
|
+
for (const f of entry.figures) {
|
|
972
|
+
if ((f.type === "text" || f.type === "marker") && contains(bounds, f)) return center(f.x, f.y);
|
|
973
|
+
if (f.type === "line") return center((f.from.x + f.to.x) / 2, (f.from.y + f.to.y) / 2);
|
|
974
|
+
if (f.type === "rect" && f.x <= bounds.right && f.x + f.width >= bounds.left && f.y <= bounds.bottom && f.y + f.height >= bounds.top) {
|
|
975
|
+
return center(
|
|
976
|
+
(Math.max(f.x, bounds.left) + Math.min(f.x + f.width, bounds.right)) / 2,
|
|
977
|
+
(Math.max(f.y, bounds.top) + Math.min(f.y + f.height, bounds.bottom)) / 2
|
|
978
|
+
);
|
|
979
|
+
}
|
|
980
|
+
if (f.type === "polyline") {
|
|
981
|
+
for (let i = 1; i < f.points.length; i++) {
|
|
982
|
+
const clipped = clipDrawingLine(f.points[i - 1], f.points[i], bounds);
|
|
983
|
+
if (clipped) return center((clipped.from.x + clipped.to.x) / 2, (clipped.from.y + clipped.to.y) / 2);
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
return null;
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
// packages/bindings/react-native/src/drawings.tsx
|
|
991
|
+
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
992
|
+
var serial = 0;
|
|
993
|
+
function useDrawingInteraction(frame, props, ink, surface) {
|
|
994
|
+
const localStore = useMemo2(() => new DrawingStore(), []);
|
|
995
|
+
const store = props.drawingStore ?? localStore;
|
|
996
|
+
const snapshot = useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);
|
|
997
|
+
const tool = props.drawingTool;
|
|
998
|
+
const placement = useRef3(null), drag = useRef3(null);
|
|
999
|
+
const [, refresh] = useState(0);
|
|
1000
|
+
function invalidate() {
|
|
1001
|
+
refresh((n) => n + 1);
|
|
1002
|
+
}
|
|
1003
|
+
function cancel() {
|
|
1004
|
+
const hadDraft = placement.current !== null || drag.current !== null;
|
|
1005
|
+
placement.current = null;
|
|
1006
|
+
drag.current = null;
|
|
1007
|
+
if (hadDraft) {
|
|
1008
|
+
invalidate();
|
|
1009
|
+
props.onDrawingProgress?.(0, null);
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
useEffect2(() => {
|
|
1013
|
+
cancel();
|
|
1014
|
+
}, [store, tool]);
|
|
1015
|
+
const geometries = useMemo2(() => frame && !snapshot.viewHidden ? snapshot.drawings.flatMap((item) => projectDrawing(item, frame.project, frame.model.geometry, frame.drawingContext) ?? []) : [], [frame, snapshot.drawings, snapshot.viewHidden]);
|
|
1016
|
+
const regions = useMemo2(() => drawingRegions(geometries.find((g) => g.id === snapshot.selectedId)), [geometries, snapshot.selectedId]);
|
|
1017
|
+
const draft = drag.current;
|
|
1018
|
+
const preview = draft && frame ? projectDrawing({ ...draft.original, anchors: draft.anchors }, frame.project, frame.model.geometry, frame.drawingContext) : null;
|
|
1019
|
+
function anchorAt(p) {
|
|
1020
|
+
if (!frame || !contains(frame.model.geometry, p)) return null;
|
|
1021
|
+
if (props.drawingMagnet !== false && (tool && tool !== "brush" && tool !== "highlighter" || drag.current?.index != null)) {
|
|
1022
|
+
const snap = nearestOHLC(frame, p);
|
|
1023
|
+
if (snap) return { timestamp: snap.timestamp, price: snap.price };
|
|
1024
|
+
}
|
|
1025
|
+
return frame.unproject(p.x, p.y);
|
|
1026
|
+
}
|
|
1027
|
+
function commit(points2) {
|
|
1028
|
+
if (!tool) return;
|
|
1029
|
+
let added;
|
|
1030
|
+
try {
|
|
1031
|
+
added = store.add({
|
|
1032
|
+
id: "rn-" + Date.now().toString(36) + "-" + (++serial).toString(36),
|
|
1033
|
+
type: tool,
|
|
1034
|
+
anchors: points2,
|
|
1035
|
+
...drawingUsesText(tool) ? { text: props.drawingText } : {},
|
|
1036
|
+
...tool === "image" ? { image: props.drawingImage } : {},
|
|
1037
|
+
...props.drawingColor ? { style: { color: props.drawingColor } } : {}
|
|
1038
|
+
});
|
|
1039
|
+
} catch (reason) {
|
|
1040
|
+
cancel();
|
|
1041
|
+
const error = reason instanceof Error ? reason : new Error(String(reason));
|
|
1042
|
+
if (props.onDrawingError) props.onDrawingError(error);
|
|
1043
|
+
else console.warn("[Super Chart] " + error.message);
|
|
1044
|
+
return;
|
|
1045
|
+
}
|
|
1046
|
+
cancel();
|
|
1047
|
+
store.select(added.id);
|
|
1048
|
+
props.onDrawingComplete?.(added);
|
|
1049
|
+
}
|
|
1050
|
+
function finishPath() {
|
|
1051
|
+
if (isPathDrawing(tool ?? void 0) && placement.current && placement.current.points.length >= 2) commit(placement.current.points);
|
|
1052
|
+
}
|
|
1053
|
+
function tap(p) {
|
|
1054
|
+
const anchor = anchorAt(p);
|
|
1055
|
+
if (!anchor || snapshot.viewHidden) return false;
|
|
1056
|
+
if (!tool) {
|
|
1057
|
+
const hit = hitTestDrawingGeometry(geometries, snapshot.selectedId, p, 12);
|
|
1058
|
+
store.select(hit?.id ?? null);
|
|
1059
|
+
return hit !== null;
|
|
1060
|
+
}
|
|
1061
|
+
if (tool === "brush" || tool === "highlighter") return false;
|
|
1062
|
+
const variable = isPathDrawing(tool), previous = placement.current, now = Date.now();
|
|
1063
|
+
if (variable && previous && previous.points.length >= 2 && now - previous.lastTap < 350 && Math.hypot(p.x - previous.last.x, p.y - previous.last.y) < 16) {
|
|
1064
|
+
finishPath();
|
|
1065
|
+
return true;
|
|
1066
|
+
}
|
|
1067
|
+
const points2 = [...previous?.points ?? [], anchor];
|
|
1068
|
+
placement.current = { points: points2, last: p, lastTap: now };
|
|
1069
|
+
const count = drawingAnchorCount(tool);
|
|
1070
|
+
if (variable ? points2.length >= 256 : points2.length === count) commit(points2);
|
|
1071
|
+
else {
|
|
1072
|
+
props.onDrawingProgress?.(points2.length, variable ? null : count);
|
|
1073
|
+
invalidate();
|
|
1074
|
+
}
|
|
1075
|
+
return true;
|
|
1076
|
+
}
|
|
1077
|
+
function begin(p) {
|
|
1078
|
+
const anchor = anchorAt(p);
|
|
1079
|
+
if (!anchor || snapshot.viewHidden) return false;
|
|
1080
|
+
if (tool === "brush" || tool === "highlighter") {
|
|
1081
|
+
placement.current = { points: [anchor], last: p, lastTap: 0 };
|
|
1082
|
+
invalidate();
|
|
1083
|
+
return true;
|
|
1084
|
+
}
|
|
1085
|
+
if (tool || !snapshot.selectedId) return false;
|
|
1086
|
+
const hit = hitTestDrawingGeometry(geometries, snapshot.selectedId, p, 14);
|
|
1087
|
+
if (!hit || hit.id !== snapshot.selectedId) return false;
|
|
1088
|
+
const original = snapshot.drawings.find((d) => d.id === hit.id);
|
|
1089
|
+
if (!original || original.locked) return false;
|
|
1090
|
+
drag.current = { original, index: hit.anchorIndex, start: anchor, anchors: original.anchors };
|
|
1091
|
+
return true;
|
|
1092
|
+
}
|
|
1093
|
+
function move(p) {
|
|
1094
|
+
const anchor = anchorAt(p);
|
|
1095
|
+
if (!anchor) return;
|
|
1096
|
+
const edit = drag.current;
|
|
1097
|
+
if (edit) {
|
|
1098
|
+
edit.anchors = edit.index === null ? edit.original.anchors.map((a) => ({ timestamp: a.timestamp + anchor.timestamp - edit.start.timestamp, price: a.price + anchor.price - edit.start.price })) : moveDrawingHandle(edit.original, edit.index, anchor);
|
|
1099
|
+
invalidate();
|
|
1100
|
+
return;
|
|
1101
|
+
}
|
|
1102
|
+
const stroke2 = placement.current;
|
|
1103
|
+
if (stroke2 && (tool === "brush" || tool === "highlighter") && stroke2.points.length < 2048 && Math.hypot(stroke2.last.x - p.x, stroke2.last.y - p.y) >= 2) {
|
|
1104
|
+
stroke2.points.push(anchor);
|
|
1105
|
+
stroke2.last = p;
|
|
1106
|
+
invalidate();
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
function end(p) {
|
|
1110
|
+
move(p);
|
|
1111
|
+
const edit = drag.current;
|
|
1112
|
+
if (edit) {
|
|
1113
|
+
if (store.getSnapshot().drawings.find((d) => d.id === edit.original.id) === edit.original) {
|
|
1114
|
+
store.update(edit.original.id, { anchors: edit.anchors });
|
|
1115
|
+
}
|
|
1116
|
+
cancel();
|
|
1117
|
+
} else if (tool === "brush" || tool === "highlighter") {
|
|
1118
|
+
const points2 = placement.current?.points;
|
|
1119
|
+
if (points2 && points2.length >= 2) commit(points2);
|
|
1120
|
+
else cancel();
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
const points = placement.current?.points.flatMap((a) => frame?.project(a.timestamp, a.price) ?? []) ?? [];
|
|
1124
|
+
const stroke = tool === "brush" || tool === "highlighter";
|
|
1125
|
+
const placementColor = props.drawingColor ?? ink;
|
|
1126
|
+
const nodes = /* @__PURE__ */ jsxs3(G3, { children: [
|
|
1127
|
+
geometries.map((g) => /* @__PURE__ */ jsx3(DrawingShape, { geometry: preview?.id === g.id ? preview : g, selected: snapshot.selectedId === g.id, ink, surface, locale: props.locale, precision: props.precision ?? frame?.pricePrecision ?? 2 }, g.id)),
|
|
1128
|
+
points.length > 0 && /* @__PURE__ */ jsxs3(G3, { children: [
|
|
1129
|
+
points.length > 1 && /* @__PURE__ */ jsx3(Path2, { d: linePath(points), fill: "none", stroke: placementColor, strokeWidth: tool === "highlighter" ? 12 : 2, opacity: tool === "highlighter" ? 0.4 : 1, strokeDasharray: stroke ? void 0 : [4, 3], strokeLinejoin: "round", strokeLinecap: "round" }),
|
|
1130
|
+
(stroke ? points.slice(-1) : points).map((point, i) => /* @__PURE__ */ jsx3(Circle3, { cx: point.x, cy: point.y, r: 4, fill: surface, stroke: placementColor, strokeWidth: 2 }, i))
|
|
1131
|
+
] })
|
|
1132
|
+
] });
|
|
1133
|
+
return { nodes, tap, begin, move, end, cancel, finishPath, regions, editingHandle: () => drag.current?.index != null };
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
// packages/bindings/react-native/src/avatars.ts
|
|
1137
|
+
var AvatarCache = class {
|
|
1138
|
+
constructor(limit = 128) {
|
|
1139
|
+
this.limit = limit;
|
|
1140
|
+
}
|
|
1141
|
+
limit;
|
|
1142
|
+
entries = /* @__PURE__ */ new Map();
|
|
1143
|
+
warm(uri, fetch, now = Date.now) {
|
|
1144
|
+
if (!/^https?:\/\//i.test(uri)) return;
|
|
1145
|
+
const previous = this.entries.get(uri);
|
|
1146
|
+
if (previous && (previous.pending || now() < previous.retryAt)) return;
|
|
1147
|
+
if (!previous && this.entries.size >= this.limit) {
|
|
1148
|
+
const finished = [...this.entries].find(([, entry2]) => !entry2.pending);
|
|
1149
|
+
if (!finished) return;
|
|
1150
|
+
this.entries.delete(finished[0]);
|
|
1151
|
+
}
|
|
1152
|
+
const entry = { pending: true, retryAt: 0 };
|
|
1153
|
+
this.entries.set(uri, entry);
|
|
1154
|
+
const finish = (ok) => {
|
|
1155
|
+
entry.pending = false;
|
|
1156
|
+
entry.retryAt = ok ? Infinity : now() + 3e4;
|
|
1157
|
+
};
|
|
1158
|
+
fetch(uri).then(finish, () => finish(false));
|
|
1159
|
+
}
|
|
1160
|
+
};
|
|
1161
|
+
|
|
1162
|
+
// packages/bindings/react-native/src/LayerControls.tsx
|
|
1163
|
+
import { useEffect as useEffect3, useRef as useRef4, useState as useState2 } from "react";
|
|
1164
|
+
import { AccessibilityInfo, BackHandler, findNodeHandle, FlatList, Pressable, StyleSheet, Text as Text3, View } from "react-native";
|
|
1165
|
+
import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
1166
|
+
function annotationDescription(annotation, precision, locale) {
|
|
1167
|
+
const prices = annotation.anchors.flatMap((a) => a.price !== void 0 ? [formatPrice(a.price, precision, locale)] : []);
|
|
1168
|
+
return [annotation.text?.trim() || annotation.kind, ...prices].join(" \xB7 ");
|
|
1169
|
+
}
|
|
1170
|
+
function useScreenReader() {
|
|
1171
|
+
const [enabled, setEnabled] = useState2(false);
|
|
1172
|
+
useEffect3(() => {
|
|
1173
|
+
let active = true, changed = false;
|
|
1174
|
+
const sub = AccessibilityInfo.addEventListener("screenReaderChanged", (value) => {
|
|
1175
|
+
changed = true;
|
|
1176
|
+
setEnabled(value);
|
|
1177
|
+
});
|
|
1178
|
+
AccessibilityInfo.isScreenReaderEnabled().then((value) => {
|
|
1179
|
+
if (active && !changed) setEnabled(value);
|
|
1180
|
+
}).catch(() => {
|
|
1181
|
+
});
|
|
1182
|
+
return () => {
|
|
1183
|
+
active = false;
|
|
1184
|
+
sub.remove();
|
|
1185
|
+
};
|
|
1186
|
+
}, []);
|
|
1187
|
+
return enabled;
|
|
1188
|
+
}
|
|
1189
|
+
function focusControl(node) {
|
|
1190
|
+
if (!node) return;
|
|
1191
|
+
if (typeof AccessibilityInfo.sendAccessibilityEvent === "function") AccessibilityInfo.sendAccessibilityEvent(node, "focus");
|
|
1192
|
+
else {
|
|
1193
|
+
const tag = findNodeHandle(node);
|
|
1194
|
+
if (typeof tag === "number") AccessibilityInfo.setAccessibilityFocus(tag);
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
function LayerControls(props) {
|
|
1198
|
+
const reader = useScreenReader(), { bounds, offsetX, clusters, annotations, hidden, choices, choose, locale, precision, ink, surface } = props;
|
|
1199
|
+
const moreButton = useRef4(null);
|
|
1200
|
+
const heading = useRef4(null);
|
|
1201
|
+
const restoreFocus = useRef4(false);
|
|
1202
|
+
useEffect3(() => {
|
|
1203
|
+
if (choices || !restoreFocus.current) return;
|
|
1204
|
+
restoreFocus.current = false;
|
|
1205
|
+
if (!reader) return;
|
|
1206
|
+
const id = requestAnimationFrame(() => focusControl(moreButton.current));
|
|
1207
|
+
return () => cancelAnimationFrame(id);
|
|
1208
|
+
}, [choices, reader]);
|
|
1209
|
+
useEffect3(() => {
|
|
1210
|
+
if (!choices) return;
|
|
1211
|
+
const subscription = BackHandler.addEventListener("hardwareBackPress", () => {
|
|
1212
|
+
choose(null);
|
|
1213
|
+
return true;
|
|
1214
|
+
});
|
|
1215
|
+
return () => subscription.remove();
|
|
1216
|
+
}, [choices, choose]);
|
|
1217
|
+
const zh = /^zh\b/i.test(locale ?? new Intl.NumberFormat().resolvedOptions().locale);
|
|
1218
|
+
const more = zh ? "\u9084\u6709 " + hidden.length + " \u5247" : "+" + hidden.length + " more";
|
|
1219
|
+
const description = (a) => annotationDescription(a, precision, locale);
|
|
1220
|
+
function proxy(key, x, y, label, press) {
|
|
1221
|
+
const left = Math.max(bounds.left, Math.min(x - 22, bounds.right - 44)) + offsetX;
|
|
1222
|
+
const top = Math.max(bounds.top, Math.min(y - 22, bounds.bottom - 44));
|
|
1223
|
+
return /* @__PURE__ */ jsx4(
|
|
1224
|
+
Pressable,
|
|
1225
|
+
{
|
|
1226
|
+
accessible: true,
|
|
1227
|
+
accessibilityLabel: label,
|
|
1228
|
+
accessibilityRole: press ? "button" : "text",
|
|
1229
|
+
onPress: press,
|
|
1230
|
+
style: [styles.target, { left, top }]
|
|
1231
|
+
},
|
|
1232
|
+
key
|
|
1233
|
+
);
|
|
1234
|
+
}
|
|
1235
|
+
return /* @__PURE__ */ jsxs4(View, { pointerEvents: "box-none", style: StyleSheet.absoluteFill, children: [
|
|
1236
|
+
reader && !choices && clusters.map((c) => proxy(
|
|
1237
|
+
"marker-" + c.slot,
|
|
1238
|
+
c.x,
|
|
1239
|
+
c.y,
|
|
1240
|
+
c.representative.label + (zh ? "\uFF0C" + c.members.length + " \u5247\u5E02\u5834\u89C0\u9EDE" : ", " + c.members.length + " market events"),
|
|
1241
|
+
props.onMarkerPress && (() => props.onMarkerPress?.(c.members))
|
|
1242
|
+
)),
|
|
1243
|
+
reader && !choices && annotations.map(({ entry, point }) => proxy(
|
|
1244
|
+
"annotation-" + entry.spec.key,
|
|
1245
|
+
point.x,
|
|
1246
|
+
point.y,
|
|
1247
|
+
(zh ? "AI \u6A19\u8A3B\uFF0C" : "AI annotation, ") + description(entry.spec),
|
|
1248
|
+
props.onAnnotationPress && (() => props.onAnnotationPress?.(entry.spec))
|
|
1249
|
+
)),
|
|
1250
|
+
!choices && hidden.length > 0 && /* @__PURE__ */ jsx4(
|
|
1251
|
+
Pressable,
|
|
1252
|
+
{
|
|
1253
|
+
ref: moreButton,
|
|
1254
|
+
accessibilityRole: "button",
|
|
1255
|
+
onPress: () => {
|
|
1256
|
+
restoreFocus.current = true;
|
|
1257
|
+
choose(hidden);
|
|
1258
|
+
},
|
|
1259
|
+
hitSlop: 4,
|
|
1260
|
+
accessibilityLabel: zh ? "\u9084\u6709 " + hidden.length + " \u5247\u91CD\u758A\u7684 AI \u6A19\u8A3B" : hidden.length + " more overlapping AI annotations",
|
|
1261
|
+
style: [styles.more, { left: bounds.left + offsetX + 6, top: Math.max(bounds.top, bounds.bottom - 44), backgroundColor: surface, borderColor: ink }],
|
|
1262
|
+
children: /* @__PURE__ */ jsx4(Text3, { style: { color: ink, fontWeight: "600" }, children: more })
|
|
1263
|
+
}
|
|
1264
|
+
),
|
|
1265
|
+
choices && /* @__PURE__ */ jsxs4(View, { accessibilityViewIsModal: true, onAccessibilityEscape: () => choose(null), style: [StyleSheet.absoluteFill, styles.backdrop], children: [
|
|
1266
|
+
/* @__PURE__ */ jsx4(Pressable, { style: StyleSheet.absoluteFill, accessible: false, onPress: () => choose(null) }),
|
|
1267
|
+
/* @__PURE__ */ jsxs4(View, { style: [styles.sheet, { backgroundColor: surface }], children: [
|
|
1268
|
+
/* @__PURE__ */ jsxs4(View, { style: styles.header, children: [
|
|
1269
|
+
/* @__PURE__ */ jsx4(Text3, { ref: heading, accessible: true, accessibilityRole: "header", onLayout: () => {
|
|
1270
|
+
if (reader) focusControl(heading.current);
|
|
1271
|
+
}, style: [styles.title, { color: ink }], children: zh ? "AI \u6A19\u8A3B" : "AI annotations" }),
|
|
1272
|
+
/* @__PURE__ */ jsx4(Pressable, { accessibilityRole: "button", onPress: () => choose(null), style: styles.close, children: /* @__PURE__ */ jsx4(Text3, { style: { color: ink }, children: zh ? "\u95DC\u9589" : "Close" }) })
|
|
1273
|
+
] }),
|
|
1274
|
+
/* @__PURE__ */ jsx4(FlatList, { data: choices, keyExtractor: (item) => item.key, keyboardShouldPersistTaps: "handled", renderItem: ({ item }) => props.onAnnotationPress ? /* @__PURE__ */ jsx4(Pressable, { accessibilityRole: "button", style: styles.row, onPress: () => {
|
|
1275
|
+
restoreFocus.current = false;
|
|
1276
|
+
choose(null);
|
|
1277
|
+
props.onAnnotationPress?.(item);
|
|
1278
|
+
}, children: /* @__PURE__ */ jsx4(Text3, { style: { color: ink }, children: description(item) }) }) : /* @__PURE__ */ jsx4(Text3, { style: [styles.row, { color: ink }], children: description(item) }) })
|
|
1279
|
+
] })
|
|
1280
|
+
] })
|
|
1281
|
+
] });
|
|
1282
|
+
}
|
|
1283
|
+
var styles = StyleSheet.create({
|
|
1284
|
+
target: { position: "absolute", width: 44, height: 44 },
|
|
1285
|
+
more: { position: "absolute", minHeight: 44, justifyContent: "center", paddingHorizontal: 9, borderWidth: StyleSheet.hairlineWidth, borderRadius: 12 },
|
|
1286
|
+
backdrop: { flex: 1, justifyContent: "flex-end", backgroundColor: "rgba(0,0,0,0.38)" },
|
|
1287
|
+
sheet: { maxHeight: "75%", padding: 16, paddingBottom: 32, borderTopLeftRadius: 20, borderTopRightRadius: 20 },
|
|
1288
|
+
header: { flexDirection: "row", alignItems: "center", justifyContent: "space-between" },
|
|
1289
|
+
title: { fontSize: 18, fontWeight: "600" },
|
|
1290
|
+
close: { minHeight: 44, justifyContent: "center", paddingHorizontal: 8 },
|
|
1291
|
+
row: { minHeight: 48, justifyContent: "center", paddingVertical: 12 }
|
|
1292
|
+
});
|
|
1293
|
+
|
|
1294
|
+
// packages/bindings/react-native/src/markerBuckets.ts
|
|
1295
|
+
import { nearestBarIndex as nearestBarIndex2 } from "@supersolutions/super-chart-core";
|
|
1296
|
+
function markerBucketSpan(frame) {
|
|
1297
|
+
const { i0, i1 } = frame.snapshot.viewport;
|
|
1298
|
+
return Math.max(1, Math.ceil(48 * (i1 - i0) / Math.max(1, frame.model.geometry.plotWidth) - 1e-8));
|
|
1299
|
+
}
|
|
1300
|
+
function indexMarkers(bars, markers, span) {
|
|
1301
|
+
const buckets = /* @__PURE__ */ new Map();
|
|
1302
|
+
if (!bars.length) return buckets;
|
|
1303
|
+
const last = bars.length - 1;
|
|
1304
|
+
for (const marker of markers) {
|
|
1305
|
+
if (!Number.isFinite(marker.time) || !Number.isFinite(marker.price)) continue;
|
|
1306
|
+
let index;
|
|
1307
|
+
if (marker.time < bars[0].timestamp || marker.time > bars[last].timestamp) {
|
|
1308
|
+
if (last === 0) continue;
|
|
1309
|
+
const edge = marker.time < bars[0].timestamp ? 0 : last;
|
|
1310
|
+
const period = edge === 0 ? bars[1].timestamp - bars[0].timestamp : bars[last].timestamp - bars[last - 1].timestamp;
|
|
1311
|
+
index = edge + Math.round((marker.time - bars[edge].timestamp) / period);
|
|
1312
|
+
} else index = nearestBarIndex2(bars, marker.time) ?? 0;
|
|
1313
|
+
const slot = Math.floor(index / span), bucket = buckets.get(slot);
|
|
1314
|
+
if (!bucket) {
|
|
1315
|
+
buckets.set(slot, { members: [marker], representative: marker });
|
|
1316
|
+
continue;
|
|
1317
|
+
}
|
|
1318
|
+
bucket.members.push(marker);
|
|
1319
|
+
const prev = bucket.representative;
|
|
1320
|
+
if (Boolean(marker.avatarUri) !== Boolean(prev.avatarUri) ? Boolean(marker.avatarUri) : marker.time > prev.time || marker.time === prev.time && marker.id < prev.id) bucket.representative = marker;
|
|
1321
|
+
}
|
|
1322
|
+
return buckets;
|
|
1323
|
+
}
|
|
1324
|
+
function visibleMarkerClusters(frame, buckets, span, bounds = frame.model.geometry) {
|
|
1325
|
+
const geometry = frame.model.geometry, view = frame.snapshot.viewport;
|
|
1326
|
+
if (bounds.right - bounds.left < 32 || bounds.bottom - bounds.top < 32) return [];
|
|
1327
|
+
const result = [];
|
|
1328
|
+
const step = geometry.plotWidth / Math.max(1, view.i1 - view.i0);
|
|
1329
|
+
const leftIndex = view.i0 + (bounds.left - geometry.left) / step;
|
|
1330
|
+
const rightIndex = view.i0 + (bounds.right - geometry.left) / step;
|
|
1331
|
+
const first = Math.floor((leftIndex - 0.5) / span), last = Math.floor((rightIndex + 0.5) / span);
|
|
1332
|
+
for (let slot = first; slot <= last; slot++) {
|
|
1333
|
+
const bucket = buckets.get(slot);
|
|
1334
|
+
if (!bucket) continue;
|
|
1335
|
+
const { representative, members } = bucket;
|
|
1336
|
+
const anchor = frame.project(representative.time, representative.price);
|
|
1337
|
+
if (!anchor) continue;
|
|
1338
|
+
if (!contains(bounds, anchor) && !members.some((m) => {
|
|
1339
|
+
const p = frame.project(m.time, m.price);
|
|
1340
|
+
return p !== null && contains(bounds, p);
|
|
1341
|
+
})) continue;
|
|
1342
|
+
const center = geometry.left + (slot * span + (span - 1) / 2 - view.i0) * step;
|
|
1343
|
+
const x = Math.min(bounds.right - 14, Math.max(bounds.left + 14, center));
|
|
1344
|
+
const preferredY = anchor.y < bounds.top + 48 ? anchor.y + 25 : anchor.y - 24;
|
|
1345
|
+
const y = Math.min(bounds.bottom - 16, Math.max(bounds.top + 20, preferredY));
|
|
1346
|
+
result.push({ slot, x, y, anchor, representative, members });
|
|
1347
|
+
}
|
|
1348
|
+
return result;
|
|
1349
|
+
}
|
|
1350
|
+
|
|
1351
|
+
// packages/bindings/react-native/src/overlays.tsx
|
|
1352
|
+
import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
1353
|
+
var avatars = new AvatarCache();
|
|
1354
|
+
var EMPTY_ANNOTATIONS = [];
|
|
1355
|
+
var EMPTY_MARKERS = [];
|
|
1356
|
+
var DEFAULT_COLORS = { accent: "#8468ef", bull: "#008b72", bear: "#d34f66", neutral: "#858398", surface: "#ffffff" };
|
|
1357
|
+
function Figure({ figure: f, color, palette, scale }) {
|
|
1358
|
+
const ink = f.color ?? ("tone" in f && f.tone ? palette[f.tone] : color);
|
|
1359
|
+
if (f.type === "text") {
|
|
1360
|
+
const chars = Array.from(f.text);
|
|
1361
|
+
const label = chars.length > 26 ? chars.slice(0, 25).join("") + "\u2026" : f.text;
|
|
1362
|
+
return /* @__PURE__ */ jsx5(Text4, { x: f.x, y: f.y, fontSize: 10 * scale, fontWeight: "600", fill: ink, textAnchor: f.align === "center" ? "middle" : f.align === "right" ? "end" : "start", children: label });
|
|
1363
|
+
}
|
|
1364
|
+
if (f.type === "marker") {
|
|
1365
|
+
const r = f.size ?? 5;
|
|
1366
|
+
if (f.shape === "circle") return /* @__PURE__ */ jsx5(Circle4, { cx: f.x, cy: f.y, r, fill: ink });
|
|
1367
|
+
const triangle = f.shape === "triangle-up" || f.shape === "triangle-down";
|
|
1368
|
+
const direction = f.shape === "triangle-down" ? -1 : 1;
|
|
1369
|
+
const d = triangle ? linePath([{ x: f.x, y: f.y - direction * r }, { x: f.x + r, y: f.y + direction * r }, { x: f.x - r, y: f.y + direction * r }]) + " Z" : "M" + f.x + " " + (f.y - r) + "l" + r + " " + r + "l-" + r + " " + r + "l-" + r + " -" + r + "Z";
|
|
1370
|
+
return /* @__PURE__ */ jsx5(Path3, { d, fill: ink });
|
|
1371
|
+
}
|
|
1372
|
+
const dash = f.dash === "solid" ? void 0 : [...f.dash ?? [4, 3]];
|
|
1373
|
+
if (f.type === "line") return /* @__PURE__ */ jsx5(Line2, { x1: f.from.x, y1: f.from.y, x2: f.to.x, y2: f.to.y, stroke: ink, strokeWidth: f.width ?? 1.5, strokeDasharray: dash });
|
|
1374
|
+
const stroke = f.stroke === false ? "none" : ink;
|
|
1375
|
+
if (f.type === "rect") return /* @__PURE__ */ jsx5(Rect3, { x: f.x, y: f.y, width: f.width, height: f.height, fill: ink, fillOpacity: f.fillOpacity ?? 0, stroke, strokeDasharray: dash, strokeWidth: 1 });
|
|
1376
|
+
return /* @__PURE__ */ jsx5(Path3, { d: linePath(f.points) + (f.closed ? " Z" : ""), fill: ink, fillOpacity: f.fillOpacity ?? 0, stroke, strokeWidth: f.width ?? 1.5, strokeDasharray: dash });
|
|
1377
|
+
}
|
|
1378
|
+
function Bubble({ cluster, prefix, surface, accent, scale }) {
|
|
1379
|
+
const representative = cluster.representative;
|
|
1380
|
+
const { x, y, anchor } = cluster, color = representative.color ?? accent;
|
|
1381
|
+
const clip = prefix + "-avatar-" + cluster.slot;
|
|
1382
|
+
const count = cluster.members.length;
|
|
1383
|
+
const badge = count > 99 ? "99+" : String(count);
|
|
1384
|
+
const badgeWidth = Math.max(13, badge.length * 5.8 + 5) * scale;
|
|
1385
|
+
const initials = Array.from(representative.label.trim())[0]?.toLocaleUpperCase() ?? "\u2022";
|
|
1386
|
+
return /* @__PURE__ */ jsxs5(G4, { children: [
|
|
1387
|
+
/* @__PURE__ */ jsx5(Line2, { x1: anchor.x, y1: anchor.y, x2: x, y2: y, stroke: color, strokeOpacity: 0.65 }),
|
|
1388
|
+
/* @__PURE__ */ jsx5(Circle4, { cx: anchor.x, cy: anchor.y, r: 2, fill: color }),
|
|
1389
|
+
/* @__PURE__ */ jsx5(Circle4, { cx: x, cy: y, r: 12.5, fill: surface, stroke: color, strokeWidth: 2 }),
|
|
1390
|
+
/* @__PURE__ */ jsx5(Text4, { x, y: y + 4 * scale, textAnchor: "middle", fontSize: 11 * scale, fontWeight: "700", fill: color, children: initials }),
|
|
1391
|
+
representative.avatarUri && /* @__PURE__ */ jsxs5(G4, { children: [
|
|
1392
|
+
/* @__PURE__ */ jsx5(Defs, { children: /* @__PURE__ */ jsx5(ClipPath, { id: clip, children: /* @__PURE__ */ jsx5(Circle4, { cx: x, cy: y, r: 11 }) }) }),
|
|
1393
|
+
/* @__PURE__ */ jsx5(Image2, { href: { uri: representative.avatarUri }, x: x - 11, y: y - 11, width: 22, height: 22, preserveAspectRatio: "xMidYMid slice", clipPath: "url(#" + clip + ")" })
|
|
1394
|
+
] }),
|
|
1395
|
+
count > 1 && /* @__PURE__ */ jsxs5(G4, { children: [
|
|
1396
|
+
/* @__PURE__ */ jsx5(Rect3, { x: x + 3, y: y - 5 - 13 * scale, width: badgeWidth, height: 13 * scale, rx: 6, fill: color, stroke: surface, strokeWidth: 1 }),
|
|
1397
|
+
/* @__PURE__ */ jsx5(Text4, { x: x + 3 + badgeWidth / 2, y: y - 5 - 3.4 * scale, fill: surface, fontSize: 8 * scale, textAnchor: "middle", fontWeight: "700", children: badge })
|
|
1398
|
+
] })
|
|
1399
|
+
] });
|
|
1400
|
+
}
|
|
1401
|
+
function useNativeLayers(frame, props, window) {
|
|
1402
|
+
const { fontScale: scale } = useWindowDimensions2();
|
|
1403
|
+
const [choices, choose] = useState3(null);
|
|
1404
|
+
const id = "sc" + useId().replace(/[^a-zA-Z0-9_-]/g, "");
|
|
1405
|
+
const palette = useMemo3(() => ({ ...DEFAULT_COLORS, ...props.layerColors }), [props.layerColors]);
|
|
1406
|
+
const annotations = props.annotations ?? EMPTY_ANNOTATIONS, markers = props.markers ?? EMPTY_MARKERS;
|
|
1407
|
+
const bounds = frame?.model.geometry;
|
|
1408
|
+
const visible = useMemo3(() => bounds && {
|
|
1409
|
+
left: window?.left ?? bounds.left,
|
|
1410
|
+
right: window?.right ?? bounds.right,
|
|
1411
|
+
top: bounds.top,
|
|
1412
|
+
bottom: bounds.bottom
|
|
1413
|
+
}, [bounds, window?.left, window?.right]);
|
|
1414
|
+
const wide = window !== void 0;
|
|
1415
|
+
const layout = useMemo3(() => {
|
|
1416
|
+
if (!frame || !visible) return { painted: [], visible: [], hidden: [] };
|
|
1417
|
+
const project = (clip) => annotations.flatMap((a) => projectAnnotation(frame, a, palette, props.locale, clip, props.precision) ?? []);
|
|
1418
|
+
const inView = layoutAnnotationLabels(project(visible), visible, scale);
|
|
1419
|
+
if (!wide) return { ...inView, painted: inView.visible };
|
|
1420
|
+
const byId = new Map(inView.visible.map((a) => [a.spec.key, a.figures.filter((f) => f.type === "text")]));
|
|
1421
|
+
const painted = project(frame.model.geometry).map((a) => ({ ...a, figures: [...a.figures.filter((f) => f.type !== "text"), ...byId.get(a.spec.key) ?? []] }));
|
|
1422
|
+
return { ...inView, painted };
|
|
1423
|
+
}, [frame, visible, annotations, palette, props.locale, props.precision, scale, wide]);
|
|
1424
|
+
const span = frame ? markerBucketSpan(frame) : 1, bars = frame?.drawingContext.bars;
|
|
1425
|
+
const buckets = useMemo3(() => indexMarkers(bars ?? [], markers, span), [bars, markers, span]);
|
|
1426
|
+
const { clusters, buffered } = useMemo3(() => {
|
|
1427
|
+
if (!frame || !visible) return { clusters: [], buffered: [] };
|
|
1428
|
+
const clusters2 = visibleMarkerClusters(frame, buckets, span, visible);
|
|
1429
|
+
if (!wide) return { clusters: clusters2, buffered: clusters2 };
|
|
1430
|
+
const visibleBySlot = new Map(clusters2.map((c) => [c.slot, c]));
|
|
1431
|
+
const buffered2 = visibleMarkerClusters(frame, buckets, span).map((c) => visibleBySlot.get(c.slot) ?? c);
|
|
1432
|
+
return { clusters: clusters2, buffered: buffered2 };
|
|
1433
|
+
}, [frame, visible, buckets, span, wide]);
|
|
1434
|
+
useEffect4(() => {
|
|
1435
|
+
for (const c of buffered) if (c.representative.avatarUri) avatars.warm(c.representative.avatarUri, (uri) => NativeImage.prefetch(uri));
|
|
1436
|
+
}, [buffered]);
|
|
1437
|
+
const focus = useMemo3(() => visible ? layout.visible.flatMap((entry) => {
|
|
1438
|
+
const point = annotationPosition(entry, visible);
|
|
1439
|
+
return point ? [{ entry, point }] : [];
|
|
1440
|
+
}) : [], [layout, visible]);
|
|
1441
|
+
const drawing = useDrawingInteraction(frame, props, palette.accent, palette.surface);
|
|
1442
|
+
function tap(point) {
|
|
1443
|
+
if (!bounds || !contains(bounds, point)) return false;
|
|
1444
|
+
if (props.drawingTool) return drawing.tap(point);
|
|
1445
|
+
if (props.onMarkerPress) {
|
|
1446
|
+
const cluster = clusters.find((c) => Math.hypot(c.x - point.x, c.y - point.y) <= 24);
|
|
1447
|
+
if (cluster) {
|
|
1448
|
+
props.onMarkerPress(cluster.members);
|
|
1449
|
+
return true;
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
if (drawing.tap(point)) return true;
|
|
1453
|
+
const hits = layout.visible.filter((entry) => hitsAnnotation(entry, point, scale)).map((a) => a.spec);
|
|
1454
|
+
if (hits.length > 1) {
|
|
1455
|
+
choose(hits);
|
|
1456
|
+
return true;
|
|
1457
|
+
}
|
|
1458
|
+
if (hits.length === 1 && props.onAnnotationPress) {
|
|
1459
|
+
props.onAnnotationPress(hits[0]);
|
|
1460
|
+
return true;
|
|
1461
|
+
}
|
|
1462
|
+
return false;
|
|
1463
|
+
}
|
|
1464
|
+
const annotationNodes = useMemo3(() => layout.painted.map(({ spec, figures, color }) => /* @__PURE__ */ jsx5(G4, { children: figures.map((f, i) => /* @__PURE__ */ jsx5(Figure, { figure: f, color, palette, scale }, i)) }, spec.key)), [layout, palette, scale]);
|
|
1465
|
+
const bubbleNodes = useMemo3(() => buffered.map((c) => /* @__PURE__ */ jsx5(Bubble, { cluster: c, prefix: id, surface: palette.surface, accent: palette.accent, scale }, c.slot)), [buffered, id, palette, scale]);
|
|
1466
|
+
const controls = visible && props.interactionMode !== "none" && (clusters.length > 0 || focus.length > 0) && /* @__PURE__ */ jsx5(
|
|
1467
|
+
LayerControls,
|
|
1468
|
+
{
|
|
1469
|
+
bounds: visible,
|
|
1470
|
+
offsetX: window?.offsetX ?? 0,
|
|
1471
|
+
clusters,
|
|
1472
|
+
annotations: focus,
|
|
1473
|
+
hidden: layout.hidden,
|
|
1474
|
+
choices,
|
|
1475
|
+
choose,
|
|
1476
|
+
locale: props.locale,
|
|
1477
|
+
precision: props.precision ?? frame?.pricePrecision ?? 2,
|
|
1478
|
+
ink: palette.accent,
|
|
1479
|
+
surface: palette.surface,
|
|
1480
|
+
onMarkerPress: props.onMarkerPress,
|
|
1481
|
+
onAnnotationPress: props.onAnnotationPress
|
|
1482
|
+
}
|
|
1483
|
+
);
|
|
1484
|
+
return { ...drawing, tap, controls, nodes: bounds && /* @__PURE__ */ jsxs5(G4, { children: [
|
|
1485
|
+
/* @__PURE__ */ jsx5(Defs, { children: /* @__PURE__ */ jsx5(ClipPath, { id, children: /* @__PURE__ */ jsx5(Rect3, { x: bounds.left, y: bounds.top, width: bounds.right - bounds.left, height: bounds.bottom - bounds.top }) }) }),
|
|
1486
|
+
/* @__PURE__ */ jsxs5(G4, { clipPath: "url(#" + id + ")", children: [
|
|
1487
|
+
annotationNodes,
|
|
1488
|
+
drawing.nodes,
|
|
1489
|
+
bubbleNodes
|
|
1490
|
+
] })
|
|
1491
|
+
] }) };
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
// packages/bindings/react-native/src/plot.tsx
|
|
1495
|
+
import * as React6 from "react";
|
|
1496
|
+
import { useWindowDimensions as useWindowDimensions3 } from "react-native";
|
|
1497
|
+
import { ClipPath as ClipPath2, Defs as Defs2, G as G5, Line as Line3, Path as Path4, Rect as Rect4, Text as Text5 } from "react-native-svg";
|
|
1498
|
+
import {
|
|
1499
|
+
timeAxisTicks
|
|
1500
|
+
} from "@supersolutions/super-chart-core";
|
|
1501
|
+
import { Fragment, jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
1502
|
+
var px = (value) => String(Math.round(value * 100) / 100);
|
|
1503
|
+
var swatches = ["#438be0", "#d79036", "#b467cf", "#45a8a3", "#e07b78"];
|
|
1504
|
+
function seriesColor(pane, id, theme) {
|
|
1505
|
+
const index = pane.frame.model.plottedSeries.findIndex((series) => series.source.id === id);
|
|
1506
|
+
return pane.frame.figureStyles?.get(id)?.color ?? (index < 0 ? theme.accent : swatches[index % swatches.length]);
|
|
1507
|
+
}
|
|
1508
|
+
function linePath2(points) {
|
|
1509
|
+
let previous = -2;
|
|
1510
|
+
return points.map((point) => {
|
|
1511
|
+
const command = point.index === previous + 1 ? "L" : "M";
|
|
1512
|
+
previous = point.index;
|
|
1513
|
+
return command + px(point.x) + " " + px(point.y);
|
|
1514
|
+
}).join("");
|
|
1515
|
+
}
|
|
1516
|
+
function bodyWidth(model) {
|
|
1517
|
+
const step = model.xPositions.length > 1 ? Math.abs(model.xPositions[1] - model.xPositions[0]) : 7;
|
|
1518
|
+
return Math.max(0.75, Math.min(25, step * 0.68));
|
|
1519
|
+
}
|
|
1520
|
+
function Candles({ model, mode, theme }) {
|
|
1521
|
+
if (mode === "line") {
|
|
1522
|
+
const points = model.plottedCandles.map((bar) => ({ x: bar.x, y: model.y(bar.c), index: bar.index }));
|
|
1523
|
+
return /* @__PURE__ */ jsx6(Path4, { d: linePath2(points), fill: "none", stroke: theme.accent, strokeWidth: 1.8 });
|
|
1524
|
+
}
|
|
1525
|
+
const bodies = ["", ""], wicks = ["", ""];
|
|
1526
|
+
const width = bodyWidth(model);
|
|
1527
|
+
for (const bar of model.plottedCandles) {
|
|
1528
|
+
const side = bar.c >= bar.o ? 0 : 1;
|
|
1529
|
+
wicks[side] += "M" + px(bar.x) + " " + px(bar.wickTop) + "V" + px(bar.wickBottom);
|
|
1530
|
+
bodies[side] += "M" + px(bar.x - width / 2) + " " + px(bar.bodyTop) + "h" + px(width) + "v" + px(Math.max(1, bar.bodyBottom - bar.bodyTop)) + "h-" + px(width) + "Z";
|
|
1531
|
+
}
|
|
1532
|
+
return /* @__PURE__ */ jsx6(Fragment, { children: [theme.up, theme.down].map((color, side) => /* @__PURE__ */ jsxs6(G5, { children: [
|
|
1533
|
+
/* @__PURE__ */ jsx6(Path4, { d: wicks[side], stroke: color, strokeWidth: 1, fill: "none" }),
|
|
1534
|
+
/* @__PURE__ */ jsx6(Path4, { d: bodies[side], fill: color })
|
|
1535
|
+
] }, side)) });
|
|
1536
|
+
}
|
|
1537
|
+
function Series({ pane, theme, behind }) {
|
|
1538
|
+
const { model, figureStyles, snapshot } = pane.frame;
|
|
1539
|
+
const width = bodyWidth(model);
|
|
1540
|
+
return /* @__PURE__ */ jsx6(Fragment, { children: model.plottedSeries.filter(({ source }) => source.type === "bar" === behind).map(({ source, points, zeroY }) => {
|
|
1541
|
+
const style = figureStyles?.get(source.id);
|
|
1542
|
+
const color = seriesColor(pane, source.id, theme);
|
|
1543
|
+
if (source.type === "scatter") {
|
|
1544
|
+
const circles = points.map((p) => "M" + px(p.x) + " " + px(p.y) + "h0.05").join("");
|
|
1545
|
+
return /* @__PURE__ */ jsx6(Path4, { d: circles, stroke: color, strokeLinecap: "round", strokeWidth: 3, fill: "none" }, source.id);
|
|
1546
|
+
}
|
|
1547
|
+
if (source.type !== "bar") return /* @__PURE__ */ jsx6(
|
|
1548
|
+
Path4,
|
|
1549
|
+
{
|
|
1550
|
+
d: linePath2(points),
|
|
1551
|
+
fill: "none",
|
|
1552
|
+
stroke: color,
|
|
1553
|
+
strokeWidth: style?.lineWidth ?? 1.5,
|
|
1554
|
+
strokeDasharray: style?.dash ? Array.from(style.dash) : void 0
|
|
1555
|
+
},
|
|
1556
|
+
source.id
|
|
1557
|
+
);
|
|
1558
|
+
const buckets = /* @__PURE__ */ new Map();
|
|
1559
|
+
const baseline = zeroY ?? model.y(style?.base ?? 0);
|
|
1560
|
+
if (!Number.isFinite(baseline)) return null;
|
|
1561
|
+
points.forEach((point, i) => {
|
|
1562
|
+
const previous = points[i - 1]?.value ?? point.value;
|
|
1563
|
+
const bar = snapshot.bars[point.index];
|
|
1564
|
+
let stroke = color;
|
|
1565
|
+
if (style?.byChange) stroke = point.value >= previous ? theme.up : theme.down;
|
|
1566
|
+
else if (style?.momentum) stroke = point.value >= 0 ? theme.up : theme.down;
|
|
1567
|
+
else if (style?.key === "volume" && bar) stroke = bar.close >= bar.open ? theme.up : theme.down;
|
|
1568
|
+
const muted = style?.momentum && point.value >= 0 !== point.value >= previous;
|
|
1569
|
+
const bucket = stroke + (muted ? "|muted" : "");
|
|
1570
|
+
buckets.set(bucket, (buckets.get(bucket) ?? "") + "M" + px(point.x) + " " + px(baseline) + "V" + px(point.y));
|
|
1571
|
+
});
|
|
1572
|
+
return /* @__PURE__ */ jsx6(G5, { opacity: source.overlay ? 0.4 : 0.85, children: Array.from(buckets, ([key, path]) => /* @__PURE__ */ jsx6(
|
|
1573
|
+
Path4,
|
|
1574
|
+
{
|
|
1575
|
+
d: path,
|
|
1576
|
+
stroke: key.split("|")[0],
|
|
1577
|
+
opacity: key.endsWith("|muted") ? 0.52 : 1,
|
|
1578
|
+
strokeWidth: width,
|
|
1579
|
+
fill: "none"
|
|
1580
|
+
},
|
|
1581
|
+
key
|
|
1582
|
+
)) }, source.id);
|
|
1583
|
+
}) });
|
|
1584
|
+
}
|
|
1585
|
+
function Bands({ pane, theme }) {
|
|
1586
|
+
const series = pane.frame.model.plottedSeries;
|
|
1587
|
+
return /* @__PURE__ */ jsx6(Fragment, { children: series.flatMap((item) => {
|
|
1588
|
+
const style = pane.frame.figureStyles?.get(item.source.id);
|
|
1589
|
+
if (!style?.fillTo) return [];
|
|
1590
|
+
const owner = JSON.parse(item.source.id)[0];
|
|
1591
|
+
const other = series.find((s) => s.source.id === JSON.stringify([owner, style.fillTo]));
|
|
1592
|
+
if (!other) return [];
|
|
1593
|
+
const byIndex = new Map(other.points.map((point) => [point.index, point]));
|
|
1594
|
+
const paths = ["", ""];
|
|
1595
|
+
const colors = style.fillColors ?? [seriesColor(pane, item.source.id, theme), seriesColor(pane, item.source.id, theme)];
|
|
1596
|
+
const vertex = (x, y) => px(x) + " " + px(y);
|
|
1597
|
+
for (let i = 1; i < item.points.length; i++) {
|
|
1598
|
+
const a = item.points[i - 1], b = item.points[i];
|
|
1599
|
+
if (b.index !== a.index + 1) continue;
|
|
1600
|
+
const c = byIndex.get(a.index), d = byIndex.get(b.index);
|
|
1601
|
+
if (!c || !d) continue;
|
|
1602
|
+
const before = a.y - c.y, after = b.y - d.y;
|
|
1603
|
+
const side = (before || after) > 0 ? 1 : 0;
|
|
1604
|
+
const start = "M" + vertex(a.x, a.y), end = "L" + vertex(b.x, b.y) + "L" + vertex(b.x, d.y);
|
|
1605
|
+
if (before * after < 0) {
|
|
1606
|
+
const t = before / (before - after);
|
|
1607
|
+
const cross = vertex(a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t);
|
|
1608
|
+
paths[side] += start + "L" + cross + "L" + vertex(a.x, c.y) + "Z";
|
|
1609
|
+
paths[1 - side] += "M" + cross + end + "Z";
|
|
1610
|
+
} else paths[side] += start + end + "L" + vertex(a.x, c.y) + "Z";
|
|
1611
|
+
}
|
|
1612
|
+
return paths.map((path, side) => /* @__PURE__ */ jsx6(Path4, { d: path, fill: colors[side], fillOpacity: 0.1 }, item.source.id + side));
|
|
1613
|
+
}) });
|
|
1614
|
+
}
|
|
1615
|
+
var ChartPlot = React6.memo(function ChartPlot2({
|
|
1616
|
+
frame,
|
|
1617
|
+
mode,
|
|
1618
|
+
theme,
|
|
1619
|
+
precision,
|
|
1620
|
+
timespan,
|
|
1621
|
+
locale,
|
|
1622
|
+
timeZone,
|
|
1623
|
+
symbolTimezone,
|
|
1624
|
+
clipPrefix,
|
|
1625
|
+
part
|
|
1626
|
+
}) {
|
|
1627
|
+
const { fontScale } = useWindowDimensions3();
|
|
1628
|
+
const chart = part !== "axis", axis = part !== "plot";
|
|
1629
|
+
const { geometry, xPositions } = frame.model;
|
|
1630
|
+
const ticks = timeAxisTicks(frame.snapshot.bars.map((bar) => bar.timestamp), xPositions, {
|
|
1631
|
+
minSpacing: 55 * fontScale,
|
|
1632
|
+
left: geometry.left,
|
|
1633
|
+
right: geometry.right,
|
|
1634
|
+
timeZone,
|
|
1635
|
+
symbolTimezone,
|
|
1636
|
+
timespan,
|
|
1637
|
+
locale
|
|
1638
|
+
});
|
|
1639
|
+
const latest = frame.snapshot.latestBar;
|
|
1640
|
+
return /* @__PURE__ */ jsx6(Fragment, { children: frame.panes.map((pane, i) => {
|
|
1641
|
+
const { model } = pane.frame;
|
|
1642
|
+
const g = model.geometry;
|
|
1643
|
+
const clip = clipPrefix + "pane" + i;
|
|
1644
|
+
const primary = pane.id === "price";
|
|
1645
|
+
const lastY = primary && latest ? pane.scale.y(latest.close) : NaN;
|
|
1646
|
+
const showLast = lastY >= g.top && lastY <= g.bottom;
|
|
1647
|
+
const lastColor = latest && latest.close < latest.open ? theme.down : theme.up;
|
|
1648
|
+
const lastTag = latest ? formatScaleLabel(pane.scale.label(latest.close, precision), locale) : "";
|
|
1649
|
+
let prevLabelY = -Infinity;
|
|
1650
|
+
return /* @__PURE__ */ jsxs6(G5, { translateY: pane.top, children: [
|
|
1651
|
+
/* @__PURE__ */ jsx6(Defs2, { children: /* @__PURE__ */ jsx6(ClipPath2, { id: clip, children: /* @__PURE__ */ jsx6(Rect4, { x: g.left, y: g.top, width: g.plotWidth, height: g.plotHeight }) }) }),
|
|
1652
|
+
model.yTicks.slice().sort((a, b) => pane.scale.y(a) - pane.scale.y(b)).map((value) => {
|
|
1653
|
+
const y = pane.scale.y(value);
|
|
1654
|
+
if (!Number.isFinite(y) || y < g.top || y > g.bottom || y - prevLabelY < 22 * fontScale) return null;
|
|
1655
|
+
prevLabelY = y;
|
|
1656
|
+
return /* @__PURE__ */ jsxs6(G5, { children: [
|
|
1657
|
+
chart && /* @__PURE__ */ jsx6(Line3, { x1: g.left, x2: g.right, y1: y, y2: y, stroke: theme.grid, strokeWidth: 0.7 }),
|
|
1658
|
+
axis && (!showLast || Math.abs(y - lastY) > 15 * fontScale) && /* @__PURE__ */ jsx6(Text5, { x: g.right + 4, y: y + 3.5 * fontScale, fontSize: 10 * fontScale, fill: theme.muted, children: formatScaleLabel(pane.scale.label(value, primary ? precision : 2), locale) })
|
|
1659
|
+
] }, value);
|
|
1660
|
+
}),
|
|
1661
|
+
chart && /* @__PURE__ */ jsxs6(G5, { clipPath: "url(#" + clip + ")", children: [
|
|
1662
|
+
/* @__PURE__ */ jsx6(Bands, { pane, theme }),
|
|
1663
|
+
(pane.frame.levels ?? []).map((value) => /* @__PURE__ */ jsx6(
|
|
1664
|
+
Line3,
|
|
1665
|
+
{
|
|
1666
|
+
x1: g.left,
|
|
1667
|
+
x2: g.right,
|
|
1668
|
+
y1: model.y(value),
|
|
1669
|
+
y2: model.y(value),
|
|
1670
|
+
stroke: theme.muted,
|
|
1671
|
+
strokeDasharray: [3, 4],
|
|
1672
|
+
strokeWidth: 0.7
|
|
1673
|
+
},
|
|
1674
|
+
value
|
|
1675
|
+
)),
|
|
1676
|
+
/* @__PURE__ */ jsx6(Series, { pane, theme, behind: true }),
|
|
1677
|
+
primary && /* @__PURE__ */ jsx6(Candles, { model, theme, mode }),
|
|
1678
|
+
/* @__PURE__ */ jsx6(Series, { pane, theme, behind: false }),
|
|
1679
|
+
showLast && /* @__PURE__ */ jsx6(Line3, { x1: g.left, x2: g.right, y1: lastY, y2: lastY, stroke: lastColor, strokeDasharray: [2, 4] })
|
|
1680
|
+
] }),
|
|
1681
|
+
axis && showLast && /* @__PURE__ */ jsxs6(G5, { children: [
|
|
1682
|
+
/* @__PURE__ */ jsx6(Rect4, { x: g.right, y: lastY - 9 * fontScale, width: g.width - g.right, height: 18 * fontScale, rx: 3, fill: theme.background }),
|
|
1683
|
+
/* @__PURE__ */ jsx6(Rect4, { x: g.right, y: lastY - 9 * fontScale, width: g.width - g.right, height: 18 * fontScale, rx: 3, fill: lastColor, opacity: 0.16 }),
|
|
1684
|
+
/* @__PURE__ */ jsx6(Text5, { x: g.right + 4, y: lastY + 3.5 * fontScale, fontSize: 10.5 * fontScale, fontWeight: "bold", fill: lastColor, children: lastTag })
|
|
1685
|
+
] }),
|
|
1686
|
+
axis && pane.frame.title && /* @__PURE__ */ jsx6(Text5, { x: g.left + 3, y: 14 * fontScale, fill: theme.muted, fontSize: 10 * fontScale, children: pane.frame.title }),
|
|
1687
|
+
chart && i === frame.panes.length - 1 && ticks.map((tick) => {
|
|
1688
|
+
const x = xPositions[tick.index];
|
|
1689
|
+
const align = x < g.left + 20 ? "start" : x > g.right - 20 ? "end" : "middle";
|
|
1690
|
+
return /* @__PURE__ */ jsx6(
|
|
1691
|
+
Text5,
|
|
1692
|
+
{
|
|
1693
|
+
x,
|
|
1694
|
+
y: Math.min(pane.height - 5, g.bottom + 17 * fontScale),
|
|
1695
|
+
textAnchor: align,
|
|
1696
|
+
fill: theme.muted,
|
|
1697
|
+
fontSize: 10 * fontScale,
|
|
1698
|
+
children: tick.label
|
|
1699
|
+
},
|
|
1700
|
+
tick.index
|
|
1701
|
+
);
|
|
1702
|
+
})
|
|
1703
|
+
] }, pane.id);
|
|
1704
|
+
}) });
|
|
1705
|
+
});
|
|
1706
|
+
|
|
1707
|
+
// packages/bindings/react-native/src/SuperChart.tsx
|
|
1708
|
+
import { Fragment as Fragment2, jsx as jsx7, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
1709
|
+
var NativeSurface = React7.forwardRef(function NativeSurface2(props, ref) {
|
|
1710
|
+
const {
|
|
1711
|
+
period,
|
|
1712
|
+
symbol,
|
|
1713
|
+
indicators = DEFAULT_STUDIES,
|
|
1714
|
+
indicatorDefinitions,
|
|
1715
|
+
mode = "candles",
|
|
1716
|
+
showVolume = true,
|
|
1717
|
+
showLegend = true,
|
|
1718
|
+
priceScale,
|
|
1719
|
+
onInspect,
|
|
1720
|
+
onChartPress,
|
|
1721
|
+
renderOverlay,
|
|
1722
|
+
locale,
|
|
1723
|
+
timeZone,
|
|
1724
|
+
symbolTimezone,
|
|
1725
|
+
interactionMode = "chart",
|
|
1726
|
+
style,
|
|
1727
|
+
testID
|
|
1728
|
+
} = props;
|
|
1729
|
+
const scheme = useColorScheme();
|
|
1730
|
+
const { fontScale } = useWindowDimensions4();
|
|
1731
|
+
const theme = React7.useMemo(() => ({ ...scheme === "dark" ? DARK_THEME : LIGHT_THEME, ...props.theme }), [scheme, props.theme]);
|
|
1732
|
+
const committedInputs = React7.useRef(props);
|
|
1733
|
+
React7.useLayoutEffect(() => {
|
|
1734
|
+
committedInputs.current = props;
|
|
1735
|
+
}, [props]);
|
|
1736
|
+
const [heldInputs, holdInputs] = React7.useState(null);
|
|
1737
|
+
const navigation = React7.useCallback((active) => {
|
|
1738
|
+
if (!active) {
|
|
1739
|
+
holdInputs(null);
|
|
1740
|
+
return;
|
|
1741
|
+
}
|
|
1742
|
+
const { bars: bars2, markers, annotations } = committedInputs.current;
|
|
1743
|
+
holdInputs((previous) => previous ?? { bars: bars2, markers, annotations });
|
|
1744
|
+
}, []);
|
|
1745
|
+
const market = heldInputs ?? props;
|
|
1746
|
+
const { bars } = market;
|
|
1747
|
+
const [size, setSize] = React7.useState({ width: 0, height: 0 });
|
|
1748
|
+
const onLayout = React7.useCallback((e) => {
|
|
1749
|
+
const { width, height } = e.nativeEvent.layout;
|
|
1750
|
+
setSize((previous) => previous.width === width && previous.height === height ? previous : { width, height });
|
|
1751
|
+
}, []);
|
|
1752
|
+
const raw = React7.useMemo(() => normalizeBars(bars, 1).bars, [bars]);
|
|
1753
|
+
const display = React7.useMemo(() => mode === "heikin-ashi" ? toHeikinAshi(raw) : raw, [raw, mode]);
|
|
1754
|
+
const computeIndicators = React7.useMemo(() => createStudyComputer(indicators, showVolume, indicatorDefinitions), [indicators, showVolume, indicatorDefinitions]);
|
|
1755
|
+
const studies = React7.useMemo(() => computeIndicators(raw), [computeIndicators, raw]);
|
|
1756
|
+
const [anchor, setAnchor] = React7.useState(null);
|
|
1757
|
+
const viewport = React7.useMemo(() => resolveWindow(raw, anchor, size.width - 62), [raw, anchor, size.width]);
|
|
1758
|
+
const snapshot = React7.useMemo(() => snapshotForWindow(display, viewport, mode), [display, viewport, mode]);
|
|
1759
|
+
const requestedPrecision = typeof props.precision === "number" && Number.isInteger(props.precision) ? Math.max(0, Math.min(12, props.precision)) : void 0;
|
|
1760
|
+
const precision = React7.useMemo(() => requestedPrecision ?? derivePrecision(snapshot.bars), [requestedPrecision, snapshot]);
|
|
1761
|
+
const gutter = Math.min(size.width * 0.4, Math.max(53, 14 + 6.5 * fontScale * formatPrice(snapshot.bars[0]?.close ?? 0, precision, locale).length));
|
|
1762
|
+
const [manualRange, setManualRange] = React7.useState(null);
|
|
1763
|
+
React7.useEffect(() => setManualRange(null), [priceScale?.mode, priceScale?.range?.[0], priceScale?.range?.[1]]);
|
|
1764
|
+
const layout = React7.useMemo(() => ({ axisGutter: gutter, priceScale: manualRange ? { ...priceScale, range: manualRange } : priceScale }), [
|
|
1765
|
+
gutter,
|
|
1766
|
+
manualRange,
|
|
1767
|
+
priceScale?.mode,
|
|
1768
|
+
priceScale?.reversed,
|
|
1769
|
+
priceScale?.lockBarRatio,
|
|
1770
|
+
priceScale?.range?.[0],
|
|
1771
|
+
priceScale?.range?.[1]
|
|
1772
|
+
]);
|
|
1773
|
+
const frame = React7.useMemo(() => size.width >= 80 && size.height >= 60 && raw.length ? buildEngineFrame2(snapshot, raw, studies, size.width, size.height, layout, void 0, raw) : null, [snapshot, raw, studies, size, layout]);
|
|
1774
|
+
const layerColors = React7.useMemo(() => ({
|
|
1775
|
+
bull: theme.up,
|
|
1776
|
+
bear: theme.down,
|
|
1777
|
+
accent: theme.accent,
|
|
1778
|
+
neutral: theme.muted,
|
|
1779
|
+
surface: theme.background,
|
|
1780
|
+
...props.layerColors
|
|
1781
|
+
}), [theme, props.layerColors]);
|
|
1782
|
+
const buffer = React7.useMemo(() => frame && interactionMode !== "none" ? bufferedFrame(frame, size.width, size.height, raw, display, studies, layout) : { frame, extra: 0, width: size.width }, [frame, size, raw, display, studies, layout, interactionMode]);
|
|
1783
|
+
const layers = useNativeLayers(buffer.frame, { ...props, markers: market.markers, annotations: market.annotations, layerColors }, frame && buffer.extra ? {
|
|
1784
|
+
left: frame.model.geometry.left + buffer.extra,
|
|
1785
|
+
right: frame.model.geometry.right + buffer.extra,
|
|
1786
|
+
offsetX: -buffer.extra
|
|
1787
|
+
} : void 0);
|
|
1788
|
+
const widePoint = (p) => ({ x: p.x + buffer.extra, y: p.y });
|
|
1789
|
+
const hits = {
|
|
1790
|
+
...layers,
|
|
1791
|
+
begin: (p) => layers.begin(widePoint(p)),
|
|
1792
|
+
move: (p) => layers.move(widePoint(p)),
|
|
1793
|
+
tap: (p) => layers.tap(widePoint(p)),
|
|
1794
|
+
end: (p) => layers.end(widePoint(p))
|
|
1795
|
+
};
|
|
1796
|
+
const [sight, setSight] = React7.useState(null);
|
|
1797
|
+
const aim = (finger, lifted = false) => {
|
|
1798
|
+
if (!finger || !frame) {
|
|
1799
|
+
setSight(null);
|
|
1800
|
+
return null;
|
|
1801
|
+
}
|
|
1802
|
+
const point = drawingSight(frame, finger, lifted);
|
|
1803
|
+
const magnet = props.drawingMagnet !== false && (props.drawingTool && props.drawingTool !== "brush" && props.drawingTool !== "highlighter" || layers.editingHandle());
|
|
1804
|
+
const target = magnet && nearestOHLC(frame, point) || point;
|
|
1805
|
+
setSight(target);
|
|
1806
|
+
return target;
|
|
1807
|
+
};
|
|
1808
|
+
const [cursor, setCursor] = React7.useState(null);
|
|
1809
|
+
const cursorRef = React7.useRef(null);
|
|
1810
|
+
const inspect = React7.useCallback((point) => {
|
|
1811
|
+
const next = point && frame ? (frame.inspectBar ?? frame.inspect)(point.x)?.displayBar ?? null : null;
|
|
1812
|
+
const time = next?.timestamp ?? null;
|
|
1813
|
+
if (cursorRef.current === time) return;
|
|
1814
|
+
cursorRef.current = time;
|
|
1815
|
+
setCursor(time);
|
|
1816
|
+
onInspect?.(next);
|
|
1817
|
+
}, [frame, onInspect]);
|
|
1818
|
+
const reset = React7.useCallback(() => {
|
|
1819
|
+
setAnchor(null);
|
|
1820
|
+
setManualRange(null);
|
|
1821
|
+
inspect(null);
|
|
1822
|
+
}, [inspect]);
|
|
1823
|
+
const changeViewport = React7.useCallback((next) => {
|
|
1824
|
+
setAnchor(windowAnchor(raw, next));
|
|
1825
|
+
}, [raw]);
|
|
1826
|
+
function zoom(factor) {
|
|
1827
|
+
inspect(null);
|
|
1828
|
+
changeViewport(zoomContinuousViewport2(viewport, raw.length, factor, 0.5, CHART_LIMITS));
|
|
1829
|
+
}
|
|
1830
|
+
const gesture = useChartGestures({ frame, mode: interactionMode, drawing: !!props.drawingTool, layers: hits, inspect, changeViewport, reset, onPress: onChartPress, aim });
|
|
1831
|
+
const axisDrag = React7.useRef(null);
|
|
1832
|
+
const motion = useChartMotion({
|
|
1833
|
+
frame,
|
|
1834
|
+
mode: interactionMode,
|
|
1835
|
+
input: gesture,
|
|
1836
|
+
drawing: !!props.drawingTool,
|
|
1837
|
+
regions: layers.regions,
|
|
1838
|
+
extra: buffer.extra,
|
|
1839
|
+
commit: changeViewport,
|
|
1840
|
+
navigation,
|
|
1841
|
+
axisStart: (y) => {
|
|
1842
|
+
if (!frame) return;
|
|
1843
|
+
const g = frame.model.geometry, scale = frame.panes[0].scale;
|
|
1844
|
+
const fraction = (y - g.top) / g.plotHeight;
|
|
1845
|
+
axisDrag.current = { range: [scale.min, scale.max], fraction: priceScale?.reversed ? fraction : 1 - fraction, height: g.plotHeight };
|
|
1846
|
+
},
|
|
1847
|
+
axisMove: (dy) => {
|
|
1848
|
+
const drag = axisDrag.current;
|
|
1849
|
+
if (drag) setManualRange(dragPriceRange(drag.range, drag.fraction, dy, drag.height, priceScale?.mode));
|
|
1850
|
+
},
|
|
1851
|
+
axisTap: () => setManualRange(null)
|
|
1852
|
+
});
|
|
1853
|
+
const previousMode = React7.useRef({ mode, interactionMode, tool: props.drawingTool });
|
|
1854
|
+
React7.useLayoutEffect(() => {
|
|
1855
|
+
const previous = previousMode.current;
|
|
1856
|
+
if (previous.mode !== mode || previous.interactionMode !== interactionMode || previous.tool !== props.drawingTool) {
|
|
1857
|
+
motion.stop();
|
|
1858
|
+
gesture.cancel();
|
|
1859
|
+
previousMode.current = { mode, interactionMode, tool: props.drawingTool };
|
|
1860
|
+
}
|
|
1861
|
+
}, [mode, interactionMode, props.drawingTool, motion.stop, gesture]);
|
|
1862
|
+
React7.useImperativeHandle(ref, () => ({
|
|
1863
|
+
resetViewport: () => {
|
|
1864
|
+
motion.stop();
|
|
1865
|
+
reset();
|
|
1866
|
+
},
|
|
1867
|
+
zoom: (factor) => {
|
|
1868
|
+
motion.stop();
|
|
1869
|
+
zoom(factor);
|
|
1870
|
+
},
|
|
1871
|
+
finishPath: layers.finishPath,
|
|
1872
|
+
clearInspection: () => inspect(null)
|
|
1873
|
+
}));
|
|
1874
|
+
const inspectCallback = React7.useRef(onInspect);
|
|
1875
|
+
inspectCallback.current = onInspect;
|
|
1876
|
+
React7.useEffect(() => () => {
|
|
1877
|
+
gesture.cancel();
|
|
1878
|
+
if (cursorRef.current !== null) inspectCallback.current?.(null);
|
|
1879
|
+
}, [gesture]);
|
|
1880
|
+
const clipPrefix = "nativeChart" + React7.useId().replace(/[^a-z0-9]/gi, "");
|
|
1881
|
+
const timespan = props.timespan ?? periodTimespan(period);
|
|
1882
|
+
const selected = frame && cursor !== null ? frame.snapshot.bars.find((b) => b.timestamp === cursor) : void 0;
|
|
1883
|
+
const cross = selected && frame ? frame.project(selected.timestamp, selected.close) : null;
|
|
1884
|
+
const selectedDate = React7.useMemo(() => {
|
|
1885
|
+
if (!selected || !Number.isFinite(new Date(selected.timestamp).getTime())) return "";
|
|
1886
|
+
const daily = ["day", "week", "month", "year"].includes(timespan);
|
|
1887
|
+
try {
|
|
1888
|
+
return new Intl.DateTimeFormat(locale, {
|
|
1889
|
+
month: "short",
|
|
1890
|
+
day: "numeric",
|
|
1891
|
+
year: daily ? "numeric" : void 0,
|
|
1892
|
+
hour: daily ? void 0 : "2-digit",
|
|
1893
|
+
minute: daily ? void 0 : "2-digit",
|
|
1894
|
+
timeZone: (daily ? symbolTimezone : timeZone) ?? "UTC"
|
|
1895
|
+
}).format(selected.timestamp);
|
|
1896
|
+
} catch {
|
|
1897
|
+
return new Date(selected.timestamp).toISOString().slice(0, daily ? 10 : 16);
|
|
1898
|
+
}
|
|
1899
|
+
}, [selected, timespan, locale, symbolTimezone, timeZone]);
|
|
1900
|
+
const onAccessibilityAction = (event) => {
|
|
1901
|
+
motion.stop();
|
|
1902
|
+
const action = event.nativeEvent.actionName;
|
|
1903
|
+
if (action === "activate") {
|
|
1904
|
+
reset();
|
|
1905
|
+
return;
|
|
1906
|
+
}
|
|
1907
|
+
if (action !== "increment" && action !== "decrement") return;
|
|
1908
|
+
const delta = Math.max(1, Math.round(viewportSpan3(viewport) / 3)) * (action === "increment" ? 1 : -1);
|
|
1909
|
+
changeViewport(clampContinuousViewport4({ i0: viewport.i0 + delta, i1: viewport.i1 + delta }, raw.length, CHART_LIMITS));
|
|
1910
|
+
};
|
|
1911
|
+
const legend = frame?.legend?.filter((entry) => !entry.overlay) ?? [];
|
|
1912
|
+
const latestBar = display[display.length - 1];
|
|
1913
|
+
const accessibilityValue = selected ? selectedDate + ", " + formatPrice(selected.close, precision, locale) : latestBar && formatPrice(latestBar.close, precision, locale);
|
|
1914
|
+
return /* @__PURE__ */ jsx7(GestureHandlerRootView, { style: [styles2.surface, { backgroundColor: theme.background }, style], onLayout, testID, children: frame && buffer.frame ? /* @__PURE__ */ jsxs7(Fragment2, { children: [
|
|
1915
|
+
/* @__PURE__ */ jsx7(View2, { pointerEvents: "none", style: [styles2.plotWindow, { width: frame.model.geometry.right, height: size.height }], children: /* @__PURE__ */ jsx7(Animated.View, { style: [styles2.strip, { left: -buffer.extra, width: buffer.width, height: size.height }, motion.animatedStyle], children: /* @__PURE__ */ jsxs7(Svg, { width: buffer.width, height: size.height, accessible: false, children: [
|
|
1916
|
+
/* @__PURE__ */ jsx7(
|
|
1917
|
+
ChartPlot,
|
|
1918
|
+
{
|
|
1919
|
+
part: "plot",
|
|
1920
|
+
frame: buffer.frame,
|
|
1921
|
+
theme,
|
|
1922
|
+
mode,
|
|
1923
|
+
precision,
|
|
1924
|
+
timespan,
|
|
1925
|
+
locale,
|
|
1926
|
+
timeZone,
|
|
1927
|
+
symbolTimezone,
|
|
1928
|
+
clipPrefix
|
|
1929
|
+
}
|
|
1930
|
+
),
|
|
1931
|
+
/* @__PURE__ */ jsxs7(G6, { clipPath: "url(#" + clipPrefix + "pane0)", children: [
|
|
1932
|
+
layers.nodes,
|
|
1933
|
+
renderOverlay && /* @__PURE__ */ jsx7(G6, { translateX: buffer.extra, children: renderOverlay(frame) })
|
|
1934
|
+
] })
|
|
1935
|
+
] }) }) }),
|
|
1936
|
+
/* @__PURE__ */ jsxs7(Svg, { width: size.width, height: size.height, accessible: false, pointerEvents: "none", children: [
|
|
1937
|
+
/* @__PURE__ */ jsx7(
|
|
1938
|
+
ChartPlot,
|
|
1939
|
+
{
|
|
1940
|
+
part: "axis",
|
|
1941
|
+
frame,
|
|
1942
|
+
theme,
|
|
1943
|
+
mode,
|
|
1944
|
+
precision,
|
|
1945
|
+
timespan,
|
|
1946
|
+
locale,
|
|
1947
|
+
timeZone,
|
|
1948
|
+
symbolTimezone,
|
|
1949
|
+
clipPrefix: clipPrefix + "axis"
|
|
1950
|
+
}
|
|
1951
|
+
),
|
|
1952
|
+
selected && cross && /* @__PURE__ */ jsxs7(G6, { children: [
|
|
1953
|
+
/* @__PURE__ */ jsx7(
|
|
1954
|
+
Line4,
|
|
1955
|
+
{
|
|
1956
|
+
x1: cross.x,
|
|
1957
|
+
x2: cross.x,
|
|
1958
|
+
y1: frame.model.geometry.top,
|
|
1959
|
+
y2: size.height - 28,
|
|
1960
|
+
stroke: theme.muted,
|
|
1961
|
+
strokeDasharray: [3, 3]
|
|
1962
|
+
}
|
|
1963
|
+
),
|
|
1964
|
+
/* @__PURE__ */ jsx7(
|
|
1965
|
+
Line4,
|
|
1966
|
+
{
|
|
1967
|
+
x1: frame.model.geometry.left,
|
|
1968
|
+
x2: frame.model.geometry.right,
|
|
1969
|
+
y1: cross.y,
|
|
1970
|
+
y2: cross.y,
|
|
1971
|
+
stroke: theme.muted,
|
|
1972
|
+
strokeDasharray: [3, 3]
|
|
1973
|
+
}
|
|
1974
|
+
),
|
|
1975
|
+
/* @__PURE__ */ jsx7(Rect5, { x: cross.x - 3, y: cross.y - 3, width: 6, height: 6, rx: 3, fill: theme.accent }),
|
|
1976
|
+
/* @__PURE__ */ jsx7(SvgText, { x: frame.model.geometry.right + 3, y: cross.y - 5, fill: theme.text, fontSize: 10 * fontScale, children: formatPrice(selected.close, precision, locale) })
|
|
1977
|
+
] }),
|
|
1978
|
+
sight && /* @__PURE__ */ jsx7(PrecisionGuide, { point: sight, frame, theme, precision, locale, fontScale })
|
|
1979
|
+
] }),
|
|
1980
|
+
(showLegend || selected) && /* @__PURE__ */ jsxs7(View2, { pointerEvents: "none", style: [styles2.legend, { backgroundColor: theme.background, maxWidth: size.width - gutter - 12 }], children: [
|
|
1981
|
+
/* @__PURE__ */ jsx7(Text6, { numberOfLines: 1, style: [styles2.title, { color: theme.text }], children: selected ? selectedDate : symbol + " \xB7 " + period }),
|
|
1982
|
+
selected ? /* @__PURE__ */ jsx7(Text6, { numberOfLines: 2, style: [styles2.values, { color: theme.text }], children: "O " + formatPrice(selected.open, precision, locale) + " H " + formatPrice(selected.high, precision, locale) + " L " + formatPrice(selected.low, precision, locale) + " C " + formatPrice(selected.close, precision, locale) }) : legend.length > 0 && /* @__PURE__ */ jsxs7(Text6, { numberOfLines: 1, style: [styles2.values, { color: theme.muted }], children: [
|
|
1983
|
+
legend.slice(0, 3).map((entry, i) => /* @__PURE__ */ jsx7(Text6, { style: { color: seriesColor(frame.panes[0], entry.seriesIds[0], theme) }, children: (i ? " " : "") + entry.label }, entry.id)),
|
|
1984
|
+
legend.length > 3 ? " +" + (legend.length - 3) : ""
|
|
1985
|
+
] })
|
|
1986
|
+
] }),
|
|
1987
|
+
/* @__PURE__ */ jsx7(GestureDetector, { gesture: motion.gesture, children: /* @__PURE__ */ jsx7(
|
|
1988
|
+
View2,
|
|
1989
|
+
{
|
|
1990
|
+
collapsable: false,
|
|
1991
|
+
style: StyleSheet2.absoluteFill,
|
|
1992
|
+
pointerEvents: interactionMode === "none" ? "none" : "box-only",
|
|
1993
|
+
accessible: true,
|
|
1994
|
+
accessibilityRole: interactionMode === "none" ? "image" : "adjustable",
|
|
1995
|
+
accessibilityLabel: props.accessibilityLabel ?? symbol + ", " + period,
|
|
1996
|
+
accessibilityValue: { text: accessibilityValue },
|
|
1997
|
+
accessibilityActions: interactionMode === "none" ? [] : [
|
|
1998
|
+
{ name: "increment" },
|
|
1999
|
+
{ name: "decrement" },
|
|
2000
|
+
{ name: "activate" }
|
|
2001
|
+
],
|
|
2002
|
+
onAccessibilityAction
|
|
2003
|
+
}
|
|
2004
|
+
) }),
|
|
2005
|
+
layers.controls
|
|
2006
|
+
] }) : !raw.length && /* @__PURE__ */ jsx7(Text6, { style: { color: theme.muted }, children: props.emptyLabel ?? "No chart data" }) });
|
|
2007
|
+
});
|
|
2008
|
+
var SuperChart = React7.forwardRef(function SuperChart2(props, ref) {
|
|
2009
|
+
return /* @__PURE__ */ jsx7(NativeSurface, { ref, ...props }, JSON.stringify([props.symbol, props.period]));
|
|
2010
|
+
});
|
|
2011
|
+
var styles2 = StyleSheet2.create({
|
|
2012
|
+
surface: { flex: 1, overflow: "hidden", justifyContent: "center", alignItems: "center" },
|
|
2013
|
+
plotWindow: { position: "absolute", top: 0, left: 0, overflow: "hidden" },
|
|
2014
|
+
strip: { position: "absolute", top: 0 },
|
|
2015
|
+
legend: { position: "absolute", top: 3, left: 8, paddingHorizontal: 3, paddingVertical: 1, borderRadius: 3 },
|
|
2016
|
+
title: { fontSize: 11, fontWeight: "600" },
|
|
2017
|
+
values: { fontSize: 10, fontVariant: ["tabular-nums"] }
|
|
2018
|
+
});
|
|
2019
|
+
export {
|
|
2020
|
+
DARK_THEME,
|
|
2021
|
+
LIGHT_THEME,
|
|
2022
|
+
SuperChart
|
|
2023
|
+
};
|