@funnest/charts 0.5.2 → 0.6.1

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/chart.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { type Locale } from './model/time-format';
2
2
  import { TimeScale, type IndexRange, type TimeScaleOptions } from './model/time-scale';
3
- import { type IndicatorParams, type IndicatorType } from './indicators/definitions';
3
+ import type { IndicatorDefinition, IndicatorParams, IndicatorType } from './indicators/definitions';
4
4
  import { type IndicatorConfig, type IndicatorPatch } from './indicators/manager';
5
- import { type Drawing, type DrawingType } from './objects/drawings';
6
- import { type ExecutionMarker, type LineHandle, type OrderLineOptions, type PositionLineOptions } from './objects/trading';
5
+ import { type Drawing, type DrawingDefinition, type DrawingType } from './objects/drawings';
6
+ import { type AlertLineOptions, type ExecutionMarker, type LineHandle, type OrderLineOptions, type PositionLineOptions } from './objects/trading';
7
7
  import { type ChartSettings, type ChartState } from './settings';
8
8
  import { type TradingAdapter } from './objects/trading-sync';
9
9
  import { type ChartType, type CrosshairInfo, type PaneId } from './render/renderer';
@@ -33,6 +33,30 @@ export interface ChartOptions {
33
33
  historyBatchSize?: number;
34
34
  /** The user's fills, positions and orders, synced per symbol. See TradingAdapter. */
35
35
  trading?: TradingAdapter;
36
+ /** Extra indicators (same shape as the built-ins). They appear in the widget's indicator picker. */
37
+ indicatorDefinitions?: readonly IndicatorDefinition[];
38
+ /** Extra drawing tools. They appear in the widget's drawing bar. */
39
+ drawingDefinitions?: readonly DrawingDefinition[];
40
+ }
41
+ /** A symbol overlaid for comparison. */
42
+ export interface CompareInfo {
43
+ symbol: string;
44
+ /** Display name once resolved (the symbol until then). */
45
+ name: string;
46
+ color: string;
47
+ /** Bars are loaded. */
48
+ ready: boolean;
49
+ }
50
+ /** Bar replay: history is cut at a past bar and played forward. */
51
+ export interface ReplayStatus {
52
+ /** Waiting for the user to click the bar to start from. */
53
+ selecting: boolean;
54
+ active: boolean;
55
+ playing: boolean;
56
+ /** Bars still hidden to the right. */
57
+ remaining: number;
58
+ /** Milliseconds between bars while playing. */
59
+ interval: number;
36
60
  }
