openalgo-charts 1.0.1 → 1.0.3

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.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /** Library version string. Matches package.json (published npm release). */
2
- declare const VERSION = "1.0.1";
2
+ declare const VERSION = "1.0.3";
3
3
  /** Returns the current library version. */
4
4
  declare function version(): string;
5
5
 
@@ -220,6 +220,18 @@ declare class TimeScale {
220
220
  xToIndex(x: number): number;
221
221
  /** Currently visible logical index range (fractional, unclamped to data). */
222
222
  visibleRange(): LogicalRange;
223
+ /** Alias of `visibleRange()` for naming parity with common charting APIs. */
224
+ getVisibleLogicalRange(): LogicalRange;
225
+ /**
226
+ * Set the visible logical range (best effort): pick a bar spacing so the span
227
+ * fills the width and anchor the right edge at `range.to`. Bar spacing is
228
+ * clamped to [min,max], so an extreme span lands at the nearest zoom. Fires the
229
+ * change handler so a host that mutates the scale directly still repaints.
230
+ */
231
+ setVisibleLogicalRange(range: LogicalRange): void;
232
+ /** Repaint hook injected by the host chart, fired after `setVisibleLogicalRange`. */
233
+ setChangeHandler(fn: (() => void) | null): void;
234
+ private _onChange;
223
235
  /**
224
236
  * Pan by a pixel delta. Positive `dx` drags chart content to the right
225
237
  * (revealing older bars), matching a natural left-button drag.
@@ -351,8 +363,18 @@ interface SeriesStyle {
351
363
  hollow?: boolean;
352
364
  /** Scale candle body width by volume / maxVisibleVolume (volume candles). */
353
365
  volumeScaled?: boolean;
366
+ /** Whether the series is drawn and counted in autoscale. Default true. */
367
+ visible?: boolean;
368
+ /** Optional label carried with the series (for host-drawn legends). */
369
+ title?: string;
370
+ /** Show the dashed horizontal last-price line across the plot. Default true. */
371
+ priceLineVisible?: boolean;
372
+ /** Show the last-value tag on the price axis. Default true. */
373
+ lastValueVisible?: boolean;
354
374
  color?: string;
355
375
  lineWidth?: number;
376
+ /** Line dash style for line/step/area/HLC series. Default 'solid'. */
377
+ lineStyle?: 'solid' | 'dashed' | 'dotted';
356
378
  step?: boolean;
357
379
  markers?: boolean;
358
380
  markerRadius?: number;
@@ -385,6 +407,18 @@ interface ChartTheme {
385
407
  axisText: string;
386
408
  axisLine: string;
387
409
  crosshair: string;
410
+ /** Axis label font size in px (default 11). */
411
+ axisFontSize?: number;
412
+ /** Grid line dash style (default 'solid'). */
413
+ gridStyle?: 'solid' | 'dashed' | 'dotted';
414
+ /** Crosshair line dash style (default 'dashed'). */
415
+ crosshairStyle?: 'solid' | 'dashed' | 'dotted';
416
+ /** Crosshair line width in device px (default 1 = hairline). */
417
+ crosshairWidth?: number;
418
+ /** Background of the crosshair value tags (defaults to `crosshair`). */
419
+ crosshairLabelBackground?: string;
420
+ /** Show the crosshair price/time value tags (default true). */
421
+ crosshairLabelVisible?: boolean;
388
422
  upColor: string;
389
423
  downColor: string;
390
424
  wickUpColor: string;
@@ -526,10 +560,17 @@ declare class SeriesMarkers implements IPrimitive {
526
560
  * so the core never switches on type.
527
561
  */
528
562
 
563
+ /**
564
+ * Which price axis a series maps to. 'right' (default) and 'left' each draw an
565
+ * axis and autoscale independently; '' is a hidden overlay scale (no axis, its
566
+ * own autoscale) used to pin a volume histogram inside the price pane.
567
+ */
568
+ type PriceScaleId = 'right' | 'left' | '';
529
569
  interface SeriesRecord {
530
570
  dataId: SeriesId;
531
571
  type: SeriesType;
532
572
  style: SeriesStyle;
573
+ scaleId: PriceScaleId;
533
574
  }
534
575
  /** Public handle returned by `chart.addSeries(...)`. */
535
576
  interface SeriesApi {
@@ -541,10 +582,30 @@ interface SeriesApi {
541
582
  update(bar: SeriesDataItem): void;
542
583
  /** Current bars for this series (sorted old -> new, normalized to OHLC). Handy for computing the next live update. */
543
584
  getData(): Bar[];
585
+ /** Merge a partial style into the series and repaint (recolor, `{ visible:false }` to hide, ...). */
586
+ applyOptions(style: Partial<SeriesStyle>): void;
587
+ /** Remove the series from its pane and free its data rows. */
588
+ remove(): void;
589
+ /** The price scale this series maps to (call `.setOptions({ marginTop, marginBottom })` on it). */
590
+ priceScale(): PriceScale;
544
591
  /** Create a markers layer (buy/sell signals, shapes) bound to this series. */
545
592
  createMarkers(): SeriesMarkers;
546
593
  }
547
594
 
595
+ /**
596
+ * Axis label rendering (ARCHITECTURE.md §6, §5.3). Price axis (right strip) and
597
+ * time axis (bottom strip). Time labels switch from clock to date at IST day
598
+ * boundaries; gaps are already collapsed by the logical-index time scale.
599
+ */
600
+
601
+ /**
602
+ * Boundary class of a time-axis label, passed to a custom `timeFormatter` as a
603
+ * hint so a host can render adaptive labels (year at year boundaries, month at
604
+ * month boundaries, day otherwise, clock intraday) — parity with common
605
+ * `tickMarkFormatter(time, tickMarkType)` APIs.
606
+ */
607
+ type TickMarkType = 'year' | 'month' | 'day' | 'time' | 'timeWithSeconds';
608
+
548
609
  /**
549
610
  * A pane is one vertically-stacked drawing region (price pane, volume pane,
550
611
  * indicator pane). It owns a base + top canvas (ARCHITECTURE.md §3.1) and a
@@ -556,6 +617,8 @@ interface PaneRenderContext {
556
617
  dataLayer: DataLayer;
557
618
  dpr: number;
558
619
  priceAxisWidth: number;
620
+ /** Left inset (px) reserved chart-wide for a left price axis; 0/absent when none. */
621
+ leftAxisWidth?: number;
559
622
  timeAxisHeight: number;
560
623
  /** Only the bottom pane draws the time axis. */
561
624
  showTimeAxis: boolean;
@@ -570,13 +633,16 @@ interface PaneRenderContext {
570
633
  /** Draw the horizontal (price) grid lines. */
571
634
  showHorzGrid: boolean;
572
635
  /** Optional custom time label formatter (UTC seconds -> string). Defaults to IST. */
573
- timeFormatter?: (utcSeconds: number) => string;
636
+ timeFormatter?: (utcSeconds: number, tickMark?: TickMarkType) => string;
574
637
  }
575
638
  declare class Pane {
576
639
  readonly element: HTMLElement;
577
640
  readonly base: CanvasLayer;
578
641
  readonly top: CanvasLayer;
579
642
  readonly priceScale: PriceScale;
643
+ /** Extra scales created on demand: left axis and a hidden overlay (volume). */
644
+ private _leftScale;
645
+ private _overlayScale;
580
646
  /** Relative height weight within the chart (price=1, volume≈0.3). */
581
647
  weight: number;
582
648
  private readonly _series;
@@ -585,6 +651,14 @@ declare class Pane {
585
651
  private _height;
586
652
  constructor(doc: Document);
587
653
  addSeries(record: SeriesRecord): void;
654
+ /** The PriceScale for a scale id, creating the left/overlay scale on first use. */
655
+ private _scaleFor;
656
+ /** The price scale a series maps to (for the series handle's `priceScale()`). */
657
+ scaleOf(record: SeriesRecord): PriceScale;
658
+ /** True when a left-axis scale is active (some series maps to it). */
659
+ hasLeftScale(): boolean;
660
+ /** Remove a series record if present; returns true if it was found. */
661
+ removeSeries(record: SeriesRecord): boolean;
588
662
  series(): readonly SeriesRecord[];
589
663
  addPrimitive(primitive: IPrimitive, host: PrimitiveHost): void;
590
664
  /** Remove a primitive if present; returns true if it was found. */
@@ -596,8 +670,9 @@ declare class Pane {
596
670
  hitTestPrimitives(x: number, y: number, ctx: PaneRenderContext): PrimitiveHit | null;
597
671
  resize(width: number, height: number, dpr: number): void;
598
672
  private _layout;
599
- /** Recompute the price range from the visible bars of all series in this pane. */
673
+ /** Autoscale each active price scale from its own series (independent axes). */
600
674
  autoscale(ctx: PaneRenderContext): void;
675
+ private _autoscaleScale;
601
676
  /** Paint background + grid + series + axes on the base canvas. */
602
677
  paintBase(ctx: PaneRenderContext): void;
603
678
  /**
@@ -1014,14 +1089,37 @@ interface ChartOptions {
1014
1089
  * omitted, labels use IST (Indian market default). e.g. for UTC:
1015
1090
  * `(s) => new Date(s * 1000).toISOString().slice(11, 16)`.
1016
1091
  */
1017
- timeFormatter?: (utcSeconds: number) => string;
1092
+ timeFormatter?: (utcSeconds: number, tickMark?: TickMarkType) => string;
1018
1093
  }
1019
1094
  interface AddSeriesOptions {
1020
1095
  /** Target pane index (0 = price). Higher panes are created on demand. */
1021
1096
  paneIndex?: number;
1022
1097
  /** Style overrides merged onto the chart type's defaults. */
1023
1098
  style?: SeriesStyle;
1099
+ /**
1100
+ * Which price axis this series maps to. 'right' (default) and 'left' each draw
1101
+ * an axis and autoscale independently; '' is a hidden overlay scale (no axis)
1102
+ * for a volume histogram inside the price pane.
1103
+ */
1104
+ priceScaleId?: PriceScaleId;
1105
+ /**
1106
+ * Value formatting applied to this series' price scale (axis + crosshair tag):
1107
+ * `price` (tick-size precision), `volume` (compact 1.2K / 3.4M / 5.6B), or a
1108
+ * `custom` formatter (currency, percent, ...).
1109
+ */
1110
+ priceFormat?: {
1111
+ type: 'price';
1112
+ precision?: number;
1113
+ minMove?: number;
1114
+ } | {
1115
+ type: 'volume';
1116
+ } | {
1117
+ type: 'custom';
1118
+ formatter: (value: number) => string;
1119
+ };
1024
1120
  }
1121
+ /** Compact volume/number formatter (1.2K / 3.4M / 5.6B). */
1122
+ declare function compactVolume(v: number): string;
1025
1123
  /**
1026
1124
  * Emitted on every crosshair move (and `null` fields on pointer-leave) so a host
1027
1125
  * can render an OHLC legend / tooltip. `bar` is the hovered bar of the primary
@@ -1047,7 +1145,7 @@ declare class Chart {
1047
1145
  private readonly _container;
1048
1146
  private readonly _doc;
1049
1147
  private readonly _pixelRatio;
1050
- private readonly _theme;
1148
+ private _theme;
1051
1149
  private readonly _panes;
1052
1150
  private readonly _loop;
1053
1151
  private readonly _dataLayer;
@@ -1106,6 +1204,7 @@ declare class Chart {
1106
1204
  private _priceFormatter;
1107
1205
  private _priceScaleOptions;
1108
1206
  private _timeFormatter;
1207
+ private _leftAxisWidth;
1109
1208
  constructor(container: HTMLElement, options?: ChartOptions);
1110
1209
  /** Register a callback fired when the user pans near the left (oldest) edge. */
1111
1210
  setHistoryLoader(loader: () => void): void;
@@ -1113,6 +1212,12 @@ declare class Chart {
1113
1212
  historyLoadComplete(): void;
1114
1213
  get dataLayer(): DataLayer;
1115
1214
  get timeScale(): TimeScale;
1215
+ /** Restore a saved logical range (e.g. preserve the user's zoom across a data reload). */
1216
+ setVisibleLogicalRange(range: LogicalRange): void;
1217
+ /** The current visible logical range. */
1218
+ getVisibleLogicalRange(): LogicalRange;
1219
+ /** Fit all bars into view (no-arg convenience; bar count from the data). */
1220
+ fitContent(): void;
1116
1221
  /** The keyboard shortcut manager (null when shortcuts are disabled). */
1117
1222
  get shortcuts(): ShortcutManager | null;
1118
1223
  /**
@@ -1203,12 +1308,30 @@ declare class Chart {
1203
1308
  * Set a custom time-axis + crosshair label formatter (UTC seconds -> string)
1204
1309
  * at runtime. Pass undefined to restore the IST default.
1205
1310
  */
1206
- setTimeFormatter(fn: ((utcSeconds: number) => string) | undefined): void;
1311
+ setTimeFormatter(fn: ((utcSeconds: number, tickMark?: TickMarkType) => string) | undefined): void;
1312
+ /** Swap the palette at runtime (dark/light toggle) without recreating the chart. */
1313
+ setTheme(theme: ChartTheme): void;
1314
+ /**
1315
+ * Apply a subset of chart options at runtime (theme, grid, formatters,
1316
+ * crosshair mode) without recreating the chart.
1317
+ */
1318
+ applyOptions(opts: {
1319
+ theme?: ChartTheme;
1320
+ grid?: {
1321
+ vertLines?: boolean;
1322
+ horzLines?: boolean;
1323
+ };
1324
+ priceFormatter?: ((price: number) => string) | null;
1325
+ timeFormatter?: ((utcSeconds: number, tickMark?: TickMarkType) => string) | undefined;
1326
+ crosshairMode?: CrosshairMode;
1327
+ }): void;
1207
1328
  panes(): readonly Pane[];
1208
1329
  invalidate(build: (mask: InvalidateMask) => void): void;
1209
1330
  applySize(width: number, height: number): void;
1210
1331
  /** Distribute height across panes by weight; sync the shared time-scale width. */
1211
1332
  private _relayout;
1333
+ /** Reserve a chart-wide left-axis column when any pane has a left price scale. */
1334
+ private _recomputeLeftAxis;
1212
1335
  private _weightTotal;
1213
1336
  /** Cumulative top + height of each pane, by weight (the source of truth for hit-testing). */
1214
1337
  private _paneLayout;
@@ -2031,4 +2154,4 @@ declare function lerp(a: number, b: number, t: number): number;
2031
2154
  */
2032
2155
  declare function roundToTick(value: number, step: number): number;
2033
2156
 
2034
- export { ALT_PRESET, type AddSeriesOptions, type AggTick, BUILTIN_COMMANDS, type Bar, type BarUpdate, type BarsRequest, CandleBuilder, type CandleBuilderOptions, type CandleStyle, type CandleUpdate, Chart, type ChartEvent, type ChartOptions, type ChartTheme, type CrosshairMoveEvent, type CustomShortcut, DEFAULT_CANDLE_BUILDER_OPTIONS, DEFAULT_CANDLE_STYLE, DEFAULT_HISTOGRAM_STYLE, DEFAULT_KEYMAP, DEFAULT_PRICE_SCALE_OPTIONS, DEFAULT_THEME, DEFAULT_TIME_SCALE_OPTIONS, DEFAULT_TRADING_COLORS, type DataFeed, type DepthLevel, type DrawItem, EventMarkers, FakeDataFeed, type FeedScheduler, type HistogramStyle, type IPrimitive, IST_OFFSET_SECONDS, InvalidationLevel, type KeymapEntry, type LateTickPolicy, type LinePoint, type LogicalRange, LogoWatermark, type LogoWatermarkOptions, type LtpEvent, type MarkerPosition, type MarkerShape, type MarkerSize, type MarketDepth, type OpenAlgoConfig, OpenAlgoDataFeed, type OpenAlgoLiveConfig, OpenAlgoLiveDataFeed, type OpenAlgoTradeConfig, OpenAlgoTradeFeed, type OpenAlgoWsConfig, OpenAlgoWsFeed, type OrderSide$1 as OrderSide, type OrderType$1 as OrderType, type OriginalTime, Pane, type PaneInvalidation, type PlaceOrder, type PositionSide, PriceLine, type PriceLineOptions, type PriceRange, PriceScale, type PriceScaleMode, type PriceScaleOptions, type PrimitiveHit, type PrimitiveHost, type PrimitiveRenderContext, type RendererEntry, type SeriesApi, type SeriesDataItem, type SeriesMarker, SeriesMarkers, type SeriesRenderContext, type SeriesStyle, type SeriesType, type ShortcutListItem, ShortcutManager, type ShortcutManagerOptions, type ShortcutPreset, type ShortcutScope, type ShortcutTriggerEvent, type Size, type SocketFactory, type SocketLike, type SupertrendPoint, type Tick, TickBarAggregator, type TickTimeframe, TimeScale, type TimeScaleOp, type TimeScaleOptions, type TradeFeed, type TradeMarkerVariant, TradeMarkersPrimitive, type TradingColors, TradingController, type TradingHost, type TradingLineStyle, type TradingLineVariant, type TradingOrder, type TradingOrderSide, type TradingOrderType, type TradingPosition, type TradingSettings, type TradingSyncPayload, type TradingTrade, type UTCSeconds, type UnsubscribeFn, VERSION, type VolumeMode, type WatermarkPosition, type Whitespace, type WsControlMessage, type WsMode, type WsState, type ZOrder, atr, autoscaleRange, bestHit, bitmapSize, clamp, conflateBars, conflateItems, conflationGroupSize, createChart, darkTheme, drawShape, effectiveMarkerPx, ema, emaSeries, epochMsToUtcSeconds, eventToCombo, formatCombo, formatIstDate, formatIstTime, formatIstTimeSeconds, formatSubscribe, formatUnsubscribe, generateBars, getChartType, intervalToSeconds, isNewIstDay, isReservedCombo, isValidCombo, isWhitespace, istStringToUtcSeconds, lerp, lightTheme, mapHistoryResponse, mapOrder, mapPosition, markerSizePx, mergeBars, niceTicks, normalizeCombo, optimalBarWidth, parseCombo, parseMessage, precisionForStep, registerChartType, registeredChartTypes, roundToTick, rowTimeToUtcSeconds, rsi, rsiSeries, snapToDevicePixel, supertrend, supertrendSeries, toBar, trueRange, utcSecondsToIstDateString, utcSecondsToIstParts, version, verticalGradient, watermarkRect };
2157
+ export { ALT_PRESET, type AddSeriesOptions, type AggTick, BUILTIN_COMMANDS, type Bar, type BarUpdate, type BarsRequest, CandleBuilder, type CandleBuilderOptions, type CandleStyle, type CandleUpdate, Chart, type ChartEvent, type ChartOptions, type ChartTheme, type CrosshairMoveEvent, type CustomShortcut, DEFAULT_CANDLE_BUILDER_OPTIONS, DEFAULT_CANDLE_STYLE, DEFAULT_HISTOGRAM_STYLE, DEFAULT_KEYMAP, DEFAULT_PRICE_SCALE_OPTIONS, DEFAULT_THEME, DEFAULT_TIME_SCALE_OPTIONS, DEFAULT_TRADING_COLORS, type DataFeed, type DepthLevel, type DrawItem, EventMarkers, FakeDataFeed, type FeedScheduler, type HistogramStyle, type IPrimitive, IST_OFFSET_SECONDS, InvalidationLevel, type KeymapEntry, type LateTickPolicy, type LinePoint, type LogicalRange, LogoWatermark, type LogoWatermarkOptions, type LtpEvent, type MarkerPosition, type MarkerShape, type MarkerSize, type MarketDepth, type OpenAlgoConfig, OpenAlgoDataFeed, type OpenAlgoLiveConfig, OpenAlgoLiveDataFeed, type OpenAlgoTradeConfig, OpenAlgoTradeFeed, type OpenAlgoWsConfig, OpenAlgoWsFeed, type OrderSide$1 as OrderSide, type OrderType$1 as OrderType, type OriginalTime, Pane, type PaneInvalidation, type PlaceOrder, type PositionSide, PriceLine, type PriceLineOptions, type PriceRange, PriceScale, type PriceScaleId, type PriceScaleMode, type PriceScaleOptions, type PrimitiveHit, type PrimitiveHost, type PrimitiveRenderContext, type RendererEntry, type SeriesApi, type SeriesDataItem, type SeriesMarker, SeriesMarkers, type SeriesRenderContext, type SeriesStyle, type SeriesType, type ShortcutListItem, ShortcutManager, type ShortcutManagerOptions, type ShortcutPreset, type ShortcutScope, type ShortcutTriggerEvent, type Size, type SocketFactory, type SocketLike, type SupertrendPoint, type Tick, TickBarAggregator, type TickMarkType, type TickTimeframe, TimeScale, type TimeScaleOp, type TimeScaleOptions, type TradeFeed, type TradeMarkerVariant, TradeMarkersPrimitive, type TradingColors, TradingController, type TradingHost, type TradingLineStyle, type TradingLineVariant, type TradingOrder, type TradingOrderSide, type TradingOrderType, type TradingPosition, type TradingSettings, type TradingSyncPayload, type TradingTrade, type UTCSeconds, type UnsubscribeFn, VERSION, type VolumeMode, type WatermarkPosition, type Whitespace, type WsControlMessage, type WsMode, type WsState, type ZOrder, atr, autoscaleRange, bestHit, bitmapSize, clamp, compactVolume, conflateBars, conflateItems, conflationGroupSize, createChart, darkTheme, drawShape, effectiveMarkerPx, ema, emaSeries, epochMsToUtcSeconds, eventToCombo, formatCombo, formatIstDate, formatIstTime, formatIstTimeSeconds, formatSubscribe, formatUnsubscribe, generateBars, getChartType, intervalToSeconds, isNewIstDay, isReservedCombo, isValidCombo, isWhitespace, istStringToUtcSeconds, lerp, lightTheme, mapHistoryResponse, mapOrder, mapPosition, markerSizePx, mergeBars, niceTicks, normalizeCombo, optimalBarWidth, parseCombo, parseMessage, precisionForStep, registerChartType, registeredChartTypes, roundToTick, rowTimeToUtcSeconds, rsi, rsiSeries, snapToDevicePixel, supertrend, supertrendSeries, toBar, trueRange, utcSecondsToIstDateString, utcSecondsToIstParts, version, verticalGradient, watermarkRect };