@alphacharts/core 0.1.0 → 0.1.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/internal.js CHANGED
@@ -1 +1,7 @@
1
- export { o as GLContext, s as GLSL_COMMON, t as HOLE_TEST, n as InstanceWindow, r as RECORD_BYTES, i as RECORD_FLOATS, a as chooseLevel } from "./window-uK2QNvv5.js";
1
+ import { E as e, a as t, i as n, n as r, o as i, r as a, s as o, t as s } from "./window-WvcPCDkK.js";
2
+ //#region src/version.ts
3
+ var c = "0.1.1";
4
+ //#endregion
5
+ export { c as CORE_VERSION, i as GLContext, o as GLSL_COMMON, s as HOLE_TEST, r as InstanceWindow, a as RECORD_BYTES, n as RECORD_FLOATS, t as chooseLevel, e as onFault };
6
+
7
+ //# sourceMappingURL=internal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.js","names":["onFault","chooseLevel","RECORD_FLOATS","InstanceWindow","GLContext","RECORD_BYTES","GLSL_COMMON","HOLE_TEST","CORE_VERSION"],"sources":["../src/version.ts"],"sourcesContent":["// Kept equal to package.json by test/fault.test.ts. Read by @alphacharts/report through /internal.\nexport const CORE_VERSION = \"0.1.1\";\n"],"mappings":";;AACA,IAAaQ,IAAe"}
@@ -94,3 +94,26 @@ export declare class PriceLine implements PanePrimitive {
94
94
  draw(ctx: CanvasRenderingContext2D, view: PaneView): void;
95
95
  axisLabels(view: PaneView): readonly AxisLabel[];
96
96
  }
97
+ /**
98
+ * A background colour per bar, drawn behind the series of the pane it is attached to (`Series.attachPrimitive`).
99
+ * It takes no part in autoscale (a primitive never does) and costs nothing while no bar is shaded. Colours are
100
+ * keyed by bar time (UTC ms), so they stay with their bars when the timeline is re-indexed; a time with no bar on
101
+ * the chart draws nothing. Runs of equal colour on neighbouring bars are painted as one rectangle.
102
+ */
103
+ export declare class BarShading implements PanePrimitive {
104
+ private host;
105
+ private times;
106
+ private colors;
107
+ private n;
108
+ private shown;
109
+ private any;
110
+ /** Replace every shade: strictly increasing times, packed 0xRRGGBBAA colours (0 = no shade). */
111
+ set(time: Float64Array, color: Uint32Array): void;
112
+ /** Shade one bar: replaces the colour at `time` when the bar is known, else appends (a time later than the last). */
113
+ setAt(time: number, color: number): void;
114
+ clear(): void;
115
+ setVisible(visible: boolean): void;
116
+ attached(host: PrimitiveHost): void;
117
+ detached(): void;
118
+ drawBackground(ctx: CanvasRenderingContext2D, view: PaneView): void;
119
+ }
@@ -1,4 +1,4 @@
1
- import type { ColumnarOhlc, ColumnarValue, OhlcBar, SeriesData, ValuePoint } from "../data/model.js";
1
+ import type { ColumnarColors, ColumnarOhlc, ColumnarValue, OhlcBar, SeriesData, ValuePoint } from "../data/model.js";
2
2
  import { type SeriesMarker } from "./markers.js";
3
3
  import type { PanePrimitive } from "./primitives.js";
4
4
  import { type CommonSeriesOptions, type SeriesOptions, type SeriesShapes, type SeriesType } from "./series-types.js";
