acttrader-charts 1.1.2 → 1.2.0-beta.2

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 CHANGED
@@ -1,4 +1,4 @@
1
- # acttrader-charts
1
+ # ActCharts
2
2
 
3
3
  A performant, zero-dependency stock charting library built on Canvas 2D.
4
4
  Dual ESM/CJS output, TypeScript-first.
@@ -84,6 +84,35 @@ chart.removeIndicator('SMA');
84
84
 
85
85
  Indicator pills appear inline above the chart (up to 2 visible; beyond that collapses into a dropdown).
86
86
 
87
+ #### Multiple instances of the same study
88
+
89
+ Parameterized studies support **multiple simultaneous instances** — e.g. EMA-20, EMA-50 and
90
+ EMA-200, or RSI-14 alongside RSI-7. Each instance gets an auto-cycled color so they're visually
91
+ distinct, and oscillators (RSI, MACD, …) each render in their own stacked sub-pane.
92
+
93
+ ```ts
94
+ chart.addIndicatorByName('EMA'); // EMA-20 (default)
95
+ chart.addIndicatorByName('EMA'); // a 2nd EMA, different color
96
+ // or build instances directly with different params:
97
+ chart.addIndicator(new EMA(50, '#22c55e'));
98
+ chart.addIndicator(new EMA(200, '#ef4444'));
99
+ ```
100
+
101
+ Selecting an already-active study in the Studies dropdown **adds another instance**. Remove a
102
+ specific instance via its pill **×** or the settings dialog's Remove button.
103
+
104
+ Each instance has a unique `instanceId` (e.g. `"EMA#3"`). Listen for it via the `indicatorAdded`
105
+ event and pass it to `removeIndicator` to target one instance:
106
+
107
+ ```ts
108
+ chart.on('indicatorAdded', ({ instanceId, shortName, params }) => { /* track it */ });
109
+ chart.removeIndicator('EMA#3'); // remove that one instance
110
+ chart.removeIndicator('EMA'); // (back-compat) remove ALL EMA instances
111
+ ```
112
+
113
+ A handful of studies remain **single-instance** (re-selecting toggles them off): `VOL`, `OBV`,
114
+ `A/D`, `AO`, `VWAP`, `Ichimoku`, `PSAR`, `Pivot`, and Heikin-Ashi.
115
+
87
116
  ### Drawing Tools
88
117
 
89
118
  ```ts
@@ -115,6 +144,50 @@ To push ticks directly without an adapter (e.g. from your own WebSocket handler)
115
144
  chart.pushTick({ time: Date.now(), bid: 1.2055, ask: 1.2057, volume: 120 });
116
145
  ```
117
146
 
147
+ ### Compare symbols
148
+
149
+ Overlay one or more comparison instruments on the main chart, normalized to
150
+ percent change from the leftmost visible bar — TradingView-style. Compares are
151
+ historical-only (no live streaming) and persist across primary symbol /
152
+ timeframe switches; the library refetches them automatically against the new
153
+ primary range whenever the chart's range changes.
154
+
155
+ ```ts
156
+ const chart = new ChartEngine({
157
+ container: document.getElementById('chart')!,
158
+ symbol: 'AAPL',
159
+ isins: ['AAPL', 'MSFT', 'GOOG', 'SPY', 'NVDA'],
160
+ headerLayout: 'advanced', // Compare button lives in this toolbar
161
+ initialCompares: ['SPY'], // optional — added on first dataLoaded
162
+ maxCompares: 8, // optional — default 8
163
+ compareDataLoader: async ({ symbol, start, end, interval }) => {
164
+ const res = await fetch(
165
+ `/api/bars?symbol=${symbol}&interval=${interval}` +
166
+ `&start=${start.toISOString()}&end=${end.toISOString()}`
167
+ );
168
+ return res.json(); // OHLCVBar[]
169
+ },
170
+ dataLoader: async (params) => fetchBars('AAPL', params),
171
+ });
172
+
173
+ // Programmatic API
174
+ await chart.addCompare('MSFT');
175
+ chart.removeCompare('MSFT');
176
+ chart.clearCompares();
177
+ chart.getCompares(); // [{ symbol, color, status }]
178
+
179
+ // Events
180
+ chart.on('compareAdded', ({ symbol, color }) => console.log('+', symbol));
181
+ chart.on('compareRemoved', ({ symbol }) => console.log('-', symbol));
182
+ chart.on('compareError', ({ symbol, message }) => console.warn(symbol, message));
183
+ ```
184
+
185
+ When any compare is active the Y-axis switches to percent (`+12.34%` /
186
+ `-5.67%`); removing every compare returns it to absolute-price labels.
187
+ The Compare button in the advanced toolbar opens an in-chart picker filtered
188
+ by `isins` (with the primary symbol and active compares hidden). To keep the
189
+ old consumer-owned flow, omit `compareDataLoader` and wire `onCompareClick`.
190
+
118
191
  ### Trade From Chart (TFC) — `setLevels`
