lightweight-charts-indicators 0.13.0 → 0.13.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/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/render/index.d.ts +1 -0
- package/dist/render/index.d.ts.map +1 -1
- package/dist/render/primitives.d.ts +31 -8
- package/dist/render/primitives.d.ts.map +1 -1
- package/dist/render/renderer.d.ts +10 -1
- package/dist/render/renderer.d.ts.map +1 -1
- package/dist/render.mjs +91 -56
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -325095,4 +325095,4 @@ var registryPart11 = [
|
|
|
325095
325095
|
}
|
|
325096
325096
|
];
|
|
325097
325097
|
var indicatorRegistry = [...registryPart1, ...registryPart11, ...registryPart2, ...registryPart3, ...registryPart4, ...registryPart5, ...registryPart6, ...registryPart7, ...registryPart8, ...registryPart9, ...registryPart10];
|
|
325098
|
-
var version = "0.13.
|
|
325098
|
+
var version = "0.13.1";
|
package/dist/index.d.ts
CHANGED
|
@@ -3356,5 +3356,5 @@ export type { ChartContext, VisibleRange, SymbolRequest, SymbolInfo } from './ch
|
|
|
3356
3356
|
export { MissingSymbolDataError, symbolBarsOf } from './chart-context';
|
|
3357
3357
|
export { mintickOf, timezoneOf, tickeridOf, tickerOf, symbolTypeOf, currencyOf, basecurrencyOf, rootOf, foregroundColorOf, backgroundColorOf, lastBarConfirmedOf, nowOf, visibleRangeOf, } from './chart-context';
|
|
3358
3358
|
export { securityOther, securityOtherValues, securityLowerTf, otherSymbolChart, spreadSymbols, spreadBars, spreadOptions, type OtherSymbolOptions, type OtherSymbolChart, type SymbolCalendar, } from './other-symbol';
|
|
3359
|
-
export declare const version = "0.13.
|
|
3359
|
+
export declare const version = "0.13.1";
|
|
3360
3360
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.mjs
CHANGED
|
@@ -324254,7 +324254,7 @@ var registryPart11 = [
|
|
|
324254
324254
|
}
|
|
324255
324255
|
];
|
|
324256
324256
|
var indicatorRegistry = [...registryPart1, ...registryPart11, ...registryPart2, ...registryPart3, ...registryPart4, ...registryPart5, ...registryPart6, ...registryPart7, ...registryPart8, ...registryPart9, ...registryPart10];
|
|
324257
|
-
var version = "0.13.
|
|
324257
|
+
var version = "0.13.1";
|
|
324258
324258
|
export {
|
|
324259
324259
|
ADR,
|
|
324260
324260
|
ADX,
|
package/dist/render/index.d.ts
CHANGED
|
@@ -10,4 +10,5 @@
|
|
|
10
10
|
export { IndicatorRenderer, type RenderableIndicator, type IndicatorRendererOptions, type RenderOptions, type PlotOverride, } from './renderer';
|
|
11
11
|
export { ThinHistogramPaneView, type HistogramItem, type ThinHistogramOptions } from './histogram-series';
|
|
12
12
|
export { parseColor, withOpacity, isTransparent, type Rgba } from './color';
|
|
13
|
+
export { type FutureSlots } from './primitives';
|
|
13
14
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/render/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EACL,iBAAiB,EACjB,KAAK,mBAAmB,EACxB,KAAK,wBAAwB,EAC7B,KAAK,aAAa,EAClB,KAAK,YAAY,GAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,qBAAqB,EAAE,KAAK,aAAa,EAAE,KAAK,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1G,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,aAAa,EAAE,KAAK,IAAI,EAAE,MAAM,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/render/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EACL,iBAAiB,EACjB,KAAK,mBAAmB,EACxB,KAAK,wBAAwB,EAC7B,KAAK,aAAa,EAClB,KAAK,YAAY,GAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,qBAAqB,EAAE,KAAK,aAAa,EAAE,KAAK,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1G,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,aAAa,EAAE,KAAK,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5E,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -9,24 +9,46 @@ import type { CanvasRenderingTarget2D } from 'fancy-canvas';
|
|
|
9
9
|
import type { Bar, FillData, ArrowData } from 'oakscriptjs';
|
|
10
10
|
import type { BgColorData, LabelData, LineDrawingData, BoxData, LinefillData, PolylineData, TableData, MarkerData, PineSize } from '../types';
|
|
11
11
|
import { type GradientPart } from './color';
|
|
12
|
+
/**
|
|
13
|
+
* Bar slots after the last bar of a time after it, on the host's calendar: the number of future bars that open after
|
|
14
|
+
* the last bar and at or before `time` (the slot of the bar that holds the time). `lastTime` and `time` in the units
|
|
15
|
+
* of the bar times.
|
|
16
|
+
*/
|
|
17
|
+
export type FutureSlots = (time: number, lastTime: number) => number;
|
|
18
|
+
/** The x coordinates of a drawing are times given by the script (xloc.bar_time), not bar indexes */
|
|
19
|
+
export declare function scriptTimes(item: object): boolean;
|
|
12
20
|
/**
|
|
13
21
|
* Bars of the chart and the slots after the last bar.
|
|
14
22
|
* Indicators give points on future bars (Pine bar_index + k, plot offsets) the time lastTime + k * interval
|
|
15
|
-
* (barTime).
|
|
16
|
-
*
|
|
23
|
+
* (barTime): slot k. A drawing in script times (xloc.bar_time) may end at any later time: it is drawn on the slot of
|
|
24
|
+
* the future bar that holds the time, counted on the host's calendar when it gives one (`futureSlots`: the trading
|
|
25
|
+
* sessions, as the time scale of a stock skips nights, weekends and holidays), else one slot per bar interval of
|
|
26
|
+
* calendar time. With extendTimeScale the renderer adds whitespace points up to the last slot drawn.
|
|
17
27
|
*/
|
|
18
28
|
export declare class BarGrid {
|
|
19
29
|
bars: Bar[];
|
|
20
30
|
byTime: Map<number, Bar>;
|
|
21
31
|
interval: number;
|
|
32
|
+
/** Host's count of the bar slots after the last bar of a script time (null: calendar time) */
|
|
33
|
+
futureSlots: FutureSlots | null;
|
|
34
|
+
private slotCache;
|
|
22
35
|
setBars(bars: Bar[]): void;
|
|
36
|
+
/** Count the slots of script times with `futureSlots` from now on (null: calendar time) */
|
|
37
|
+
setFutureSlots(futureSlots: FutureSlots | null): void;
|
|
23
38
|
get lastTime(): number;
|
|
24
|
-
/**
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Bar slot after the last bar that holds `time` (0 when time is not after the last bar or the slot is unknown).
|
|
41
|
+
* `script`: a time given by the script (xloc.bar_time), counted on the host's calendar.
|
|
42
|
+
*/
|
|
43
|
+
slotsAfter(time: number, script?: boolean): number;
|
|
44
|
+
/** A time after the last bar moved to the time of its slot on the bar interval grid; other times unchanged */
|
|
45
|
+
snap(time: number, script?: boolean): number;
|
|
46
|
+
/**
|
|
47
|
+
* x coordinate of a time: its bar on the time scale, or for a time after the last bar, its slot counted from the
|
|
48
|
+
* last bar (the time scale may hold whitespace points of other drawings after the last bar, not one per slot). Always
|
|
49
|
+
* a whole bar position: the time scale places no fractional logical index (it answers 0 for one).
|
|
50
|
+
*/
|
|
51
|
+
x(timeScale: ReturnType<IChartApi['timeScale']>, time: number, script?: boolean): number | null;
|
|
30
52
|
}
|
|
31
53
|
/** Fill of a result; per-bar colours may hold na (null) values */
|
|
32
54
|
export type PlotFill = FillData & {
|
|
@@ -55,6 +77,7 @@ export declare function markerSizeMult(size: MarkerData['size']): number;
|
|
|
55
77
|
export declare function anchorData(points: Array<{
|
|
56
78
|
time: number;
|
|
57
79
|
value: number;
|
|
80
|
+
script?: boolean;
|
|
58
81
|
}>, grid: BarGrid): LineData<Time>[];
|
|
59
82
|
/**
|
|
60
83
|
* Base class for Series Primitives that need access to chart/series references
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"primitives.d.ts","sourceRoot":"","sources":["../../src/render/primitives.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EACV,SAAS,EACT,UAAU,EACV,kBAAkB,EAClB,sBAAsB,EACtB,gBAAgB,EAChB,uBAAuB,EACvB,QAAQ,EACR,IAAI,EACJ,UAAU,EACX,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAE5D,OAAO,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,KAAK,EACV,WAAW,EACX,SAAS,EACT,eAAe,EACf,OAAO,EACP,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,UAAU,EACV,QAAQ,EACT,MAAM,UAAU,CAAC;AAClB,OAAO,EAA6B,KAAK,YAAY,EAAgB,MAAM,SAAS,CAAC;AAIrF
|
|
1
|
+
{"version":3,"file":"primitives.d.ts","sourceRoot":"","sources":["../../src/render/primitives.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EACV,SAAS,EACT,UAAU,EACV,kBAAkB,EAClB,sBAAsB,EACtB,gBAAgB,EAChB,uBAAuB,EACvB,QAAQ,EACR,IAAI,EACJ,UAAU,EACX,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAE5D,OAAO,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,KAAK,EACV,WAAW,EACX,SAAS,EACT,eAAe,EACf,OAAO,EACP,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,UAAU,EACV,QAAQ,EACT,MAAM,UAAU,CAAC;AAClB,OAAO,EAA6B,KAAK,YAAY,EAAgB,MAAM,SAAS,CAAC;AAIrF;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,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|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { type IChartApi, type ISeriesApi, type SeriesType, type Time } from 'lightweight-charts';
|
|
10
10
|
import type { Bar, PlotConfig, HLineConfig, FillConfig, ArrowConfig, IndicatorResult } from 'oakscriptjs';
|
|
11
|
+
import { type FutureSlots } from './primitives';
|
|
11
12
|
/** The indicator description the renderer needs: a registry entry or an indicator module satisfies it */
|
|
12
13
|
export interface RenderableIndicator {
|
|
13
14
|
/** Overlay indicator (price pane) or own pane */
|
|
@@ -37,6 +38,12 @@ export interface IndicatorRendererOptions {
|
|
|
37
38
|
mainSeries?: ISeriesApi<SeriesType, Time>;
|
|
38
39
|
/** Add bar slots after the last bar for drawings on future bars (default false: placed without extending) */
|
|
39
40
|
extendTimeScale?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Slots after the last bar of a time given by a script drawing (xloc.bar_time) on the chart's calendar: the number
|
|
43
|
+
* of future bars that open after the last bar and at or before the time (see {@link FutureSlots}). Default: one slot
|
|
44
|
+
* per bar interval of calendar time.
|
|
45
|
+
*/
|
|
46
|
+
futureSlots?: FutureSlots;
|
|
40
47
|
/** Keep the indicator pane when clear() empties it (pane height kept; default false) */
|
|
41
48
|
preserveEmptyPane?: boolean;
|
|
42
49
|
}
|
|
@@ -86,6 +93,8 @@ export declare class IndicatorRenderer {
|
|
|
86
93
|
/** Data last set on each series */
|
|
87
94
|
private lastData;
|
|
88
95
|
constructor(chart: IChartApi, options?: IndicatorRendererOptions);
|
|
96
|
+
/** Calendar of the slots after the last bar for the next render() (null: calendar time) */
|
|
97
|
+
setFutureSlots(futureSlots: FutureSlots | null): void;
|
|
89
98
|
/** Pane of a non-overlay indicator for the next render() */
|
|
90
99
|
setPaneIndex(paneIndex: number): void;
|
|
91
100
|
/** The series this instance created: plot series first (plotConfig order), then the others */
|
|
@@ -172,7 +181,7 @@ export declare class IndicatorRenderer {
|
|
|
172
181
|
private drawBoxes;
|
|
173
182
|
private drawLinefills;
|
|
174
183
|
private drawPolylines;
|
|
175
|
-
/** Whitespace points after the last bar up to `
|
|
184
|
+
/** Whitespace points after the last bar up to slot `k` (bar slots for drawings and plot points on future bars) */
|
|
176
185
|
private addFutureSlots;
|
|
177
186
|
/**
|
|
178
187
|
* Tables (table.new) as DOM overlays in the chart element, on their pane (the price pane with force_overlay), at
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../../src/render/renderer.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EASL,KAAK,SAAS,EACd,KAAK,UAAU,EAIf,KAAK,UAAU,EAQf,KAAK,IAAI,EAQV,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EACV,GAAG,EACH,UAAU,EACV,WAAW,EACX,UAAU,EAEV,WAAW,EAEX,eAAe,EAChB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../../src/render/renderer.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EASL,KAAK,SAAS,EACd,KAAK,UAAU,EAIf,KAAK,UAAU,EAQf,KAAK,IAAI,EAQV,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EACV,GAAG,EACH,UAAU,EACV,WAAW,EACX,UAAU,EAEV,WAAW,EAEX,eAAe,EAChB,MAAM,aAAa,CAAC;AAerB,OAAO,EAIL,KAAK,WAAW,EAwBjB,MAAM,cAAc,CAAC;AAGtB,yGAAyG;AACzG,MAAM,WAAW,mBAAmB;IAClC,iDAAiD;IACjD,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,UAAU,EAAE,CAAC;IACzB,WAAW,CAAC,EAAE,WAAW,EAAE,CAAC;IAC5B,UAAU,CAAC,EAAE,UAAU,EAAE,CAAC;IAC1B,WAAW,CAAC,EAAE,WAAW,EAAE,CAAC;CAC7B;AAED,8CAA8C;AAC9C,MAAM,WAAW,YAAY;IA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{ barInterval } from "oakscriptjs";
|
|
129
|
+
function scriptTimes(item) {
|
|
130
|
+
return item.xloc === "bar_time";
|
|
131
|
+
}
|
|
129
132
|
var BarGrid = class {
|
|
130
133
|
bars = [];
|
|
131
134
|
byTime = /* @__PURE__ */ new Map();
|
|
132
135
|
interval = 0;
|
|
136
|
+
/** Host's count of the bar slots after the last bar of a script time (null: calendar time) */
|
|
137
|
+
futureSlots = null;
|
|
138
|
+
slotCache = /* @__PURE__ */ new Map();
|
|
133
139
|
setBars(bars) {
|
|
134
140
|
this.bars = bars;
|
|
135
141
|
this.byTime = new Map(bars.map((b) => [b.time, b]));
|
|
136
142
|
this.interval = barInterval(bars);
|
|
143
|
+
this.slotCache.clear();
|
|
144
|
+
}
|
|
145
|
+
/** Count the slots of script times with `futureSlots` from now on (null: calendar time) */
|
|
146
|
+
setFutureSlots(futureSlots) {
|
|
147
|
+
this.futureSlots = futureSlots;
|
|
148
|
+
this.slotCache.clear();
|
|
137
149
|
}
|
|
138
150
|
get lastTime() {
|
|
139
151
|
return this.bars.length ? this.bars[this.bars.length - 1].time : NaN;
|
|
140
152
|
}
|
|
141
|
-
/**
|
|
142
|
-
|
|
143
|
-
|
|
153
|
+
/**
|
|
154
|
+
* Bar slot after the last bar that holds `time` (0 when time is not after the last bar or the slot is unknown).
|
|
155
|
+
* `script`: a time given by the script (xloc.bar_time), counted on the host's calendar.
|
|
156
|
+
*/
|
|
157
|
+
slotsAfter(time, script = false) {
|
|
158
|
+
if (!(time > this.lastTime))
|
|
144
159
|
return 0;
|
|
145
|
-
|
|
160
|
+
if (!script || !this.futureSlots)
|
|
161
|
+
return this.interval > 0 ? Math.floor((time - this.lastTime) / this.interval + 1e-9) : 0;
|
|
162
|
+
let k = this.slotCache.get(time);
|
|
163
|
+
if (k === void 0) {
|
|
164
|
+
k = this.futureSlots(time, this.lastTime);
|
|
165
|
+
k = Number.isFinite(k) ? Math.max(0, Math.floor(k)) : 0;
|
|
166
|
+
this.slotCache.set(time, k);
|
|
167
|
+
}
|
|
168
|
+
return k;
|
|
146
169
|
}
|
|
147
|
-
/** A time after the last bar moved to the
|
|
148
|
-
snap(time) {
|
|
170
|
+
/** A time after the last bar moved to the time of its slot on the bar interval grid; other times unchanged */
|
|
171
|
+
snap(time, script = false) {
|
|
149
172
|
if (!(time > this.lastTime) || !(this.interval > 0))
|
|
150
173
|
return time;
|
|
151
|
-
return this.lastTime +
|
|
174
|
+
return this.lastTime + this.slotsAfter(time, script) * this.interval;
|
|
152
175
|
}
|
|
153
|
-
/**
|
|
154
|
-
|
|
176
|
+
/**
|
|
177
|
+
* x coordinate of a time: its bar on the time scale, or for a time after the last bar, its slot counted from the
|
|
178
|
+
* last bar (the time scale may hold whitespace points of other drawings after the last bar, not one per slot). Always
|
|
179
|
+
* a whole bar position: the time scale places no fractional logical index (it answers 0 for one).
|
|
180
|
+
*/
|
|
181
|
+
x(timeScale, time, script = false) {
|
|
182
|
+
if (time > this.lastTime) {
|
|
183
|
+
if (!(this.interval > 0) && !(script && this.futureSlots))
|
|
184
|
+
return null;
|
|
185
|
+
const lastX = timeScale.timeToCoordinate(this.lastTime);
|
|
186
|
+
const lastLogical = lastX == null ? null : timeScale.coordinateToLogical(lastX);
|
|
187
|
+
if (lastLogical == null)
|
|
188
|
+
return null;
|
|
189
|
+
const c = timeScale.logicalToCoordinate(Math.round(lastLogical) + this.slotsAfter(time, script));
|
|
190
|
+
return c == null ? null : c;
|
|
191
|
+
}
|
|
155
192
|
const x = timeScale.timeToCoordinate(time);
|
|
156
|
-
|
|
157
|
-
return x;
|
|
158
|
-
if (!(time > this.lastTime) || !(this.interval > 0))
|
|
159
|
-
return null;
|
|
160
|
-
const lastX = timeScale.timeToCoordinate(this.lastTime);
|
|
161
|
-
const lastLogical = lastX == null ? null : timeScale.coordinateToLogical(lastX);
|
|
162
|
-
if (lastLogical == null)
|
|
163
|
-
return null;
|
|
164
|
-
const logical = Math.round(lastLogical) + (time - this.lastTime) / this.interval;
|
|
165
|
-
const c = timeScale.logicalToCoordinate(logical);
|
|
166
|
-
return c == null ? null : c;
|
|
193
|
+
return x == null ? null : x;
|
|
167
194
|
}
|
|
168
195
|
};
|
|
169
196
|
function gradientAt(g, i) {
|
|
@@ -184,7 +211,7 @@ function anchorData(points, grid) {
|
|
|
184
211
|
for (const p of points) {
|
|
185
212
|
if (p.value == null || Number.isNaN(p.value) || p.time == null || Number.isNaN(p.time))
|
|
186
213
|
continue;
|
|
187
|
-
const t = grid.snap(p.time);
|
|
214
|
+
const t = grid.snap(p.time, p.script);
|
|
188
215
|
if (!byTime.has(t))
|
|
189
216
|
byTime.set(t, p.value);
|
|
190
217
|
}
|
|
@@ -940,9 +967,10 @@ function arrowHead(ctx, tipX, tipY, fromX, fromY, width) {
|
|
|
940
967
|
ctx.stroke();
|
|
941
968
|
}
|
|
942
969
|
function linePoints(env, line) {
|
|
943
|
-
const
|
|
970
|
+
const script = scriptTimes(line);
|
|
971
|
+
const x1 = env.grid.x(env.timeScale, line.time1, script);
|
|
944
972
|
const y1 = env.series.priceToCoordinate(line.price1);
|
|
945
|
-
const x2 = env.grid.x(env.timeScale, line.time2);
|
|
973
|
+
const x2 = env.grid.x(env.timeScale, line.time2, script);
|
|
946
974
|
const y2 = env.series.priceToCoordinate(line.price2);
|
|
947
975
|
if (x1 == null || y1 == null || x2 == null || y2 == null)
|
|
948
976
|
return null;
|
|
@@ -1031,8 +1059,9 @@ function polylinePath(pts, curved, closed) {
|
|
|
1031
1059
|
}
|
|
1032
1060
|
function drawPolyline(env, poly) {
|
|
1033
1061
|
const pts = [];
|
|
1062
|
+
const script = scriptTimes(poly);
|
|
1034
1063
|
for (const p of poly.points) {
|
|
1035
|
-
const x = env.grid.x(env.timeScale, p.time);
|
|
1064
|
+
const x = env.grid.x(env.timeScale, p.time, script);
|
|
1036
1065
|
const y = env.series.priceToCoordinate(p.price);
|
|
1037
1066
|
if (x != null && y != null)
|
|
1038
1067
|
pts.push([x, y]);
|
|
@@ -1192,9 +1221,10 @@ function drawBoxText(ctx, box, left, top, w, h) {
|
|
|
1192
1221
|
lines.forEach((l, k) => ctx.fillText(l, x, y0 + lineHeight * (k + 0.5)));
|
|
1193
1222
|
}
|
|
1194
1223
|
function drawBox(env, box) {
|
|
1195
|
-
const
|
|
1224
|
+
const script = scriptTimes(box);
|
|
1225
|
+
const x1 = env.grid.x(env.timeScale, box.time1, script);
|
|
1196
1226
|
const y1 = env.series.priceToCoordinate(box.price1);
|
|
1197
|
-
const x2 = env.grid.x(env.timeScale, box.time2);
|
|
1227
|
+
const x2 = env.grid.x(env.timeScale, box.time2, script);
|
|
1198
1228
|
const y2 = env.series.priceToCoordinate(box.price2);
|
|
1199
1229
|
if (x1 == null || y1 == null || x2 == null || y2 == null)
|
|
1200
1230
|
return;
|
|
@@ -1244,7 +1274,7 @@ var LABEL_CORNERS = {
|
|
|
1244
1274
|
label_upper_right: [-1, 1]
|
|
1245
1275
|
};
|
|
1246
1276
|
function drawLabel(env, label) {
|
|
1247
|
-
const x = env.grid.x(env.timeScale, label.time);
|
|
1277
|
+
const x = env.grid.x(env.timeScale, label.time, scriptTimes(label));
|
|
1248
1278
|
if (x == null)
|
|
1249
1279
|
return;
|
|
1250
1280
|
const yloc = label.yloc ?? "price";
|
|
@@ -1596,6 +1626,7 @@ var IndicatorRenderer = class {
|
|
|
1596
1626
|
constructor(chart, options = {}) {
|
|
1597
1627
|
this.chart = chart;
|
|
1598
1628
|
this.opts = { ...options };
|
|
1629
|
+
this.grid.setFutureSlots(options.futureSlots ?? null);
|
|
1599
1630
|
}
|
|
1600
1631
|
opts;
|
|
1601
1632
|
grid = new BarGrid();
|
|
@@ -1618,6 +1649,11 @@ var IndicatorRenderer = class {
|
|
|
1618
1649
|
reused = /* @__PURE__ */ new Set();
|
|
1619
1650
|
/** Data last set on each series */
|
|
1620
1651
|
lastData = /* @__PURE__ */ new WeakMap();
|
|
1652
|
+
/** Calendar of the slots after the last bar for the next render() (null: calendar time) */
|
|
1653
|
+
setFutureSlots(futureSlots) {
|
|
1654
|
+
this.opts.futureSlots = futureSlots ?? void 0;
|
|
1655
|
+
this.grid.setFutureSlots(futureSlots);
|
|
1656
|
+
}
|
|
1621
1657
|
/** Pane of a non-overlay indicator for the next render() */
|
|
1622
1658
|
setPaneIndex(paneIndex) {
|
|
1623
1659
|
this.opts.paneIndex = paneIndex;
|
|
@@ -1683,7 +1719,7 @@ var IndicatorRenderer = class {
|
|
|
1683
1719
|
if (r.polylines?.length)
|
|
1684
1720
|
this.drawPolylines(r.polylines, pane);
|
|
1685
1721
|
if (this.opts.extendTimeScale)
|
|
1686
|
-
this.addFutureSlots(
|
|
1722
|
+
this.addFutureSlots(lastOutputSlot(r, this.grid));
|
|
1687
1723
|
if (r.tables?.length)
|
|
1688
1724
|
this.drawTables(r.tables, pane);
|
|
1689
1725
|
}
|
|
@@ -2265,34 +2301,33 @@ var IndicatorRenderer = class {
|
|
|
2265
2301
|
}
|
|
2266
2302
|
}
|
|
2267
2303
|
drawLabels(labels, pane) {
|
|
2268
|
-
this.drawLayers(labels, pane, (l) => l.forceOverlay, (l) => [{ time: l.time, value: l.price }], drawLabel, "top");
|
|
2304
|
+
this.drawLayers(labels, pane, (l) => l.forceOverlay, (l) => [{ time: l.time, value: l.price, script: scriptTimes(l) }], drawLabel, "top");
|
|
2269
2305
|
}
|
|
2270
2306
|
drawLines(lines, pane) {
|
|
2271
2307
|
this.drawLayers(lines, pane, (l) => l.forceOverlay, (l) => [
|
|
2272
|
-
{ time: l.time1, value: l.price1 },
|
|
2273
|
-
{ time: l.time2, value: l.price2 }
|
|
2308
|
+
{ time: l.time1, value: l.price1, script: scriptTimes(l) },
|
|
2309
|
+
{ time: l.time2, value: l.price2, script: scriptTimes(l) }
|
|
2274
2310
|
], drawLine, "normal");
|
|
2275
2311
|
}
|
|
2276
2312
|
drawBoxes(boxes, pane) {
|
|
2277
2313
|
this.drawLayers(boxes, pane, (b) => b.forceOverlay, (b) => [
|
|
2278
|
-
{ time: b.time1, value: b.price1 },
|
|
2279
|
-
{ time: b.time2, value: b.price2 }
|
|
2314
|
+
{ time: b.time1, value: b.price1, script: scriptTimes(b) },
|
|
2315
|
+
{ time: b.time2, value: b.price2, script: scriptTimes(b) }
|
|
2280
2316
|
], drawBox, "bottom");
|
|
2281
2317
|
}
|
|
2282
2318
|
drawLinefills(fills, pane) {
|
|
2283
2319
|
this.drawLayers(fills, pane, (f) => f.line1.forceOverlay, (f) => [
|
|
2284
|
-
{ time: f.line1.time1, value: f.line1.price1 },
|
|
2285
|
-
{ time: f.line1.time2, value: f.line1.price2 },
|
|
2286
|
-
{ time: f.line2.time1, value: f.line2.price1 },
|
|
2287
|
-
{ time: f.line2.time2, value: f.line2.price2 }
|
|
2320
|
+
{ time: f.line1.time1, value: f.line1.price1, script: scriptTimes(f.line1) },
|
|
2321
|
+
{ time: f.line1.time2, value: f.line1.price2, script: scriptTimes(f.line1) },
|
|
2322
|
+
{ time: f.line2.time1, value: f.line2.price1, script: scriptTimes(f.line2) },
|
|
2323
|
+
{ time: f.line2.time2, value: f.line2.price2, script: scriptTimes(f.line2) }
|
|
2288
2324
|
], drawLinefill, "bottom");
|
|
2289
2325
|
}
|
|
2290
2326
|
drawPolylines(polylines, pane) {
|
|
2291
|
-
this.drawLayers(polylines, pane, (p) => p.forceOverlay, (p) => p.points.map((pt) => ({ time: pt.time, value: pt.price })), drawPolyline, "normal");
|
|
2327
|
+
this.drawLayers(polylines, pane, (p) => p.forceOverlay, (p) => p.points.map((pt) => ({ time: pt.time, value: pt.price, script: scriptTimes(p) })), drawPolyline, "normal");
|
|
2292
2328
|
}
|
|
2293
|
-
/** Whitespace points after the last bar up to `
|
|
2294
|
-
addFutureSlots(
|
|
2295
|
-
const k = this.grid.slotsAfter(maxTime);
|
|
2329
|
+
/** Whitespace points after the last bar up to slot `k` (bar slots for drawings and plot points on future bars) */
|
|
2330
|
+
addFutureSlots(k) {
|
|
2296
2331
|
if (k <= 0)
|
|
2297
2332
|
return;
|
|
2298
2333
|
const series = this.anchor(0, false);
|
|
@@ -2389,11 +2424,11 @@ function samePoint(a, b) {
|
|
|
2389
2424
|
n--;
|
|
2390
2425
|
return n === 0;
|
|
2391
2426
|
}
|
|
2392
|
-
function
|
|
2393
|
-
let max =
|
|
2394
|
-
const see = (t) => {
|
|
2395
|
-
if (typeof t === "number"
|
|
2396
|
-
max = t;
|
|
2427
|
+
function lastOutputSlot(r, grid) {
|
|
2428
|
+
let max = 0;
|
|
2429
|
+
const see = (t, script = false) => {
|
|
2430
|
+
if (typeof t === "number")
|
|
2431
|
+
max = Math.max(max, grid.slotsAfter(t, script));
|
|
2397
2432
|
};
|
|
2398
2433
|
for (const points of Object.values(r.plots ?? {})) {
|
|
2399
2434
|
for (let i = points.length - 1; i >= 0; i--) {
|
|
@@ -2409,24 +2444,24 @@ function lastOutputTime(r) {
|
|
|
2409
2444
|
for (const a of r.arrows ?? [])
|
|
2410
2445
|
see(a.time);
|
|
2411
2446
|
for (const l of r.labels ?? [])
|
|
2412
|
-
see(l.time);
|
|
2447
|
+
see(l.time, scriptTimes(l));
|
|
2413
2448
|
for (const l of r.lines ?? []) {
|
|
2414
|
-
see(l.time1);
|
|
2415
|
-
see(l.time2);
|
|
2449
|
+
see(l.time1, scriptTimes(l));
|
|
2450
|
+
see(l.time2, scriptTimes(l));
|
|
2416
2451
|
}
|
|
2417
2452
|
for (const b of r.boxes ?? []) {
|
|
2418
|
-
see(b.time1);
|
|
2419
|
-
see(b.time2);
|
|
2453
|
+
see(b.time1, scriptTimes(b));
|
|
2454
|
+
see(b.time2, scriptTimes(b));
|
|
2420
2455
|
}
|
|
2421
2456
|
for (const f of r.linefills ?? []) {
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2457
|
+
for (const l of [f.line1, f.line2]) {
|
|
2458
|
+
see(l.time1, scriptTimes(l));
|
|
2459
|
+
see(l.time2, scriptTimes(l));
|
|
2460
|
+
}
|
|
2426
2461
|
}
|
|
2427
2462
|
for (const p of r.polylines ?? [])
|
|
2428
2463
|
for (const pt of p.points)
|
|
2429
|
-
see(pt.time);
|
|
2464
|
+
see(pt.time, scriptTimes(p));
|
|
2430
2465
|
return max;
|
|
2431
2466
|
}
|
|
2432
2467
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lightweight-charts-indicators",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "1713 technical analysis indicators for the lightweight-charts library",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"homepage": "https://github.com/deepentropy/lightweight-charts-indicators#readme",
|
|
62
62
|
"peerDependencies": {
|
|
63
63
|
"lightweight-charts": ">=5.2.0 <6.0.0",
|
|
64
|
-
"oakscriptjs": ">=0.11.
|
|
64
|
+
"oakscriptjs": ">=0.11.3 <0.12.0"
|
|
65
65
|
},
|
|
66
66
|
"peerDependenciesMeta": {
|
|
67
67
|
"lightweight-charts": {
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"@types/node": "^20.10.6",
|
|
73
73
|
"esbuild": "^0.19.11",
|
|
74
74
|
"lightweight-charts": "^5.2.1",
|
|
75
|
-
"oakscriptjs": "^0.11.
|
|
75
|
+
"oakscriptjs": "^0.11.3",
|
|
76
76
|
"rimraf": "^6.1.0",
|
|
77
77
|
"typescript": "^5.3.3",
|
|
78
78
|
"vite": "^5.4.0",
|