37
61
  export interface ChartEvents {
38
62
  crosshairMove: CrosshairInfo | null;
@@ -68,8 +92,30 @@ export interface ChartEvents {
68
92
  /** Realtime connection state/latency reported by the datafeed. */
69
93
  connectionChange: ConnectionState;
70
94
  indicatorsChange: IndicatorConfig[];
95
+ /** Undo/redo availability changed (drawings and indicators are tracked). */
96
+ historyChange: {
97
+ canUndo: boolean;
98
+ canRedo: boolean;
99
+ };
100
+ comparesChange: CompareInfo[];
101
+ replayChange: ReplayStatus;
102
+ /**
103
+ * Right-click on the chart (mouse only). While anything listens, the browser's own menu is
104
+ * suppressed — the widget shows its menu (undo, horizontal line here, reset…).
105
+ */
106
+ contextMenu: ChartContextMenu;
71
107
  error: unknown;
72
108
  }
109
+ export interface ChartContextMenu {
110
+ /** Pixels relative to the chart element. */
111
+ x: number;
112
+ y: number;
113
+ pane: PaneId;
114
+ /** Price under the pointer (tick-rounded) when it's over the price pane, else null. */
115
+ price: number | null;
116
+ /** Time of the bar under the pointer, or null past the data. */
117
+ time: number | null;
118
+ }
73
119
  export interface ChartPaneLayout {
74
120
  id: PaneId;
75
121
  kind: 'main' | 'volume' | 'indicator';
@@ -165,6 +211,18 @@ export declare class Chart {
165
211
  private loadingHistory;
166
212
  private noMoreHistory;
167
213
  private historyRequestedFor;
214
+ private countdownLabel;
215
+ /** Undo/redo of drawings + indicators, as JSON snapshots. */
216
+ private readonly history;
217
+ private readonly compares;
218
+ private compareVersion;
219
+ /** Base bar index of the % axis and compare lines (the first visible bar). */
220
+ private percentBaseIndex;
221
+ private replayState;
222
+ private replaySelecting;
223
+ /** Pane height weights the user set by dragging borders (unset panes use PANE_WEIGHT). */
224
+ private readonly paneWeights;
225
+ private paneWeightTotal;
168
226
  constructor(container: HTMLElement, options?: ChartOptions);
169
227
  /** Replaces all bars and scrolls to the latest. */
170
228
  setData(bars: readonly Bar[]): void;
@@ -256,6 +314,8 @@ export declare class Chart {
256
314
  /** Restores drawings (e.g. from storage). */
257
315
  setDrawings(drawings: readonly Drawing[]): void;
258
316
  updateDrawing(id: string, patch: Partial<Omit<Drawing, 'id'>>): void;
317
+ /** Adds a drawing (e.g. a horizontal line at a price) and selects it. Returns its id. */
318
+ addDrawing(drawing: Omit<Drawing, 'id'>): string;
259
319
  removeDrawing(id: string): void;
260
320
  clearDrawings(): void;
261
321
  get selectedDrawing(): Drawing | null;
@@ -272,6 +332,65 @@ export declare class Chart {
272
332
  /** Formatted indicator values at a bar index (default: the last bar), for legends. */
273
333
  indicatorLegend(index?: number): IndicatorLegendItem[];
274
334
  private indicatorsChanged;
335
+ /** Built-in and custom indicators this chart can add. */
336
+ indicatorDefinitions(): IndicatorDefinition[];
337
+ indicatorDefinition(type: IndicatorType): IndicatorDefinition | undefined;
338
+ /** Built-in and custom drawing tools, in drawing-bar order. */
339
+ drawingDefinitions(): DrawingDefinition[];
340
+ /**
341
+ * Moves the border above pane `index` (1 = between the price pane and the next one) by `dy` px.
342
+ * The two neighbouring panes trade height; the rest keep theirs. Users do this by dragging.
343
+ */
344
+ resizePane(index: number, dy: number): void;
345
+ /** Back to the default pane heights. */
346
+ resetPaneSizes(): void;
347
+ get canUndo(): boolean;
348
+ get canRedo(): boolean;
349
+ /** Reverts the last drawing or indicator change. */
350
+ undo(): void;
351
+ redo(): void;
352
+ private historySnapshot;
353
+ private recordHistory;
354
+ private resetHistory;
355
+ private applyHistory;
356
+ private emitHistory;
357
+ /**
358
+ * Overlays another symbol's closes as a line, rebased to the first visible bar. The price
359
+ * axis switches to % while any symbol is compared. Needs the `datafeed` option.
360
+ */
361
+ addCompare(symbol: string): Promise<void>;
362
+ removeCompare(symbol: string): void;
363
+ getCompares(): CompareInfo[];
364
+ /** Each compared symbol's % change from the first visible bar, at `index` (default: the last bar). */
365
+ compareLegend(index?: number): (CompareInfo & {
366
+ value: string;
367
+ })[];
368
+ private comparesChanged;
369
+ /** (Re)loads a compared symbol's bars at the current resolution, back to the main series' first bar. */
370
+ private reloadCompare;
371
+ /** Pages a compared symbol's history back until it covers the main series' first bar. */
372
+ private loadOlderCompare;
373
+ /** Compare closes at each main bar (the compare bar at or before its time). */
374
+ private alignedCompare;
375
+ /** Compare lines in main-price space, each rebased so its first visible value sits on the main close there. */
376
+ private compareOverlays;
377
+ get replay(): ReplayStatus;
378
+ /** Arms start picking: the next click on the chart starts a replay from that bar. Esc cancels. */
379
+ setReplaySelecting(on: boolean): void;
380
+ /** Hides every bar after `time` (UTC ms); reveal them with replayStep/replayPlay. */
381
+ startReplay(time: number): void;
382
+ /** Reveals the next `count` hidden bars. */
383
+ replayStep(count?: number): void;
384
+ /** Plays one bar every `interval` ms (default: the last speed used, initially 1000). */
385
+ replayPlay(interval?: number): void;
386
+ /** Changes the playback speed (ms per bar), also while playing. */
387
+ setReplayInterval(interval: number): void;
388
+ replayPause(): void;
389
+ /** Leaves replay and shows every bar again (including live ones that arrived meanwhile). */
390
+ stopReplay(): void;
391
+ private endReplay;
392
+ private stopReplayTimer;
393
+ private emitReplay;
275
394
  private indicatorScale;
276
395
  /**
277
396
  * Connects the user's account (fills, positions, orders). The chart loads them for the
@@ -282,6 +401,8 @@ export declare class Chart {
282
401
  addPositionLine(options: PositionLineOptions): LineHandle<PositionLineOptions>;
283
402
  /** Pending order line. Pass `onMove` to make it draggable and `onCancel` for an × button. */
284
403
  addOrderLine(options: OrderLineOptions): LineHandle<OrderLineOptions>;
404
+ /** Price alert line (dotted, gray, "알림" label). Pass `onMove` to make it draggable and `onCancel` for an ×. */
405
+ addAlertLine(options: AlertLineOptions): LineHandle<AlertLineOptions>;
285
406
  /** Fill markers (▲ buy under the bar, ▼ sell above). Replaces the previous set. */
286
407
  setExecutions(markers: readonly ExecutionMarker[]): void;
287
408
  setTheme(theme: Partial<ThemeTokens>): void;
@@ -307,6 +428,15 @@ export declare class Chart {
307
428
  private barInterval;
308
429
  private paneCoords;
309
430
  private computeFrame;
431
+ /** Price-pane tick values for the current axis mode. */
432
+ private mainTicks;
433
+ private percentBase;
434
+ /** Price-axis tick labels: prices, or "+2.5%" on a % axis (decimals follow the step). */
435
+ private mainTickFormat;
436
+ /** Crosshair and last-price label of the price pane. */
437
+ private mainValueFormat;
438
+ /** Time left in the last bar, when it's still forming (null otherwise). */
439
+ private countdownText;
310
440
  /** Auto-scales the price pane to visible candles and overlay indicators; returns the candle extremes. */
311
441
  private autoScale;
312
442
  private autoScaleIndicator;
@@ -325,6 +455,8 @@ export declare class Chart {
325
455
  private createInteractionHost;
326
456
  /** Esc cancels a drawing in progress or deselects; Delete/Backspace removes the selected drawing. */
327
457
  private observeKeyboard;
458
+ /** Repaints when the bar-close countdown ticks over (once a second, only while it shows or changes). */
459
+ private observeCountdown;
328
460
  private observeSize;
329
461
  /** Theme values using `var(--x)` follow the host page's dark-mode / theme switches automatically. */
330
462
  private observeThemeVariables;
package/dist/events.d.ts CHANGED
@@ -3,5 +3,6 @@ export declare class Emitter<Events extends object> {
3
3
  private readonly listeners;
4
4
  on<K extends keyof Events>(event: K, listener: Listener<Events[K]>): () => void;
5
5
  emit<K extends keyof Events>(event: K, payload: Events[K]): void;
6
+ has<K extends keyof Events>(event: K): boolean;
6
7
  clear(): void;
7
8
  }
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  export { Chart, createChart, fallbackResolution } from './chart';
2
2
  export { DEFAULT_CHART_SETTINGS, parseChartState } from './settings';
3
3
  export type { ChartSettings, ChartState } from './settings';
4
- export type { ChartEvents, ChartLayout, ChartOptions, ChartPaneLayout, IndicatorLegendItem } from './chart';
4
+ export type { ChartContextMenu, ChartEvents, ChartLayout, ChartOptions, ChartPaneLayout, CompareInfo, IndicatorLegendItem, ReplayStatus } from './chart';
5
+ export type { PriceScaleMode } from './model/price-scale';
5
6
  export type { CrosshairInfo, PaneId } from './render/renderer';
6
7
  export type { Locale } from './model/time-format';
7
8
  export type { IndexRange, TimeScaleOptions } from './model/time-scale';
@@ -12,15 +13,18 @@ export type { FormatPriceOptions } from './price';
12
13
  export { decimalsOf, formatCompact, formatPrice, krxTickSize, resolveTickSize, roundToTick } from './price';
13
14
  export { isIntradayResolution, resolutionToMs } from './resolution';
14
15
  export type { ChartType } from './render/renderer';
15
- export type { Drawing, DrawingPoint, DrawingType } from './objects/drawings';
16
- export { FIB_LEVELS } from './objects/drawings';
16
+ export type { BuiltinDrawingType, Drawing, DrawingDefinition, DrawingGeometry, DrawingPoint, DrawingRenderContext, DrawingType, } from './objects/drawings';
17
+ export { BUILTIN_DRAWINGS, distToSegment, FIB_LEVELS } from './objects/drawings';
18
+ export type { PaneCoords } from './objects/types';
19
+ export type { Painter } from './render/painter';
20
+ export type { Palette } from './render/renderer';
17
21
  export { snapToOhlc } from './objects/magnet';
18
- export type { ExecutionGroup, ExecutionMarker, LineHandle, OrderLineOptions, PositionLineOptions } from './objects/trading';
22
+ export type { AlertLineOptions, ExecutionGroup, ExecutionMarker, LineHandle, OrderLineOptions, PositionLineOptions } from './objects/trading';
19
23
  export type { Execution, OrderInfo, PositionInfo, TradingAdapter, TradingCallbacks } from './objects/trading-sync';
20
24
  export { bucketStart, TickAggregator, timeZoneOffset } from './realtime';
21
25
  export type { Tick } from './realtime';
22
26
  export { INDICATORS, SERIES_COLORS } from './indicators/definitions';
23
- export type { IndicatorDefinition, IndicatorOutput, IndicatorParams, IndicatorParamSpec, IndicatorSeries, IndicatorType, } from './indicators/definitions';
27
+ export type { BuiltinIndicatorType, IndicatorDefinition, IndicatorOutput, IndicatorParams, IndicatorParamSpec, IndicatorSeries, IndicatorType, } from './indicators/definitions';
24
28
  export type { IndicatorConfig, IndicatorPatch } from './indicators/manager';
25
29
  export { maLines, PRICE_SOURCES, priceSource } from './indicators/definitions';
26
30
  export type { MaLine, PriceSource, SeriesStyle } from './indicators/definitions';