119
192
 
120
193
  TFC renders draggable price levels for open positions and pending orders.
@@ -252,6 +325,7 @@ When `enableTrading` is on and live BID/ASK data is streaming, hovering / activa
252
325
  | `series` | | `"candlestick"` | Initial chart type |
253
326
  | `showVolume` | | `true` | Show volume overlay |
254
327
  | `showUI` | | `true` | Render top / bottom / left bars. When `false`, the loading overlay is also suppressed (mobile wrappers provide their own) |
328
+ | `hideHeader` | | `false` | Hide only the chart header (TopBar / AdvancedToolbar / CompactToolbar, per `headerLayout`). Bottom bar, left drawing tools, and on-canvas overlays remain on their own flags. Drive the chart from your own UI via `setTimeframe(tf)`, `setSeries(type)`, `addIndicatorByName(name)`, `removeIndicator(name)` |
255
329
  | `showDrawingTools` | | `true` | Show drawing toolbar and pencil button |
256
330
  | `showFullscreenButton` | | `true` | Show the fullscreen toggle button in the top bar. Set to `false` to hide it entirely. Mobile wrappers (Android / iOS) default this to `false` |
257
331
  | `timeframe` | | `"1D"` | Initial timeframe |
@@ -274,6 +348,9 @@ When `enableTrading` is on and live BID/ASK data is streaming, hovering / activa
274
348
  | `targetCandleWidth` | | `10` | Target px width per candle for auto-calculating initial bar count |
275
349
  | `durationTimeframeMap` | | *(see below)* | Override duration → timeframe pairings |
276
350
  | `dataLoader` | | — | `(params) => Promise<OHLCVBar[]>` auto-called on load / change |
351
+ | `compareDataLoader` | | — | `({ symbol, start, end, interval }) => Promise<OHLCVBar[]>` — fetches bars for a compare symbol. Set this to enable the library-owned Compare flow. |
352
+ | `initialCompares` | | — | Symbols to auto-add as compares once the initial primary range is loaded |
353
+ | `maxCompares` | | `8` | Maximum concurrent compare symbols. Adding beyond emits `compareError` |
277
354
  | `themeOverrides` | | — | Deep-partial color overrides applied on top of the built-in dark/light themes |
278
355
  | `uiConfig` | | `DEFAULT_UI_CONFIG` | Deep-partial size / font overrides per component |
279
356
  | `labels` | | `DEFAULT_LABELS` | Deep-partial string overrides for i18n/translation |
@@ -555,10 +632,16 @@ chart.setVolume(show: boolean): this
555
632
  ### Indicators
556
633
 
557
634
  ```ts
558
- chart.addIndicator(indicator: IIndicator): this
559
- chart.removeIndicator(name: string): this
635
+ chart.addIndicator(indicator: IIndicator, initialParams?: IndicatorParams): this
636
+ chart.addIndicatorByName(shortName: string, params?: IndicatorParams): void
637
+ chart.removeIndicator(idOrShortName: string): this
560
638
  ```
561
639
 
640
+ - `addIndicator` / `addIndicatorByName` — add a study. Multi-instance studies add a new instance
641
+ per call (auto-cycled color); single-instance studies toggle. `params` overrides period/color/source.
642
+ - `removeIndicator` — pass an `instanceId` (e.g. `"EMA#3"`, from the `indicatorAdded` event) to remove
643
+ that one instance, or a `shortName` (e.g. `"EMA"`) to remove **all** instances of that type.
644
+
562
645
  ### Drawing Tools
563
646
 
