hyperprop-charting-library 0.1.20 → 0.1.22
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 +50 -0
- package/dist/hyperprop-charting-library.cjs +704 -12
- package/dist/hyperprop-charting-library.d.ts +50 -1
- package/dist/hyperprop-charting-library.js +704 -12
- package/dist/index.cjs +704 -12
- package/dist/index.d.cts +50 -1
- package/dist/index.d.ts +50 -1
- package/dist/index.js +704 -12
- package/docs/API.md +63 -0
- package/docs/RECIPES.md +61 -0
- package/package.json +1 -1
package/docs/API.md
CHANGED
|
@@ -61,6 +61,7 @@ Top-level options:
|
|
|
61
61
|
- `orderLines?: OrderLineOptions[]`
|
|
62
62
|
- `tickerLine?: TickerLineOptions`
|
|
63
63
|
- `dashPatterns?: Partial<DashPatternOptions>` (controls dotted/dashed spacing)
|
|
64
|
+
- `indicators?: IndicatorInstanceOptions[]` (initial indicator instances, built-in includes `"volume"`)
|
|
64
65
|
|
|
65
66
|
### `AxisOptions`
|
|
66
67
|
|
|
@@ -238,6 +239,62 @@ Connector/fill visuals:
|
|
|
238
239
|
- `fillToPrice?: number`
|
|
239
240
|
- `fillColor?: string`
|
|
240
241
|
|
|
242
|
+
### `IndicatorInstanceOptions`
|
|
243
|
+
|
|
244
|
+
- `id?: string`
|
|
245
|
+
- `type: string` (registered indicator id, e.g. `"volume"`)
|
|
246
|
+
- `visible?: boolean` (default `true`)
|
|
247
|
+
- `pane?: "overlay" | "separate"`
|
|
248
|
+
- `paneHeightRatio?: number` (for separate panes; `0.08` to `0.45` recommended)
|
|
249
|
+
- `inputs?: Record<string, unknown>` (plugin-specific parameters)
|
|
250
|
+
|
|
251
|
+
### `IndicatorPlugin`
|
|
252
|
+
|
|
253
|
+
- `id: string`
|
|
254
|
+
- `name: string`
|
|
255
|
+
- `pane?: "overlay" | "separate"` (default `"overlay"`)
|
|
256
|
+
- `paneHeightRatio?: number` (for separate panes)
|
|
257
|
+
- `defaultInputs?: Record<string, unknown>`
|
|
258
|
+
- `draw(ctx, renderContext, inputs): void`
|
|
259
|
+
|
|
260
|
+
`IndicatorRenderContext` includes:
|
|
261
|
+
|
|
262
|
+
- shared x-window and visible index range (`startIndex`, `endIndex`, `xStart`, `xSpan`)
|
|
263
|
+
- pane bounds (`chartLeft`, `chartRight`, `chartTop`, `chartBottom`, `chartWidth`, `chartHeight`)
|
|
264
|
+
- `xFromIndex(index)` helper
|
|
265
|
+
- `yFromPrice(price)` helper (available for overlay indicators, `null` for separate-pane indicators)
|
|
266
|
+
- theme colors (`upColor`, `downColor`)
|
|
267
|
+
|
|
268
|
+
Built-in:
|
|
269
|
+
|
|
270
|
+
- `"volume"`: separate pane histogram (uses `OhlcDataPoint.v`)
|
|
271
|
+
- `"sma"`: Simple Moving Average (overlay)
|
|
272
|
+
- `"ema"`: Exponential Moving Average (overlay)
|
|
273
|
+
- `"rsi"`: Relative Strength Index (separate pane, 30/50/70 guides)
|
|
274
|
+
- `"wma"`: Weighted Moving Average (overlay)
|
|
275
|
+
- `"vwma"`: Volume Weighted Moving Average (overlay, uses `OhlcDataPoint.v`)
|
|
276
|
+
- `"rma"`: Wilder's Moving Average (overlay)
|
|
277
|
+
- `"hma"`: Hull Moving Average (overlay)
|
|
278
|
+
- `"stddev"`: Standard Deviation (separate pane)
|
|
279
|
+
- `"atr"`: Average True Range (separate pane)
|
|
280
|
+
|
|
281
|
+
Example:
|
|
282
|
+
|
|
283
|
+
```ts
|
|
284
|
+
const emaId = chart.addIndicator("ema", { length: 34, source: "close" });
|
|
285
|
+
const rsiId = chart.addIndicator("rsi", { length: 14 }, { pane: "separate", paneHeightRatio: 0.18 });
|
|
286
|
+
|
|
287
|
+
// resize pane later (useful for drag-handle UX in frontend)
|
|
288
|
+
chart.updateIndicator(rsiId, { paneHeightRatio: 0.12 });
|
|
289
|
+
|
|
290
|
+
// remove when needed
|
|
291
|
+
chart.removeIndicator(emaId);
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
Volume/VWMA note:
|
|
295
|
+
|
|
296
|
+
- if your data has no `v`, `volume`/`vwma` will have limited or no output.
|
|
297
|
+
|
|
241
298
|
---
|
|
242
299
|
|
|
243
300
|
## `ChartInstance` Methods
|
|
@@ -264,5 +321,11 @@ Connector/fill visuals:
|
|
|
264
321
|
- `resetViewport(): void` (fit x + reset y auto-scale)
|
|
265
322
|
- `setDoubleClickEnabled(enabled: boolean): void`
|
|
266
323
|
- `setDoubleClickAction(action: "reset" | "placeLimitOrder"): void`
|
|
324
|
+
- `registerIndicator(plugin: IndicatorPlugin): void`
|
|
325
|
+
- `unregisterIndicator(type: string): void`
|
|
326
|
+
- `addIndicator(type: string, inputs?: Record<string, unknown>, options?: Partial<IndicatorInstanceOptions>): string`
|
|
327
|
+
- `updateIndicator(id: string, patch: Partial<IndicatorInstanceOptions>): void`
|
|
328
|
+
- `removeIndicator(id: string): void`
|
|
329
|
+
- `setIndicators(indicators: IndicatorInstanceOptions[]): void`
|
|
267
330
|
- `resize(width?: number, height?: number): void`
|
|
268
331
|
- `destroy(): void`
|
package/docs/RECIPES.md
CHANGED
|
@@ -91,6 +91,67 @@ const chart = createChart(root, {
|
|
|
91
91
|
});
|
|
92
92
|
```
|
|
93
93
|
|
|
94
|
+
## Add built-in indicators
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
const emaId = chart.addIndicator("ema", { length: 34, source: "close" });
|
|
98
|
+
const rsiId = chart.addIndicator("rsi", { length: 14 }, { pane: "separate", paneHeightRatio: 0.18 });
|
|
99
|
+
const volumeId = chart.addIndicator("volume", { upOpacity: 0.72, downOpacity: 0.72 });
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Available built-ins:
|
|
103
|
+
|
|
104
|
+
- `volume`, `sma`, `ema`, `rsi`, `wma`, `vwma`, `rma`, `hma`, `stddev`, `atr`
|
|
105
|
+
|
|
106
|
+
## Resize indicator pane from frontend
|
|
107
|
+
|
|
108
|
+
Use `paneHeightRatio` so your app can wire a drag handle or slider:
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
const volumeId = chart.addIndicator("volume", {}, { paneHeightRatio: 0.2 });
|
|
112
|
+
|
|
113
|
+
// e.g. on slider/drag updates:
|
|
114
|
+
chart.updateIndicator(volumeId, { paneHeightRatio: 0.1 });
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Recommended range:
|
|
118
|
+
|
|
119
|
+
- `0.08` to `0.45` (library clamps to safe bounds)
|
|
120
|
+
|
|
121
|
+
## Remove or hide indicators
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
const id = chart.addIndicator("ema", { length: 21 });
|
|
125
|
+
chart.updateIndicator(id, { visible: false }); // hide
|
|
126
|
+
chart.removeIndicator(id); // remove
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Volume and VWMA data requirement
|
|
130
|
+
|
|
131
|
+
`volume` and `vwma` use `OhlcDataPoint.v`. If `v` is missing, output can be empty/limited.
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
const data = [
|
|
135
|
+
{ t: "2026-01-01T00:00:00Z", o: 100, h: 103, l: 99, c: 102, v: 125000 }
|
|
136
|
+
];
|
|
137
|
+
chart.setData(data);
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Register a custom indicator plugin
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
chart.registerIndicator({
|
|
144
|
+
id: "my-overlay-line",
|
|
145
|
+
name: "My Overlay Line",
|
|
146
|
+
pane: "overlay",
|
|
147
|
+
defaultInputs: { color: "#22d3ee", width: 2 },
|
|
148
|
+
draw: (ctx, rc, inputs) => {
|
|
149
|
+
if (!rc.yFromPrice) return;
|
|
150
|
+
// draw custom line with rc.xFromIndex + rc.yFromPrice
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
```
|
|
154
|
+
|
|
94
155
|
## Add a draggable pending limit line
|
|
95
156
|
|
|
96
157
|
```ts
|