oakscriptjs 0.12.0 → 0.12.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/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/script/index.d.ts +17 -0
- package/dist/cjs/script/index.d.ts.map +1 -1
- package/dist/cjs/script/index.js +24 -5
- package/dist/cjs/script/index.js.map +2 -2
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/script/index.d.ts +17 -0
- package/dist/esm/script/index.d.ts.map +1 -1
- package/dist/esm/script/index.js +27 -5
- package/dist/esm/script/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/script/index.ts +28 -5
package/src/script/index.ts
CHANGED
|
@@ -708,15 +708,33 @@ export interface ScriptPlotOptions {
|
|
|
708
708
|
editable?: boolean;
|
|
709
709
|
}
|
|
710
710
|
|
|
711
|
+
/**
|
|
712
|
+
* Titles of untitled outputs, as the PineScript compiler names them (reference metadata of a script whose outputs have
|
|
713
|
+
* no title): the Style settings and the alert output lists show them.
|
|
714
|
+
*/
|
|
715
|
+
export const DEFAULT_OUTPUT_TITLES = {
|
|
716
|
+
plot: 'Plot',
|
|
717
|
+
hline: 'Level',
|
|
718
|
+
plotFill: 'Plots Background',
|
|
719
|
+
hlineFill: 'Hlines Background',
|
|
720
|
+
shape: 'Shapes',
|
|
721
|
+
char: 'Chars',
|
|
722
|
+
arrow: 'Arrows',
|
|
723
|
+
bgcolor: 'Background Color',
|
|
724
|
+
barcolor: 'Bar Color',
|
|
725
|
+
candle: 'PlotCandle',
|
|
726
|
+
bar: 'PlotBar',
|
|
727
|
+
} as const;
|
|
728
|
+
|
|
711
729
|
/** PineScript `plot()` — declares the plot and supplies its data in one call. */
|
|
712
|
-
function plotImpl(series: Series, title
|
|
730
|
+
function plotImpl(series: Series, title: string = DEFAULT_OUTPUT_TITLES.plot, options: ScriptPlotOptions = {}): PlotHandle {
|
|
713
731
|
const c = collector();
|
|
714
732
|
const id = `plot${c.plotConfig.length}`;
|
|
715
733
|
const perBar = Array.isArray(options.color) ? options.color : undefined;
|
|
716
734
|
const staticColor = typeof options.color === 'string' ? options.color : (perBar?.[perBar.length - 1] ?? '#2962FF');
|
|
717
735
|
c.plotConfig.push({
|
|
718
736
|
id,
|
|
719
|
-
title
|
|
737
|
+
title,
|
|
720
738
|
color: staticColor,
|
|
721
739
|
lineWidth: options.linewidth,
|
|
722
740
|
style: options.style,
|
|
@@ -726,7 +744,7 @@ function plotImpl(series: Series, title?: string, options: ScriptPlotOptions = {
|
|
|
726
744
|
forceOverlay: options.force_overlay,
|
|
727
745
|
...(options.editable === false ? { editable: false } : {}),
|
|
728
746
|
});
|
|
729
|
-
c.outputs.push({ kind: 'plot', id, title
|
|
747
|
+
c.outputs.push({ kind: 'plot', id, title });
|
|
730
748
|
const values = series.toArray();
|
|
731
749
|
const b = bars();
|
|
732
750
|
const data: TimeValue[] = [];
|
|
@@ -770,7 +788,7 @@ export interface ScriptHLineOptions {
|
|
|
770
788
|
}
|
|
771
789
|
|
|
772
790
|
/** PineScript `hline()` — a static horizontal level. Default line style: dashed (PineScript). */
|
|
773
|
-
function hlineImpl(price: number, title
|
|
791
|
+
function hlineImpl(price: number, title: string = DEFAULT_OUTPUT_TITLES.hline, options: ScriptHLineOptions = {}): PlotHandle {
|
|
774
792
|
const c = collector();
|
|
775
793
|
const id = `hline${c.hlineConfig.length}`;
|
|
776
794
|
c.hlineConfig.push({
|
|
@@ -874,6 +892,7 @@ export function fill(a: PlotHandle, b: PlotHandle, ...args: unknown[]): void {
|
|
|
874
892
|
editable = args[2];
|
|
875
893
|
}
|
|
876
894
|
const id = `fill${c.fillConfig.length}`;
|
|
895
|
+
title ??= a.kind === 'hline' && b.kind === 'hline' ? DEFAULT_OUTPUT_TITLES.hlineFill : DEFAULT_OUTPUT_TITLES.plotFill;
|
|
877
896
|
const topColor = gradient && sameColor(gradient.topColor);
|
|
878
897
|
const bottomColor = gradient && sameColor(gradient.bottomColor);
|
|
879
898
|
const hlines = a.kind === 'hline' && b.kind === 'hline';
|
|
@@ -981,6 +1000,7 @@ function emitMarkers(
|
|
|
981
1000
|
): void {
|
|
982
1001
|
const c = collector();
|
|
983
1002
|
const id = `${kind}${c.shapeConfig.filter((s) => s.kind === kind).length}`;
|
|
1003
|
+
title ??= DEFAULT_OUTPUT_TITLES[kind];
|
|
984
1004
|
const style: ShapeStyle | 'char' = kind === 'shape' ? (options.style ?? 'xcross') : 'char';
|
|
985
1005
|
const char = kind === 'char' ? (options.char ?? '*') : undefined;
|
|
986
1006
|
const location = options.location ?? 'abovebar';
|
|
@@ -1063,6 +1083,7 @@ export interface PlotArrowOptions {
|
|
|
1063
1083
|
export function plotarrow(series: Series, title?: string, options: PlotArrowOptions = {}): void {
|
|
1064
1084
|
const c = collector();
|
|
1065
1085
|
const id = `arrow${c.arrowConfig.length}`;
|
|
1086
|
+
title ??= DEFAULT_OUTPUT_TITLES.arrow;
|
|
1066
1087
|
const pick = (col: string | Array<string | undefined> | undefined, fallback: string, i: number): string | undefined =>
|
|
1067
1088
|
col === undefined ? fallback : typeof col === 'string' ? col : col[i];
|
|
1068
1089
|
const colorup = typeof options.colorup === 'string' ? options.colorup : '#00FF00';
|
|
@@ -1108,7 +1129,7 @@ function emitBarColors(
|
|
|
1108
1129
|
c.barColorConfig.push({
|
|
1109
1130
|
id,
|
|
1110
1131
|
kind,
|
|
1111
|
-
title: options.title,
|
|
1132
|
+
title: options.title ?? DEFAULT_OUTPUT_TITLES[kind],
|
|
1112
1133
|
offset: options.offset,
|
|
1113
1134
|
forceOverlay: options.force_overlay,
|
|
1114
1135
|
// a constant colour is a palette of one colour (PineScript)
|
|
@@ -1219,6 +1240,7 @@ export function plotcandle(
|
|
|
1219
1240
|
): void {
|
|
1220
1241
|
const c = collector();
|
|
1221
1242
|
const id = `plotcandle${c.candleConfig.filter((x) => x.kind === 'candle').length}`;
|
|
1243
|
+
title ??= DEFAULT_OUTPUT_TITLES.candle;
|
|
1222
1244
|
c.candleConfig.push({
|
|
1223
1245
|
id,
|
|
1224
1246
|
kind: 'candle',
|
|
@@ -1259,6 +1281,7 @@ export function plotbar(
|
|
|
1259
1281
|
): void {
|
|
1260
1282
|
const c = collector();
|
|
1261
1283
|
const id = `plotbar${c.candleConfig.filter((x) => x.kind === 'bar').length}`;
|
|
1284
|
+
title ??= DEFAULT_OUTPUT_TITLES.bar;
|
|
1262
1285
|
c.candleConfig.push({
|
|
1263
1286
|
id,
|
|
1264
1287
|
kind: 'bar',
|