lightweight-charts-drawing 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +243 -0
- package/dist/index.d.ts +4017 -0
- package/dist/lightweight-charts-drawing.es.js +10616 -0
- package/dist/lightweight-charts-drawing.es.js.map +1 -0
- package/dist/lightweight-charts-drawing.umd.js +2 -0
- package/dist/lightweight-charts-drawing.umd.js.map +1 -0
- package/package.json +53 -0
package/README.md
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
# lightweight-charts-drawing
|
|
2
|
+
|
|
3
|
+
**[Live Demo](https://deepentropy.github.io/lightweight-charts-drawing/)**
|
|
4
|
+
|
|
5
|
+
68 drawing tools for TradingView's lightweight-charts library. Includes trend lines, Fibonacci tools, Gann analysis, channels, pitchforks, shapes, annotations, and forecasting tools.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install lightweight-charts-drawing lightweight-charts
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { createChart, CandlestickSeries } from 'lightweight-charts';
|
|
17
|
+
import { DrawingManager, TrendLine, FibRetracement } from 'lightweight-charts-drawing';
|
|
18
|
+
|
|
19
|
+
// Create chart
|
|
20
|
+
const chart = createChart(document.getElementById('chart')!, {
|
|
21
|
+
width: 800,
|
|
22
|
+
height: 400,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const series = chart.addSeries(CandlestickSeries);
|
|
26
|
+
series.setData([/* ... your OHLC data ... */]);
|
|
27
|
+
|
|
28
|
+
// Set up drawing manager
|
|
29
|
+
const manager = new DrawingManager();
|
|
30
|
+
manager.attach(chart, series, document.getElementById('chart')!);
|
|
31
|
+
|
|
32
|
+
// Add a trend line
|
|
33
|
+
const trendLine = new TrendLine('tl-1', [
|
|
34
|
+
{ time: '2024-01-15', price: 100 },
|
|
35
|
+
{ time: '2024-02-15', price: 110 },
|
|
36
|
+
], { lineColor: '#2962FF', lineWidth: 2 });
|
|
37
|
+
|
|
38
|
+
manager.addDrawing(trendLine);
|
|
39
|
+
|
|
40
|
+
// Add a Fibonacci retracement
|
|
41
|
+
const fib = new FibRetracement('fib-1', [
|
|
42
|
+
{ time: '2024-01-01', price: 95 },
|
|
43
|
+
{ time: '2024-03-01', price: 115 },
|
|
44
|
+
]);
|
|
45
|
+
|
|
46
|
+
manager.addDrawing(fib);
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Lightweight-Charts Integration Example
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import { createChart, CandlestickSeries, ColorType } from 'lightweight-charts';
|
|
53
|
+
import {
|
|
54
|
+
DrawingManager,
|
|
55
|
+
TrendLine,
|
|
56
|
+
HorizontalLine,
|
|
57
|
+
Rectangle,
|
|
58
|
+
TextAnnotation,
|
|
59
|
+
getToolRegistry,
|
|
60
|
+
} from 'lightweight-charts-drawing';
|
|
61
|
+
|
|
62
|
+
// Create chart
|
|
63
|
+
const container = document.getElementById('chart')!;
|
|
64
|
+
const chart = createChart(container, {
|
|
65
|
+
layout: {
|
|
66
|
+
background: { type: ColorType.Solid, color: '#131722' },
|
|
67
|
+
textColor: '#d1d4dc',
|
|
68
|
+
},
|
|
69
|
+
width: 1000,
|
|
70
|
+
height: 500,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
const series = chart.addSeries(CandlestickSeries);
|
|
74
|
+
series.setData([/* ... OHLC data ... */]);
|
|
75
|
+
|
|
76
|
+
// Initialize drawing manager
|
|
77
|
+
const manager = new DrawingManager();
|
|
78
|
+
manager.attach(chart, series, container);
|
|
79
|
+
|
|
80
|
+
// Listen for events
|
|
81
|
+
manager.on('drawing:selected', (event) => {
|
|
82
|
+
console.log('Selected:', event.drawingId);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// Add drawings programmatically
|
|
86
|
+
const support = new HorizontalLine('support', [
|
|
87
|
+
{ time: '2024-01-01' as any, price: 95 },
|
|
88
|
+
], { lineColor: '#26a69a', lineWidth: 1 });
|
|
89
|
+
|
|
90
|
+
manager.addDrawing(support);
|
|
91
|
+
|
|
92
|
+
// Select, deselect, remove
|
|
93
|
+
manager.selectDrawing('support');
|
|
94
|
+
manager.deselectAll();
|
|
95
|
+
manager.removeDrawing('support');
|
|
96
|
+
|
|
97
|
+
// Export/import drawings as JSON
|
|
98
|
+
const json = manager.exportDrawings();
|
|
99
|
+
// manager.importDrawings(json, factory);
|
|
100
|
+
|
|
101
|
+
// Access the tool registry for all 68 tool definitions
|
|
102
|
+
const registry = getToolRegistry();
|
|
103
|
+
const allTools = registry.getAllTools();
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Screenshots
|
|
107
|
+
|
|
108
|
+
### Trend Line Tools
|
|
109
|
+

|
|
110
|
+
|
|
111
|
+
### Gann & Fibonacci Tools
|
|
112
|
+

|
|
113
|
+
|
|
114
|
+
### Forecasting & Measurement Tools
|
|
115
|
+

|
|
116
|
+
|
|
117
|
+
### Geometric Shapes
|
|
118
|
+

|
|
119
|
+
|
|
120
|
+
### Annotation Tools
|
|
121
|
+

|
|
122
|
+
|
|
123
|
+
## Available Drawing Tools (68)
|
|
124
|
+
|
|
125
|
+
### Lines
|
|
126
|
+
|
|
127
|
+
| Tool | Export | Anchors |
|
|
128
|
+
|------|--------|---------|
|
|
129
|
+
| Trend Line | `TrendLine` | 2 |
|
|
130
|
+
| Ray | `Ray` | 2 |
|
|
131
|
+
| Info Line | `InfoLine` | 2 |
|
|
132
|
+
| Extended Line | `ExtendedLine` | 2 |
|
|
133
|
+
| Trend Angle | `TrendAngle` | 2 |
|
|
134
|
+
| Horizontal Line | `HorizontalLine` | 1 |
|
|
135
|
+
| Horizontal Ray | `HorizontalRay` | 1 |
|
|
136
|
+
| Vertical Line | `VerticalLine` | 1 |
|
|
137
|
+
| Cross Line | `CrossLine` | 1 |
|
|
138
|
+
|
|
139
|
+
### Channels
|
|
140
|
+
|
|
141
|
+
| Tool | Export | Anchors |
|
|
142
|
+
|------|--------|---------|
|
|
143
|
+
| Parallel Channel | `ParallelChannel` | 3 |
|
|
144
|
+
| Regression Trend | `RegressionTrend` | 2 |
|
|
145
|
+
| Flat Top/Bottom | `FlatTopBottom` | 3 |
|
|
146
|
+
| Disjoint Channel | `DisjointChannel` | 4 |
|
|
147
|
+
|
|
148
|
+
### Pitchforks
|
|
149
|
+
|
|
150
|
+
| Tool | Export | Anchors |
|
|
151
|
+
|------|--------|---------|
|
|
152
|
+
| Andrews Pitchfork | `AndrewsPitchfork` | 3 |
|
|
153
|
+
| Schiff Pitchfork | `SchiffPitchfork` | 3 |
|
|
154
|
+
| Modified Schiff Pitchfork | `ModifiedSchiffPitchfork` | 3 |
|
|
155
|
+
| Inside Pitchfork | `InsidePitchfork` | 3 |
|
|
156
|
+
|
|
157
|
+
### Fibonacci
|
|
158
|
+
|
|
159
|
+
| Tool | Export | Anchors |
|
|
160
|
+
|------|--------|---------|
|
|
161
|
+
| Fib Retracement | `FibRetracement` | 2 |
|
|
162
|
+
| Fib Extension | `FibExtension` | 3 |
|
|
163
|
+
| Fib Channel | `FibChannel` | 3 |
|
|
164
|
+
| Fib Time Zone | `FibTimeZone` | 2 |
|
|
165
|
+
| Fib Speed Fan | `FibSpeedFan` | 2 |
|
|
166
|
+
| Fib Time Extension | `FibTimeExtension` | 3 |
|
|
167
|
+
| Fib Circles | `FibCircles` | 2 |
|
|
168
|
+
| Fib Spiral | `FibSpiral` | 2 |
|
|
169
|
+
| Fib Arcs | `FibArcs` | 2 |
|
|
170
|
+
| Fib Wedge | `FibWedge` | 3 |
|
|
171
|
+
| Pitchfan | `Pitchfan` | 3 |
|
|
172
|
+
|
|
173
|
+
### Gann
|
|
174
|
+
|
|
175
|
+
| Tool | Export | Anchors |
|
|
176
|
+
|------|--------|---------|
|
|
177
|
+
| Gann Box | `GannBox` | 2 |
|
|
178
|
+
| Gann Fan | `GannFan` | 2 |
|
|
179
|
+
| Gann Square Fixed | `GannSquareFixed` | 1 |
|
|
180
|
+
| Gann Square | `GannSquare` | 2 |
|
|
181
|
+
|
|
182
|
+
### Forecasting & Measurement
|
|
183
|
+
|
|
184
|
+
| Tool | Export | Anchors |
|
|
185
|
+
|------|--------|---------|
|
|
186
|
+
| Long Position | `LongPosition` | 3 |
|
|
187
|
+
| Short Position | `ShortPosition` | 3 |
|
|
188
|
+
| Forecast | `Forecast` | 2 |
|
|
189
|
+
| Bars Pattern | `BarsPattern` | 3 |
|
|
190
|
+
| Projection | `Projection` | 3 |
|
|
191
|
+
| Price Range | `PriceRange` | 2 |
|
|
192
|
+
| Date Range | `DateRange` | 2 |
|
|
193
|
+
| Date & Price Range | `DatePriceRange` | 2 |
|
|
194
|
+
|
|
195
|
+
### Shapes
|
|
196
|
+
|
|
197
|
+
| Tool | Export | Anchors |
|
|
198
|
+
|------|--------|---------|
|
|
199
|
+
| Rectangle | `Rectangle` | 2 |
|
|
200
|
+
| Rotated Rectangle | `RotatedRectangle` | 3 |
|
|
201
|
+
| Circle | `Circle` | 2 |
|
|
202
|
+
| Triangle | `Triangle` | 3 |
|
|
203
|
+
| Ellipse | `Ellipse` | 2 |
|
|
204
|
+
| Arc | `Arc` | 3 |
|
|
205
|
+
| Path | `Path` | 2+ |
|
|
206
|
+
| Polyline | `Polyline` | 2+ |
|
|
207
|
+
| Curve | `Curve` | 4 |
|
|
208
|
+
| Double Curve | `DoubleCurve` | 3 |
|
|
209
|
+
|
|
210
|
+
### Annotations
|
|
211
|
+
|
|
212
|
+
| Tool | Export | Anchors |
|
|
213
|
+
|------|--------|---------|
|
|
214
|
+
| Text | `TextAnnotation` | 1 |
|
|
215
|
+
| Callout | `Callout` | 2 |
|
|
216
|
+
| Anchored Text | `AnchoredText` | 2 |
|
|
217
|
+
| Note | `Note` | 1 |
|
|
218
|
+
| Price Note | `PriceNote` | 1 |
|
|
219
|
+
| Price Label | `PriceLabel` | 1 |
|
|
220
|
+
| Flag Mark | `FlagMark` | 1 |
|
|
221
|
+
| Pin | `Pin` | 1 |
|
|
222
|
+
| Comment | `Comment` | 1 |
|
|
223
|
+
| Signpost | `Signpost` | 1 |
|
|
224
|
+
| Table | `Table` | 1 |
|
|
225
|
+
| Brush | `Brush` | 2+ |
|
|
226
|
+
| Highlighter | `Highlighter` | 2+ |
|
|
227
|
+
| Arrow | `Arrow` | 2 |
|
|
228
|
+
| Arrow Marker | `ArrowMarker` | 1 |
|
|
229
|
+
| Arrow Mark Up | `ArrowMarkUp` | 1 |
|
|
230
|
+
| Arrow Mark Down | `ArrowMarkDown` | 1 |
|
|
231
|
+
|
|
232
|
+
## Architecture
|
|
233
|
+
|
|
234
|
+
Each drawing tool follows a two-class pattern:
|
|
235
|
+
|
|
236
|
+
- **Tool class** (e.g. `TrendLine`) - extends `Drawing`, holds anchors/state, implements hit testing and geometry computation
|
|
237
|
+
- **Pane view** (e.g. `TrendLinePaneView`) - implements `IPrimitivePaneView` from lightweight-charts, handles canvas rendering
|
|
238
|
+
|
|
239
|
+
The `DrawingManager` orchestrates lifecycle, selection, drag-editing, and event emission.
|
|
240
|
+
|
|
241
|
+
## License
|
|
242
|
+
|
|
243
|
+
MIT
|