hyperprop-charting-library 0.1.135 → 0.1.137

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.
@@ -91,6 +91,16 @@ interface ChartOptions {
91
91
  }
92
92
  type IndicatorPane = "overlay" | "separate";
93
93
  type DrawingToolType = "horizontal-line" | "vertical-line" | "trendline" | "ray" | "fib-retracement" | "fib-extension" | "long-position" | "short-position" | "price-range" | "rectangle" | "text" | "note"
94
+ /** Three-point parallel channel: two clicks set the base line, a third sets the offset. */
95
+ | "parallel-channel"
96
+ /** Two-anchor bounding-box ellipse (created like `rectangle`). */
97
+ | "ellipse"
98
+ /** Trendline with an arrowhead at the second point. */
99
+ | "arrow"
100
+ /** Freehand polyline: press and drag to draw, release to commit. */
101
+ | "brush"
102
+ /** Text box with a connector line pointing at an anchored bar/price. */
103
+ | "callout"
94
104
  /**
95
105
  * TradingView-style ruler. Unlike every other tool it is transient: the
96
106
  * measurement overlay is never added to the drawings list (no
@@ -573,6 +583,15 @@ interface ChartInstance {
573
583
  onDrawingEditText: (handler: ((event: DrawingSelectEvent) => void) | null) => void;
574
584
  setMagnetMode: (mode: "none" | "weak" | "strong") => void;
575
585
  getMagnetMode: () => "none" | "weak" | "strong";
586
+ /**
587
+ * Change the price-scale mode ("linear" | "log" | "percent") and/or invert
588
+ * the axis. Log maps prices through log10, percent relabels the axis
589
+ * relative to the first visible bar's close (TradingView behavior), and
590
+ * invert flips the axis top-to-bottom. Only the main price pane is
591
+ * affected; indicator panes keep their own scales.
592
+ */
593
+ setPriceScale: (options: Partial<PriceScaleOptions>) => void;
594
+ getPriceScale: () => PriceScaleOptions;
576
595
  cancelDrawing: () => boolean;
577
596
  setTradeMarkers: (markers: TradeMarkerOptions[]) => void;
578
597
  onDrawingHover: (handler: ((event: DrawingHoverEvent) => void) | null) => void;
@@ -588,6 +607,28 @@ interface ChartInstance {
588
607
  updateIndicator: (id: string, patch: Partial<IndicatorInstanceOptions>) => void;
589
608
  removeIndicator: (id: string) => void;
590
609
  setIndicators: (indicators: IndicatorInstanceOptions[]) => void;
610
+ /**
611
+ * Snapshot the full user-visible chart setup (chart type, viewport,
612
+ * drawings, indicators, magnet mode, drawing defaults) as one versioned,
613
+ * JSON-serializable blob. Persist it anywhere and restore with `loadState`.
614
+ */
615
+ saveState: () => ChartSavedState;
616
+ /**
617
+ * Restore a `saveState()` snapshot. Tolerant of partial blobs — missing
618
+ * sections are left untouched, so it also works as a bulk setter. Register
619
+ * any custom script indicator plugins *before* calling this, otherwise
620
+ * their instances are dropped with a console warning.
621
+ */
622
+ loadState: (state: Partial<ChartSavedState>) => void;
623
+ /**
624
+ * Render the current frame to an image data URL (default PNG). Everything
625
+ * drawn on the chart canvas is included — candles, indicators, drawings,
626
+ * legends — at the device pixel ratio the chart renders at.
627
+ */
628
+ takeScreenshot: (options?: {
629
+ type?: "image/png" | "image/jpeg";
630
+ quality?: number;
631
+ }) => string;
591
632
  resize: (width?: number, height?: number) => void;
592
633
  destroy: () => void;
593
634
  }
@@ -611,6 +652,29 @@ interface ViewportState {
611
652
  /** Manual Y-axis max override (null = auto-scale). */
612
653
  yMax: number | null;
613
654
  }
655
+ /**
656
+ * Everything a host needs to persist to restore the user's chart setup with
657
+ * one `loadState()` call: series style, viewport, drawings, indicator
658
+ * instances, magnet mode and per-tool drawing defaults. Chart *data* is not
659
+ * included — feed bars through `setData` as usual. Custom (script) indicator
660
+ * plugins must be registered before `loadState` so their instances resolve.
661
+ */
662
+ interface ChartSavedState {
663
+ version: 1;
664
+ chartType: ChartType;
665
+ viewport: ViewportState;
666
+ drawings: DrawingObjectOptions[];
667
+ indicators: IndicatorInstanceOptions[];
668
+ magnetMode: "none" | "weak" | "strong";
669
+ /** Optional for backward compatibility with pre-0.1.137 blobs. */
670
+ priceScale?: PriceScaleOptions;
671
+ drawingDefaults: Partial<Record<DrawingToolType, DrawingDefaults>>;
672
+ }
673
+ type PriceScaleMode = "linear" | "log" | "percent";
674
+ interface PriceScaleOptions {
675
+ mode: PriceScaleMode;
676
+ inverted: boolean;
677
+ }
614
678
 