564
647
  ```ts
@@ -786,6 +869,8 @@ chart.on('seriesChange', ({ series }) => {});
786
869
  chart.on('streamStatus', ({ status }) => {}); // 'connected' | 'reconnecting' | 'disconnected'
787
870
  chart.on('dataLoaded', ({ timeframe, interval, start, end }) => {});
788
871
  chart.on('newBar', ({ completedBar, openingBar, intervalMs }) => {});
872
+ chart.on('indicatorAdded', ({ instanceId, shortName, params }) => {}); // a study instance was added — keep instanceId to remove it later
873
+ chart.on('indicatorRemoved', ({ instanceId, shortName }) => {});
789
874
  chart.on('stateChange', ({ symbol, state }) => {
790
875
  // Fires after every user-driven config change (timeframe, series, theme,
791
876
  // indicators, drawings, volume). `state` is a full serializable snapshot.
@@ -817,6 +902,113 @@ chart.on('tradeLevelBracketActivated', ({ label, bracketType, price, isFullscree
817
902
 
818
903
  ---
819
904
 
905
+ ## Multi-Pane Layouts
906
+
907
+ The library ships everything you need to put multiple synchronised `ChartEngine`s on one screen — preset definitions, a layout-picker popover, cross-pane sync, and a composite snapshot helper. The library *emits intent*; the host renders the grid.
908
+
909
+ ### Enabling the layout & snapshot UI
910
+
911
+ Pass two flags to `ChartConfig` (and optionally pick a header variant):
912
+
913
+ ```ts
914
+ const chart = new ChartEngine({
915
+ container,
916
+ headerLayout: 'advanced', // 'simple' (default) | 'advanced' | 'compact'
917
+ enableMultipleLayouts: true, // shows Layout button + 26 preset picker
918
+ enableSnapshot: true, // shows Snapshot button + Download/Copy popover
919
+ });
920
+
921
+ chart.on('layoutChange', ({ presetId, preset, sync }) => {
922
+ // Mount / teardown panes to match preset.count
923
+ // Apply sync flags to your ChartGroup
924
+ });
925
+
926
+ chart.on('snapshot', ({ dataUrl, action }) => {
927
+ // Native wrappers can intercept here to save via platform APIs
928
+ });
929
+ ```
930
+
931
+ ### `ChartGroup` — cross-pane sync
932
+
933
+ `ChartGroup` listens to events on the *active* engine and mirrors them to the others:
934
+
935
+ | Sync flag | Source event | Action on other panes
936
+ | ------------ | ------------------ | ----------------------------------------
937
+ | `interval` | `timeframeChange` | `setTimeframe` (skip if equal)
938
+ | `crosshair` | `crosshair` | `timeToBarIndex` → `setCrosshair`
939
+ | `time` | `pan` | `setViewport({ startIndex, endIndex })`
940
+ | `dateRange` | `zoom` | `setViewport({ startIndex, endIndex })`
941
+ | `symbol` | push (`broadcastSymbol`) | `setSymbol` (host still fetches data)
942
+
943
+ ```ts
944
+ import { ChartGroup, DEFAULT_LAYOUT_SYNC } from 'acttrader-charts';
945
+
946
+ const group = new ChartGroup({ sync: DEFAULT_LAYOUT_SYNC });
947
+ group.add('p1', engineA);
948
+ group.add('p2', engineB);
949
+ group.setActive('p1');
950
+
951
+ // react to user picking a preset
952
+ chart.on('layoutChange', ({ sync }) => group.setSync(sync));
953
+
954
+ // user picked a new symbol on the active pane
955
+ group.broadcastSymbol('AAPL', 'p1');
956
+ ```
957
+
958
+ `ChartEngine.setViewport` / `setCrosshair` deliberately do **not** re-emit `pan` / `zoom` / `crosshair`, so the mirror is safe from feedback loops.
959
+
960
+ ### Custom layout presets
961
+
962
+ Register an extra preset alongside the 26 built-ins; it appears in the picker automatically:
963
+
964
+ ```ts
965
+ import { registerCustomPreset } from 'acttrader-charts';
966
+
967
+ registerCustomPreset({
968
+ id: 'my-3-wide-left',
969
+ count: 3,
970
+ cols: '2fr 1fr',
971
+ rows: '1fr 1fr',
972
+ areas: '"a b" "a c"',
973
+ areaOrder: ['a', 'b', 'c'],
974
+ icon: '<svg>…</svg>',
975
+ });
976
+ ```
977
+
978
+ Persistence is the host's job — serialise the preset to your store, call `registerCustomPreset` again on app boot.
979
+
980
+ ### Composite snapshot of a multi-pane grid
981
+
982
+ `SnapshotPopover` captures the single active chart. For a whole-grid PNG, hand the cell rectangles to the group:
983
+
984
+ ```ts
985
+ const containerRect = gridEl.getBoundingClientRect();
986
+ const rects = paneIds.map(id => {
987
+ const cell = cellEls.get(id)!.getBoundingClientRect();
988
+ return {
989
+ paneId: id,
990
+ x: cell.left - containerRect.left,
991
+ y: cell.top - containerRect.top,
992
+ w: cell.width,
993
+ h: cell.height,
994
+ };
995
+ });
996
+
997
+ const dataUrl = group.toCompositeDataUrl({
998
+ width: containerRect.width,
999
+ height: containerRect.height,
1000
+ rects,
1001
+ });
1002
+ ```
1003
+
1004
+ The composite excludes trade levels (positions, SL/TP) — same rule as `chart.toDataUrl()`.
1005
+
1006
+ ### Native wrapper parity
1007
+
1008
+ `enableMultipleLayouts`, `enableSnapshot`, `headerLayout`, the `layoutChange` event, and the `snapshot` event are all exposed by [charts-android](../charts-android) and [charts-ios](../charts-ios) — see their READMEs for native usage.
1009
+
1010
+ ---
1011
+
820
1012
  ## Custom Indicator
821
1013
 
822
1014
  Implement `IIndicator` and pass it to `addIndicator()`:
@@ -1,3 +1,50 @@
1
+ /**
2
+ * Definition of a multi-chart layout preset (grid template).
3
+ * Used by the chart-owned LayoutPopover and emitted via the `layoutChange` event.
4
+ * The host project is responsible for actually mounting N panes per `count`.
5
+ */
6
+ interface LayoutPreset {
7
+ id: string;
8
+ count: number;
9
+ cols: string;
10
+ rows: string;
11
+ areas?: string;
12
+ areaOrder?: string[];
13
+ icon: string;
14
+ }
15
+ /** Cross-pane sync toggles emitted alongside layoutChange. */
16
+ interface LayoutSyncState {
17
+ symbol: boolean;
18
+ interval: boolean;
19
+ crosshair: boolean;
20
+ time: boolean;
21
+ dateRange: boolean;
22
+ }
23
+ declare const LAYOUT_PRESETS: LayoutPreset[];
24
+ declare const PRESETS_BY_COUNT: Record<number, LayoutPreset[]>;
25
+ declare const PRESET_COUNTS: number[];
26
+ /**
27
+ * Register a preset that appears alongside the built-ins in `getAllPresets()`
28
+ * and the chart-owned `LayoutPopover`. Re-registering the same id overwrites.
29
+ * Throws when the id collides with a built-in preset.
30
+ */
31
+ declare function registerCustomPreset(preset: LayoutPreset): void;
32
+ /** Remove a previously registered custom preset. No-op for unknown ids. */
33
+ declare function unregisterCustomPreset(id: string): void;
34
+ /** All registered custom presets, in insertion order. */
35
+ declare function getCustomPresets(): LayoutPreset[];
36
+ /** Built-ins followed by registered custom presets. */
37
+ declare function getAllPresets(): LayoutPreset[];
38
+ /**
39
+ * Resolve a preset by id, checking custom presets first, then built-ins. Falls
40
+ * back to the single-pane preset when nothing matches.
41
+ */
42
+ declare function getPreset(id: string): LayoutPreset;
43
+ /** Human-readable label for each preset, useful in status bars / tooltips. */
44
+ declare const PRESET_LABEL: Record<string, string>;
45
+ /** Default sync state — matches the host's current defaults in useChartLayout.ts. */
46
+ declare const DEFAULT_LAYOUT_SYNC: LayoutSyncState;
47
+
1
48
  declare class ScaleManager {
2
49
  private static readonly VERTICAL_PADDING_PX;
3
50
  xToPixel(index: number, viewport: Viewport, chartWidth: number): number;
@@ -37,6 +84,11 @@ interface DrawingToolbarUiConfig {
37
84
  btnGap: number;
38
85
  /** Container width (px) below which LeftBar switches to mobile layout */
39
86
  mobileBreakpoint: number;
87
+ /**
88
+ * Use Lucide-style modern SVG icons for the drawing toolbar categories.
89
+ * Default: `false` (original icons, unchanged for all existing consumers).
90
+ */
91
+ modernIcons?: boolean;
40
92
  }
41
93
  interface TopBarUiConfig {
42
94
  /** Height of the top bar strip */
@@ -354,6 +406,11 @@ interface ChartThemeUi {
354
406
  reconnecting: string;
355
407
  disconnected: string;
356
408
  };
409
+ /**
410
+ * Background color of the scroll-to-latest (➕) button.
411
+ * When omitted the button uses the chart background + axisBorder border (neutral style).
412
+ */
413
+ scrollToEndBtnBg?: string;
357
414
  }
358
415
  /** Colors specific to the drawing toolbar (LeftBar). */
359
416
  interface DrawingToolbarColors {
@@ -546,6 +603,13 @@ interface DataLoaderParams {
546
603
  end: Date;
547
604
  interval: string;
548
605
  }
606
+ /**
607
+ * Params passed to `compareDataLoader`. Mirrors `DataLoaderParams` but also
608
+ * carries the compare symbol so a single loader can serve multiple compares.
609
+ */
610
+ interface CompareDataLoaderParams extends DataLoaderParams {
611
+ symbol: string;
612
+ }
549
613
  /**
550
614
  * Per-theme deep-partial color overrides applied on top of the built-in
551
615
  * dark / light themes. Only the keys you supply are replaced.
@@ -935,6 +999,125 @@ interface ChartConfig {
935
999
  * Default: `false` (bar is hidden).
936
1000
  */
937
1001
  showBottomBar?: boolean;
1002
+ /**
1003
+ * Text-decoration for the clickable symbol name in the top-left OHLCV strip.
1004
+ * Default: `'underline'` (existing behaviour).
1005
+ * - `'underline'` → persistent underline whenever the symbol is clickable
1006
+ * - `'none'` → never underline; click handler still attached
1007
+ * - `'hover'` → no resting underline, but `:hover` / `:focus-visible` reveal one
1008
+ * (preferred for branded designs that still want a link affordance)
1009
+ */
1010
+ symbolNameDecoration?: 'underline' | 'none' | 'hover';
1011
+ /** Called when the user clicks "Add alert" in the trade popover. Omit to hide the alert row. */
1012
+ onAddAlert?: (price: number) => void;
1013
+ /**
1014
+ * Header layout variant. Default `'simple'`.
1015
+ * - `'simple'` — original top-bar with dropdowns + duration buttons
1016
+ * - `'advanced'` — compact toolbar with timeframe pills + Compare/1-Click
1017
+ * - `'compact'` — slim per-pane toolbar (timeframe + series + indicators only),
1018
+ * sized for multi-pane grid cells. Symbol is changed via the
1019
+ * on-canvas OHLC strip label (no symbol button in this variant).
1020
+ *
1021
+ * If both `headerLayout` and the deprecated `features.advancedToolbar` are set,
1022
+ * `headerLayout` wins.
1023
+ */
1024
+ headerLayout?: 'simple' | 'advanced' | 'compact';
1025
+ /**
1026
+ * Hide the chart header entirely (simple TopBar / AdvancedToolbar /
1027
+ * CompactToolbar — whichever `headerLayout` would have rendered).
1028
+ *
1029
+ * Use when the host UI provides its own controls and drives the chart via
1030
+ * `setTimeframe`, `setSeries`, `addIndicatorByName`, `removeIndicator`.
1031
+ *
1032
+ * Independent of `showUI` (which hides ALL UI) and `showBottomBar` /
1033
+ * drawing-tools / OHLC strip flags. Default: `false` (header visible).
1034
+ */
1035
+ hideHeader?: boolean;
1036
+ /**
1037
+ * Show the Layout button and built-in multi-chart layout preset popover.
1038
+ * Default `false`. Works in both `'simple'` and `'advanced'` header layouts.
1039
+ *
1040
+ * The chart owns ONLY the picker UI. Selecting a preset emits a `layoutChange`
1041
+ * event with `{ presetId, preset, sync }`; the host project is responsible for
1042
+ * mounting the actual N-pane grid of ChartEngine instances and applying sync.
1043
+ *
1044
+ * Suppresses the deprecated `onLayoutClick` callback if also provided
1045
+ * (a one-time `console.warn` is logged at init).
1046
+ */
1047
+ enableMultipleLayouts?: boolean;
1048
+ /**
1049
+ * Show the Snapshot button and built-in Download/Copy popover.
1050
+ * Default `false`. Works in both `'simple'` and `'advanced'` header layouts.
1051
+ *
1052
+ * The chart emits a `snapshot` event with `{ dataUrl, action }` BEFORE
1053
+ * attempting the native browser action — mobile wrappers (Android/iOS)
1054
+ * can intercept via the JS bridge to use native APIs (Photos library,
1055
+ * UIPasteboard, ClipboardManager) where browser permissions are restricted.
1056
+ *
1057
+ * Suppresses the deprecated `onScreenshotClick` callback if also provided
1058
+ * (a one-time `console.warn` is logged at init).
1059
+ */
1060
+ enableSnapshot?: boolean;
1061
+ /**
1062
+ * Opt-in feature flags. All flags default to `false` / disabled so existing
1063
+ * consumers are completely unaffected when this field is omitted.
1064
+ */
1065
+ features?: {
1066
+ /**
1067
+ * @deprecated Use top-level `headerLayout: 'advanced'` instead. Will be
1068
+ * removed in a future major version. Currently treated as an alias.
1069
+ */
1070
+ advancedToolbar?: boolean;
1071
+ };
1072
+ /**
1073
+ * Fetches historical OHLC bars for a compare symbol. When provided, the
1074
+ * library owns the Compare flow end-to-end: clicking the Compare button
1075
+ * opens an in-chart picker (reusing `isins`), and this loader is invoked
1076
+ * to populate each chosen compare. It is also re-invoked whenever the
1077
+ * primary symbol's range changes (timeframe switch, primary-symbol switch,
1078
+ * history pan-back, `resetData`) so compares stay aligned.
1079
+ *
1080
+ * No streaming — compares are historical-only in v1.
1081
+ */
1082
+ compareDataLoader?: (params: CompareDataLoaderParams) => Promise<OHLCVBar[]>;
1083
+ /**
1084
+ * Compare symbols to add automatically on chart init. Each one triggers a
1085
+ * `compareDataLoader` call against the initial primary range.
1086
+ */
1087
+ initialCompares?: string[];
1088
+ /**
1089
+ * Maximum number of concurrent compare symbols. Attempting to add beyond
1090
+ * this emits a `compareError` event instead of fetching. Default: `8`.
1091
+ */
1092
+ maxCompares?: number;
1093
+ /**
1094
+ * @deprecated With `enableMultipleLayouts: true`, the chart owns the popover
1095
+ * and emits a `layoutChange` event. Listen to that event instead.
1096
+ * Still honored when `enableMultipleLayouts` is omitted/false.
1097
+ */
1098
+ onLayoutClick?: () => void;
1099
+ /**
1100
+ * Called when the user toggles the 1-Click Trade button. Receives the new
1101
+ * active state as a boolean. The button is rendered in whichever toolbar is
1102
+ * active (default `TopBar` or `AdvancedToolbar`).
1103
+ *
1104
+ * **When omitted, the 1-Click Trade button is hidden** — callback presence
1105
+ * gates the button's visibility, matching the pattern used by
1106
+ * `onLayoutClick` / `onScreenshotClick`.
1107
+ */
1108
+ onOneClickTradeToggle?: (active: boolean) => void;
1109
+ /**
1110
+ * @deprecated Renamed to `onOneClickTradeToggle` for clarity. Will be
1111
+ * removed in a future major version. If both are provided,
1112
+ * `onOneClickTradeToggle` wins and a console warning is emitted.
1113
+ */
1114
+ onOneClickToggle?: (active: boolean) => void;
1115
+ /**
1116
+ * @deprecated With `enableSnapshot: true`, the chart owns the popover and
1117
+ * emits a `snapshot` event. Listen to that event instead.
1118
+ * Still honored when `enableSnapshot` is omitted/false.
1119
+ */
1120
+ onScreenshotClick?: () => void;
938
1121
  /**
939
1122
  * @deprecated DraftOrderQtyInput has been removed. This option is a no-op.
940
1123
  * Accepted for backward compatibility only.
@@ -1045,6 +1228,13 @@ interface IWebSocketAdapter {
1045
1228
  }
1046
1229
  type IndicatorParams = Record<string, number | string>;
1047
1230
  interface ActiveIndicatorState {
1231
+ /**
1232
+ * Unique per-instance identifier (e.g. "EMA#3"). Distinguishes multiple
1233
+ * active instances of the same indicator type. All per-instance state and
1234
+ * UI (results cache, sub-pane overlays, scale factors, pills) is keyed by
1235
+ * this, not by `shortName` — so e.g. EMA-20, EMA-50 and EMA-200 can coexist.
1236
+ */
1237
+ instanceId: string;
1048
1238
  indicator: IIndicator;
1049
1239
  shortName: string;
1050
1240
  currentParams: IndicatorParams;
@@ -1067,6 +1257,12 @@ interface IndicatorStateEntry {
1067
1257
  shortName: string;
1068
1258
  params: IndicatorParams;
1069
1259
  visible?: boolean;
1260
+ /**
1261
+ * Per-instance id captured at serialization time. Optional for backward
1262
+ * compatibility — configs saved before multi-instance support omit it, and
1263
+ * `setState` mints a fresh id when it's absent.
1264
+ */
1265
+ instanceId?: string;
1070
1266
  }
1071
1267
  /** Color overrides for the chart canvas elements (background, grid, candles, etc.). */
1072
1268
  interface CanvasColorSettings {
@@ -1126,6 +1322,11 @@ interface ChartState {
1126
1322
  factor: number;
1127
1323
  panOffset: number;
1128
1324
  };
1325
+ /**
1326
+ * Active compare symbols at snapshot time. The library will re-add each
1327
+ * one (in order) via `compareDataLoader` when this state is restored.
1328
+ */
1329
+ compares?: string[];
1129
1330
  }
1130
1331
  interface CrosshairPosition {
1131
1332
  x: number;
@@ -1135,7 +1336,12 @@ interface CrosshairPosition {
1135
1336
  bar: OHLCVBar | null;
1136
1337
  }
1137
1338
  type ChartEventMap = {
1138
- crosshair: CrosshairPosition;
1339
+ /**
1340
+ * Crosshair position changed. Payload is `null` when the crosshair leaves
1341
+ * the chart area or is otherwise cleared — listeners that mirror crosshair
1342
+ * across multiple panes use `null` to clear the mirrored crosshair.
1343
+ */
1344
+ crosshair: CrosshairPosition | null;
1139
1345
  click: CrosshairPosition;
1140
1346
  zoom: {
1141
1347
  viewport: Viewport;
@@ -1327,6 +1533,60 @@ type ChartEventMap = {
1327
1533
  bracketOrderLabel?: string;
1328
1534
  }>;
1329
1535
  };
1536
+ /**
1537
+ * Emitted when the user picks a preset in the multi-layout popover or toggles
1538
+ * a sync option. Fires only when `enableMultipleLayouts: true`. The host
1539
+ * project listens to this event to mount/teardown N panes accordingly.
1540
+ */
1541
+ layoutChange: {
1542
+ presetId: string;
1543
+ preset: LayoutPreset;
1544
+ sync: LayoutSyncState;
1545
+ };
1546
+ /**
1547
+ * Emitted when the user picks Download or Copy from the snapshot popover.
1548
+ * Fires only when `enableSnapshot: true`. The chart attempts the native
1549
+ * browser action immediately after emitting; mobile wrappers can intercept
1550
+ * via the JS bridge to short-circuit and use platform APIs.
1551
+ */
1552
+ snapshot: {
1553
+ /** Full PNG data URL of the composited chart canvas. */
1554
+ dataUrl: string;
1555
+ action: 'download' | 'copy';
1556
+ };
1557
+ /** Emitted after a compare symbol has been added and its bars resolved. */
1558
+ compareAdded: {
1559
+ symbol: string;
1560
+ color: string;
1561
+ };
1562
+ /** Emitted when a compare symbol is removed (×, `removeCompare`, or `clearCompares`). */
1563
+ compareRemoved: {
1564
+ symbol: string;
1565
+ };
1566
+ /**
1567
+ * Emitted when adding a compare or fetching its bars fails — e.g. no
1568
+ * `compareDataLoader` configured, loader rejected, or `maxCompares` reached.
1569
+ */
1570
+ compareError: {
1571
+ symbol: string;
1572
+ message: string;
1573
+ };
1574
+ /**
1575
+ * Emitted after an indicator instance is added. `instanceId` uniquely
1576
+ * identifies the instance (e.g. "EMA#3") so callers can later remove that
1577
+ * specific instance via `removeIndicator(instanceId)` — important now that
1578
+ * multiple instances of the same `shortName` can coexist.
1579
+ */
1580
+ indicatorAdded: {
1581
+ instanceId: string;
1582
+ shortName: string;
1583
+ params: IndicatorParams;
1584
+ };
1585
+ /** Emitted after an indicator instance is removed (pill ×, settings dialog, or `removeIndicator`). */
1586
+ indicatorRemoved: {
1587
+ instanceId: string;
1588
+ shortName: string;
1589
+ };
1330
1590
  };
1331
1591
  /** Distinguishes level types: historical trade, open position, or pending order. */
1332
1592
  type TradeLevelType = 'trade' | 'position' | 'pending';
@@ -1518,4 +1778,4 @@ declare class MACD implements IIndicator {
1518
1778
  render(ctx: CanvasRenderingContext2D, results: IndicatorResult[], scale: ScaleManager, viewport: Viewport, paneHeight: number, rangeOverride?: PriceRange): void;
1519
1779
  }
1520
1780
 
1521
- export { type IndicatorOverlayColors as $, type AnyDrawingStyle as A, BollingerBands as B, type ChartConfig as C, type DrawingToolType as D, DEFAULT_DRAWING_TOOLBAR_CONFIG as E, DEFAULT_INDICATOR_OVERLAY_CONFIG as F, DEFAULT_LABELS as G, DEFAULT_PRICE_AXIS_CONFIG as H, type IIndicator as I, DEFAULT_TIME_AXIS_CONFIG as J, DEFAULT_TOP_BAR_CONFIG as K, DEFAULT_TRADE_BUTTON_CONFIG as L, DEFAULT_UI_CONFIG as M, type DataLoaderParams as N, type OHLCVBar as O, type PriceRange as P, type DeepPartial$1 as Q, type DeepPartialChartTheme as R, type SeriesType as S, type Timeframe as T, type DialogLabels as U, type Viewport as V, type DrawingToolbarColors as W, type DrawingToolbarLabels as X, type DrawingToolbarUiConfig as Y, type Duration as Z, EMA as _, type ChartEventMap as a, type IndicatorOverlayUiConfig as a0, type IndicatorParams as a1, type IndicatorResult as a2, type IndicatorStateEntry as a3, LIGHT_THEME as a4, MACD as a5, type OhlcLabels as a6, type OrderSubmit as a7, type Padding as a8, type PendingOrderLevel as a9, type PositionLevel as aa, type PositionRenderStyle as ab, type PriceAxisUiConfig as ac, RSI as ad, SMA as ae, type Theme as af, type ThemeOverrides as ag, type TimeAxisUiConfig as ah, type TopBarColors as ai, type TopBarLabels as aj, type TopBarUiConfig as ak, type TradeButtonUiConfig as al, type TradeDisplayFilter as am, type TradeLabels as an, type TradeLevel as ao, type TradeLevelColors as ap, type TradePanelColors as aq, type UiConfig as ar, deepMergeTheme as as, resolveCssVarsInTheme as at, resolveLabels as au, resolveUiConfig as av, type PriceSource as aw, type ChartState as b, type IDrawing as c, type IWebSocketAdapter as d, type TradeLevelType as e, type AnyLevel as f, type DrawingPoint as g, ScaleManager as h, type DrawingHandle as i, type ChartTheme as j, type SerializedDrawing as k, type Tick as l, type StreamStatus as m, type ActiveIndicatorState as n, type BottomBarColors as o, type BottomBarLabels as p, type BottomBarUiConfig as q, type CanvasColorSettings as r, type ChartLabels as s, type ChartMiscLabels as t, type ChartThemeUi as u, type CrosshairPosition as v, type CrosshairUiConfig as w, DARK_THEME as x, DEFAULT_BOTTOM_BAR_CONFIG as y, DEFAULT_CROSSHAIR_CONFIG as z };
1781
+ export { type DrawingToolbarUiConfig as $, type AnyDrawingStyle as A, BollingerBands as B, type ChartConfig as C, type DrawingToolType as D, DEFAULT_CROSSHAIR_CONFIG as E, DEFAULT_DRAWING_TOOLBAR_CONFIG as F, DEFAULT_INDICATOR_OVERLAY_CONFIG as G, DEFAULT_LABELS as H, type IIndicator as I, DEFAULT_LAYOUT_SYNC as J, DEFAULT_PRICE_AXIS_CONFIG as K, type LayoutSyncState as L, DEFAULT_TIME_AXIS_CONFIG as M, DEFAULT_TOP_BAR_CONFIG as N, type OHLCVBar as O, type PriceRange as P, DEFAULT_TRADE_BUTTON_CONFIG as Q, DEFAULT_UI_CONFIG as R, type SeriesType as S, type Timeframe as T, type DataLoaderParams as U, type Viewport as V, type DeepPartial$1 as W, type DeepPartialChartTheme as X, type DialogLabels as Y, type DrawingToolbarColors as Z, type DrawingToolbarLabels as _, type IndicatorParams as a, type Duration as a0, EMA as a1, type IndicatorOverlayColors as a2, type IndicatorOverlayUiConfig as a3, type IndicatorResult as a4, type IndicatorStateEntry as a5, LAYOUT_PRESETS as a6, LIGHT_THEME as a7, type LayoutPreset as a8, MACD as a9, getAllPresets as aA, getCustomPresets as aB, getPreset as aC, registerCustomPreset as aD, resolveCssVarsInTheme as aE, resolveLabels as aF, resolveUiConfig as aG, unregisterCustomPreset as aH, type PriceSource as aI, type OhlcLabels as aa, type OrderSubmit as ab, PRESETS_BY_COUNT as ac, PRESET_COUNTS as ad, PRESET_LABEL as ae, type Padding as af, type PendingOrderLevel as ag, type PositionLevel as ah, type PositionRenderStyle as ai, type PriceAxisUiConfig as aj, RSI as ak, SMA as al, type Theme as am, type ThemeOverrides as an, type TimeAxisUiConfig as ao, type TopBarColors as ap, type TopBarLabels as aq, type TopBarUiConfig as ar, type TradeButtonUiConfig as as, type TradeDisplayFilter as at, type TradeLabels as au, type TradeLevel as av, type TradeLevelColors as aw, type TradePanelColors as ax, type UiConfig as ay, deepMergeTheme as az, type ChartEventMap as b, type ChartState as c, type IDrawing as d, type IWebSocketAdapter as e, type TradeLevelType as f, type ChartTheme as g, type AnyLevel as h, type DrawingPoint as i, ScaleManager as j, type DrawingHandle as k, type SerializedDrawing as l, type Tick as m, type StreamStatus as n, type ActiveIndicatorState as o, type BottomBarColors as p, type BottomBarLabels as q, type BottomBarUiConfig as r, type CanvasColorSettings as s, type ChartLabels as t, type ChartMiscLabels as u, type ChartThemeUi as v, type CrosshairPosition as w, type CrosshairUiConfig as x, DARK_THEME as y, DEFAULT_BOTTOM_BAR_CONFIG as z };