hyperprop-charting-library 0.1.135 → 0.1.136
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/dist/hyperprop-charting-library.cjs +549 -5
- package/dist/hyperprop-charting-library.d.ts +49 -1
- package/dist/hyperprop-charting-library.js +549 -5
- package/dist/index.cjs +549 -5
- package/dist/index.d.cts +49 -1
- package/dist/index.d.ts +49 -1
- package/dist/index.js +549 -5
- package/docs/API.md +44 -3
- package/package.json +1 -1
package/docs/API.md
CHANGED
|
@@ -483,9 +483,34 @@ chart.setActiveDrawingTool("fib-extension"); // three clicks: trend start, tre
|
|
|
483
483
|
chart.setActiveDrawingTool("long-position"); // single click drops a long risk/reward box
|
|
484
484
|
chart.setActiveDrawingTool("short-position"); // single click drops a short risk/reward box
|
|
485
485
|
chart.setActiveDrawingTool("measure"); // next drag (or click-move-click) measures; see below
|
|
486
|
+
chart.setActiveDrawingTool("parallel-channel"); // three clicks: base start, base end, parallel offset
|
|
487
|
+
chart.setActiveDrawingTool("ellipse"); // two clicks: opposite corners of the bounding box
|
|
488
|
+
chart.setActiveDrawingTool("arrow"); // like trendline, with an arrowhead at the second point
|
|
489
|
+
chart.setActiveDrawingTool("brush"); // press and drag to draw freehand; release commits
|
|
490
|
+
chart.setActiveDrawingTool("callout"); // two clicks: anchor tip, then text box (opens text editor)
|
|
486
491
|
chart.setActiveDrawingTool(null); // back to normal cursor/pan
|
|
487
492
|
```
|
|
488
493
|
|
|
494
|
+
New shape/annotation tools:
|
|
495
|
+
|
|
496
|
+
- `parallel-channel`: three-point channel, TradingView style. The first two
|
|
497
|
+
clicks set the base trendline; the third click sets the parallel offset.
|
|
498
|
+
Renders both lines, a dashed centre line, and a translucent fill. Handles:
|
|
499
|
+
the two base anchors plus a third on the parallel line. The offset is
|
|
500
|
+
constant in price, so the channel stays parallel at any zoom.
|
|
501
|
+
- `ellipse`: two-anchor bounding-box ellipse, created and resized exactly like
|
|
502
|
+
`rectangle` (corner handles, including the derived corners).
|
|
503
|
+
- `arrow`: a `trendline` with a filled arrowhead at the second point (head
|
|
504
|
+
size scales with `width`). Supports the same Shift 0/45/90° constraint.
|
|
505
|
+
- `brush`: freehand polyline. Press and drag to draw; release commits. Points
|
|
506
|
+
are appended only when the cursor moves ≥3px, and strokes render smoothed
|
|
507
|
+
with quadratic curves. No reshape handles — drag the stroke body to move it.
|
|
508
|
+
- `callout`: anchored text box. First click drops the anchor (arrow tip),
|
|
509
|
+
second click places the box, and `onDrawingEditText` fires so the host can
|
|
510
|
+
show its text editor. Stores content in `label` and size in `fontSize`, like
|
|
511
|
+
`text`/`note`. The connector line + arrowhead re-route to the box edge
|
|
512
|
+
nearest the anchor.
|
|
513
|
+
|
|
489
514
|
Use `getDrawings()` / `setDrawings()` for persistence.
|
|
490
515
|
|
|
491
516
|
### Measure tool (TradingView-style ruler)
|
|
@@ -533,12 +558,12 @@ an up measurement, red for down.
|
|
|
533
558
|
- `resetViewport(): void` (fit x + reset y auto-scale)
|
|
534
559
|
- `setSelectedDrawing(id: string | null): void` (marks a drawing selected; only the selected/drafted drawing renders its handles, and position tools render their lines/labels only while selected)
|
|
535
560
|
- `onDrawingDoubleClick(handler): void` (fires when a drawing is double-clicked; use it to open a settings dialog, e.g. for position tools)
|
|
536
|
-
- `onDrawingEditText(handler): void` (fires when a `text`/`note` tool is placed or double-clicked; use it to show an inline text editor at `{x, y}` and write the result back via `updateDrawing(id, { label })`).
|
|
561
|
+
- `onDrawingEditText(handler): void` (fires when a `text`/`note`/`callout` tool is placed or double-clicked; use it to show an inline text editor at `{x, y}` and write the result back via `updateDrawing(id, { label })`). These drawings store their content in `label` and size in `fontSize`.
|
|
537
562
|
- `setTradeMarkers(markers: TradeMarkerOptions[]): void` — draw trade execution markers (arrow + `qty @ price` label) on the candle of each fill's `time`. Buy = arrow below the low pointing up; sell = arrow above the high pointing down. Each marker: `{ time (ms|ISO), price, side: "buy"|"sell", qty?, text?, color?, textColor? }` (defaults: buy `#2962ff`, sell `#f23645`, text `#d1d4dc`). Markers resolve to bars by time, so they persist across timeframe switches and scrolling. Pass `[]` to clear.
|
|
538
563
|
- `cancelDrawing(): boolean` — abort an in-progress multi-click drawing (between the first click and the final point, e.g. a half-drawn trendline/ray/fib). Returns `true` if a draft was cancelled. Wire it to Escape.
|
|
539
|
-
- Hold **Shift** while drawing or dragging an endpoint of a `trendline`/`ray` to constrain it to the nearest 0/45/90° angle (e.g. a perfectly horizontal line).
|
|
564
|
+
- Hold **Shift** while drawing or dragging an endpoint of a `trendline`/`ray`/`arrow` to constrain it to the nearest 0/45/90° angle (e.g. a perfectly horizontal line).
|
|
540
565
|
- `setMagnetMode(mode): void` / `getMagnetMode()` — magnet/snap for all drawing tools. `"none"` off, `"weak"` snaps to a candle's OHLC only when the cursor is near a value, `"strong"` always snaps to the nearest OHLC of the bar under the cursor. Holding Cmd/Ctrl while drawing/dragging forces strong snapping regardless of the mode.
|
|
541
|
-
- `setActiveDrawingTool(tool: DrawingToolType | null): void` (`DrawingToolType` = `"horizontal-line" | "vertical-line" | "trendline" | "ray" | "fib-retracement" | "fib-extension" | "long-position" | "short-position" | "price-range" | "rectangle" | "text" | "note" | "measure"`)
|
|
566
|
+
- `setActiveDrawingTool(tool: DrawingToolType | null): void` (`DrawingToolType` = `"horizontal-line" | "vertical-line" | "trendline" | "ray" | "fib-retracement" | "fib-extension" | "long-position" | "short-position" | "price-range" | "rectangle" | "text" | "note" | "parallel-channel" | "ellipse" | "arrow" | "brush" | "callout" | "measure"`)
|
|
542
567
|
- `getActiveDrawingTool(): DrawingToolType | null`
|
|
543
568
|
- `onActiveDrawingToolChange(handler: ((tool: DrawingToolType | null) => void) | null): void` — fires whenever the active tool changes, including the chart auto-reverting to the cursor after a tool completes (all tools do this when their shape is placed; `measure` does it after every measurement). Keeps host toolbars in sync without polling.
|
|
544
569
|
- `setDrawings(drawings: DrawingObjectOptions[]): void`
|
|
@@ -558,6 +583,22 @@ an up measurement, red for down.
|
|
|
558
583
|
- `updateIndicator(id: string, patch: Partial<IndicatorInstanceOptions>): void`
|
|
559
584
|
- `removeIndicator(id: string): void`
|
|
560
585
|
- `setIndicators(indicators: IndicatorInstanceOptions[]): void`
|
|
586
|
+
- `saveState(): ChartSavedState` — one JSON-serializable snapshot of the full user-visible setup: `{ version: 1, chartType, viewport, drawings, indicators, magnetMode, drawingDefaults }`. Chart *data* is not included; keep feeding bars through `setData`/`upsertBar`.
|
|
587
|
+
- `loadState(state: Partial<ChartSavedState>): void` — restore a `saveState()` blob. Tolerant of partial blobs (missing sections are left untouched), so it doubles as a bulk setter. Register custom script indicator plugins with `registerIndicator` *before* calling it so their instances resolve. Viewport is applied last so pane changes don't clobber the restore.
|
|
588
|
+
- `takeScreenshot(options?: { type?: "image/png" | "image/jpeg"; quality?: number }): string` — returns a data URL of the current frame (default PNG) at the chart's device pixel ratio. Everything on the canvas is included: series, indicators, panes, drawings, legends.
|
|
589
|
+
|
|
590
|
+
```ts
|
|
591
|
+
// Persist / restore the user's whole chart setup
|
|
592
|
+
localStorage.setItem("layout", JSON.stringify(chart.saveState()));
|
|
593
|
+
chart.loadState(JSON.parse(localStorage.getItem("layout")!));
|
|
594
|
+
|
|
595
|
+
// Download a chart snapshot
|
|
596
|
+
const link = document.createElement("a");
|
|
597
|
+
link.href = chart.takeScreenshot();
|
|
598
|
+
link.download = "chart.png";
|
|
599
|
+
link.click();
|
|
600
|
+
```
|
|
601
|
+
|
|
561
602
|
- `resize(width?: number, height?: number): void`
|
|
562
603
|
- `destroy(): void`
|
|
563
604
|
|