@lightfin/core 0.0.0-stage → 0.0.1
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/README.md +114 -2
- package/dist/annotations/annotations.d.ts +190 -0
- package/dist/annotations/annotations.d.ts.map +1 -0
- package/dist/annotations/annotations.test.d.ts +2 -0
- package/dist/annotations/annotations.test.d.ts.map +1 -0
- package/dist/annotations/draw.d.ts +116 -0
- package/dist/annotations/draw.d.ts.map +1 -0
- package/dist/annotations/fib.d.ts +31 -0
- package/dist/annotations/fib.d.ts.map +1 -0
- package/dist/annotations/geometry.d.ts +43 -0
- package/dist/annotations/geometry.d.ts.map +1 -0
- package/dist/annotations/index.d.ts +39 -0
- package/dist/annotations/index.d.ts.map +1 -0
- package/dist/annotations/labels.d.ts +42 -0
- package/dist/annotations/labels.d.ts.map +1 -0
- package/dist/annotations/lines.d.ts +90 -0
- package/dist/annotations/lines.d.ts.map +1 -0
- package/dist/annotations/measure.d.ts +14 -0
- package/dist/annotations/measure.d.ts.map +1 -0
- package/dist/annotations/schema.d.ts +242 -0
- package/dist/annotations/schema.d.ts.map +1 -0
- package/dist/annotations/schema.js +150 -0
- package/dist/annotations/schema.js.map +1 -0
- package/dist/annotations/schema.test.d.ts +2 -0
- package/dist/annotations/schema.test.d.ts.map +1 -0
- package/dist/annotations/shapes.d.ts +47 -0
- package/dist/annotations/shapes.d.ts.map +1 -0
- package/dist/annotations/tools.d.ts +14 -0
- package/dist/annotations/tools.d.ts.map +1 -0
- package/dist/annotations/types.d.ts +121 -0
- package/dist/annotations/types.d.ts.map +1 -0
- package/dist/annotations/validate.d.ts +11 -0
- package/dist/annotations/validate.d.ts.map +1 -0
- package/dist/annotations.js +1581 -0
- package/dist/annotations.js.map +1 -0
- package/dist/api/createChart.d.ts +9 -0
- package/dist/api/createChart.d.ts.map +1 -0
- package/dist/chart/a11y.d.ts +38 -0
- package/dist/chart/a11y.d.ts.map +1 -0
- package/dist/chart/a11y.test.d.ts +2 -0
- package/dist/chart/a11y.test.d.ts.map +1 -0
- package/dist/chart/chart.d.ts +406 -0
- package/dist/chart/chart.d.ts.map +1 -0
- package/dist/chart/events.d.ts +8 -0
- package/dist/chart/events.d.ts.map +1 -0
- package/dist/chart/indicators.d.ts +96 -0
- package/dist/chart/indicators.d.ts.map +1 -0
- package/dist/chart/indicators.test.d.ts +2 -0
- package/dist/chart/indicators.test.d.ts.map +1 -0
- package/dist/chart/options.d.ts +128 -0
- package/dist/chart/options.d.ts.map +1 -0
- package/dist/chart/options.test.d.ts +2 -0
- package/dist/chart/options.test.d.ts.map +1 -0
- package/dist/chart/primitive.d.ts +65 -0
- package/dist/chart/primitive.d.ts.map +1 -0
- package/dist/chrome/colorPicker.d.ts +17 -0
- package/dist/chrome/colorPicker.d.ts.map +1 -0
- package/dist/chrome/dom.d.ts +72 -0
- package/dist/chrome/dom.d.ts.map +1 -0
- package/dist/chrome/drawingToolbar.d.ts +13 -0
- package/dist/chrome/drawingToolbar.d.ts.map +1 -0
- package/dist/chrome/drawingTools.d.ts +30 -0
- package/dist/chrome/drawingTools.d.ts.map +1 -0
- package/dist/chrome/format.d.ts +32 -0
- package/dist/chrome/format.d.ts.map +1 -0
- package/dist/chrome/format.test.d.ts +2 -0
- package/dist/chrome/format.test.d.ts.map +1 -0
- package/dist/chrome/fullscreen.test.d.ts +2 -0
- package/dist/chrome/fullscreen.test.d.ts.map +1 -0
- package/dist/chrome/hud.d.ts +48 -0
- package/dist/chrome/hud.d.ts.map +1 -0
- package/dist/chrome/index.d.ts +129 -0
- package/dist/chrome/index.d.ts.map +1 -0
- package/dist/chrome/indicatorsMenu.test.d.ts +2 -0
- package/dist/chrome/indicatorsMenu.test.d.ts.map +1 -0
- package/dist/chrome/modals.d.ts +20 -0
- package/dist/chrome/modals.d.ts.map +1 -0
- package/dist/chrome/popover.d.ts +22 -0
- package/dist/chrome/popover.d.ts.map +1 -0
- package/dist/chrome/styles.d.ts +7 -0
- package/dist/chrome/styles.d.ts.map +1 -0
- package/dist/chrome/toolbars.d.ts +47 -0
- package/dist/chrome/toolbars.d.ts.map +1 -0
- package/dist/chrome.js +1302 -0
- package/dist/chrome.js.map +1 -0
- package/dist/chunks/events-z0vVGhWP.js +18 -0
- package/dist/chunks/events-z0vVGhWP.js.map +1 -0
- package/dist/chunks/helpers-C-rzHiVC.js +65 -0
- package/dist/chunks/helpers-C-rzHiVC.js.map +1 -0
- package/dist/chunks/timezone-DRcINAK1.js +108 -0
- package/dist/chunks/timezone-DRcINAK1.js.map +1 -0
- package/dist/data/barReader.d.ts +22 -0
- package/dist/data/barReader.d.ts.map +1 -0
- package/dist/data/dataSource.d.ts +46 -0
- package/dist/data/dataSource.d.ts.map +1 -0
- package/dist/data/feed.d.ts +53 -0
- package/dist/data/feed.d.ts.map +1 -0
- package/dist/data/feed.test.d.ts +2 -0
- package/dist/data/feed.test.d.ts.map +1 -0
- package/dist/data/store.d.ts +90 -0
- package/dist/data/store.d.ts.map +1 -0
- package/dist/data/store.test.d.ts +2 -0
- package/dist/data/store.test.d.ts.map +1 -0
- package/dist/data/types.d.ts +41 -0
- package/dist/data/types.d.ts.map +1 -0
- package/dist/event-tags.js +125 -0
- package/dist/event-tags.js.map +1 -0
- package/dist/eventTags/index.d.ts +75 -0
- package/dist/eventTags/index.d.ts.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1829 -0
- package/dist/index.js.map +1 -0
- package/dist/indicators/adx.d.ts +19 -0
- package/dist/indicators/adx.d.ts.map +1 -0
- package/dist/indicators/adx.js +100 -0
- package/dist/indicators/adx.js.map +1 -0
- package/dist/indicators/atr.d.ts +16 -0
- package/dist/indicators/atr.d.ts.map +1 -0
- package/dist/indicators/atr.js +39 -0
- package/dist/indicators/atr.js.map +1 -0
- package/dist/indicators/bollinger.d.ts +18 -0
- package/dist/indicators/bollinger.d.ts.map +1 -0
- package/dist/indicators/bollinger.js +59 -0
- package/dist/indicators/bollinger.js.map +1 -0
- package/dist/indicators/cci.d.ts +17 -0
- package/dist/indicators/cci.d.ts.map +1 -0
- package/dist/indicators/cci.js +48 -0
- package/dist/indicators/cci.js.map +1 -0
- package/dist/indicators/ema.d.ts +15 -0
- package/dist/indicators/ema.d.ts.map +1 -0
- package/dist/indicators/ema.js +37 -0
- package/dist/indicators/ema.js.map +1 -0
- package/dist/indicators/helpers.d.ts +47 -0
- package/dist/indicators/helpers.d.ts.map +1 -0
- package/dist/indicators/index.d.ts +16 -0
- package/dist/indicators/index.d.ts.map +1 -0
- package/dist/indicators/indicators.test.d.ts +2 -0
- package/dist/indicators/indicators.test.d.ts.map +1 -0
- package/dist/indicators/keltner.d.ts +20 -0
- package/dist/indicators/keltner.d.ts.map +1 -0
- package/dist/indicators/keltner.js +74 -0
- package/dist/indicators/keltner.js.map +1 -0
- package/dist/indicators/macd.d.ts +20 -0
- package/dist/indicators/macd.d.ts.map +1 -0
- package/dist/indicators/macd.js +83 -0
- package/dist/indicators/macd.js.map +1 -0
- package/dist/indicators/obv.d.ts +14 -0
- package/dist/indicators/obv.d.ts.map +1 -0
- package/dist/indicators/obv.js +32 -0
- package/dist/indicators/obv.js.map +1 -0
- package/dist/indicators/roc.d.ts +16 -0
- package/dist/indicators/roc.d.ts.map +1 -0
- package/dist/indicators/roc.js +41 -0
- package/dist/indicators/roc.js.map +1 -0
- package/dist/indicators/rsi.d.ts +17 -0
- package/dist/indicators/rsi.d.ts.map +1 -0
- package/dist/indicators/rsi.js +69 -0
- package/dist/indicators/rsi.js.map +1 -0
- package/dist/indicators/sma.d.ts +14 -0
- package/dist/indicators/sma.d.ts.map +1 -0
- package/dist/indicators/sma.js +31 -0
- package/dist/indicators/sma.js.map +1 -0
- package/dist/indicators/stochastic.d.ts +23 -0
- package/dist/indicators/stochastic.d.ts.map +1 -0
- package/dist/indicators/stochastic.js +80 -0
- package/dist/indicators/stochastic.js.map +1 -0
- package/dist/indicators/types.d.ts +155 -0
- package/dist/indicators/types.d.ts.map +1 -0
- package/dist/indicators/volumeMa.d.ts +15 -0
- package/dist/indicators/volumeMa.d.ts.map +1 -0
- package/dist/indicators/volumeMa.js +37 -0
- package/dist/indicators/volumeMa.js.map +1 -0
- package/dist/indicators/vwap.d.ts +16 -0
- package/dist/indicators/vwap.d.ts.map +1 -0
- package/dist/indicators/vwap.js +32 -0
- package/dist/indicators/vwap.js.map +1 -0
- package/dist/indicators/williamsR.d.ts +19 -0
- package/dist/indicators/williamsR.d.ts.map +1 -0
- package/dist/indicators/williamsR.js +49 -0
- package/dist/indicators/williamsR.js.map +1 -0
- package/dist/indicators/wma.d.ts +15 -0
- package/dist/indicators/wma.d.ts.map +1 -0
- package/dist/indicators/wma.js +37 -0
- package/dist/indicators/wma.js.map +1 -0
- package/dist/indicators.js +0 -0
- package/dist/interaction/crosshair.d.ts +25 -0
- package/dist/interaction/crosshair.d.ts.map +1 -0
- package/dist/interaction/orderIntent.d.ts +40 -0
- package/dist/interaction/orderIntent.d.ts.map +1 -0
- package/dist/interaction/orderIntent.test.d.ts +2 -0
- package/dist/interaction/orderIntent.test.d.ts.map +1 -0
- package/dist/interaction/panzoom.d.ts +65 -0
- package/dist/interaction/panzoom.d.ts.map +1 -0
- package/dist/interaction/panzoom.test.d.ts +2 -0
- package/dist/interaction/panzoom.test.d.ts.map +1 -0
- package/dist/price-lines.js +62 -0
- package/dist/price-lines.js.map +1 -0
- package/dist/priceLines/index.d.ts +56 -0
- package/dist/priceLines/index.d.ts.map +1 -0
- package/dist/render/layers.d.ts +36 -0
- package/dist/render/layers.d.ts.map +1 -0
- package/dist/render/loadingIndicator.d.ts +20 -0
- package/dist/render/loadingIndicator.d.ts.map +1 -0
- package/dist/render/scheduler.d.ts +19 -0
- package/dist/render/scheduler.d.ts.map +1 -0
- package/dist/scales/priceScale.d.ts +35 -0
- package/dist/scales/priceScale.d.ts.map +1 -0
- package/dist/scales/scales.test.d.ts +2 -0
- package/dist/scales/scales.test.d.ts.map +1 -0
- package/dist/scales/ticks.d.ts +21 -0
- package/dist/scales/ticks.d.ts.map +1 -0
- package/dist/scales/ticks.test.d.ts +2 -0
- package/dist/scales/ticks.test.d.ts.map +1 -0
- package/dist/scales/timeIndex.d.ts +12 -0
- package/dist/scales/timeIndex.d.ts.map +1 -0
- package/dist/scales/timeIndex.test.d.ts +2 -0
- package/dist/scales/timeIndex.test.d.ts.map +1 -0
- package/dist/scales/timeScale.d.ts +45 -0
- package/dist/scales/timeScale.d.ts.map +1 -0
- package/dist/scales/timeTicks.d.ts +36 -0
- package/dist/scales/timeTicks.d.ts.map +1 -0
- package/dist/scales/timeTicks.test.d.ts +2 -0
- package/dist/scales/timeTicks.test.d.ts.map +1 -0
- package/dist/scales/timezone.d.ts +24 -0
- package/dist/scales/timezone.d.ts.map +1 -0
- package/dist/scales/timezone.test.d.ts +2 -0
- package/dist/scales/timezone.test.d.ts.map +1 -0
- package/dist/series/bar.d.ts +15 -0
- package/dist/series/bar.d.ts.map +1 -0
- package/dist/series/candlestick.d.ts +18 -0
- package/dist/series/candlestick.d.ts.map +1 -0
- package/dist/series/line.d.ts +20 -0
- package/dist/series/line.d.ts.map +1 -0
- package/dist/series/series.d.ts +96 -0
- package/dist/series/series.d.ts.map +1 -0
- package/dist/series/series.test.d.ts +2 -0
- package/dist/series/series.test.d.ts.map +1 -0
- package/dist/series/volume.d.ts +24 -0
- package/dist/series/volume.d.ts.map +1 -0
- package/package.json +62 -4
package/README.md
CHANGED
|
@@ -1,3 +1,115 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @lightfin/core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A lightweight, dependency-free financial charting library for the web —
|
|
4
|
+
candlesticks, volume, indicators, drawing tools, smooth pan/zoom, and live
|
|
5
|
+
data, rendered on HTML5 Canvas2D. Framework-agnostic vanilla TypeScript,
|
|
6
|
+
tree-shakeable, and easy to wire to any data source.
|
|
7
|
+
|
|
8
|
+
Bars in, chart out. Lightfin renders and handles interaction; data,
|
|
9
|
+
persistence, and the trading UI stay with the host. It is not a backtesting
|
|
10
|
+
engine, a data service, or an order-entry UI — `onOrderIntent` fires
|
|
11
|
+
price and coordinates so the host can open its own form.
|
|
12
|
+
|
|
13
|
+
Part of the [Lightfin monorepo](../../README.md). Open work is in
|
|
14
|
+
[ROADMAP.md](../../ROADMAP.md).
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
No runtime dependencies.
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
bun add @lightfin/core
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
React apps should also add `@lightfin/react` (`react` and this package are
|
|
25
|
+
its peer dependencies).
|
|
26
|
+
|
|
27
|
+
## Quick start
|
|
28
|
+
|
|
29
|
+
Give the container a size. The chart fills it and watches for resizes.
|
|
30
|
+
|
|
31
|
+
```html
|
|
32
|
+
<div id="chart" style="height: 420px"></div>
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { createChart } from '@lightfin/core'
|
|
37
|
+
|
|
38
|
+
const chart = createChart(document.querySelector('#chart')!, {
|
|
39
|
+
volumeVisible: true,
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
const series = chart.addCandlestickSeries()
|
|
43
|
+
series.setData([
|
|
44
|
+
{ time: 1704067200, open: 100, high: 104, low: 99, close: 103, volume: 1200 },
|
|
45
|
+
{ time: 1704070800, open: 103, high: 106, low: 102, close: 101, volume: 980 },
|
|
46
|
+
])
|
|
47
|
+
|
|
48
|
+
series.setChartType('line') // 'candlestick' | 'bar' | 'line' | 'area'
|
|
49
|
+
series.update(bar) // live tick or a new bar
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
`time` is a UTC timestamp in integer Unix seconds. `setData` replaces the
|
|
53
|
+
series; `update` appends or revises the latest bar.
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
const sma = await chart.addIndicator(import('@lightfin/core/indicators/sma'), {
|
|
57
|
+
period: 20,
|
|
58
|
+
})
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## What's included
|
|
62
|
+
|
|
63
|
+
- **Series** — candlestick, bar, line, and area, switchable in place with
|
|
64
|
+
`setChartType()`. Volume histogram on a hidden sub-scale.
|
|
65
|
+
- **Indicators** — 16 built-ins (SMA, EMA, WMA, Bollinger, Keltner, VWAP, RSI,
|
|
66
|
+
MACD, Stochastic, Williams %R, CCI, ROC, ADX, ATR, OBV, Volume MA), overlaid
|
|
67
|
+
or on a resizable pane. Each is its own subpath so unused ones stay out of
|
|
68
|
+
the bundle. Custom indicators use the same contract.
|
|
69
|
+
- **Drawing tools** — 21 types (lines, channels, pitchfork, regression, fibs,
|
|
70
|
+
shapes, brush, labels, position and range measures) with undo/redo, lock/hide,
|
|
71
|
+
and a per-drawing style toolbar. JSON in and out, including a schema an AI
|
|
72
|
+
can drive.
|
|
73
|
+
- **Live data** — `setData` for a static series, or a `DataSource` that pages
|
|
74
|
+
history and merges a live stream. Follow-mode keeps the latest bar in view.
|
|
75
|
+
- **Chrome** — optional HUD/legend, interval and chart-type toolbars, indicator
|
|
76
|
+
menu, go-to-date modal, exchange clock, fullscreen.
|
|
77
|
+
- **Price lines and event tags** — host-managed order and position lines;
|
|
78
|
+
earnings and dividend tags along the price pane. The host renders the detail
|
|
79
|
+
card and the order form.
|
|
80
|
+
- **Interaction** — pointer pan/zoom anchored on the cursor, crosshair (including
|
|
81
|
+
touch press-and-hold), magnet mode, keyboard control with screen-reader output.
|
|
82
|
+
|
|
83
|
+
## Subpath exports
|
|
84
|
+
|
|
85
|
+
The package entry is the chart engine, series, axes, and crosshair. Everything
|
|
86
|
+
else is opt-in:
|
|
87
|
+
|
|
88
|
+
| Import | What it adds |
|
|
89
|
+
| --- | --- |
|
|
90
|
+
| `@lightfin/core` | Chart engine, series, axes, crosshair, pan/zoom |
|
|
91
|
+
| `@lightfin/core/indicators/<id>` | One indicator, usually via dynamic `import()` |
|
|
92
|
+
| `@lightfin/core/annotations` | Drawing tools |
|
|
93
|
+
| `@lightfin/core/annotations/schema` | JSON Schema for AI-driven drawings |
|
|
94
|
+
| `@lightfin/core/chrome` | HUD, legend, toolbars, clock |
|
|
95
|
+
| `@lightfin/core/price-lines` | Order and position price lines |
|
|
96
|
+
| `@lightfin/core/event-tags` | Earnings and dividend tags |
|
|
97
|
+
|
|
98
|
+
## Development
|
|
99
|
+
|
|
100
|
+
From the monorepo root (see the [root README](../../README.md)):
|
|
101
|
+
|
|
102
|
+
```sh
|
|
103
|
+
bun run dev # this package's /demo playground
|
|
104
|
+
bun run --filter @lightfin/core test
|
|
105
|
+
bun run --filter @lightfin/core test:e2e
|
|
106
|
+
bun run --filter @lightfin/core build
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
`demo/` is the manual playground and the Playwright target. It loads live
|
|
110
|
+
BTC/USDT from Binance; `?feed=mock` uses a deterministic offline feed and
|
|
111
|
+
`?live=0` holds the chart still. `demo/stress.html` loads 500k bars.
|
|
112
|
+
|
|
113
|
+
## License
|
|
114
|
+
|
|
115
|
+
MIT
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import type { Chart } from '../chart/chart';
|
|
2
|
+
import type { Annotation, AnnotationInput, AnnotationStyle, AnnotationType, ToolPreset } from './types';
|
|
3
|
+
/** Payloads of the events {@link Annotations.on} can subscribe to. */
|
|
4
|
+
export interface AnnotationsEventMap {
|
|
5
|
+
/**
|
|
6
|
+
* A drawing was added, removed, moved, restyled, or edited, or an undo or
|
|
7
|
+
* redo ran — the moment to persist {@link Annotations.toJSON}. Fires once
|
|
8
|
+
* at the end of a drag, and not for {@link Annotations.load}.
|
|
9
|
+
*/
|
|
10
|
+
change: void;
|
|
11
|
+
/** The active drawing tool changed (null: back to the cursor). */
|
|
12
|
+
toolChange: AnnotationType | null;
|
|
13
|
+
/** The selected drawing's id, or null when nothing is selected. */
|
|
14
|
+
selectionChange: string | null;
|
|
15
|
+
}
|
|
16
|
+
/** What {@link Annotations.update} can change. */
|
|
17
|
+
export type AnnotationPatch = Partial<Pick<Annotation, 'points' | 'style' | 'text' | 'shape' | 'locked'>>;
|
|
18
|
+
/**
|
|
19
|
+
* Drawing tools on a chart: lines, channels, Fibonacci tools,
|
|
20
|
+
* shapes, labels, and measurements (see {@link AnnotationType}). Pick a tool
|
|
21
|
+
* with {@link setTool}, then drag or click out its points on the price pane;
|
|
22
|
+
* select a drawing to drag it or its handles. Delete/Backspace removes the
|
|
23
|
+
* selection, Escape cancels, Ctrl/⌘+Z undoes (Shift, or Ctrl+Y, redoes), and
|
|
24
|
+
* double-clicking a text or callout edits it.
|
|
25
|
+
*
|
|
26
|
+
* Drawings anchor to time + price, so they hold their place across pan/zoom,
|
|
27
|
+
* history backfill, and interval switches. Committed drawings paint on the
|
|
28
|
+
* series layer; the selected one and any in progress paint on the overlay,
|
|
29
|
+
* so dragging never repaints the rest.
|
|
30
|
+
*/
|
|
31
|
+
export declare class Annotations {
|
|
32
|
+
private readonly chart;
|
|
33
|
+
private readonly handle;
|
|
34
|
+
private readonly events;
|
|
35
|
+
private items;
|
|
36
|
+
private selectedId;
|
|
37
|
+
private activeTool;
|
|
38
|
+
private preset;
|
|
39
|
+
private sticky;
|
|
40
|
+
private allLocked;
|
|
41
|
+
private shown;
|
|
42
|
+
private draft;
|
|
43
|
+
private drag;
|
|
44
|
+
private editor;
|
|
45
|
+
private past;
|
|
46
|
+
private future;
|
|
47
|
+
private snapshot;
|
|
48
|
+
private readonly fits;
|
|
49
|
+
private readonly ownsTabIndex;
|
|
50
|
+
constructor(chart: Chart);
|
|
51
|
+
/** Subscribe to an event (see {@link AnnotationsEventMap}); returns an unsubscribe. */
|
|
52
|
+
on<K extends keyof AnnotationsEventMap>(type: K, handler: (payload: AnnotationsEventMap[K]) => void): () => void;
|
|
53
|
+
/** The active drawing tool, or null for the cursor (select/move). */
|
|
54
|
+
get tool(): AnnotationType | null;
|
|
55
|
+
/** The preset the active tool was armed with, if any. */
|
|
56
|
+
get toolPreset(): ToolPreset | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* Arm a drawing tool (null: back to the cursor), optionally with a preset
|
|
59
|
+
* its drawings start from — `setTool('trendline', { style: { extend:
|
|
60
|
+
* 'end' } })` draws rays. Reverts to the cursor after one drawing unless
|
|
61
|
+
* {@link setStickyTool} is on.
|
|
62
|
+
*/
|
|
63
|
+
setTool(tool: AnnotationType | null, preset?: ToolPreset): void;
|
|
64
|
+
/** Whether the tool stays armed after a drawing. */
|
|
65
|
+
get stickyTool(): boolean;
|
|
66
|
+
/** Keep the tool armed after each drawing (Escape returns to the cursor). */
|
|
67
|
+
setStickyTool(on: boolean): void;
|
|
68
|
+
/** Whether every drawing is locked against moving, regardless of its own `locked`. */
|
|
69
|
+
get locked(): boolean;
|
|
70
|
+
setLocked(on: boolean): void;
|
|
71
|
+
/** Whether drawings are shown. */
|
|
72
|
+
get visible(): boolean;
|
|
73
|
+
/** Show or hide every drawing (hidden ones can't be selected; arming a tool shows them). */
|
|
74
|
+
setVisible(on: boolean): void;
|
|
75
|
+
/** The selected drawing's id, or null. */
|
|
76
|
+
get selected(): string | null;
|
|
77
|
+
select(id: string | null): void;
|
|
78
|
+
/**
|
|
79
|
+
* Every drawing (or just `group`'s), oldest (bottom) first, as plain
|
|
80
|
+
* JSON-safe copies.
|
|
81
|
+
*/
|
|
82
|
+
list(group?: string): Annotation[];
|
|
83
|
+
toJSON(): Annotation[];
|
|
84
|
+
get(id: string): Annotation | null;
|
|
85
|
+
/**
|
|
86
|
+
* The style a drawing paints with, theme defaults filled in — e.g. for a
|
|
87
|
+
* style editor to show. Null for an unknown id.
|
|
88
|
+
*/
|
|
89
|
+
effectiveStyle(id: string): AnnotationStyle | null;
|
|
90
|
+
/**
|
|
91
|
+
* Add a drawing; returns its id. Throws, listing every problem (see
|
|
92
|
+
* {@link validateAnnotation}), if it's malformed or its id is taken.
|
|
93
|
+
*/
|
|
94
|
+
add(input: AnnotationInput): string;
|
|
95
|
+
/**
|
|
96
|
+
* Replace all drawings, e.g. with ones restored from storage, and start a
|
|
97
|
+
* fresh undo history. Throws if any is malformed.
|
|
98
|
+
*/
|
|
99
|
+
load(inputs: readonly AnnotationInput[]): void;
|
|
100
|
+
/**
|
|
101
|
+
* Swap `group`'s drawings for `inputs` (each tagged with `group`) in one
|
|
102
|
+
* change, leaving every other drawing alone — e.g. an AI's latest
|
|
103
|
+
* analysis replacing its previous one. Validates all first, so a malformed
|
|
104
|
+
* input changes nothing. Returns the new ids.
|
|
105
|
+
*/
|
|
106
|
+
replace(group: string, inputs: readonly AnnotationInput[]): string[];
|
|
107
|
+
/**
|
|
108
|
+
* Move, restyle (merged over the current style; an `undefined` field
|
|
109
|
+
* reverts to its default), relabel, reshape, or lock a drawing. Throws,
|
|
110
|
+
* changing nothing, if the result is malformed.
|
|
111
|
+
*/
|
|
112
|
+
update(id: string, patch: AnnotationPatch): void;
|
|
113
|
+
remove(id: string): void;
|
|
114
|
+
/** Remove every drawing, or just `group`'s. */
|
|
115
|
+
clear(group?: string): void;
|
|
116
|
+
/**
|
|
117
|
+
* Copy a drawing (as the user's, unlocked) a little right of and below
|
|
118
|
+
* the original, on top, and select it. Returns its id, or null for an
|
|
119
|
+
* unknown id.
|
|
120
|
+
*/
|
|
121
|
+
clone(id: string): string | null;
|
|
122
|
+
/** Draw a drawing above all others. */
|
|
123
|
+
bringToFront(id: string): void;
|
|
124
|
+
/** Draw a drawing below all others. */
|
|
125
|
+
sendToBack(id: string): void;
|
|
126
|
+
get canUndo(): boolean;
|
|
127
|
+
get canRedo(): boolean;
|
|
128
|
+
/** Revert the last change; false when there's nothing to undo. */
|
|
129
|
+
undo(): boolean;
|
|
130
|
+
/** Reapply the last undone change; false when there's nothing to redo. */
|
|
131
|
+
redo(): boolean;
|
|
132
|
+
/** Edit a drawing's text (a caption, for types that aren't text) in place. */
|
|
133
|
+
editText(id: string): void;
|
|
134
|
+
/** Detach from the chart and drop all listeners. */
|
|
135
|
+
dispose(): void;
|
|
136
|
+
private find;
|
|
137
|
+
private changed;
|
|
138
|
+
private restore;
|
|
139
|
+
private reorder;
|
|
140
|
+
private isLocked;
|
|
141
|
+
private underEditor;
|
|
142
|
+
private env;
|
|
143
|
+
/** Map an annotation's points to CSS px, or null with no data to anchor to. */
|
|
144
|
+
private resolve;
|
|
145
|
+
/** A regression's fitted line in CSS px. */
|
|
146
|
+
private fit;
|
|
147
|
+
private paint;
|
|
148
|
+
private draw;
|
|
149
|
+
private drawOverlay;
|
|
150
|
+
private paintSelection;
|
|
151
|
+
/** A horizontal line's price on the price axis, in the line's color. */
|
|
152
|
+
private paintPriceBadge;
|
|
153
|
+
/** Handle positions, kept inside the pane so off-screen anchors stay grabbable. */
|
|
154
|
+
private handlePoints;
|
|
155
|
+
/** The drawing (and handle, on the selected one) under a point, topmost first. */
|
|
156
|
+
private hitTest;
|
|
157
|
+
private pointerDown;
|
|
158
|
+
private startDrawing;
|
|
159
|
+
/** Take the press: focus the chart for keys, and keep the browser from selecting text. */
|
|
160
|
+
private claim;
|
|
161
|
+
/** Take the press but leave focus in the text editor it just opened. */
|
|
162
|
+
private claimForEditor;
|
|
163
|
+
/** The data point at a pixel, unsnapped: between bars and off the magnet. */
|
|
164
|
+
private freePoint;
|
|
165
|
+
/** The data point at a pixel, on the nearest bar's time. */
|
|
166
|
+
private toPoint;
|
|
167
|
+
/** Points moved by whole bars (nearest to `dx` px) and exactly `dy` px in price. */
|
|
168
|
+
private shifted;
|
|
169
|
+
private pointerMove;
|
|
170
|
+
private pointerUp;
|
|
171
|
+
private commitDraft;
|
|
172
|
+
/**
|
|
173
|
+
* Add a just-drawn drawing and select it, then return to the cursor unless
|
|
174
|
+
* the tool is sticky. A text or callout opens its editor instead of
|
|
175
|
+
* committing; the edit commits it.
|
|
176
|
+
*/
|
|
177
|
+
private finish;
|
|
178
|
+
private cursor;
|
|
179
|
+
private onKeyDown;
|
|
180
|
+
private onDblClick;
|
|
181
|
+
/**
|
|
182
|
+
* Edit a drawing's text in place, over its label. Enter or clicking away
|
|
183
|
+
* commits, Shift+Enter starts a new line, Escape reverts. A text or
|
|
184
|
+
* callout left empty is removed; any other drawing loses its caption.
|
|
185
|
+
*/
|
|
186
|
+
private openEditor;
|
|
187
|
+
/** Commit any open text edit. */
|
|
188
|
+
private closeEditor;
|
|
189
|
+
}
|
|
190
|
+
//# sourceMappingURL=annotations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"annotations.d.ts","sourceRoot":"","sources":["../../src/annotations/annotations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAY,MAAM,gBAAgB,CAAA;AAmBrD,OAAO,KAAK,EACV,UAAU,EACV,eAAe,EAEf,eAAe,EACf,cAAc,EACd,UAAU,EACX,MAAM,SAAS,CAAA;AAGhB,sEAAsE;AACtE,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,MAAM,EAAE,IAAI,CAAA;IACZ,kEAAkE;IAClE,UAAU,EAAE,cAAc,GAAG,IAAI,CAAA;IACjC,mEAAmE;IACnE,eAAe,EAAE,MAAM,GAAG,IAAI,CAAA;CAC/B;AAED,kDAAkD;AAClD,MAAM,MAAM,eAAe,GAAG,OAAO,CACnC,IAAI,CAAC,UAAU,EAAE,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC,CACnE,CAAA;AA+BD;;;;;;;;;;;;GAYG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAO;IAC7B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiB;IACxC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqC;IAC5D,OAAO,CAAC,KAAK,CAAmB;IAChC,OAAO,CAAC,UAAU,CAAsB;IACxC,OAAO,CAAC,UAAU,CAA8B;IAChD,OAAO,CAAC,MAAM,CAAwB;IACtC,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,KAAK,CAAO;IACp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OAAO,CAAC,OAAO;IASf,OAAO,CAAC,OAAO;IAWf,OAAO,CAAC,OAAO;IAUf,OAAO,CAAC,QAAQ;IAKhB,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,GAAG;IAUX,+EAA+E;IAC/E,OAAO,CAAC,OAAO;IAgBf,4CAA4C;IAC5C,OAAO,CAAC,GAAG;IA2BX,OAAO,CAAC,KAAK;IAUb,OAAO,CAAC,IAAI;IAYZ,OAAO,CAAC,WAAW;IAoBnB,OAAO,CAAC,cAAc;IA8BtB,wEAAwE;IACxE,OAAO,CAAC,eAAe;IAoBvB,mFAAmF;IACnF,OAAO,CAAC,YAAY;IASpB,kFAAkF;IAClF,OAAO,CAAC,OAAO;IA4Bf,OAAO,CAAC,WAAW;IA0CnB,OAAO,CAAC,YAAY;IAmCpB,0FAA0F;IAC1F,OAAO,CAAC,KAAK;IAMb,wEAAwE;IACxE,OAAO,CAAC,cAAc;IAKtB,6EAA6E;IAC7E,OAAO,CAAC,SAAS;IAOjB,4DAA4D;IAC5D,OAAO,CAAC,OAAO;IAOf,oFAAoF;IACpF,OAAO,CAAC,OAAO;IAmBf,OAAO,CAAC,WAAW;IAyCnB,OAAO,CAAC,SAAS;IAkCjB,OAAO,CAAC,WAAW;IAMnB;;;;OAIG;IACH,OAAO,CAAC,MAAM;IAUd,OAAO,CAAC,MAAM;IAMd,OAAO,CAAC,SAAS,CAuBhB;IAED,OAAO,CAAC,UAAU,CAOjB;IAED;;;;OAIG;IACH,OAAO,CAAC,UAAU;IA8FlB,iCAAiC;IACjC,OAAO,CAAC,WAAW;CAGpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"annotations.test.d.ts","sourceRoot":"","sources":["../../src/annotations/annotations.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import type { PlotRect } from '../chart/chart';
|
|
2
|
+
import type { ChartTheme } from '../chart/options';
|
|
3
|
+
import type { Px } from './geometry';
|
|
4
|
+
import type { Annotation, AnnotationStyle, LineEnds, LineStyle } from './types';
|
|
5
|
+
/** How far (CSS px) from a drawing a press still grabs it. */
|
|
6
|
+
export declare const HIT_SLOP = 6;
|
|
7
|
+
export interface DrawEnv {
|
|
8
|
+
pane: PlotRect;
|
|
9
|
+
dpr: number;
|
|
10
|
+
theme: ChartTheme;
|
|
11
|
+
/** Pixels per bar slot. */
|
|
12
|
+
barWidth: number;
|
|
13
|
+
formatPrice(price: number): string;
|
|
14
|
+
}
|
|
15
|
+
export interface ResolvedStyle {
|
|
16
|
+
color: string;
|
|
17
|
+
lineWidth: number;
|
|
18
|
+
lineStyle: LineStyle;
|
|
19
|
+
fontSize: number;
|
|
20
|
+
/** CSS font shorthand for the drawing's text. */
|
|
21
|
+
font: string;
|
|
22
|
+
textColor: string;
|
|
23
|
+
/** Fill color, or null for none; painted at {@link fillAlpha}. */
|
|
24
|
+
fill: string | null;
|
|
25
|
+
fillAlpha: number;
|
|
26
|
+
extend: LineEnds;
|
|
27
|
+
arrow: LineEnds;
|
|
28
|
+
}
|
|
29
|
+
/** An annotation mapped to the screen: `px[i]` is `points[i]` in CSS px. */
|
|
30
|
+
export interface Resolved {
|
|
31
|
+
ann: Annotation;
|
|
32
|
+
px: Px[];
|
|
33
|
+
style: ResolvedStyle;
|
|
34
|
+
/** A regression's fitted line and its band's half-height (CSS px); null without enough bars. */
|
|
35
|
+
fit?: {
|
|
36
|
+
a: Px;
|
|
37
|
+
b: Px;
|
|
38
|
+
band: number;
|
|
39
|
+
} | null;
|
|
40
|
+
}
|
|
41
|
+
/** Where a label is drawn: its anchor and how the text sits around it. */
|
|
42
|
+
export interface LabelAnchor {
|
|
43
|
+
x: number;
|
|
44
|
+
y: number;
|
|
45
|
+
align: 'left' | 'center' | 'right';
|
|
46
|
+
baseline: 'top' | 'middle' | 'bottom';
|
|
47
|
+
}
|
|
48
|
+
export interface ToolSpec {
|
|
49
|
+
/**
|
|
50
|
+
* Points the user places, in order: one click each, except that dragging
|
|
51
|
+
* from the first press places the second. Freehand tools take this many
|
|
52
|
+
* or more, recorded along a drag.
|
|
53
|
+
*/
|
|
54
|
+
points: number;
|
|
55
|
+
freehand?: true;
|
|
56
|
+
/**
|
|
57
|
+
* Place every point from one click (CSS px), e.g. a position's default
|
|
58
|
+
* target and stop.
|
|
59
|
+
*/
|
|
60
|
+
place?(at: Px, env: {
|
|
61
|
+
barWidth: number;
|
|
62
|
+
}): Px[];
|
|
63
|
+
/**
|
|
64
|
+
* Drag handles, each `[a, b]`: it sits at point `a`'s time and point `b`'s
|
|
65
|
+
* price, and dragging it sets exactly those two.
|
|
66
|
+
*/
|
|
67
|
+
handles: readonly (readonly [number, number])[];
|
|
68
|
+
/** Where handle `i` is drawn, when not at its points (see {@link handles}). */
|
|
69
|
+
handleAt?(r: Resolved, i: number): Px;
|
|
70
|
+
draw(ctx: CanvasRenderingContext2D, r: Resolved, env: DrawEnv): void;
|
|
71
|
+
hit(r: Resolved, p: Px): boolean;
|
|
72
|
+
/** Where the drawing's `text` goes as a caption (types that draw it themselves omit this). */
|
|
73
|
+
caption?(r: Resolved, env: DrawEnv): LabelAnchor;
|
|
74
|
+
/** Show the price on the price axis, like a horizontal line. */
|
|
75
|
+
badge?: true;
|
|
76
|
+
/** The drawing is its text: edit it on placement and double-click. */
|
|
77
|
+
editsText?: true;
|
|
78
|
+
}
|
|
79
|
+
/** The last-painted box around a drawing's label, if any. */
|
|
80
|
+
export declare function labelBox(ann: Annotation): {
|
|
81
|
+
a: Px;
|
|
82
|
+
b: Px;
|
|
83
|
+
} | undefined;
|
|
84
|
+
export declare function clearLabelBox(ann: Annotation): void;
|
|
85
|
+
/**
|
|
86
|
+
* Fill a (multi-line) label in the drawing's font and text color, on an
|
|
87
|
+
* optional background box `pad` px larger all round, and record the box for
|
|
88
|
+
* hit-testing. Returns the box.
|
|
89
|
+
*/
|
|
90
|
+
export declare function fillLabel(ctx: CanvasRenderingContext2D, { ann, style }: Resolved, text: string, at: LabelAnchor, background?: {
|
|
91
|
+
color: string;
|
|
92
|
+
alpha?: number;
|
|
93
|
+
pad: number;
|
|
94
|
+
}, color?: string): {
|
|
95
|
+
a: Px;
|
|
96
|
+
b: Px;
|
|
97
|
+
};
|
|
98
|
+
/** One line of text at `at`, in the drawing's font (no hit box). */
|
|
99
|
+
export declare function fillText(ctx: CanvasRenderingContext2D, style: ResolvedStyle, text: string, at: LabelAnchor, color: string): void;
|
|
100
|
+
export declare function stroke(ctx: CanvasRenderingContext2D, style: Pick<ResolvedStyle, 'color' | 'lineWidth' | 'lineStyle'>): void;
|
|
101
|
+
export declare function line(ctx: CanvasRenderingContext2D, a: Px, b: Px): void;
|
|
102
|
+
/** Fill a closed polygon with the drawing's fill, if it has one. */
|
|
103
|
+
export declare function fillPolygon(ctx: CanvasRenderingContext2D, style: ResolvedStyle, pts: readonly Px[], alpha?: number): void;
|
|
104
|
+
/** Length of an arrowhead for a line `w` px wide. */
|
|
105
|
+
export declare const arrowLength: (w: number) => number;
|
|
106
|
+
/** A filled arrowhead with its tip at `to`, pointing away from `from`. */
|
|
107
|
+
export declare function arrowHead(ctx: CanvasRenderingContext2D, from: Px, to: Px, style: Pick<ResolvedStyle, 'color' | 'lineWidth'>): void;
|
|
108
|
+
export declare function resolveStyle(ann: Annotation, theme: ChartTheme): ResolvedStyle;
|
|
109
|
+
/**
|
|
110
|
+
* The style a drawing paints with, defaults filled in (fill: as a color
|
|
111
|
+
* with its opacity, where it has one) — e.g. for a style editor to show.
|
|
112
|
+
*/
|
|
113
|
+
export declare function effectiveStyle(ann: Annotation, theme: ChartTheme): AnnotationStyle;
|
|
114
|
+
/** `#rgb`/`#rrggbb`/`rgb()` at opacity `alpha`; other colors as they are. */
|
|
115
|
+
export declare function withAlpha(color: string, alpha: number): string;
|
|
116
|
+
//# sourceMappingURL=draw.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"draw.d.ts","sourceRoot":"","sources":["../../src/annotations/draw.ts"],"names":[],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,IAAI,CAcN;AAiCD,wBAAgB,YAAY,CAC1B,GAAG,EAAE,UAAU,EACf,KAAK,EAAE,UAAU,GAChB,aAAa,CAmBf;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,GAAG,EAAE,UAAU,EACf,KAAK,EAAE,UAAU,GAChB,eAAe,CAgBjB;AAgBD,6EAA6E;AAC7E,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAgB9D"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { DrawEnv, Resolved } from './draw';
|
|
2
|
+
import type { Px } from './geometry';
|
|
3
|
+
export declare const FIB_LEVELS: readonly [0, 0.236, 0.382, 0.5, 0.618, 0.786, 1];
|
|
4
|
+
export declare const FIB_EXTENSION_LEVELS: readonly [0, 0.236, 0.382, 0.5, 0.618, 0.786, 1, 1.272, 1.618, 2, 2.618];
|
|
5
|
+
export declare const FIB_TOOLS: {
|
|
6
|
+
fib: {
|
|
7
|
+
points: number;
|
|
8
|
+
handles: [number, number][];
|
|
9
|
+
draw(ctx: CanvasRenderingContext2D, r: Resolved, env: DrawEnv): void;
|
|
10
|
+
hit: (r: Resolved, p: Px) => boolean;
|
|
11
|
+
caption: ({ px: [a, b] }: Resolved) => {
|
|
12
|
+
x: number;
|
|
13
|
+
y: number;
|
|
14
|
+
align: "right";
|
|
15
|
+
baseline: "bottom";
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
fibExtension: {
|
|
19
|
+
points: number;
|
|
20
|
+
handles: [number, number][];
|
|
21
|
+
draw(ctx: CanvasRenderingContext2D, r: Resolved, env: DrawEnv): void;
|
|
22
|
+
hit: (r: Resolved, p: Px) => boolean;
|
|
23
|
+
caption: (r: Resolved) => {
|
|
24
|
+
x: number;
|
|
25
|
+
y: number;
|
|
26
|
+
align: "right";
|
|
27
|
+
baseline: "bottom";
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=fib.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fib.d.ts","sourceRoot":"","sources":["../../src/annotations/fib.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAY,MAAM,QAAQ,CAAA;AAEzD,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,YAAY,CAAA;AAGpC,eAAO,MAAM,UAAU,YAAI,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAU,CAAA;AAC1E,eAAO,MAAM,oBAAoB,YAC/B,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,CACrD,CAAA;AA2FV,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;CAsDc,CAAA"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { LineEnds } from './types';
|
|
2
|
+
export interface Px {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
}
|
|
6
|
+
/** Distance from `p` to the segment `a`–`b`. */
|
|
7
|
+
export declare function distToSegment(p: Px, a: Px, b: Px): number;
|
|
8
|
+
/** Distance from `p` to the nearest segment of a polyline. */
|
|
9
|
+
export declare function distToPolyline(p: Px, pts: readonly Px[]): number;
|
|
10
|
+
/** Whether `p` lies within the box spanned by `a` and `b`, grown by `pad`. */
|
|
11
|
+
export declare function inBox(p: Px, a: Px, b: Px, pad?: number): boolean;
|
|
12
|
+
/** Whether `p` lies inside a polygon (even-odd rule). */
|
|
13
|
+
export declare function inPolygon(p: Px, pts: readonly Px[]): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Whether `p` lies inside the ellipse inscribed in the box spanned by `a`
|
|
16
|
+
* and `b`, grown by `pad`.
|
|
17
|
+
*/
|
|
18
|
+
export declare function inEllipse(p: Px, a: Px, b: Px, pad?: number): boolean;
|
|
19
|
+
export declare const add: (a: Px, b: Px) => Px;
|
|
20
|
+
export declare const sub: (a: Px, b: Px) => Px;
|
|
21
|
+
export declare const mid: (a: Px, b: Px) => Px;
|
|
22
|
+
/** The segment `a`–`b`, run out past the chosen ends. */
|
|
23
|
+
export declare function extendLine(a: Px, b: Px, ends: LineEnds): [Px, Px];
|
|
24
|
+
/**
|
|
25
|
+
* Snap a CSS-px coordinate so a horizontal/vertical line `lineWidth` CSS px
|
|
26
|
+
* wide covers whole device pixels: centered on a pixel for odd device widths,
|
|
27
|
+
* on a pixel edge for even ones.
|
|
28
|
+
*/
|
|
29
|
+
export declare function crisp(cssPx: number, lineWidth: number, dpr: number): number;
|
|
30
|
+
/** A least-squares line through closes: its price at the first and last bar, and the residuals' deviation. */
|
|
31
|
+
export interface Fit {
|
|
32
|
+
from: number;
|
|
33
|
+
to: number;
|
|
34
|
+
start: number;
|
|
35
|
+
end: number;
|
|
36
|
+
deviation: number;
|
|
37
|
+
}
|
|
38
|
+
/** Fit a line through the closes of `bars` (oldest first) by bar index; null under two bars. */
|
|
39
|
+
export declare function fitCloses(bars: readonly {
|
|
40
|
+
time: number;
|
|
41
|
+
close: number;
|
|
42
|
+
}[]): Fit | null;
|
|
43
|
+
//# sourceMappingURL=geometry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geometry.d.ts","sourceRoot":"","sources":["../../src/annotations/geometry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAEvC,MAAM,WAAW,EAAE;IACjB,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;CACV;AAED,gDAAgD;AAChD,wBAAgB,aAAa,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,GAAG,MAAM,CASzD;AA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SAAS;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,EAAE,GAC/C,GAAG,GAAG,IAAI,CAuBZ"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @lightfin/core/annotations — opt-in drawing tools: lines,
|
|
3
|
+
* channels, Fibonacci tools, shapes, labels, and measurements.
|
|
4
|
+
*
|
|
5
|
+
* Its own subpath export, so the core bundle never includes annotation code
|
|
6
|
+
* unless a consumer imports it. Drawings serialize to plain JSON for the host
|
|
7
|
+
* to persist:
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { createAnnotations } from '@lightfin/core/annotations'
|
|
11
|
+
* const drawings = createAnnotations(chart)
|
|
12
|
+
* drawings.load(JSON.parse(localStorage.drawings ?? '[]'))
|
|
13
|
+
* drawings.on('change', () => {
|
|
14
|
+
* localStorage.drawings = JSON.stringify(drawings.toJSON())
|
|
15
|
+
* })
|
|
16
|
+
* drawings.setTool('trendline') // or pass `drawings` to createChrome()
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* A program — say an AI — annotates through the same JSON, as a group it
|
|
20
|
+
* replaces wholesale; `@lightfin/core/annotations/schema` describes the
|
|
21
|
+
* JSON for a model:
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* drawings.replace('ai', [
|
|
25
|
+
* { type: 'hline', points: [{ time, price: 64_200 }], text: 'Support' },
|
|
26
|
+
* { type: 'marker', shape: 'arrowUp', points: [{ time, price: low }] },
|
|
27
|
+
* ])
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
import type { Chart } from '../chart/chart';
|
|
31
|
+
import { Annotations } from './annotations';
|
|
32
|
+
export { Annotations } from './annotations';
|
|
33
|
+
export type { AnnotationPatch, AnnotationsEventMap } from './annotations';
|
|
34
|
+
export { FIB_EXTENSION_LEVELS, FIB_LEVELS } from './tools';
|
|
35
|
+
export { validateAnnotation } from './validate';
|
|
36
|
+
export type { Annotation, AnnotationInput, AnnotationPoint, AnnotationStyle, AnnotationType, LineEnds, LineStyle, MarkerShape, ToolPreset, } from './types';
|
|
37
|
+
/** Attach drawing tools to `chart`. */
|
|
38
|
+
export declare function createAnnotations(chart: Chart): Annotations;
|
|
39
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/annotations/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAE3C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,YAAY,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AACzE,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAC/C,YAAY,EACV,UAAU,EACV,eAAe,EACf,eAAe,EACf,eAAe,EACf,cAAc,EACd,QAAQ,EACR,SAAS,EACT,WAAW,EACX,UAAU,GACX,MAAM,SAAS,CAAA;AAEhB,uCAAuC;AACvC,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,KAAK,GAAG,WAAW,CAE3D"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Resolved } from './draw';
|
|
2
|
+
import type { Px } from './geometry';
|
|
3
|
+
export declare const LABEL_TOOLS: {
|
|
4
|
+
text: {
|
|
5
|
+
points: number;
|
|
6
|
+
handles: never[];
|
|
7
|
+
editsText: true;
|
|
8
|
+
draw(ctx: CanvasRenderingContext2D, r: Resolved): void;
|
|
9
|
+
hit: () => false;
|
|
10
|
+
};
|
|
11
|
+
callout: {
|
|
12
|
+
points: number;
|
|
13
|
+
handles: [number, number][];
|
|
14
|
+
editsText: true;
|
|
15
|
+
draw(ctx: CanvasRenderingContext2D, r: Resolved): void;
|
|
16
|
+
hit: ({ px: [a, b] }: Resolved, p: Px) => boolean;
|
|
17
|
+
};
|
|
18
|
+
priceLabel: {
|
|
19
|
+
points: number;
|
|
20
|
+
handles: [number, number][];
|
|
21
|
+
draw(ctx: CanvasRenderingContext2D, r: Resolved, { formatPrice }: import("./draw").DrawEnv): void;
|
|
22
|
+
hit: ({ px: [a] }: Resolved, p: Px) => boolean;
|
|
23
|
+
};
|
|
24
|
+
marker: {
|
|
25
|
+
points: number;
|
|
26
|
+
handles: [number, number][];
|
|
27
|
+
draw(ctx: CanvasRenderingContext2D, { ann, px: [a], style }: Resolved): void;
|
|
28
|
+
hit(r: Resolved, p: Px): boolean;
|
|
29
|
+
caption(r: Resolved): {
|
|
30
|
+
x: number;
|
|
31
|
+
y: number;
|
|
32
|
+
align: "center";
|
|
33
|
+
baseline: "top";
|
|
34
|
+
} | {
|
|
35
|
+
x: number;
|
|
36
|
+
y: number;
|
|
37
|
+
align: "center";
|
|
38
|
+
baseline: "bottom";
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=labels.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"labels.d.ts","sourceRoot":"","sources":["../../src/annotations/labels.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAY,MAAM,QAAQ,CAAA;AAEhD,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,YAAY,CAAA;AAuCpC,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkIY,CAAA"}
|