lightweight-charts-indicators 0.20.3 → 0.22.0
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/helpers.d.ts +1 -0
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.mjs +329 -0
- package/dist/index.cjs +333 -9
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +333 -9
- package/dist/live-run.d.ts.map +1 -1
- package/dist/packed-series.d.ts +52 -0
- package/dist/packed-series.d.ts.map +1 -0
- package/package.json +1 -1
package/dist/helpers.d.ts
CHANGED
package/dist/helpers.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC"}
|
package/dist/helpers.mjs
CHANGED
|
@@ -619,6 +619,322 @@ import {
|
|
|
619
619
|
saveDrawingCheckpoint,
|
|
620
620
|
setDrawingBar
|
|
621
621
|
} from "oakscriptjs";
|
|
622
|
+
|
|
623
|
+
// src/packed-series.ts
|
|
624
|
+
var PACKED = Symbol.for("lightweight-charts-indicators/packed-series");
|
|
625
|
+
function isPoint(p) {
|
|
626
|
+
if (p === null || typeof p !== "object" || Array.isArray(p) || Object.getPrototypeOf(p) !== Object.prototype)
|
|
627
|
+
return false;
|
|
628
|
+
let k = 0;
|
|
629
|
+
for (const f in p) {
|
|
630
|
+
if (k === 0 && f !== "time")
|
|
631
|
+
return false;
|
|
632
|
+
if (k === 1)
|
|
633
|
+
return f === "value" && typeof p.time === "number" && typeof p.value === "number";
|
|
634
|
+
k++;
|
|
635
|
+
}
|
|
636
|
+
return false;
|
|
637
|
+
}
|
|
638
|
+
var Columns = class _Columns {
|
|
639
|
+
/** What the list holds: decided by its first value; `any` keeps them in `items`. */
|
|
640
|
+
kind = "none";
|
|
641
|
+
n = 0;
|
|
642
|
+
time;
|
|
643
|
+
value;
|
|
644
|
+
/** 1 where an entry is set (an index past the others leaves holes). */
|
|
645
|
+
has;
|
|
646
|
+
extra = {};
|
|
647
|
+
items = [];
|
|
648
|
+
constructor(capacity) {
|
|
649
|
+
const cap = Math.max(16, capacity);
|
|
650
|
+
this.time = new Float64Array(cap);
|
|
651
|
+
this.value = new Float64Array(cap);
|
|
652
|
+
this.has = new Uint8Array(cap);
|
|
653
|
+
}
|
|
654
|
+
grow(size) {
|
|
655
|
+
if (size <= this.value.length)
|
|
656
|
+
return;
|
|
657
|
+
const cap = Math.max(size, this.value.length + (this.value.length >> 1));
|
|
658
|
+
const t = new Float64Array(cap);
|
|
659
|
+
t.set(this.time.subarray(0, this.n));
|
|
660
|
+
const v = new Float64Array(cap);
|
|
661
|
+
v.set(this.value.subarray(0, this.n));
|
|
662
|
+
const h = new Uint8Array(cap);
|
|
663
|
+
h.set(this.has.subarray(0, this.n));
|
|
664
|
+
this.time = t;
|
|
665
|
+
this.value = v;
|
|
666
|
+
this.has = h;
|
|
667
|
+
}
|
|
668
|
+
get(i) {
|
|
669
|
+
if (this.kind === "any")
|
|
670
|
+
return this.items[i];
|
|
671
|
+
if (i >= this.n || !this.has[i])
|
|
672
|
+
return void 0;
|
|
673
|
+
if (this.kind === "numbers")
|
|
674
|
+
return this.value[i];
|
|
675
|
+
const p = { time: this.time[i], value: this.value[i] };
|
|
676
|
+
for (const k in this.extra) {
|
|
677
|
+
const x = this.extra[k][i];
|
|
678
|
+
if (x !== void 0)
|
|
679
|
+
p[k] = x;
|
|
680
|
+
}
|
|
681
|
+
return p;
|
|
682
|
+
}
|
|
683
|
+
/** Every entry as it was written, in a plain list (the kinds no longer hold the next value). */
|
|
684
|
+
toAny() {
|
|
685
|
+
const items = new Array(this.n);
|
|
686
|
+
for (let i = 0; i < this.n; i++)
|
|
687
|
+
if (this.has[i])
|
|
688
|
+
items[i] = this.get(i);
|
|
689
|
+
this.kind = "any";
|
|
690
|
+
this.items = items;
|
|
691
|
+
this.time = new Float64Array(0);
|
|
692
|
+
this.value = new Float64Array(0);
|
|
693
|
+
this.has = new Uint8Array(0);
|
|
694
|
+
this.extra = {};
|
|
695
|
+
}
|
|
696
|
+
set(i, p) {
|
|
697
|
+
if (this.kind === "none" && p !== void 0)
|
|
698
|
+
this.kind = isPoint(p) ? "points" : typeof p === "number" ? "numbers" : "any";
|
|
699
|
+
const fits = this.kind === "any" || p === void 0 || (this.kind === "points" ? isPoint(p) : typeof p === "number");
|
|
700
|
+
if (!fits)
|
|
701
|
+
this.toAny();
|
|
702
|
+
if (this.kind === "any") {
|
|
703
|
+
this.items[i] = p;
|
|
704
|
+
if (i >= this.n)
|
|
705
|
+
this.n = i + 1;
|
|
706
|
+
return;
|
|
707
|
+
}
|
|
708
|
+
if (i >= this.n) {
|
|
709
|
+
this.grow(i + 1);
|
|
710
|
+
this.has.fill(0, this.n, i);
|
|
711
|
+
this.n = i + 1;
|
|
712
|
+
}
|
|
713
|
+
this.has[i] = p === void 0 ? 0 : 1;
|
|
714
|
+
for (const k in this.extra) {
|
|
715
|
+
const list = this.extra[k];
|
|
716
|
+
if (i < list.length)
|
|
717
|
+
list[i] = void 0;
|
|
718
|
+
}
|
|
719
|
+
if (p === void 0)
|
|
720
|
+
return;
|
|
721
|
+
if (this.kind === "numbers") {
|
|
722
|
+
this.value[i] = p;
|
|
723
|
+
return;
|
|
724
|
+
}
|
|
725
|
+
const q = p;
|
|
726
|
+
this.time[i] = q.time;
|
|
727
|
+
this.value[i] = q.value;
|
|
728
|
+
for (const k in q) {
|
|
729
|
+
if (k === "time" || k === "value")
|
|
730
|
+
continue;
|
|
731
|
+
const x = q[k];
|
|
732
|
+
if (x !== void 0)
|
|
733
|
+
(this.extra[k] ??= [])[i] = x;
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
setLength(len) {
|
|
737
|
+
if (this.kind === "any") {
|
|
738
|
+
this.items.length = len;
|
|
739
|
+
this.n = len;
|
|
740
|
+
return;
|
|
741
|
+
}
|
|
742
|
+
if (len < this.n) {
|
|
743
|
+
for (const k in this.extra) {
|
|
744
|
+
const list = this.extra[k];
|
|
745
|
+
if (list.length > len)
|
|
746
|
+
list.length = len;
|
|
747
|
+
}
|
|
748
|
+
} else if (len > this.n) {
|
|
749
|
+
this.grow(len);
|
|
750
|
+
this.has.fill(0, this.n, len);
|
|
751
|
+
}
|
|
752
|
+
this.n = len;
|
|
753
|
+
}
|
|
754
|
+
/** Entries [a, b) in new columns. */
|
|
755
|
+
copy(a, b) {
|
|
756
|
+
const out = new _Columns(Math.max(0, b - a));
|
|
757
|
+
out.kind = this.kind;
|
|
758
|
+
out.n = Math.max(0, b - a);
|
|
759
|
+
if (this.kind === "any") {
|
|
760
|
+
out.items = this.items.slice(a, b);
|
|
761
|
+
return out;
|
|
762
|
+
}
|
|
763
|
+
out.time.set(this.time.subarray(a, b));
|
|
764
|
+
out.value.set(this.value.subarray(a, b));
|
|
765
|
+
out.has.set(this.has.subarray(a, b));
|
|
766
|
+
for (const k in this.extra)
|
|
767
|
+
out.extra[k] = this.extra[k].slice(a, b);
|
|
768
|
+
return out;
|
|
769
|
+
}
|
|
770
|
+
};
|
|
771
|
+
var isIndex = (p) => typeof p === "string" && p !== "" && String(+p >>> 0) === p;
|
|
772
|
+
function bound(x, n, fallback) {
|
|
773
|
+
if (x === void 0)
|
|
774
|
+
return fallback;
|
|
775
|
+
const v = Math.trunc(Number(x)) || 0;
|
|
776
|
+
return v < 0 ? Math.max(0, n + v) : Math.min(v, n);
|
|
777
|
+
}
|
|
778
|
+
var read = (cols, i) => cols.get(i);
|
|
779
|
+
function view(cols) {
|
|
780
|
+
const slice = (start, end) => {
|
|
781
|
+
const a = bound(start, cols.n, 0);
|
|
782
|
+
return view(cols.copy(a, Math.max(a, bound(end, cols.n, cols.n))));
|
|
783
|
+
};
|
|
784
|
+
return new Proxy([], {
|
|
785
|
+
get(target, prop, receiver) {
|
|
786
|
+
if (prop === "length")
|
|
787
|
+
return cols.n;
|
|
788
|
+
if (prop === PACKED)
|
|
789
|
+
return cols;
|
|
790
|
+
if (prop === "slice")
|
|
791
|
+
return slice;
|
|
792
|
+
if (isIndex(prop))
|
|
793
|
+
return read(cols, +prop);
|
|
794
|
+
return Reflect.get(target, prop, receiver);
|
|
795
|
+
},
|
|
796
|
+
set(target, prop, value) {
|
|
797
|
+
if (prop === "length") {
|
|
798
|
+
cols.setLength(value);
|
|
799
|
+
return true;
|
|
800
|
+
}
|
|
801
|
+
if (isIndex(prop)) {
|
|
802
|
+
cols.set(+prop, value);
|
|
803
|
+
return true;
|
|
804
|
+
}
|
|
805
|
+
return Reflect.set(target, prop, value);
|
|
806
|
+
},
|
|
807
|
+
has(target, prop) {
|
|
808
|
+
if (isIndex(prop))
|
|
809
|
+
return +prop < cols.n && (cols.kind === "any" ? +prop in cols.items : cols.has[+prop] === 1);
|
|
810
|
+
return Reflect.has(target, prop);
|
|
811
|
+
},
|
|
812
|
+
getOwnPropertyDescriptor(target, prop) {
|
|
813
|
+
if (prop === "length")
|
|
814
|
+
return { value: cols.n, writable: true, enumerable: false, configurable: false };
|
|
815
|
+
if (isIndex(prop)) {
|
|
816
|
+
const i = +prop;
|
|
817
|
+
const present = i < cols.n && (cols.kind === "any" ? i in cols.items : cols.has[i] === 1);
|
|
818
|
+
return present ? { value: read(cols, i), writable: true, enumerable: true, configurable: true } : void 0;
|
|
819
|
+
}
|
|
820
|
+
return Reflect.getOwnPropertyDescriptor(target, prop);
|
|
821
|
+
},
|
|
822
|
+
ownKeys(target) {
|
|
823
|
+
const keys = [];
|
|
824
|
+
for (let i = 0; i < cols.n; i++)
|
|
825
|
+
if (cols.kind === "any" ? i in cols.items : cols.has[i] === 1)
|
|
826
|
+
keys.push(String(i));
|
|
827
|
+
for (const k of Reflect.ownKeys(target))
|
|
828
|
+
if (!isIndex(k))
|
|
829
|
+
keys.push(k);
|
|
830
|
+
return keys;
|
|
831
|
+
},
|
|
832
|
+
deleteProperty(target, prop) {
|
|
833
|
+
if (isIndex(prop)) {
|
|
834
|
+
const i = +prop;
|
|
835
|
+
if (cols.kind === "any")
|
|
836
|
+
delete cols.items[i];
|
|
837
|
+
else if (i < cols.n)
|
|
838
|
+
cols.set(i, void 0);
|
|
839
|
+
return true;
|
|
840
|
+
}
|
|
841
|
+
return Reflect.deleteProperty(target, prop);
|
|
842
|
+
}
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
var packed = false;
|
|
846
|
+
function setPackedSeries(on) {
|
|
847
|
+
packed = on;
|
|
848
|
+
}
|
|
849
|
+
function packedSeriesMode() {
|
|
850
|
+
return packed;
|
|
851
|
+
}
|
|
852
|
+
function packedSeries(list = []) {
|
|
853
|
+
const cols = new Columns(list.length);
|
|
854
|
+
for (let i = 0; i < list.length; i++)
|
|
855
|
+
if (i in list)
|
|
856
|
+
cols.set(i, list[i]);
|
|
857
|
+
cols.setLength(list.length);
|
|
858
|
+
return view(cols);
|
|
859
|
+
}
|
|
860
|
+
function packedColumns(v) {
|
|
861
|
+
if (v === null || typeof v !== "object" || !Array.isArray(v))
|
|
862
|
+
return null;
|
|
863
|
+
const cols = v[PACKED];
|
|
864
|
+
return cols && cols.kind === "points" && cols.has.subarray(0, cols.n).every((x) => x === 1) ? cols : null;
|
|
865
|
+
}
|
|
866
|
+
var isPackedSeries = (v) => v !== null && typeof v === "object" && Array.isArray(v) && v[PACKED] !== void 0;
|
|
867
|
+
function packedFromColumns(c) {
|
|
868
|
+
const cols = new Columns(0);
|
|
869
|
+
cols.kind = "points";
|
|
870
|
+
cols.n = c.n;
|
|
871
|
+
cols.time = c.time;
|
|
872
|
+
cols.value = c.value;
|
|
873
|
+
cols.has = new Uint8Array(c.n).fill(1);
|
|
874
|
+
cols.extra = c.extra;
|
|
875
|
+
return view(cols);
|
|
876
|
+
}
|
|
877
|
+
var RUN_FIELDS = /* @__PURE__ */ new Set(["series", "lists"]);
|
|
878
|
+
function packLists(s, lists, pick) {
|
|
879
|
+
const own = s;
|
|
880
|
+
const places = /* @__PURE__ */ new Map();
|
|
881
|
+
const reached = /* @__PURE__ */ new Set();
|
|
882
|
+
const at = (list, holder, key) => {
|
|
883
|
+
const p = places.get(list);
|
|
884
|
+
if (p)
|
|
885
|
+
p.push([holder, key]);
|
|
886
|
+
else
|
|
887
|
+
places.set(list, [[holder, key]]);
|
|
888
|
+
};
|
|
889
|
+
const holders = /* @__PURE__ */ new Set();
|
|
890
|
+
for (const k of Object.keys(own)) {
|
|
891
|
+
const v = own[k];
|
|
892
|
+
if (!Array.isArray(v))
|
|
893
|
+
continue;
|
|
894
|
+
const study = !RUN_FIELDS.has(k);
|
|
895
|
+
at(v, own, k);
|
|
896
|
+
if (study)
|
|
897
|
+
reached.add(v);
|
|
898
|
+
if (isPackedSeries(v))
|
|
899
|
+
continue;
|
|
900
|
+
if (study) {
|
|
901
|
+
for (const item of v)
|
|
902
|
+
if (Array.isArray(item))
|
|
903
|
+
reached.add(item);
|
|
904
|
+
}
|
|
905
|
+
if (holders.has(v))
|
|
906
|
+
continue;
|
|
907
|
+
holders.add(v);
|
|
908
|
+
for (let j = 0; j < v.length; j++)
|
|
909
|
+
if (Array.isArray(v[j]))
|
|
910
|
+
at(v[j], v, j);
|
|
911
|
+
}
|
|
912
|
+
for (let j = 0; j < lists.length; j++) {
|
|
913
|
+
const list = lists[j];
|
|
914
|
+
if (!Array.isArray(list) || !reached.has(list) || isPackedSeries(list) || !pick(list))
|
|
915
|
+
continue;
|
|
916
|
+
const p = packedSeries(list);
|
|
917
|
+
for (const [holder, key] of places.get(list) ?? [])
|
|
918
|
+
holder[key] = p;
|
|
919
|
+
if (lists[j] !== p)
|
|
920
|
+
lists[j] = p;
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
function packRunState(s) {
|
|
924
|
+
packLists(s, s.series, () => true);
|
|
925
|
+
return s;
|
|
926
|
+
}
|
|
927
|
+
function packPointLists(s) {
|
|
928
|
+
packLists(s, s.lists, (list) => {
|
|
929
|
+
for (const x of list)
|
|
930
|
+
if (x !== void 0)
|
|
931
|
+
return isPoint(x);
|
|
932
|
+
return false;
|
|
933
|
+
});
|
|
934
|
+
return s;
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
// src/live-run.ts
|
|
622
938
|
var LAST_BAR_FIELDS = /* @__PURE__ */ new Set(["lastBarConfirmed", "lastBarNew", "realtime", "now"]);
|
|
623
939
|
function sameChart(a, b, functions = true) {
|
|
624
940
|
const keys = /* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(b)]);
|
|
@@ -675,6 +991,7 @@ function createBarRun(study, chart = {}) {
|
|
|
675
991
|
let copy = new Float64Array(0);
|
|
676
992
|
let saved = null;
|
|
677
993
|
const copyVars = study.copyVars ?? ((v) => ({ ...v }));
|
|
994
|
+
const packed2 = packedSeriesMode();
|
|
678
995
|
const limits = study.drawings;
|
|
679
996
|
let lastKey;
|
|
680
997
|
let lastData;
|
|
@@ -736,6 +1053,10 @@ function createBarRun(study, chart = {}) {
|
|
|
736
1053
|
}
|
|
737
1054
|
for (const out of s.series)
|
|
738
1055
|
out.length = n;
|
|
1056
|
+
if (packed2 && from === 0) {
|
|
1057
|
+
packRunState(s);
|
|
1058
|
+
packPointLists(s);
|
|
1059
|
+
}
|
|
739
1060
|
copy = copyBars(bars, confirmed, copy, Math.min(from, confirmed));
|
|
740
1061
|
return Object.assign(study.result(s, bars, next), { from });
|
|
741
1062
|
} catch (e) {
|
|
@@ -1213,12 +1534,19 @@ export {
|
|
|
1213
1534
|
hasCalendar,
|
|
1214
1535
|
higherTimeframeBars,
|
|
1215
1536
|
isBarSource,
|
|
1537
|
+
isPackedSeries,
|
|
1216
1538
|
lastBarConfirmedOf,
|
|
1217
1539
|
liveAlertStates,
|
|
1218
1540
|
lowerTimeframe,
|
|
1219
1541
|
mintickOf,
|
|
1220
1542
|
nowOf,
|
|
1221
1543
|
otherSymbolChart,
|
|
1544
|
+
packPointLists,
|
|
1545
|
+
packRunState,
|
|
1546
|
+
packedColumns,
|
|
1547
|
+
packedFromColumns,
|
|
1548
|
+
packedSeries,
|
|
1549
|
+
packedSeriesMode,
|
|
1222
1550
|
periodChanges,
|
|
1223
1551
|
periodStarts,
|
|
1224
1552
|
rootOf,
|
|
@@ -1230,6 +1558,7 @@ export {
|
|
|
1230
1558
|
securityStarts,
|
|
1231
1559
|
sessionFlags,
|
|
1232
1560
|
sessionHoursOf,
|
|
1561
|
+
setPackedSeries,
|
|
1233
1562
|
spreadBars,
|
|
1234
1563
|
spreadOptions,
|
|
1235
1564
|
spreadSymbols,
|