oakscriptjs 0.23.0 → 0.25.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/README.md +25 -1
- package/bin/oakscript.mjs +10 -3
- package/dist/cjs/box/index.d.ts +348 -289
- package/dist/cjs/box/index.d.ts.map +1 -1
- package/dist/cjs/box/index.js.map +2 -2
- package/dist/cjs/check/node.d.ts.map +1 -1
- package/dist/cjs/check/node.js +1 -0
- package/dist/cjs/check/node.js.map +2 -2
- package/dist/cjs/check/preview.d.ts +31 -0
- package/dist/cjs/check/preview.d.ts.map +1 -0
- package/dist/cjs/check/preview.js +303 -0
- package/dist/cjs/check/preview.js.map +7 -0
- package/dist/cjs/color/index.d.ts +11 -11
- package/dist/cjs/color/index.js.map +1 -1
- package/dist/cjs/color/parse.d.ts +2 -0
- package/dist/cjs/color/parse.d.ts.map +1 -1
- package/dist/cjs/color/parse.js +6 -0
- package/dist/cjs/color/parse.js.map +2 -2
- package/dist/cjs/compare/index.d.ts +76 -12
- package/dist/cjs/compare/index.d.ts.map +1 -1
- package/dist/cjs/compare/index.js.map +2 -2
- package/dist/cjs/drawing/registry.d.ts +28 -5
- package/dist/cjs/drawing/registry.d.ts.map +1 -1
- package/dist/cjs/drawing/registry.js +14 -0
- package/dist/cjs/drawing/registry.js.map +2 -2
- 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/label/index.d.ts +265 -187
- package/dist/cjs/label/index.d.ts.map +1 -1
- package/dist/cjs/label/index.js +1 -1
- package/dist/cjs/label/index.js.map +2 -2
- package/dist/cjs/line/index.d.ts +247 -207
- package/dist/cjs/line/index.d.ts.map +1 -1
- package/dist/cjs/line/index.js.map +2 -2
- package/dist/cjs/linefill/index.d.ts +61 -89
- package/dist/cjs/linefill/index.d.ts.map +1 -1
- package/dist/cjs/linefill/index.js.map +2 -2
- package/dist/cjs/math/index.d.ts +49 -40
- package/dist/cjs/math/index.d.ts.map +1 -1
- package/dist/cjs/math/index.js.map +2 -2
- package/dist/cjs/polyline/index.d.ts +57 -78
- package/dist/cjs/polyline/index.d.ts.map +1 -1
- package/dist/cjs/polyline/index.js.map +2 -2
- package/dist/cjs/runtime/input-active.d.ts +2 -2
- package/dist/cjs/runtime/input-active.js.map +1 -1
- package/dist/cjs/runtime/series.d.ts +241 -161
- package/dist/cjs/runtime/series.d.ts.map +1 -1
- package/dist/cjs/runtime/series.js +223 -127
- package/dist/cjs/runtime/series.js.map +2 -2
- package/dist/cjs/script/api/alert.d.ts +37 -0
- package/dist/cjs/script/api/alert.d.ts.map +1 -0
- package/dist/cjs/script/api/alert.js +17 -0
- package/dist/cjs/script/api/alert.js.map +7 -0
- package/dist/cjs/script/api/calc.d.ts +232 -0
- package/dist/cjs/script/api/calc.d.ts.map +1 -0
- package/dist/cjs/script/api/calc.js +17 -0
- package/dist/cjs/script/api/calc.js.map +7 -0
- package/dist/cjs/script/api/color.d.ts +213 -0
- package/dist/cjs/script/api/color.d.ts.map +1 -0
- package/dist/cjs/script/api/color.js +17 -0
- package/dist/cjs/script/api/color.js.map +7 -0
- package/dist/cjs/script/api/context.d.ts +764 -0
- package/dist/cjs/script/api/context.d.ts.map +1 -0
- package/dist/cjs/script/api/context.js +17 -0
- package/dist/cjs/script/api/context.js.map +7 -0
- package/dist/cjs/script/api/log.d.ts +58 -0
- package/dist/cjs/script/api/log.d.ts.map +1 -0
- package/dist/cjs/script/api/log.js +17 -0
- package/dist/cjs/script/api/log.js.map +7 -0
- package/dist/cjs/script/api/strategy.d.ts +391 -0
- package/dist/cjs/script/api/strategy.d.ts.map +1 -0
- package/dist/cjs/script/api/strategy.js +17 -0
- package/dist/cjs/script/api/strategy.js.map +7 -0
- package/dist/cjs/script/api/ta.d.ts +1012 -0
- package/dist/cjs/script/api/ta.d.ts.map +1 -0
- package/dist/cjs/script/api/ta.js +17 -0
- package/dist/cjs/script/api/ta.js.map +7 -0
- package/dist/cjs/script/api/table.d.ts +479 -0
- package/dist/cjs/script/api/table.d.ts.map +1 -0
- package/dist/cjs/script/api/table.js +17 -0
- package/dist/cjs/script/api/table.js.map +7 -0
- package/dist/cjs/script/constants.d.ts +228 -83
- package/dist/cjs/script/constants.d.ts.map +1 -1
- package/dist/cjs/script/constants.js +87 -0
- package/dist/cjs/script/constants.js.map +2 -2
- package/dist/cjs/script/define.d.ts +94 -0
- package/dist/cjs/script/define.d.ts.map +1 -0
- package/dist/cjs/script/define.js +127 -0
- package/dist/cjs/script/define.js.map +7 -0
- package/dist/cjs/script/drawing-args.d.ts.map +1 -1
- package/dist/cjs/script/drawing-args.js +1 -1
- package/dist/cjs/script/drawing-args.js.map +2 -2
- package/dist/cjs/script/formula.d.ts +53 -0
- package/dist/cjs/script/formula.d.ts.map +1 -0
- package/dist/cjs/script/formula.js +402 -0
- package/dist/cjs/script/formula.js.map +7 -0
- package/dist/cjs/script/globals.d.ts +10 -0
- package/dist/cjs/script/globals.d.ts.map +1 -1
- package/dist/cjs/script/globals.js.map +1 -1
- package/dist/cjs/script/index.d.ts +1065 -1006
- package/dist/cjs/script/index.d.ts.map +1 -1
- package/dist/cjs/script/index.js +532 -61
- package/dist/cjs/script/index.js.map +3 -3
- package/dist/cjs/script/json.d.ts +117 -0
- package/dist/cjs/script/json.d.ts.map +1 -0
- package/dist/cjs/script/json.js +321 -0
- package/dist/cjs/script/json.js.map +7 -0
- package/dist/cjs/security/other.d.ts +8 -3
- package/dist/cjs/security/other.d.ts.map +1 -1
- package/dist/cjs/security/other.js +23 -6
- package/dist/cjs/security/other.js.map +2 -2
- package/dist/cjs/str/index.d.ts +50 -75
- package/dist/cjs/str/index.d.ts.map +1 -1
- package/dist/cjs/str/index.js +2 -2
- package/dist/cjs/str/index.js.map +2 -2
- package/dist/cjs/strategy/index.d.ts +102 -1
- package/dist/cjs/strategy/index.d.ts.map +1 -1
- package/dist/cjs/strategy/index.js.map +2 -2
- package/dist/cjs/table/index.d.ts +330 -49
- package/dist/cjs/table/index.d.ts.map +1 -1
- package/dist/cjs/table/index.js +55 -27
- package/dist/cjs/table/index.js.map +2 -2
- package/dist/cjs/text/index.d.ts +12 -14
- package/dist/cjs/text/index.d.ts.map +1 -1
- package/dist/cjs/text/index.js.map +2 -2
- package/dist/cjs/types/index.d.ts +15 -8
- package/dist/cjs/types/index.d.ts.map +1 -1
- package/dist/cjs/types/index.js +12 -3
- package/dist/cjs/types/index.js.map +2 -2
- package/dist/esm/box/index.d.ts +348 -289
- package/dist/esm/box/index.d.ts.map +1 -1
- package/dist/esm/box/index.js +276 -276
- package/dist/esm/box/index.js.map +1 -1
- package/dist/esm/check/node.d.ts.map +1 -1
- package/dist/esm/check/node.js +1 -0
- package/dist/esm/check/node.js.map +1 -1
- package/dist/esm/check/preview.d.ts +31 -0
- package/dist/esm/check/preview.d.ts.map +1 -0
- package/dist/esm/check/preview.js +296 -0
- package/dist/esm/check/preview.js.map +1 -0
- package/dist/esm/color/index.d.ts +11 -11
- package/dist/esm/color/index.js +11 -11
- package/dist/esm/color/parse.d.ts +2 -0
- package/dist/esm/color/parse.d.ts.map +1 -1
- package/dist/esm/color/parse.js +7 -0
- package/dist/esm/color/parse.js.map +1 -1
- package/dist/esm/compare/index.d.ts +76 -12
- package/dist/esm/compare/index.d.ts.map +1 -1
- package/dist/esm/compare/index.js +76 -12
- package/dist/esm/compare/index.js.map +1 -1
- package/dist/esm/drawing/registry.d.ts +28 -5
- package/dist/esm/drawing/registry.d.ts.map +1 -1
- package/dist/esm/drawing/registry.js +39 -3
- package/dist/esm/drawing/registry.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/label/index.d.ts +265 -187
- package/dist/esm/label/index.d.ts.map +1 -1
- package/dist/esm/label/index.js +207 -177
- package/dist/esm/label/index.js.map +1 -1
- package/dist/esm/line/index.d.ts +247 -207
- package/dist/esm/line/index.d.ts.map +1 -1
- package/dist/esm/line/index.js +202 -194
- package/dist/esm/line/index.js.map +1 -1
- package/dist/esm/linefill/index.d.ts +61 -89
- package/dist/esm/linefill/index.d.ts.map +1 -1
- package/dist/esm/linefill/index.js +61 -89
- package/dist/esm/linefill/index.js.map +1 -1
- package/dist/esm/math/index.d.ts +49 -40
- package/dist/esm/math/index.d.ts.map +1 -1
- package/dist/esm/math/index.js +22 -9
- package/dist/esm/math/index.js.map +1 -1
- package/dist/esm/polyline/index.d.ts +57 -78
- package/dist/esm/polyline/index.d.ts.map +1 -1
- package/dist/esm/polyline/index.js +57 -78
- package/dist/esm/polyline/index.js.map +1 -1
- package/dist/esm/runtime/input-active.d.ts +2 -2
- package/dist/esm/runtime/input-active.js +2 -2
- package/dist/esm/runtime/series.d.ts +241 -161
- package/dist/esm/runtime/series.d.ts.map +1 -1
- package/dist/esm/runtime/series.js +241 -161
- package/dist/esm/runtime/series.js.map +1 -1
- package/dist/esm/script/api/alert.d.ts +37 -0
- package/dist/esm/script/api/alert.d.ts.map +1 -0
- package/dist/esm/script/api/alert.js +7 -0
- package/dist/esm/script/api/alert.js.map +1 -0
- package/dist/esm/script/api/calc.d.ts +232 -0
- package/dist/esm/script/api/calc.d.ts.map +1 -0
- package/dist/esm/script/api/calc.js +6 -0
- package/dist/esm/script/api/calc.js.map +1 -0
- package/dist/esm/script/api/color.d.ts +213 -0
- package/dist/esm/script/api/color.d.ts.map +1 -0
- package/dist/esm/script/api/color.js +6 -0
- package/dist/esm/script/api/color.js.map +1 -0
- package/dist/esm/script/api/context.d.ts +764 -0
- package/dist/esm/script/api/context.d.ts.map +1 -0
- package/dist/esm/script/api/context.js +7 -0
- package/dist/esm/script/api/context.js.map +1 -0
- package/dist/esm/script/api/log.d.ts +58 -0
- package/dist/esm/script/api/log.d.ts.map +1 -0
- package/dist/esm/script/api/log.js +6 -0
- package/dist/esm/script/api/log.js.map +1 -0
- package/dist/esm/script/api/strategy.d.ts +391 -0
- package/dist/esm/script/api/strategy.d.ts.map +1 -0
- package/dist/esm/script/api/strategy.js +7 -0
- package/dist/esm/script/api/strategy.js.map +1 -0
- package/dist/esm/script/api/ta.d.ts +1012 -0
- package/dist/esm/script/api/ta.d.ts.map +1 -0
- package/dist/esm/script/api/ta.js +6 -0
- package/dist/esm/script/api/ta.js.map +1 -0
- package/dist/esm/script/api/table.d.ts +479 -0
- package/dist/esm/script/api/table.d.ts.map +1 -0
- package/dist/esm/script/api/table.js +7 -0
- package/dist/esm/script/api/table.js.map +1 -0
- package/dist/esm/script/constants.d.ts +228 -83
- package/dist/esm/script/constants.d.ts.map +1 -1
- package/dist/esm/script/constants.js +110 -24
- package/dist/esm/script/constants.js.map +1 -1
- package/dist/esm/script/define.d.ts +94 -0
- package/dist/esm/script/define.d.ts.map +1 -0
- package/dist/esm/script/define.js +136 -0
- package/dist/esm/script/define.js.map +1 -0
- package/dist/esm/script/drawing-args.d.ts.map +1 -1
- package/dist/esm/script/drawing-args.js +2 -1
- package/dist/esm/script/drawing-args.js.map +1 -1
- package/dist/esm/script/formula.d.ts +53 -0
- package/dist/esm/script/formula.d.ts.map +1 -0
- package/dist/esm/script/formula.js +408 -0
- package/dist/esm/script/formula.js.map +1 -0
- package/dist/esm/script/globals.d.ts +10 -0
- package/dist/esm/script/globals.d.ts.map +1 -1
- package/dist/esm/script/globals.js.map +1 -1
- package/dist/esm/script/index.d.ts +1065 -1006
- package/dist/esm/script/index.d.ts.map +1 -1
- package/dist/esm/script/index.js +1099 -153
- package/dist/esm/script/index.js.map +1 -1
- package/dist/esm/script/json.d.ts +117 -0
- package/dist/esm/script/json.d.ts.map +1 -0
- package/dist/esm/script/json.js +375 -0
- package/dist/esm/script/json.js.map +1 -0
- package/dist/esm/security/other.d.ts +8 -3
- package/dist/esm/security/other.d.ts.map +1 -1
- package/dist/esm/security/other.js +45 -10
- package/dist/esm/security/other.js.map +1 -1
- package/dist/esm/str/index.d.ts +50 -75
- package/dist/esm/str/index.d.ts.map +1 -1
- package/dist/esm/str/index.js +51 -76
- package/dist/esm/str/index.js.map +1 -1
- package/dist/esm/strategy/index.d.ts +102 -1
- package/dist/esm/strategy/index.d.ts.map +1 -1
- package/dist/esm/strategy/index.js +1 -1
- package/dist/esm/strategy/index.js.map +1 -1
- package/dist/esm/table/index.d.ts +330 -49
- package/dist/esm/table/index.d.ts.map +1 -1
- package/dist/esm/table/index.js +372 -61
- package/dist/esm/table/index.js.map +1 -1
- package/dist/esm/text/index.d.ts +12 -14
- package/dist/esm/text/index.d.ts.map +1 -1
- package/dist/esm/text/index.js +12 -14
- package/dist/esm/text/index.js.map +1 -1
- package/dist/esm/types/index.d.ts +15 -8
- package/dist/esm/types/index.d.ts.map +1 -1
- package/dist/esm/types/index.js +15 -8
- package/dist/esm/types/index.js.map +1 -1
- package/docs/first-indicator.md +152 -0
- package/docs/guide.md +1185 -0
- package/docs/inventory.md +772 -0
- package/docs/no-code.md +207 -0
- package/docs/recipes.md +202 -0
- package/package.json +2 -1
- package/skills/oakscript/SKILL.md +8 -0
- package/skills/oakscript/reference/errors.md +3 -2
- package/skills/oakscript/reference/timeframes-symbols.md +4 -0
- package/src/box/index.ts +348 -289
- package/src/check/node.ts +1 -0
- package/src/check/preview.ts +307 -0
- package/src/color/index.ts +11 -11
- package/src/color/parse.ts +7 -0
- package/src/compare/index.ts +76 -12
- package/src/drawing/registry.ts +44 -5
- package/src/index.ts +1 -1
- package/src/label/index.ts +267 -189
- package/src/line/index.ts +248 -208
- package/src/linefill/index.ts +61 -89
- package/src/math/index.ts +51 -42
- package/src/polyline/index.ts +57 -78
- package/src/runtime/input-active.ts +2 -2
- package/src/runtime/series.ts +243 -163
- package/src/script/api/alert.ts +43 -0
- package/src/script/api/calc.ts +250 -0
- package/src/script/api/color.ts +245 -0
- package/src/script/api/context.ts +944 -0
- package/src/script/api/log.ts +60 -0
- package/src/script/api/strategy.ts +410 -0
- package/src/script/api/ta.ts +1115 -0
- package/src/script/api/table.ts +538 -0
- package/src/script/constants.ts +229 -25
- package/src/script/define.ts +221 -0
- package/src/script/drawing-args.ts +2 -1
- package/src/script/formula.ts +438 -0
- package/src/script/globals.ts +10 -0
- package/src/script/index.ts +1520 -241
- package/src/script/json.ts +457 -0
- package/src/security/other.ts +43 -9
- package/src/str/index.ts +51 -76
- package/src/strategy/index.ts +102 -1
- package/src/table/index.ts +388 -62
- package/src/text/index.ts +12 -14
- package/src/types/index.ts +15 -8
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/label/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Label namespace\n * Functions for creating and manipulating label drawing objects.\n *\n * @remarks\n * Labels are primarily used for annotations and marking points on the chart.\n * They have limited computational value compared to lines and boxes, but getters\n * allow retrieving position and text for conditional logic.\n *\n * @version 6\n */\n\nimport { all as allDrawings, checkBarIndex, isDeleted, register, remove } from '../drawing/registry.js';\nimport type { ChartPoint, Label, color } from '../types/index.js';\n\ntype LabelXloc = 'bar_index' | 'bar_time' | 'pane';\ntype LabelYloc = 'price' | 'abovebar' | 'belowbar';\ntype LabelStyle = NonNullable<Label['style']>;\n\n/**\n * Creates a new label (PineScript `label.new`), with a chart point or with coordinates:\n *\n * - `label.new(point, text?, xloc?, yloc?, color?, style?, textcolor?, size?, textalign?, tooltip?,\n * text_font_family?, force_overlay?, text_formatting?)`\n * - `label.new(x, y, text?, xloc?, yloc?, color?, style?, textcolor?, size?, textalign?, tooltip?,\n * text_font_family?, force_overlay?, text_formatting?)`\n *\n * With a chart point, x is `point.index` for `bar_index` labels and `point.time` for `bar_time` labels.\n *\n * @example\n * ```typescript\n * const signal = label.new(10, 105.5, 'BUY');\n * const atPoint = label.new(chartPoint.from_index(10, 105.5), 'BUY');\n * ```\n */\nexport function new_label(\n point: ChartPoint,\n text?: string,\n xloc?: LabelXloc,\n yloc?: LabelYloc,\n labelColor?: color,\n style?: LabelStyle,\n textcolor?: color,\n size?: string | number,\n textalign?: 'left' | 'center' | 'right',\n tooltip?: string,\n text_font_family?: 'default' | 'monospace',\n force_overlay?: boolean,\n text_formatting?: number\n): Label;\nexport function new_label(\n x: number,\n y: number,\n text?: string,\n xloc?: LabelXloc,\n yloc?: LabelYloc,\n labelColor?: color,\n style?: LabelStyle,\n textcolor?: color,\n size?: string | number,\n textalign?: 'left' | 'center' | 'right',\n tooltip?: string,\n text_font_family?: 'default' | 'monospace',\n force_overlay?: boolean,\n text_formatting?: number\n): Label;\nexport function new_label(...args: unknown[]): Label {\n let x: number, y: number, rest: unknown[];\n if (typeof args[0] === 'object' && args[0] !== null) {\n const point = args[0] as ChartPoint;\n rest = args.slice(1);\n x = pointX(point, (rest[1] as LabelXloc | undefined) ?? 'bar_index');\n y = point.price;\n } else {\n [x, y] = args as [number, number];\n rest = args.slice(2);\n }\n const [text, xloc, yloc, labelColor, style, textcolor, size, textalign, tooltip, text_font_family,\n force_overlay, text_formatting] = rest as [\n string?, LabelXloc?, LabelYloc?, color?, LabelStyle?, color?, (string | number)?,\n ('left' | 'center' | 'right')?, string?, ('default' | 'monospace')?, boolean?, number?,\n ];\n x = checkBarIndex('label.new', 'x', x, xloc);\n return register('label', {\n x,\n y,\n xloc: xloc ?? 'bar_index',\n yloc: yloc ?? 'price',\n // PineScript: a label without text has the text \"\" (label.get_text gives \"\")\n text: text ?? '',\n tooltip,\n color: labelColor,\n style,\n textcolor,\n size,\n textalign,\n text_font_family,\n force_overlay: force_overlay ?? false,\n text_formatting,\n });\n}\n\n/**\n * Returns the x coordinate.\n *\n * @param id - Label object\n * @returns X coordinate (bar index or timestamp)\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * const x = label.get_x(label); // Returns 50\n * ```\n */\nexport function get_x(id: Label): number {\n return id.x;\n}\n\n/**\n * Returns the y coordinate (price level).\n *\n * @param id - Label object\n * @returns Y coordinate (price)\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * const y = label.get_y(label); // Returns 155.5\n * ```\n */\nexport function get_y(id: Label): number {\n return id.y;\n}\n\n/**\n * Returns the label text content.\n *\n * @param id - Label object\n * @returns Text content (or undefined if no text)\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot High');\n * const text = label.get_text(label); // Returns 'Pivot High'\n * ```\n */\nexport function get_text(id: Label): string | undefined {\n return id.text;\n}\n\n/**\n * Creates a copy of the label object.\n *\n * @param id - Label object to copy\n * @returns New label object with same properties\n *\n * @remarks\n * Creates a shallow copy of the label. Modifications to the copy won't affect the original.\n *\n * @example\n * ```typescript\n * const original = label.new(50, 155.5, 'Pivot');\n * const copied = label.copy(original);\n *\n * // Modify copy without affecting original\n * copied.text = 'New Text';\n * ```\n */\nexport function copy(id: Label): Label {\n return register('label', { ...id });\n}\n\n// =============================================================================\n// POSITION SETTERS\n// =============================================================================\n\n/**\n * Sets the x coordinate.\n *\n * @param id - Label object to modify\n * @param x - New x coordinate\n * @returns Modified label object\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * label.set_x(label, 55); // Move to bar 55\n * ```\n */\nexport function set_x(id: Label, x: number): Label {\n if (isDeleted(id)) return id;\n x = checkBarIndex('label.set_x', 'x', x, id.xloc);\n id.x = x;\n return id;\n}\n\n/**\n * Sets the y coordinate (price level).\n *\n * @param id - Label object to modify\n * @param y - New y coordinate\n * @returns Modified label object\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * label.set_y(label, 160); // Move to price 160\n * ```\n */\nexport function set_y(id: Label, y: number): Label {\n if (isDeleted(id)) return id;\n id.y = y;\n return id;\n}\n\n/**\n * Sets both x and y coordinates.\n *\n * @param id - Label object to modify\n * @param x - New x coordinate\n * @param y - New y coordinate\n * @returns Modified label object\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * label.set_xy(label, 60, 160); // Move to (60, 160)\n * ```\n */\nexport function set_xy(id: Label, x: number, y: number): Label {\n if (isDeleted(id)) return id;\n x = checkBarIndex('label.set_x', 'x', x, id.xloc);\n id.x = x;\n id.y = y;\n return id;\n}\n\n/**\n * Sets the x-axis coordinate system.\n *\n * @param id - Label object to modify\n * @param x - New x coordinate\n * @param xloc - New coordinate system\n * @returns Modified label object\n *\n * @remarks\n * When changing xloc, you must provide an appropriate x coordinate for the new system.\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * label.set_xloc(label, 1609459200000, 'bar_time'); // Change to timestamp\n * ```\n */\nexport function set_xloc(id: Label, x: number, xloc: 'bar_index' | 'bar_time' | 'pane'): Label {\n if (isDeleted(id)) return id;\n id.x = x;\n id.xloc = xloc;\n return id;\n}\n\n/**\n * Sets the y-location mode of the label (PineScript `label.set_yloc(id, yloc)`): `price` uses the\n * label's y, `abovebar` / `belowbar` place it above / below the bar.\n */\nexport function set_yloc(id: Label, yloc: 'price' | 'abovebar' | 'belowbar'): Label {\n if (isDeleted(id)) return id;\n id.yloc = yloc;\n return id;\n}\n\n// =============================================================================\n// CONTENT SETTERS\n// =============================================================================\n\n/**\n * Sets the text content.\n *\n * @param id - Label object to modify\n * @param text - New text content\n * @returns Modified label object\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * label.set_text(label, 'Updated Text');\n * ```\n */\nexport function set_text(id: Label, text: string): Label {\n if (isDeleted(id)) return id;\n id.text = text;\n return id;\n}\n\n/**\n * Sets the tooltip text.\n *\n * @param id - Label object to modify\n * @param tooltip - New tooltip text\n * @returns Modified label object\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * label.set_tooltip(label, 'Resistance level formed at 155.5');\n * ```\n */\nexport function set_tooltip(id: Label, tooltip: string): Label {\n if (isDeleted(id)) return id;\n id.tooltip = tooltip;\n return id;\n}\n\n// =============================================================================\n// STYLING SETTERS\n// =============================================================================\n\n/**\n * Sets the label color (border and arrow).\n *\n * @param id - Label object to modify\n * @param labelColor - New color\n * @returns Modified label object\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * label.set_color(label, '#FF0000'); // Red label\n * ```\n */\nexport function set_color(id: Label, labelColor: color): Label {\n if (isDeleted(id)) return id;\n id.color = labelColor;\n return id;\n}\n\n/**\n * Sets the text color.\n *\n * @param id - Label object to modify\n * @param textColor - New text color\n * @returns Modified label object\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * label.set_textcolor(label, '#FFFFFF'); // White text\n * ```\n */\nexport function set_textcolor(id: Label, textColor: color): Label {\n if (isDeleted(id)) return id;\n id.textcolor = textColor;\n return id;\n}\n\n/**\n * Sets the label style.\n *\n * @param id - Label object to modify\n * @param style - New label style\n * @returns Modified label object\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * label.set_style(label, 'label_down'); // Arrow pointing down\n * ```\n */\nexport function set_style(\n id: Label,\n style: 'none' | 'xcross' | 'cross' | 'triangleup' | 'triangledown' | 'flag' | 'circle' |\n 'arrowup' | 'arrowdown' | 'label_up' | 'label_down' | 'label_left' | 'label_right' |\n 'label_lower_left' | 'label_lower_right' | 'label_upper_left' | 'label_upper_right' |\n 'label_center' | 'square' | 'diamond' | 'text_outline'\n): Label {\n if (isDeleted(id)) return id;\n id.style = style;\n return id;\n}\n\n/**\n * Sets the label size.\n *\n * @param id - Label object to modify\n * @param size - New size\n * @returns Modified label object\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * label.set_size(label, 'large'); // Larger label\n * ```\n */\nexport function set_size(id: Label, size: string | number): Label {\n if (isDeleted(id)) return id;\n id.size = size;\n return id;\n}\n\n/**\n * Sets the text alignment.\n *\n * @param id - Label object to modify\n * @param align - New text alignment\n * @returns Modified label object\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * label.set_textalign(label, 'center'); // Center-aligned text\n * ```\n */\nexport function set_textalign(id: Label, align: 'left' | 'center' | 'right'): Label {\n if (isDeleted(id)) return id;\n id.textalign = align;\n return id;\n}\n\n/**\n * Sets the text font family.\n *\n * @param id - Label object to modify\n * @param font - New font family\n * @returns Modified label object\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * label.set_text_font_family(label, 'monospace');\n * ```\n */\nexport function set_text_font_family(id: Label, font: 'default' | 'monospace'): Label {\n if (isDeleted(id)) return id;\n id.text_font_family = font;\n return id;\n}\n\n/**\n * Deletes the label object.\n *\n * @param id - Label object to delete\n *\n * @remarks\n * Removes the label from `label.all()`. As in PineScript, the deleted label is `na`: its getters\n * return NaN and its setters do nothing. Deleting it twice has no effect.\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * label.delete(label);\n * // label.all() no longer contains it\n * ```\n */\nexport function delete_label(id: Label): void {\n remove('label', id);\n}\n\n/** x coordinate of a chart point for an object's xloc (`na` when the point has no such coordinate). */\nfunction pointX(point: ChartPoint, xloc: 'bar_index' | 'bar_time' | 'pane'): number {\n const x = xloc === 'bar_time' ? point.time : point.index;\n return x ?? NaN;\n}\n\n/**\n * All live labels, in creation order (PineScript `label.all`). A new array.\n */\nexport function all(): Label[] {\n return allDrawings('label');\n}\n\n/**\n * Sets the label position from a chart point: `point.index` for `bar_index` labels, `point.time`\n * for `bar_time` labels, and `point.price`.\n */\nexport function set_point(id: Label, point: ChartPoint): Label {\n if (isDeleted(id)) return id;\n id.x = pointX(point, id.xloc);\n id.y = point.price;\n return id;\n}\n\n/**\n * Sets the text formatting: `text.format_none`, `text.format_bold`, `text.format_italic`,\n * or `text.format_bold + text.format_italic`.\n */\nexport function set_text_formatting(id: Label, formatting: number): Label {\n if (isDeleted(id)) return id;\n id.text_formatting = formatting;\n return id;\n}\n\n// Alias to match PineScript API\nexport { new_label as new };\nexport { delete_label as delete };\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["/**\n * Label namespace: functions that create, read, change and delete label drawings (`label.*`).\n *\n * @remarks\n * A label is a text box or a shape at one point of the chart: a bar index (`xloc.bar_index`, the default), a UNIX\n * time in ms (`xloc.bar_time`) or a percent of the pane's width (`xloc.pane`), and a price, or above / below the bar\n * with `yloc.abovebar` / `yloc.belowbar`.\n *\n * @version 6\n */\n\nimport { all as allDrawings, checkBarIndex, isDeleted, register, remove } from '../drawing/registry.js';\nimport type { ChartPoint, Label, color } from '../types/index.js';\n\ntype LabelXloc = 'bar_index' | 'bar_time' | 'pane';\ntype LabelYloc = 'price' | 'abovebar' | 'belowbar';\ntype LabelStyle = NonNullable<Label['style']>;\n\n/**\n * Draws a label at a chart point and returns its handle, to change or delete it later.\n * With `xloc.bar_index` the x of the point is its `index`, with `xloc.bar_time` its `time`. Labels above\n * `max_labels_count` (default 50) are deleted oldest first.\n * @param point - Where the label points (`chart.point.now()`, `chart.point.from_index(...)`...).\n * @param text - Text of the label; `\\n` starts a new line. Default: \"\".\n * @param xloc - What the x coordinate is: `xloc.bar_index`, `xloc.bar_time` or `xloc.pane`. Default: `xloc.bar_index`.\n * @param yloc - `yloc.price` (at the point's price), `yloc.abovebar` or `yloc.belowbar` (above the high / below the\n * low of the bar). Default: `yloc.price`.\n * @param labelColor - Colour of the label box or shape. Default: blue (#2962FF).\n * @param style - `label.style_label_down`, `label.style_label_up`, `label.style_label_left`... or a shape style\n * (`label.style_circle`, `label.style_triangleup`...). Default: `label.style_label_down`.\n * @param textcolor - Text colour. Default: white.\n * @param size - `size.tiny`, `size.small`, `size.normal`, `size.large`, `size.huge`, `size.auto`, or a size in points.\n * Default: `size.normal`.\n * @param textalign - Alignment of the text lines: `text.align_left`, `text.align_center` or `text.align_right`.\n * Default: `text.align_center`.\n * @param tooltip - Text shown when the pointer is over the label. Default: none.\n * @param text_font_family - `font.family_default` or `font.family_monospace`. Default: `font.family_default`.\n * @param force_overlay - When true, the label is drawn on the price pane even if the script has its own pane.\n * Default: false.\n * @param text_formatting - `text.format_bold`, `text.format_italic`, their sum, or `text.format_none`.\n * Default: `text.format_none`.\n * @returns The new label.\n * @example\n * ```js\n * eachBar((c) => {\n * if (c.i === c.n - 1) label.new(chart.point.now(c.high), \"Last\", { style: label.style_label_down });\n * });\n * ```\n */\nexport function new_label(\n point: ChartPoint,\n text?: string,\n xloc?: LabelXloc,\n yloc?: LabelYloc,\n labelColor?: color,\n style?: LabelStyle,\n textcolor?: color,\n size?: string | number,\n textalign?: 'left' | 'center' | 'right',\n tooltip?: string,\n text_font_family?: 'default' | 'monospace',\n force_overlay?: boolean,\n text_formatting?: number\n): Label;\n/**\n * Draws a label at (x, y) and returns its handle, to change or delete it later.\n * Inside `eachBar` a Series argument is read on the current bar; the optional arguments can also be given by name in\n * an object after the coordinates. A bar index x is rounded down. Labels above `max_labels_count` (default 50) are\n * deleted oldest first.\n * @param x - A bar index, a UNIX time in ms (`xloc.bar_time`) or a percent of the pane's width (`xloc.pane`).\n * @param y - Price of the label (not used with `yloc.abovebar` / `yloc.belowbar`).\n * @param text - Text of the label; `\\n` starts a new line. Default: \"\".\n * @param xloc - What the x coordinate is: `xloc.bar_index`, `xloc.bar_time` or `xloc.pane`. Default: `xloc.bar_index`.\n * @param yloc - `yloc.price` (at `y`), `yloc.abovebar` or `yloc.belowbar` (above the high / below the low of the\n * bar). Default: `yloc.price`.\n * @param labelColor - Colour of the label box or shape. Default: blue (#2962FF).\n * @param style - `label.style_label_down`, `label.style_label_up`, `label.style_label_left`... or a shape style\n * (`label.style_circle`, `label.style_triangleup`...). Default: `label.style_label_down`.\n * @param textcolor - Text colour. Default: white.\n * @param size - `size.tiny`, `size.small`, `size.normal`, `size.large`, `size.huge`, `size.auto`, or a size in points.\n * Default: `size.normal`.\n * @param textalign - Alignment of the text lines: `text.align_left`, `text.align_center` or `text.align_right`.\n * Default: `text.align_center`.\n * @param tooltip - Text shown when the pointer is over the label. Default: none.\n * @param text_font_family - `font.family_default` or `font.family_monospace`. Default: `font.family_default`.\n * @param force_overlay - When true, the label is drawn on the price pane even if the script has its own pane.\n * Default: false.\n * @param text_formatting - `text.format_bold`, `text.format_italic`, their sum, or `text.format_none`.\n * Default: `text.format_none`.\n * @returns The new label.\n * @example\n * ```js\n * eachBar((c) => {\n * if (c.i === c.n - 1) label.new(c.i, c.high, \"Last\", { color: color.gray, textcolor: color.white });\n * });\n * ```\n */\nexport function new_label(\n x: number,\n y: number,\n text?: string,\n xloc?: LabelXloc,\n yloc?: LabelYloc,\n labelColor?: color,\n style?: LabelStyle,\n textcolor?: color,\n size?: string | number,\n textalign?: 'left' | 'center' | 'right',\n tooltip?: string,\n text_font_family?: 'default' | 'monospace',\n force_overlay?: boolean,\n text_formatting?: number\n): Label;\nexport function new_label(...args: unknown[]): Label {\n let x: number, y: number, rest: unknown[];\n if (typeof args[0] === 'object' && args[0] !== null) {\n const point = args[0] as ChartPoint;\n rest = args.slice(1);\n x = pointX(point, (rest[1] as LabelXloc | undefined) ?? 'bar_index');\n y = point.price;\n } else {\n [x, y] = args as [number, number];\n rest = args.slice(2);\n }\n const [text, xloc, yloc, labelColor, style, textcolor, size, textalign, tooltip, text_font_family,\n force_overlay, text_formatting] = rest as [\n string?, LabelXloc?, LabelYloc?, color?, LabelStyle?, color?, (string | number)?,\n ('left' | 'center' | 'right')?, string?, ('default' | 'monospace')?, boolean?, number?,\n ];\n x = checkBarIndex('label.new', 'x', x, xloc);\n return register('label', {\n x,\n y,\n xloc: xloc ?? 'bar_index',\n yloc: yloc ?? 'price',\n // a label without text has the text \"\" (label.get_text gives \"\")\n text: text ?? '',\n tooltip,\n color: labelColor,\n style,\n textcolor,\n size,\n textalign,\n text_font_family,\n force_overlay: force_overlay ?? false,\n text_formatting,\n });\n}\n\n/**\n * Returns the x coordinate of the label.\n * @param id - The label.\n * @returns A bar index, a UNIX time in ms or a pane percent, by the label's xloc; NaN for a deleted label.\n * @example\n * ```js\n * eachBar((c) => {\n * const lb = label.new(c.i - 5, c.high, \"Pivot\");\n * const age = c.i - label.get_x(lb); // 5\n * });\n * ```\n */\nexport function get_x(id: Label): number {\n return id.x;\n}\n\n/**\n * Returns the price of the label.\n * @param id - The label.\n * @returns The label's price; NaN for a deleted label.\n * @example\n * ```js\n * eachBar((c) => {\n * const lb = label.new(c.i, c.high, \"High\");\n * const above = c.close > label.get_y(lb);\n * });\n * ```\n */\nexport function get_y(id: Label): number {\n return id.y;\n}\n\n/**\n * Returns the text of the label.\n * @param id - The label.\n * @returns The label text (\"\" when it was created without one).\n * @example\n * ```js\n * eachBar((c) => {\n * const lb = label.new(c.i, c.high, \"Up\");\n * if (label.get_text(lb) === \"Up\") label.set_color(lb, color.green);\n * });\n * ```\n */\nexport function get_text(id: Label): string | undefined {\n return id.text;\n}\n\n/**\n * Makes a new label with the same position, text and style as `id` (it counts toward `max_labels_count`).\n * Changing the copy does not change the original.\n * @param id - The label to copy.\n * @returns The new label.\n * @example\n * ```js\n * eachBar((c) => {\n * const lb = label.new(c.i, c.high, \"Mark\");\n * label.set_y(label.copy(lb), c.low); // the same label at the low\n * });\n * ```\n */\nexport function copy(id: Label): Label {\n return register('label', { ...id });\n}\n\n// =============================================================================\n// POSITION SETTERS\n// =============================================================================\n\n/**\n * Moves the label to another x. Does nothing on a deleted label.\n * @param id - The label.\n * @param x - New x: a bar index, a UNIX time in ms or a pane percent, by the label's xloc. A bar index is rounded down.\n * @returns The same label.\n * @example\n * ```js\n * eachBar((c) => {\n * const lb = label.new(c.i, c.high, \"Next\");\n * label.set_x(lb, c.i + 5);\n * });\n * ```\n */\nexport function set_x(id: Label, x: number): Label {\n if (isDeleted(id)) return id;\n x = checkBarIndex('label.set_x', 'x', x, id.xloc);\n id.x = x;\n return id;\n}\n\n/**\n * Moves the label to another price. Does nothing on a deleted label.\n * @param id - The label.\n * @param y - New price.\n * @returns The same label.\n * @example\n * ```js\n * eachBar((c) => {\n * const lb = label.new(c.i, c.high, \"Low\");\n * label.set_y(lb, c.low);\n * });\n * ```\n */\nexport function set_y(id: Label, y: number): Label {\n if (isDeleted(id)) return id;\n id.y = y;\n return id;\n}\n\n/**\n * Moves the label to another x and price. Does nothing on a deleted label.\n * @param id - The label.\n * @param x - New x: a bar index, a UNIX time in ms or a pane percent, by the label's xloc. A bar index is rounded down.\n * @param y - New price.\n * @returns The same label.\n * @example\n * ```js\n * eachBar((c) => {\n * const lb = label.new(c.i - 1, c.get(close, 1), \"Close\");\n * label.set_xy(lb, c.i, c.close);\n * });\n * ```\n */\nexport function set_xy(id: Label, x: number, y: number): Label {\n if (isDeleted(id)) return id;\n x = checkBarIndex('label.set_x', 'x', x, id.xloc);\n id.x = x;\n id.y = y;\n return id;\n}\n\n/**\n * Changes what the label's x coordinate is and sets it in that unit. Does nothing on a deleted label.\n * @param id - The label.\n * @param x - New x, in the unit of `xloc`.\n * @param xloc - `xloc.bar_index` (bar index), `xloc.bar_time` (UNIX time in ms) or `xloc.pane` (percent of the\n * pane's width).\n * @returns The same label.\n * @example\n * ```js\n * eachBar((c) => {\n * const lb = label.new(c.i, c.high, \"Now\");\n * label.set_xloc(lb, c.time, xloc.bar_time);\n * });\n * ```\n */\nexport function set_xloc(id: Label, x: number, xloc: 'bar_index' | 'bar_time' | 'pane'): Label {\n if (isDeleted(id)) return id;\n id.x = x;\n id.xloc = xloc;\n return id;\n}\n\n/**\n * Sets how the label is placed vertically. Does nothing on a deleted label.\n * @param id - The label.\n * @param yloc - `yloc.price` (at the label's price), `yloc.abovebar` (above the bar's high) or `yloc.belowbar`\n * (below the bar's low).\n * @returns The same label.\n * @example\n * ```js\n * eachBar((c) => {\n * const lb = label.new(c.i, c.close, \"Buy\", { style: label.style_label_up });\n * label.set_yloc(lb, yloc.belowbar);\n * });\n * ```\n */\nexport function set_yloc(id: Label, yloc: 'price' | 'abovebar' | 'belowbar'): Label {\n if (isDeleted(id)) return id;\n id.yloc = yloc;\n return id;\n}\n\n// =============================================================================\n// CONTENT SETTERS\n// =============================================================================\n\n/**\n * Sets the text of the label. Does nothing on a deleted label.\n * @param id - The label.\n * @param text - New text; `\\n` starts a new line.\n * @returns The same label.\n * @example\n * ```js\n * eachBar((c) => {\n * const lb = label.new(c.i, c.high, \"\");\n * label.set_text(lb, str.tostring(c.close, \"#.##\"));\n * });\n * ```\n */\nexport function set_text(id: Label, text: string): Label {\n if (isDeleted(id)) return id;\n id.text = text;\n return id;\n}\n\n/**\n * Sets the text shown when the pointer is over the label. Does nothing on a deleted label.\n * @param id - The label.\n * @param tooltip - New tooltip text.\n * @returns The same label.\n * @example\n * ```js\n * eachBar((c) => {\n * const lb = label.new(c.i, c.high, \"H\");\n * label.set_tooltip(lb, \"High \" + str.tostring(c.high));\n * });\n * ```\n */\nexport function set_tooltip(id: Label, tooltip: string): Label {\n if (isDeleted(id)) return id;\n id.tooltip = tooltip;\n return id;\n}\n\n// =============================================================================\n// STYLING SETTERS\n// =============================================================================\n\n/**\n * Sets the colour of the label box or shape. Does nothing on a deleted label.\n * @param id - The label.\n * @param labelColor - New colour (`color.red`, `\"#FF0000\"`, `color.new(color.red, 50)`...).\n * @returns The same label.\n * @example\n * ```js\n * eachBar((c) => {\n * const lb = label.new(c.i, c.high, \"Bar\");\n * label.set_color(lb, c.close > c.open ? color.green : color.red);\n * });\n * ```\n */\nexport function set_color(id: Label, labelColor: color): Label {\n if (isDeleted(id)) return id;\n id.color = labelColor;\n return id;\n}\n\n/**\n * Sets the text colour of the label. Does nothing on a deleted label.\n * @param id - The label.\n * @param textColor - New text colour.\n * @returns The same label.\n * @example\n * ```js\n * eachBar((c) => {\n * const lb = label.new(c.i, c.high, \"Note\", { style: label.style_none });\n * label.set_textcolor(lb, color.orange);\n * });\n * ```\n */\nexport function set_textcolor(id: Label, textColor: color): Label {\n if (isDeleted(id)) return id;\n id.textcolor = textColor;\n return id;\n}\n\n/**\n * Sets the label style: a box with a tip on one side, a box centred on the point, a shape, or text only.\n * Does nothing on a deleted label.\n * @param id - The label.\n * @param style - A `label.style_*` constant: `label.style_label_down`, `label.style_label_up`,\n * `label.style_label_left`, `label.style_label_right`, `label.style_label_center`, the corner styles\n * (`label.style_label_lower_left`...), the shapes (`label.style_circle`, `label.style_xcross`...),\n * `label.style_text_outline` or `label.style_none`.\n * @returns The same label.\n * @example\n * ```js\n * eachBar((c) => {\n * const lb = label.new(c.i, c.low, \"Low\");\n * label.set_style(lb, label.style_label_up);\n * });\n * ```\n */\nexport function set_style(\n id: Label,\n style: 'none' | 'xcross' | 'cross' | 'triangleup' | 'triangledown' | 'flag' | 'circle' |\n 'arrowup' | 'arrowdown' | 'label_up' | 'label_down' | 'label_left' | 'label_right' |\n 'label_lower_left' | 'label_lower_right' | 'label_upper_left' | 'label_upper_right' |\n 'label_center' | 'square' | 'diamond' | 'text_outline'\n): Label {\n if (isDeleted(id)) return id;\n id.style = style;\n return id;\n}\n\n/**\n * Sets the size of the label text (and of its shape for the shape styles). Does nothing on a deleted label.\n * @param id - The label.\n * @param size - `size.tiny`, `size.small`, `size.normal`, `size.large`, `size.huge`, `size.auto`, or a size in points.\n * @returns The same label.\n * @example\n * ```js\n * eachBar((c) => {\n * const lb = label.new(c.i, c.high, \"Big\");\n * label.set_size(lb, size.large);\n * });\n * ```\n */\nexport function set_size(id: Label, size: string | number): Label {\n if (isDeleted(id)) return id;\n id.size = size;\n return id;\n}\n\n/**\n * Sets how the lines of a multi-line text are aligned. Does nothing on a deleted label.\n * @param id - The label.\n * @param align - `text.align_left`, `text.align_center` or `text.align_right`.\n * @returns The same label.\n * @example\n * ```js\n * eachBar((c) => {\n * const lb = label.new(c.i, c.high, \"Open\\nClose\");\n * label.set_textalign(lb, text.align_left);\n * });\n * ```\n */\nexport function set_textalign(id: Label, align: 'left' | 'center' | 'right'): Label {\n if (isDeleted(id)) return id;\n id.textalign = align;\n return id;\n}\n\n/**\n * Sets the font family of the label text. Does nothing on a deleted label.\n * @param id - The label.\n * @param font - `font.family_default` or `font.family_monospace`.\n * @returns The same label.\n * @example\n * ```js\n * eachBar((c) => {\n * const lb = label.new(c.i, c.high, str.tostring(c.close, \"0.00\"));\n * label.set_text_font_family(lb, font.family_monospace);\n * });\n * ```\n */\nexport function set_text_font_family(id: Label, font: 'default' | 'monospace'): Label {\n if (isDeleted(id)) return id;\n id.text_font_family = font;\n return id;\n}\n\n/**\n * Removes the label from the chart and from `label.all`. Afterwards its getters return NaN and its setters do\n * nothing; deleting it again does nothing.\n * @param id - The label to delete.\n * @example\n * ```js\n * eachBar((c) => {\n * const lb = label.new(c.i, c.high, \"Last\");\n * if (c.i < c.n - 1) label.delete(lb); // keep only the label of the last bar\n * });\n * ```\n */\nexport function delete_label(id: Label): void {\n remove('label', id);\n}\n\n/** x coordinate of a chart point for an object's xloc (`na` when the point has no such coordinate). */\nfunction pointX(point: ChartPoint, xloc: 'bar_index' | 'bar_time' | 'pane'): number {\n const x = xloc === 'bar_time' ? point.time : point.index;\n return x ?? NaN;\n}\n\n/**\n * Returns the labels that are still on the chart, oldest first. The array is a copy.\n * (In a script, `label.all` is read as a value, without a call.)\n * @returns The live labels in creation order.\n * @example\n * ```js\n * eachBar((c) => {\n * if (c.i === c.n - 1) for (const lb of label.all) label.set_textcolor(lb, color.yellow);\n * });\n * ```\n */\nexport function all(): Label[] {\n return allDrawings('label');\n}\n\n/**\n * Moves the label to a chart point: its `index` for a `xloc.bar_index` label, its `time` for a `xloc.bar_time` label\n * (NaN when the point has none), and its `price`. Does nothing on a deleted label.\n * @param id - The label.\n * @param point - The new position.\n * @returns The same label.\n * @example\n * ```js\n * eachBar((c) => {\n * const lb = label.new(c.i, c.high, \"Here\");\n * label.set_point(lb, chart.point.now(c.low));\n * });\n * ```\n */\nexport function set_point(id: Label, point: ChartPoint): Label {\n if (isDeleted(id)) return id;\n id.x = pointX(point, id.xloc);\n id.y = point.price;\n return id;\n}\n\n/**\n * Makes the label text bold and / or italic. Does nothing on a deleted label.\n * @param id - The label.\n * @param formatting - `text.format_none`, `text.format_bold`, `text.format_italic`, or\n * `text.format_bold + text.format_italic`.\n * @returns The same label.\n * @example\n * ```js\n * eachBar((c) => {\n * const lb = label.new(c.i, c.high, \"Signal\");\n * label.set_text_formatting(lb, text.format_bold);\n * });\n * ```\n */\nexport function set_text_formatting(id: Label, formatting: number): Label {\n if (isDeleted(id)) return id;\n id.text_formatting = formatting;\n return id;\n}\n\n// Script names: label.new / label.delete\nexport { new_label as new };\nexport { delete_label as delete };\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
6
|
"names": ["allDrawings"]
|
|
7
7
|
}
|