615
679
  interface ScriptIndicatorInputDef {
616
680
  key: string;
@@ -658,6 +722,45 @@ interface ScriptComputeResult {
658
722
  guides?: number[];
659
723
  decimals?: number;
660
724
  }
725
+ interface ScriptInputOptions {
726
+ /** Stable settings key; defaults to a slug of the label. */
727
+ key?: string;
728
+ min?: number;
729
+ max?: number;
730
+ step?: number;
731
+ }
732
+ declare const SCRIPT_SOURCE_INPUT_VALUES: readonly ["open", "high", "low", "close", "hl2", "hlc3", "ohlc4"];
733
+ /**
734
+ * The `input` object passed to script top level. In value mode it resolves
735
+ * each declaration against the current settings; in recording mode it
736
+ * additionally appends every declaration to `registry`. Keys are assigned
737
+ * deterministically (same order both modes), so values always line up with
738
+ * the extracted schema.
739
+ */
740
+ declare const createScriptInputHelper: (values: Record<string, unknown> | null, registry: ScriptIndicatorInputDef[] | null) => Readonly<{
741
+ int: (label: string, defaultValue: number, options?: ScriptInputOptions) => number;
742
+ float: (label: string, defaultValue: number, options?: ScriptInputOptions) => number;
743
+ bool: (label: string, defaultValue?: boolean, options?: ScriptInputOptions) => boolean;
744
+ color: (label: string, defaultValue: string, options?: ScriptInputOptions) => string;
745
+ string: (label: string, defaultValue?: string, options?: ScriptInputOptions) => string;
746
+ select: (label: string, defaultValue: string, choices: ReadonlyArray<string | {
747
+ value: string;
748
+ label: string;
749
+ }>, options?: ScriptInputOptions) => string;
750
+ source: (label?: string, defaultValue?: string, options?: ScriptInputOptions) => string;
751
+ }>;
752
+ type ScriptInputHelper = ReturnType<typeof createScriptInputHelper>;
753
+ /**
754
+ * Discover a script's Pine-style `input.*` declarations by running its top
755
+ * level with a recording helper. Returns the declared schema (empty when the
756
+ * script declares nothing) plus a compile/runtime error message when the
757
+ * script is broken. Runs under the standard execution guard, so an infinite
758
+ * top-level loop returns a budget error instead of hanging the caller.
759
+ */
760
+ declare const extractScriptInputs: (source: string) => {
761
+ inputs: ScriptIndicatorInputDef[];
762
+ error: string | null;
763
+ };
661
764
  /**
662
765
  * Compile-check a script without registering it: returns an error message, or
663
766
  * `null` when the script compiles. Runs with the same execution guard as the
@@ -678,4 +781,4 @@ declare const compileScriptIndicator: (definition: ScriptIndicatorDefinition) =>
678
781
 
679
782
  declare function createChart(element: HTMLElement, options?: ChartOptions): ChartInstance;
680
783
 
681
- export { type AxisOptions, type BuiltInIndicatorInfo, type ChartClickEvent, type ChartInstance, type ChartOptions, type ChartType, type CrosshairMoveEvent, type CrosshairOptions, type CrosshairPriceActionEvent, type DashPatternOptions, type DrawingDefaults, type DrawingHoverEvent, type DrawingObjectOptions, type DrawingPoint, type DrawingSelectEvent, type DrawingToolType, FIB_DEFAULT_PALETTE, type GridOptions, type IndicatorInstanceOptions, type IndicatorPane, type IndicatorPaneActionEvent, type IndicatorPaneAxisOptions, type IndicatorPaneGuideLine, type IndicatorPaneHeightChangeEvent, type IndicatorPaneRenderInfo, type IndicatorPaneValue, type IndicatorPaneValueLabel, type IndicatorPlugin, type IndicatorRenderContext, type LabelsOptions, type OhlcDataPoint, type OrderActionButton, type OrderActionEvent, type OrderLineOptions, POSITION_DEFAULT_COLORS, type PriceLineOptions, type ScriptComputeResult, type ScriptIndicatorDefinition, type ScriptIndicatorInputDef, type ScriptPlotSpec, type TickerLineOptions, type TradeMarkerOptions, type ViewportState, type WatermarkOptions, compileScriptIndicator, createChart, validateScriptSource };
784
+ export { type AxisOptions, type BuiltInIndicatorInfo, type ChartClickEvent, type ChartInstance, type ChartOptions, type ChartSavedState, type ChartType, type CrosshairMoveEvent, type CrosshairOptions, type CrosshairPriceActionEvent, type DashPatternOptions, type DrawingDefaults, type DrawingHoverEvent, type DrawingObjectOptions, type DrawingPoint, type DrawingSelectEvent, type DrawingToolType, FIB_DEFAULT_PALETTE, type GridOptions, type IndicatorInstanceOptions, type IndicatorPane, type IndicatorPaneActionEvent, type IndicatorPaneAxisOptions, type IndicatorPaneGuideLine, type IndicatorPaneHeightChangeEvent, type IndicatorPaneRenderInfo, type IndicatorPaneValue, type IndicatorPaneValueLabel, type IndicatorPlugin, type IndicatorRenderContext, type LabelsOptions, type OhlcDataPoint, type OrderActionButton, type OrderActionEvent, type OrderLineOptions, POSITION_DEFAULT_COLORS, type PriceLineOptions, type PriceScaleMode, type PriceScaleOptions, SCRIPT_SOURCE_INPUT_VALUES, type ScriptComputeResult, type ScriptIndicatorDefinition, type ScriptIndicatorInputDef, type ScriptInputHelper, type ScriptInputOptions, type ScriptPlotSpec, type TickerLineOptions, type TradeMarkerOptions, type ViewportState, type WatermarkOptions, compileScriptIndicator, createChart, extractScriptInputs, validateScriptSource };