hyperprop-charting-library 0.1.142 → 0.1.144

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/index.d.cts CHANGED
@@ -83,9 +83,23 @@ interface ChartOptions {
83
83
  downsampling?: DownsamplingOptions;
84
84
  touch?: TouchOptions;
85
85
  datafeedOptions?: DatafeedOptions;
86
+ dataLine?: DataLineOptions;
87
+ animation?: AnimationOptions;
88
+ indicatorUpdate?: IndicatorUpdateOptions;
89
+ /**
90
+ * Zone every timestamp is rendered in: an IANA id ("America/New_York"),
91
+ * "utc", or "local" (default). Affects axis labels, the crosshair tag, the
92
+ * data line and day boundaries — never the underlying data.
93
+ */
94
+ timezone?: ChartTimezone;
95
+ /** Clock style for rendered times. Default "24h". */
96
+ timeFormat?: TimeFormat;
97
+ session?: SessionOptions;
98
+ history?: HistoryOptions;
86
99
  crosshair?: CrosshairOptions;
87
100
  grid?: GridOptions;
88
101
  watermark?: WatermarkOptions;
102
+ alerts?: AlertOptions[];
89
103
  priceLines?: PriceLineOptions[];
90
104
  orderLines?: OrderLineOptions[];
91
105
  tickerLine?: TickerLineOptions;
@@ -547,7 +561,7 @@ interface ChartContextMenuEvent {
547
561
  };
548
562
  }
549
563
  /** Built-in keyboard actions, reported after the chart applies them. */