@@ -11,6 +11,8 @@ export interface SeriesHost {
11
11
  setData(s: Series<SeriesType>, input: unknown): void;
12
12
  prepend(s: Series<SeriesType>, input: unknown): void;
13
13
  update(s: Series<SeriesType>, bar: unknown): void;
14
+ setColors(s: Series<SeriesType>, colors: ColumnarColors): void;
15
+ clearColors(s: Series<SeriesType>): void;
14
16
  optionsChanged(s: Series<SeriesType>, paneOrScaleMoved: boolean): void;
15
17
  markersChanged(s: Series<SeriesType>): void;
16
18
  /** Pane-relative y of a price on the series' scale; NaN when the scale has no range yet. */
@@ -39,6 +41,14 @@ export declare class Series<T extends SeriesType> {
39
41
  prepend(data: SeriesInput<T>): void;
40
42
  /** Live bar: same time as the last bar replaces it, a later time appends. */
41
43
  update(bar: SeriesBar<T>): void;
44
+ /**
45
+ * Colour individual bars of a candle or OHLC-bar series (`colors.color`: packed 0xRRGGBBAA, 0 = the series' own up/down
46
+ * colours), by time; a time with no bar is ignored. Colours belong to (series, time): `update`, `prepend` and `setData`
47
+ * keep the colours of the bars they keep. Writing the colour a bar already has changes and redraws nothing.
48
+ */
49
+ setBarColors(this: Series<"candles" | "bars">, colors: ColumnarColors): void;
50
+ /** Remove every bar colour (the colour column too): the series draws in its up/down colours again. */
51
+ clearBarColors(this: Series<"candles" | "bars">): void;
42
52
  /** The bar at `time`, or undefined. Values are the exact inputs (Float64). */
43
53
  barAt(time: number): SeriesBar<T> | undefined;
44
54
  /** Index range of the series' bars on the chart's timeline. */
@@ -8,7 +8,6 @@ export declare const F32_NAN: ColumnSpec;
8
8
  export declare const U32_ZERO: ColumnSpec;
9
9
  export declare const U8_ZERO: ColumnSpec;
10
10
  export declare class ColumnDeque {
11
- private readonly specs;
12
11
  /** Raw buffers, one per column. Replaced on growth: never cache across a write. */
13
12
  cols: TypedArray[];
14
13
  /** Buffer position of `first`. */
@@ -17,7 +16,12 @@ export declare class ColumnDeque {
17
16
  first: number;
18
17
  length: number;
19
18
  private capacity;
19
+ private readonly specs;
20
20
  constructor(specs: readonly ColumnSpec[], capacity?: number);
21
+ /** Add a column over the current range, filled with its fill value. Existing columns and indices are untouched. */
22
+ addColumn(spec: ColumnSpec): number;
23
+ /** Drop the last column (the one `addColumn` returned last). */
24
+ dropColumn(): void;
21
25
  /** One past the last absolute index. */
22
26
  get end(): number;
23
27
  /** Buffer position of absolute index `abs` (not bounds-checked). */
@@ -7,8 +7,13 @@ export interface LodSource {
7
7
  readonly h: number;
8
8
  readonly l: number;
9
9
  readonly c: number;
10
- /** Column of a packed RGBA colour per row, if the series has one. */
11
- readonly color?: number;
10
+ /** Column of a packed RGBA colour per row, if the series has one. Set when the column is added; the owner then rebuilds the pyramid. */
11
+ color?: number;
12
+ /**
13
+ * Which colour a bucket takes: "high" (default) that of the row that made its high; "any" the last non-zero colour of
14
+ * its rows, so a highlighted bar still shows when 8 or more bars share a pixel.
15
+ */
16
+ colorMode?: "high" | "any";
12
17
  }
13
18
  export declare const LOD_O = 0;
14
19
  export declare const LOD_H = 1;
@@ -9,6 +9,8 @@ export interface OhlcBar {
9
9
  high: number;
10
10
  low: number;
11
11
  close: number;
12
+ /** Per-bar colour override, CSS colour string; absent leaves the bar's colour as it is. */
13
+ color?: string;
12
14
  }
13
15
  export interface ValuePoint {
14
16
  time: number;
@@ -23,6 +25,14 @@ export interface ColumnarOhlc {
23
25
  high: Float64Array;
24
26
  low: Float64Array;
25
27
  close: Float64Array;
28
+ /** Packed 0xRRGGBBAA per bar; 0 means the series colours. Absent leaves the bars' colours as they are. */
29
+ color?: Uint32Array;
30
+ }
31
+ /** Colours alone for bars of an OHLC series, by time (times strictly increasing; a time the series has no bar at is ignored). */
32
+ export interface ColumnarColors {
33
+ time: Float64Array;
34
+ /** Packed 0xRRGGBBAA; 0 clears the bar back to the series colours. */
35
+ color: Uint32Array;
26
36
  }
27
37
  export interface ColumnarValue {
28
38
  time: Float64Array;
@@ -34,7 +44,10 @@ export type OhlcInput = readonly OhlcBar[] | ColumnarOhlc;
34
44
  export type ValueInput = readonly ValuePoint[] | ColumnarValue;
35
45
  export declare const COL_O = 0, COL_H = 1, COL_L = 2, COL_C = 3;
36
46
  export declare const COL_V = 0, COL_COLOR = 1;
37
- export type ChangeKind = "replace" | "prepend" | "update";
47
+ /** The optional colour column of an OHLC store, added by `SeriesData.enableColors`. */
48
+ export declare const COL_BAR_COLOR = 4;
49
+ /** "color": only bar colours changed (no bar, price or time did): data followers such as studies have nothing to recompute. */
50
+ export type ChangeKind = "replace" | "prepend" | "update" | "color";
38
51
  export interface DataChange {
39
52
  readonly series: SeriesData | null;
40
53
  readonly kind: ChangeKind;
@@ -50,7 +63,19 @@ export declare class SeriesData {
50
63
  readonly shape: SeriesShape;
51
64
  readonly store: ColumnDeque;
52
65
  readonly lod: Lod;
66
+ private readonly lodSrc;
67
+ /**
68
+ * A value series: whether any point may carry its own colour (set when one is written, cleared when the series is
69
+ * replaced). Conservative: renderers that draw uncoloured series faster read it.
70
+ */
71
+ pointColors: boolean;
53
72
  constructor(shape: SeriesShape);
73
+ /** Whether an OHLC series holds a per-bar colour column. */
74
+ get colored(): boolean;
75
+ /** Add the colour column (all zero) and the pyramid's colour column. A no-op when present or for a value series. */
76
+ enableColors(): void;
77
+ /** Remove the colour column again, giving its memory back. */
78
+ disableColors(): void;
54
79
  /** True when the series has a bar at timeline index i. */
55
80
  has(i: number): boolean;
56
81
  /** Value of column `col` at timeline index i (NaN when absent). */
@@ -86,6 +111,14 @@ export declare class DataModel {
86
111
  prepend(s: SeriesData, input: OhlcInput | ValueInput): void;
87
112
  /** A live bar: replaces the series' last bar if the time matches, else appends. */
88
113
  update(s: SeriesData, input: OhlcBar | ValuePoint): void;
114
+ /**
115
+ * Write bar colours of an OHLC series without touching its bars. Times the series has no bar at are ignored; a colour
116
+ * equal to the one already there changes nothing and announces nothing. Announces a "color" change over the bars that
117
+ * did change (one event), which renderers answer by patching those records.
118
+ */
119
+ setColors(s: SeriesData, input: ColumnarColors): void;
120
+ /** Remove every bar colour of an OHLC series (and the colour column). Announces one "color" change when there were any. */
121
+ clearColors(s: SeriesData): void;
89
122
  private rebuildAndEmit;
90
123
  /**
91
124
  * Replace the targets' rows and rebuild the timeline as the union of every
@@ -0,0 +1,9 @@
1
+ export type FaultSource = "draw-loop" | "ctor" | "context-lost" | "context-restored" | "shader";
2
+ export interface Fault {
3
+ source: FaultSource;
4
+ /** The thrown value; undefined for context events. */
5
+ error: unknown;
6
+ renderer?: "webgl" | "canvas2d";
7
+ }
8
+ export declare function onFault(fn: (f: Fault) => void): () => void;
9
+ export declare function emitFault(f: Fault): void;
@@ -10,7 +10,7 @@ export type { ChartPlugin, PluginApi, PluginPaneView, PluginPointer } from "./ch
10
10
  export type { SeriesBar, SeriesInput } from "./chart/series.js";
11
11
  export { registerSeriesType } from "./chart/series-types.js";
12
12
  export type { CommonSeriesOptions, LastValue, SeriesOptions, SeriesOptionsMap, SeriesType, SeriesTypeDef } from "./chart/series-types.js";
13
- export { PriceLine, crisp, dashPattern } from "./chart/primitives.js";
13
+ export { BarShading, PriceLine, crisp, dashPattern } from "./chart/primitives.js";
14
14
  export type { SeriesMarker, MarkerPosition, MarkerShape } from "./chart/markers.js";
15
15
  export type { AxisLabel, LineDash, PanePrimitive, PaneView, PriceLineOptions, PrimitiveHit, PrimitiveHost, RenderLayer } from "./chart/primitives.js";
16
16
  export { DARK, HIGH_CONTRAST, LIGHT, systemTheme } from "./chart/theme.js";
@@ -29,12 +29,12 @@ export { SyncGroup } from "./interaction/sync.js";
29
29
  export type { SyncOptions } from "./interaction/sync.js";
30
30
  export { connectDatafeed } from "./feed/datafeed.js";
31
31
  export type { BarsRequest, BarsResponse, Datafeed, FeedController, FeedOptions, Trade, TradesRequest } from "./feed/datafeed.js";
32
- export type { ColumnarOhlc, ColumnarValue, OhlcBar, ValuePoint } from "./data/model.js";
32
+ export type { ColumnarColors, ColumnarOhlc, ColumnarValue, OhlcBar, ValuePoint } from "./data/model.js";
33
33
  export type { PriceScaleOptions } from "./scale/price-scale.js";
34
34
  export type { TimeScaleOptions } from "./scale/time-scale.js";
35
35
  export type { TimeLabel } from "./scale/ticks.js";
36
36
  export type { DataChange, SeriesData, SeriesShape } from "./data/model.js";
37
- export { COL_C, COL_COLOR, COL_H, COL_L, COL_O, COL_V } from "./data/model.js";
37
+ export { COL_BAR_COLOR, COL_C, COL_COLOR, COL_H, COL_L, COL_O, COL_V } from "./data/model.js";
38
38
  export { LOD_BASE, LOD_C, LOD_COLOR, LOD_H, LOD_L, LOD_O } from "./data/lod.js";
39
39
  export { parseColor, rgba, cssColor } from "./render/color.js";
40
40
  export { barWidths } from "./render/renderers.js";
@@ -1,3 +1,6 @@
1
1
  export { InstanceWindow, chooseLevel, RECORD_FLOATS, RECORD_BYTES, HOLE_TEST } from "./render/window.js";
2
2
  export { GLContext, GLSL_COMMON } from "./render/gl.js";
3
3
  export type { Program } from "./render/gl.js";
4
+ export { CORE_VERSION } from "./version.js";
5
+ export { onFault } from "./fault.js";
6
+ export type { Fault, FaultSource } from "./fault.js";
@@ -0,0 +1 @@
1
+ export declare const CORE_VERSION = "0.1.1";