550
- type ChartKeyboardAction = "delete-drawing" | "cancel" | "pan-left" | "pan-right" | "pan-up" | "pan-down" | "zoom-in" | "zoom-out" | "reset-viewport" | "scroll-to-realtime";
564
+ type ChartKeyboardAction = "delete-drawing" | "cancel" | "undo" | "redo" | "pan-left" | "pan-right" | "pan-up" | "pan-down" | "zoom-in" | "zoom-out" | "reset-viewport" | "scroll-to-realtime";
551
565
  interface ChartKeyboardShortcutEvent {
552
566
  action: ChartKeyboardAction;
553
567
  /** The originating `KeyboardEvent.key`. */
@@ -567,6 +581,8 @@ interface KeyboardOptions {
567
581
  panBars?: number;
568
582
  /** Delete/Backspace removes the selected drawing. Default true. */
569
583
  deleteSelectedDrawing?: boolean;
584
+ /** Ctrl/Cmd+Z and Ctrl/Cmd+Shift+Z (or Ctrl+Y). Default true. */
585
+ undoRedo?: boolean;
570
586
  }
571
587
  /**
572
588
  * Deep zoom-out rendering. Once bars are narrower than `thresholdPx`, several
@@ -636,6 +652,67 @@ interface ChartTheme {
636
652
  labelBackground: string;
637
653
  }
638
654
  type ChartThemeName = "midnight" | "light" | "brand" | "dark" | "high-contrast";
655
+ /**
656
+ * The symbol/OHLC line drawn inside the top-left of the plot, like
657
+ * TradingView's data line. Values follow the crosshair while hovering and fall
658
+ * back to the latest bar otherwise. Opt-in, because hosts that already render
659
+ * their own DOM overlay shouldn't suddenly get two.
660
+ */
661
+ interface DataLineOptions {
662
+ /** Default false. */
663
+ visible?: boolean;
664
+ /** e.g. "NQU6" — drawn first, in the emphasis color. */
665
+ symbol?: string;
666
+ /** e.g. "1h". */
667
+ interval?: string;
668
+ /** e.g. "CME". */
669
+ exchange?: string;
670
+ /** O/H/L/C values for the hovered (or latest) bar. Default true. */
671
+ showOhlc?: boolean;
672
+ /** Absolute and percent change of that bar, colored by direction. Default true. */
673
+ showChange?: boolean;
674
+ /** Bar volume. Default false. */
675
+ showVolume?: boolean;
676
+ /**
677
+ * Extra chips after the values — session, currency, a "Closed" badge. Each
678
+ * renders as `label value` with an optional color and pill background.
679
+ */
680
+ details?: Array<{
681
+ label?: string;
682
+ value: string;
683
+ color?: string;
684
+ background?: string;
685
+ }>;
686
+ /** Colored dot before the symbol, e.g. green when the market is open. */
687
+ statusColor?: string;
688
+ fontSize?: number;
689
+ /** Symbol color. Defaults to the axis text color. */
690
+ symbolColor?: string;
691
+ /** Everything after the symbol. Defaults to the indicator legend color. */
692
+ textColor?: string;
693
+ }
694
+ interface IndicatorUpdateOptions {
695
+ /**
696
+ * While only the forming bar is ticking, recompute indicator series at most
697
+ * this often (ms) rather than on every frame. Values are always exact — this
698
+ * changes how often the live bar's output refreshes, not how it's computed,
699
+ * and anything structural (a bar closing, history loading, inputs changing)
700
+ * recomputes immediately. Default 80; set 0 to recompute every frame.
701
+ */
702
+ liveThrottleMs?: number;
703
+ }
704
+ interface AnimationOptions {
705
+ /**
706
+ * Ease the big viewport jumps — reset, fit-all, scroll-to-realtime — instead
707
+ * of teleporting, so it stays obvious which way the chart moved. Continuous
708
+ * gestures (drag, wheel, pinch) are never animated; they already follow the
709
+ * hand. Default true, and always skipped when the OS asks for reduced
710
+ * motion.
711
+ */
712
+ viewportTransitions?: boolean;
713
+ /** Transition length in ms. Default 260. */
714
+ durationMs?: number;
715
+ }
639
716
  /** Touch ergonomics. Fingers are blunter than a mouse cursor. */
640
717
  interface TouchOptions {
641
718
  /**
@@ -913,6 +990,80 @@ interface ChartInstance {
913
990
  type?: "image/png" | "image/jpeg";
914
991
  quality?: number;
915
992
  }) => string;
993
+ /**
994
+ * Render every timestamp in another zone — "America/New_York" for CME
995
+ * futures, "utc", "local", any IANA id. Data is untouched; only labels,
996
+ * the crosshair tag and day/session boundaries move. Unknown ids fall back
997
+ * to local time rather than throwing.
998
+ */
999
+ setTimezone: (timezone: ChartTimezone) => void;
1000
+ getTimezone: () => ChartTimezone;
1001
+ /** Switch rendered clock times between 24-hour and 12-hour. */
1002
+ setTimeFormat: (format: TimeFormat) => void;
1003
+ getTimeFormat: () => TimeFormat;
1004
+ /**
1005
+ * Teach the chart the instrument's trading hours. Session starts then get
1006
+ * their own separators (a futures day opening at 18:00 ET is one session,
1007
+ * not two calendar days) and out-of-session bars can be tinted.
1008
+ */
1009
+ setSession: (session: SessionOptions | SessionSpec | SessionPresetName | null) => void;
1010
+ getSession: () => SessionOptions;
1011
+ /**
1012
+ * Step back through drawing edits — create, move, restyle, delete, clear.
1013
+ * Returns false when there is nothing left to undo. Viewport changes are
1014
+ * deliberately not recorded (panning is not an edit), and neither are bulk
1015
+ * host syncs through `setDrawings`, so a host echoing state back never
1016
+ * pollutes the stack.
1017
+ */
1018
+ undo: () => boolean;
1019
+ redo: () => boolean;
1020
+ canUndo: () => boolean;
1021
+ canRedo: () => boolean;
1022
+ /** Current stack state, for enabling/labelling host buttons. */
1023
+ getUndoRedoState: () => UndoRedoState;
1024
+ onUndoRedoStateChange: (handler: ((state: UndoRedoState) => void) | null) => void;
1025
+ /** Drop both stacks, e.g. after loading a different symbol. */
1026
+ clearHistory: () => void;
1027
+ /**
1028
+ * Hide every bar after a chosen point and reveal them one at a time, so a
1029
+ * setup can be re-traded without lookahead. Indicators, drawings and the
1030
+ * price scale all see only the revealed bars. Live bars arriving while
1031
+ * replay runs are buffered, not shown, and `stopReplay()` restores the full
1032
+ * series.
1033
+ */
1034
+ startReplay: (options?: ReplayStartOptions) => void;
1035
+ stopReplay: () => void;
1036
+ /** Reveal `bars` more bars (negative rewinds). Default 1. */
1037
+ replayStep: (bars?: number) => void;
1038
+ replayPlay: (speed?: number) => void;
1039
+ replayPause: () => void;
1040
+ /** Bars revealed per second. */
1041
+ setReplaySpeed: (speed: number) => void;
1042
+ getReplayState: () => ReplayState;
1043
+ onReplayStateChange: (handler: ((state: ReplayState) => void) | null) => void;
1044
+ /**
1045
+ * Horizontal watch levels with a bell tag on the price axis. The chart
1046
+ * draws them, lets the user drag them, and fires `onAlertTrigger` when
1047
+ * price satisfies the condition — delivery (push, email, sound) is the
1048
+ * host's job.
1049
+ */
1050
+ setAlerts: (alerts: AlertOptions[]) => void;
1051
+ addAlert: (alert: AlertOptions) => string;
1052
+ updateAlert: (id: string, patch: Partial<AlertOptions>) => void;
1053
+ removeAlert: (id: string) => void;
1054
+ getAlerts: () => AlertOptions[];
1055
+ onAlertTrigger: (handler: ((event: AlertTriggerEvent) => void) | null) => void;
1056
+ /** Drag, delete-button and click interactions on an alert line. */
1057
+ onAlertAction: (handler: ((event: AlertActionEvent) => void) | null) => void;
1058
+ /** Badges pinned to bars (earnings, releases, your own annotations). */
1059
+ setBarMarks: (marks: BarMarkOptions[]) => void;
1060
+ getBarMarks: () => BarMarkOptions[];
1061
+ /** Badges on the time axis, for date-anchored events. */
1062
+ setTimescaleMarks: (marks: TimescaleMarkOptions[]) => void;
1063
+ getTimescaleMarks: () => TimescaleMarkOptions[];
1064
+ onMarkClick: (handler: ((event: MarkClickEvent) => void) | null) => void;
1065
+ /** Fires with the hovered mark, and with null when the pointer leaves it. */
1066
+ onMarkHover: (handler: ((event: MarkHoverEvent | null) => void) | null) => void;
916
1067
  resize: (width?: number, height?: number) => void;
917
1068
  destroy: () => void;
918
1069
  }
@@ -953,12 +1104,182 @@ interface ChartSavedState {
953
1104
  /** Optional for backward compatibility with pre-0.1.137 blobs. */
954
1105
  priceScale?: PriceScaleOptions;
955
1106
  drawingDefaults: Partial<Record<DrawingToolType, DrawingDefaults>>;
1107
+ /** Added in 0.1.144. */
1108
+ alerts?: AlertOptions[];
1109
+ timezone?: ChartTimezone;
1110
+ timeFormat?: TimeFormat;
956
1111
  }
957
1112
  type PriceScaleMode = "linear" | "log" | "percent";
958
1113
  interface PriceScaleOptions {
959
1114
  mode: PriceScaleMode;
960
1115
  inverted: boolean;
961
1116
  }
1117
+ /** IANA zone id, or the shorthands "local" (default) and "utc". */
1118
+ type ChartTimezone = "local" | "utc" | (string & {});
1119
+ type TimeFormat = "24h" | "12h";
1120
+ /** One continuous trading window in wall-clock time, e.g. 09:30 → 16:00. */
1121
+ interface SessionSegment {
1122
+ /** "HH:MM" in the session's own zone. */
1123
+ start: string;
1124
+ /** "HH:MM". Earlier than `start` means the window runs past midnight. */
1125
+ end: string;
1126
+ }
1127
+ interface SessionSpec {
1128
+ /** Zone the segment times are quoted in. Defaults to the machine zone. */
1129
+ timezone?: string;
1130
+ /**
1131
+ * Days the session *opens*, 0 = Sunday. Defaults to Monday–Friday. For a
1132
+ * window that runs past midnight this is the evening side: CME futures open
1133
+ * Sunday–Thursday (`[0,1,2,3,4]`) and trade into Monday–Friday morning, so
1134
+ * Friday evening is correctly closed for the weekend.
1135
+ */
1136
+ days?: number[];
1137
+ /** Defaults to a single all-day window. */
1138
+ segments?: SessionSegment[];
1139
+ }
1140
+ type SessionPresetName = "cme-futures" | "cme-rth" | "us-equities" | "us-equities-extended" | "24x7";
1141
+ /**
1142
+ * Trading-hours awareness. Without a spec the chart falls back to calendar
1143
+ * days for separators and shades nothing — the behavior of earlier versions.
1144
+ */
1145
+ interface SessionOptions {
1146
+ /** A preset name or your own spec. null disables session handling. */
1147
+ spec?: SessionSpec | SessionPresetName | null;
1148
+ /** Vertical rule at each session start. Default true when a spec is set. */
1149
+ separators?: boolean;
1150
+ /**
1151
+ * Tint bars that fall outside the session (overnight/extended hours), the
1152
+ * way TradingView greys pre/post market. Default false.
1153
+ */
1154
+ highlightOutOfSession?: boolean;
1155
+ outOfSessionColor?: string;
1156
+ }
1157
+ interface HistoryOptions {
1158
+ /** Default true. */
1159
+ enabled?: boolean;
1160
+ /** Steps kept before the oldest is dropped. Default 100. */
1161
+ limit?: number;
1162
+ }
1163
+ interface UndoRedoState {
1164
+ canUndo: boolean;
1165
+ canRedo: boolean;
1166
+ /** Human label of the step `undo()` would reverse, e.g. "Move drawing". */
1167
+ undoLabel: string | null;
1168
+ redoLabel: string | null;
1169
+ }
1170
+ interface ReplayStartOptions {
1171
+ /** Bar to resume from. Ignored when `fromTimeMs` is given. */
1172
+ fromIndex?: number;
1173
+ /** Resume from the bar at (or just before) this timestamp. */
1174
+ fromTimeMs?: number;
1175
+ /** Bars revealed per second while playing. Default 1. */
1176
+ speed?: number;
1177
+ /** Start playing immediately instead of waiting for `replayPlay()`. */
1178
+ play?: boolean;
1179
+ }
1180
+ interface ReplayState {
1181
+ active: boolean;
1182
+ playing: boolean;
1183
+ /** Bars per second. */
1184
+ speed: number;
1185
+ /** Index of the last revealed bar within the full series. */
1186
+ index: number;
1187
+ /** Length of the full series. */
1188
+ total: number;
1189
+ /** True once every bar has been revealed. */
1190
+ atEnd: boolean;
1191
+ /** Timestamp of the last revealed bar. */
1192
+ timeMs: number | null;
1193
+ }
1194
+ /**
1195
+ * "crossing" fires in either direction; the directional variants only fire on
1196
+ * the matching side; "greater"/"less" fire as soon as price is on that side,
1197
+ * including immediately if it already is.
1198
+ */
1199
+ type AlertCondition = "crossing" | "crossing-up" | "crossing-down" | "greater" | "less";
1200
+ interface AlertOptions {
1201
+ id?: string;
1202
+ price: number;
1203
+ /** Default "crossing". */
1204
+ condition?: AlertCondition;
1205
+ /** Extra text on the axis pill, after the price. */
1206
+ label?: string;
1207
+ color?: string;
1208
+ /** Armed and watching. Default true. */
1209
+ active?: boolean;
1210
+ /** Set by the chart when the condition is met; dims the line. */
1211
+ triggered?: boolean;
1212
+ /** Disarm after the first trigger. Default true. */
1213
+ once?: boolean;
1214
+ /** Let the user drag the line to a new price. Default true. */
1215
+ draggable?: boolean;
1216
+ }
1217
+ interface AlertTriggerEvent {
1218
+ alert: AlertOptions;
1219
+ /** Price that satisfied the condition. */
1220
+ price: number;
1221
+ timeMs: number;
1222
+ /** Bar index the trigger was detected on. */
1223
+ index: number;
1224
+ }
1225
+ interface AlertActionEvent {
1226
+ alert: AlertOptions;
1227
+ action: "move" | "remove" | "click";
1228
+ /** New price for "move". */
1229
+ price?: number;
1230
+ /** True for intermediate updates while the line is still being dragged. */
1231
+ dragging?: boolean;
1232
+ }
1233
+ type MarkShape = "circle" | "square" | "diamond" | "flag";
1234
+ /**
1235
+ * A small badge pinned to one bar — earnings, a news headline, an economic
1236
+ * release, a rule window. The chart resolves `time` to the bar it falls on.
1237
+ */
1238
+ interface BarMarkOptions {
1239
+ id?: string;
1240
+ /** Epoch ms or ISO string. */
1241
+ time: number | string;
1242
+ /** Default "below". Ignored when `price` is set. */
1243
+ position?: "above" | "below";
1244
+ /** Pin at an exact price instead of the bar's high/low. */
1245
+ price?: number;
1246
+ /** One or two characters drawn inside the badge, e.g. "E" or "FOMC"[0]. */
1247
+ label?: string;
1248
+ /** Tooltip text shown on hover. */
1249
+ text?: string;
1250
+ color?: string;
1251
+ textColor?: string;
1252
+ /** Badge radius in px. Default 7. */
1253
+ size?: number;
1254
+ shape?: MarkShape;
1255
+ }
1256
+ /** A badge on the time axis, for date-anchored events. */
1257
+ interface TimescaleMarkOptions {
1258
+ id?: string;
1259
+ time: number | string;
1260
+ label?: string;
1261
+ text?: string;
1262
+ color?: string;
1263
+ textColor?: string;
1264
+ shape?: MarkShape;
1265
+ }
1266
+ interface MarkClickEvent {
1267
+ kind: "bar" | "timescale";
1268
+ mark: BarMarkOptions | TimescaleMarkOptions;
1269
+ x: number;
1270
+ y: number;
1271
+ clientX: number;
1272
+ clientY: number;
1273
+ }
1274
+ interface MarkHoverEvent {
1275
+ kind: "bar" | "timescale";
1276
+ mark: BarMarkOptions | TimescaleMarkOptions;
1277
+ /** Canvas coordinates of the badge center. */
1278
+ x: number;
1279
+ y: number;
1280
+ clientX: number;
1281
+ clientY: number;
1282
+ }
962
1283
 
963
1284
  interface ScriptIndicatorInputDef {
964
1285
  key: string;
@@ -1076,6 +1397,15 @@ declare const compileScriptIndicator: (definition: ScriptIndicatorDefinition) =>
1076
1397
  declare const CHART_THEMES: Record<ChartThemeName, ChartTheme>;
1077
1398
  declare const CHART_THEME_NAMES: ChartThemeName[];
1078
1399
 
1400
+ /** True when the runtime accepts the zone id, so a typo can't break the chart. */
1401
+ declare const isValidTimeZone: (timeZone: string) => boolean;
1402
+ /**
1403
+ * Ready-made session definitions. `cme-futures` is the full electronic
1404
+ * session (Sunday 18:00 ET through Friday 17:00 ET with the daily 17:00–18:00
1405
+ * maintenance break); `cme-rth` is the US index pit-equivalent day session.
1406
+ */
1407
+ declare const SESSION_PRESETS: Record<SessionPresetName, SessionSpec>;
1408
+
1079
1409
  declare function createChart(element: HTMLElement, options?: ChartOptions): ChartInstance;
1080
1410
 
1081
- export { type AccessibilityOptions, type AxisOptions, type BuiltInIndicatorInfo, CHART_THEMES, CHART_THEME_NAMES, type ChartClickEvent, type ChartContextMenuEvent, type ChartContextMenuRegion, type ChartDatafeed, type ChartInstance, type ChartKeyboardAction, type ChartKeyboardShortcutEvent, type ChartLongPressEvent, type ChartOptions, type ChartSavedState, type ChartTheme, type ChartThemeName, type ChartType, type CompareSeriesOptions, type CrosshairMoveEvent, type CrosshairOptions, type CrosshairPriceActionEvent, type DashPatternOptions, type DatafeedBarsRequest, type DatafeedOptions, type DownsamplingOptions, type DrawingBounds, type DrawingDefaults, type DrawingHoverEvent, type DrawingObjectOptions, type DrawingPoint, type DrawingSelectEvent, type DrawingSelectionChangeEvent, 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 KeyboardOptions, 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 TouchOptions, type TradeMarkerOptions, type ViewportState, type WatermarkOptions, compileScriptIndicator, createChart, extractScriptInputs, validateScriptSource };
1411
+ export { type AccessibilityOptions, type AlertActionEvent, type AlertCondition, type AlertOptions, type AlertTriggerEvent, type AnimationOptions, type AxisOptions, type BarMarkOptions, type BuiltInIndicatorInfo, CHART_THEMES, CHART_THEME_NAMES, type ChartClickEvent, type ChartContextMenuEvent, type ChartContextMenuRegion, type ChartDatafeed, type ChartInstance, type ChartKeyboardAction, type ChartKeyboardShortcutEvent, type ChartLongPressEvent, type ChartOptions, type ChartSavedState, type ChartTheme, type ChartThemeName, type ChartTimezone, type ChartType, type CompareSeriesOptions, type CrosshairMoveEvent, type CrosshairOptions, type CrosshairPriceActionEvent, type DashPatternOptions, type DataLineOptions, type DatafeedBarsRequest, type DatafeedOptions, type DownsamplingOptions, type DrawingBounds, type DrawingDefaults, type DrawingHoverEvent, type DrawingObjectOptions, type DrawingPoint, type DrawingSelectEvent, type DrawingSelectionChangeEvent, type DrawingToolType, FIB_DEFAULT_PALETTE, type GridOptions, type HistoryOptions, type IndicatorInstanceOptions, type IndicatorPane, type IndicatorPaneActionEvent, type IndicatorPaneAxisOptions, type IndicatorPaneGuideLine, type IndicatorPaneHeightChangeEvent, type IndicatorPaneRenderInfo, type IndicatorPaneValue, type IndicatorPaneValueLabel, type IndicatorPlugin, type IndicatorRenderContext, type IndicatorUpdateOptions, type KeyboardOptions, type LabelsOptions, type MarkClickEvent, type MarkHoverEvent, type MarkShape, type OhlcDataPoint, type OrderActionButton, type OrderActionEvent, type OrderLineOptions, POSITION_DEFAULT_COLORS, type PriceLineOptions, type PriceScaleMode, type PriceScaleOptions, type ReplayStartOptions, type ReplayState, SCRIPT_SOURCE_INPUT_VALUES, SESSION_PRESETS, type ScriptComputeResult, type ScriptIndicatorDefinition, type ScriptIndicatorInputDef, type ScriptInputHelper, type ScriptInputOptions, type ScriptPlotSpec, type SessionOptions, type SessionPresetName, type SessionSegment, type SessionSpec, type TickerLineOptions, type TimeFormat, type TimescaleMarkOptions, type TouchOptions, type TradeMarkerOptions, type UndoRedoState, type ViewportState, type WatermarkOptions, compileScriptIndicator, createChart, extractScriptInputs, isValidTimeZone, validateScriptSource };