@orangecharts/wrun-chart-host 0.1.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.
Files changed (198) hide show
  1. package/README.md +72 -0
  2. package/dist/constants/governed-exchanges.constants.d.ts +11 -0
  3. package/dist/constants/governed-exchanges.constants.js +11 -0
  4. package/dist/constants/indicator-sets.constants.d.ts +8 -0
  5. package/dist/constants/indicator-sets.constants.js +8 -0
  6. package/dist/constants/interval.constants.d.ts +34 -0
  7. package/dist/constants/interval.constants.js +121 -0
  8. package/dist/constants/scriptEditor/technicalIndicatorScriptKeys.constants.d.ts +28 -0
  9. package/dist/constants/scriptEditor/technicalIndicatorScriptKeys.constants.js +65 -0
  10. package/dist/constants/tpo-color-schemes.constants.d.ts +30 -0
  11. package/dist/constants/tpo-color-schemes.constants.js +32 -0
  12. package/dist/host-env.d.ts +102 -0
  13. package/dist/host-env.js +26 -0
  14. package/dist/index.d.ts +93 -0
  15. package/dist/index.js +96 -0
  16. package/dist/indicators/controls/tpo-letter.util.d.ts +2 -0
  17. package/dist/indicators/controls/tpo-letter.util.js +13 -0
  18. package/dist/indicators/controls/tpo-session.util.d.ts +99 -0
  19. package/dist/indicators/controls/tpo-session.util.js +389 -0
  20. package/dist/interfaces/kscript-diagnostics.interface.d.ts +64 -0
  21. package/dist/interfaces/kscript-diagnostics.interface.js +1 -0
  22. package/dist/interfaces/om-panel-data.interface.d.ts +103 -0
  23. package/dist/interfaces/om-panel-data.interface.js +7 -0
  24. package/dist/interfaces/wrun-runtime.interface.d.ts +2659 -0
  25. package/dist/interfaces/wrun-runtime.interface.js +55 -0
  26. package/dist/utility/chart/calendar-interval.util.d.ts +24 -0
  27. package/dist/utility/chart/calendar-interval.util.js +81 -0
  28. package/dist/utility/chart/candle-bar-end.util.d.ts +15 -0
  29. package/dist/utility/chart/candle-bar-end.util.js +23 -0
  30. package/dist/utility/chart/cme-realtime.util.d.ts +24 -0
  31. package/dist/utility/chart/cme-realtime.util.js +53 -0
  32. package/dist/utility/chart/interval-ladder.util.d.ts +27 -0
  33. package/dist/utility/chart/interval-ladder.util.js +92 -0
  34. package/dist/utility/chart/kscript-drawing-prep.util.d.ts +40 -0
  35. package/dist/utility/chart/kscript-drawing-prep.util.js +184 -0
  36. package/dist/utility/chart/kscript-drawing-safe-area.util.d.ts +95 -0
  37. package/dist/utility/chart/kscript-drawing-safe-area.util.js +805 -0
  38. package/dist/utility/chart/kscript-legend-entries.util.d.ts +166 -0
  39. package/dist/utility/chart/kscript-legend-entries.util.js +538 -0
  40. package/dist/utility/chart/kscript-output-role.util.d.ts +32 -0
  41. package/dist/utility/chart/kscript-output-role.util.js +215 -0
  42. package/dist/utility/chart/kscript-provenance-keys.util.d.ts +22 -0
  43. package/dist/utility/chart/kscript-provenance-keys.util.js +56 -0
  44. package/dist/utility/chart/kscript-run-result-normalize.util.d.ts +53 -0
  45. package/dist/utility/chart/kscript-run-result-normalize.util.js +476 -0
  46. package/dist/utility/chart/kscript-run-result-shape.util.d.ts +14 -0
  47. package/dist/utility/chart/kscript-run-result-shape.util.js +66 -0
  48. package/dist/utility/chart/kscript-titancharts-container.util.d.ts +29 -0
  49. package/dist/utility/chart/kscript-titancharts-container.util.js +151 -0
  50. package/dist/utility/chart/kscript-viewport-overlays.util.d.ts +83 -0
  51. package/dist/utility/chart/kscript-viewport-overlays.util.js +443 -0
  52. package/dist/utility/chart/om-panel-push-style.util.d.ts +78 -0
  53. package/dist/utility/chart/om-panel-push-style.util.js +301 -0
  54. package/dist/utility/chart/om-panel.util.d.ts +166 -0
  55. package/dist/utility/chart/om-panel.util.js +815 -0
  56. package/dist/utility/chart/om-series.util.d.ts +42 -0
  57. package/dist/utility/chart/om-series.util.js +330 -0
  58. package/dist/utility/chart/om-target.util.d.ts +11 -0
  59. package/dist/utility/chart/om-target.util.js +24 -0
  60. package/dist/utility/chart/om-widget.util.d.ts +148 -0
  61. package/dist/utility/chart/om-widget.util.js +413 -0
  62. package/dist/utility/chart/overlay-output-budget.util.d.ts +16 -0
  63. package/dist/utility/chart/overlay-output-budget.util.js +109 -0
  64. package/dist/utility/chart/overlay-paint-flags.util.d.ts +24 -0
  65. package/dist/utility/chart/overlay-paint-flags.util.js +55 -0
  66. package/dist/utility/chart/profile-row-height.util.d.ts +21 -0
  67. package/dist/utility/chart/profile-row-height.util.js +110 -0
  68. package/dist/utility/chart/session-interval.util.d.ts +1 -0
  69. package/dist/utility/chart/session-interval.util.js +35 -0
  70. package/dist/utility/chart/technical-script-legend-value.util.d.ts +18 -0
  71. package/dist/utility/chart/technical-script-legend-value.util.js +53 -0
  72. package/dist/utility/chart/trading-day.util.d.ts +70 -0
  73. package/dist/utility/chart/trading-day.util.js +238 -0
  74. package/dist/utility/chart/wrun-legend-name.util.d.ts +25 -0
  75. package/dist/utility/chart/wrun-legend-name.util.js +87 -0
  76. package/dist/utility/chart/wrun-run-result.util.d.ts +977 -0
  77. package/dist/utility/chart/wrun-run-result.util.js +5179 -0
  78. package/dist/utility/chart/wrun-visibility-chart.util.d.ts +25 -0
  79. package/dist/utility/chart/wrun-visibility-chart.util.js +22 -0
  80. package/dist/utility/indicators/heatmap-sensitivity.util.d.ts +62 -0
  81. package/dist/utility/indicators/heatmap-sensitivity.util.js +82 -0
  82. package/dist/utility/number-format.util.d.ts +68 -0
  83. package/dist/utility/number-format.util.js +188 -0
  84. package/dist/utility/v2/opra-governed.util.d.ts +1 -0
  85. package/dist/utility/v2/opra-governed.util.js +13 -0
  86. package/dist/utility/wrun/wrun-auto-row.util.d.ts +54 -0
  87. package/dist/utility/wrun/wrun-auto-row.util.js +96 -0
  88. package/dist/utility/wrun/wrun-batched-marks.util.d.ts +341 -0
  89. package/dist/utility/wrun/wrun-batched-marks.util.js +938 -0
  90. package/dist/utility/wrun/wrun-batched-readout.util.d.ts +75 -0
  91. package/dist/utility/wrun/wrun-batched-readout.util.js +171 -0
  92. package/dist/utility/wrun/wrun-box-segment.util.d.ts +185 -0
  93. package/dist/utility/wrun/wrun-box-segment.util.js +570 -0
  94. package/dist/utility/wrun/wrun-build-memo.util.d.ts +133 -0
  95. package/dist/utility/wrun/wrun-build-memo.util.js +301 -0
  96. package/dist/utility/wrun/wrun-builtin-twin-ports.util.d.ts +25 -0
  97. package/dist/utility/wrun/wrun-builtin-twin-ports.util.js +75 -0
  98. package/dist/utility/wrun/wrun-builtin-twin.util.d.ts +9 -0
  99. package/dist/utility/wrun/wrun-builtin-twin.util.js +40 -0
  100. package/dist/utility/wrun/wrun-canvas-cache.util.d.ts +28 -0
  101. package/dist/utility/wrun/wrun-canvas-cache.util.js +56 -0
  102. package/dist/utility/wrun/wrun-canvas-readout.util.d.ts +69 -0
  103. package/dist/utility/wrun/wrun-canvas-readout.util.js +53 -0
  104. package/dist/utility/wrun/wrun-canvases.util.d.ts +295 -0
  105. package/dist/utility/wrun/wrun-canvases.util.js +1432 -0
  106. package/dist/utility/wrun/wrun-cap-notice.util.d.ts +77 -0
  107. package/dist/utility/wrun/wrun-cap-notice.util.js +296 -0
  108. package/dist/utility/wrun/wrun-card-style.util.d.ts +154 -0
  109. package/dist/utility/wrun/wrun-card-style.util.js +539 -0
  110. package/dist/utility/wrun/wrun-chart-context.util.d.ts +89 -0
  111. package/dist/utility/wrun/wrun-chart-context.util.js +213 -0
  112. package/dist/utility/wrun/wrun-chart-names.util.d.ts +23 -0
  113. package/dist/utility/wrun/wrun-chart-names.util.js +33 -0
  114. package/dist/utility/wrun/wrun-chart-time.util.d.ts +12 -0
  115. package/dist/utility/wrun/wrun-chart-time.util.js +23 -0
  116. package/dist/utility/wrun/wrun-child-overlay-id.util.d.ts +13 -0
  117. package/dist/utility/wrun/wrun-child-overlay-id.util.js +44 -0
  118. package/dist/utility/wrun/wrun-color-facts.util.d.ts +40 -0
  119. package/dist/utility/wrun/wrun-color-facts.util.js +88 -0
  120. package/dist/utility/wrun/wrun-color-settings.lazy.d.ts +26 -0
  121. package/dist/utility/wrun/wrun-color-settings.lazy.js +9 -0
  122. package/dist/utility/wrun/wrun-color-settings.util.d.ts +351 -0
  123. package/dist/utility/wrun/wrun-color-settings.util.js +1363 -0
  124. package/dist/utility/wrun/wrun-footprint-modes.util.d.ts +23 -0
  125. package/dist/utility/wrun/wrun-footprint-modes.util.js +24 -0
  126. package/dist/utility/wrun/wrun-frames.d.ts +217 -0
  127. package/dist/utility/wrun/wrun-frames.js +1021 -0
  128. package/dist/utility/wrun/wrun-handles.util.d.ts +792 -0
  129. package/dist/utility/wrun/wrun-handles.util.js +2050 -0
  130. package/dist/utility/wrun/wrun-heatmap-cell-budget.util.d.ts +156 -0
  131. package/dist/utility/wrun/wrun-heatmap-cell-budget.util.js +342 -0
  132. package/dist/utility/wrun/wrun-hosted-wire-caps.d.ts +218 -0
  133. package/dist/utility/wrun/wrun-hosted-wire-caps.js +667 -0
  134. package/dist/utility/wrun/wrun-hosted-wire.util.d.ts +40 -0
  135. package/dist/utility/wrun/wrun-hosted-wire.util.js +27 -0
  136. package/dist/utility/wrun/wrun-hover.util.d.ts +182 -0
  137. package/dist/utility/wrun/wrun-hover.util.js +534 -0
  138. package/dist/utility/wrun/wrun-hud-looks.util.d.ts +246 -0
  139. package/dist/utility/wrun/wrun-hud-looks.util.js +587 -0
  140. package/dist/utility/wrun/wrun-integration-budget.util.d.ts +47 -0
  141. package/dist/utility/wrun/wrun-integration-budget.util.js +122 -0
  142. package/dist/utility/wrun/wrun-latest-snapshot.d.ts +19 -0
  143. package/dist/utility/wrun/wrun-latest-snapshot.js +7 -0
  144. package/dist/utility/wrun/wrun-levels-child.util.d.ts +131 -0
  145. package/dist/utility/wrun/wrun-levels-child.util.js +514 -0
  146. package/dist/utility/wrun/wrun-lifecycle.contract.d.ts +75 -0
  147. package/dist/utility/wrun/wrun-lifecycle.contract.js +9 -0
  148. package/dist/utility/wrun/wrun-market-facts.util.d.ts +116 -0
  149. package/dist/utility/wrun/wrun-market-facts.util.js +238 -0
  150. package/dist/utility/wrun/wrun-output-style.util.d.ts +344 -0
  151. package/dist/utility/wrun/wrun-output-style.util.js +1239 -0
  152. package/dist/utility/wrun/wrun-overlay-identity.util.d.ts +84 -0
  153. package/dist/utility/wrun/wrun-overlay-identity.util.js +142 -0
  154. package/dist/utility/wrun/wrun-overlay-result.util.d.ts +120 -0
  155. package/dist/utility/wrun/wrun-overlay-result.util.js +219 -0
  156. package/dist/utility/wrun/wrun-pack.util.d.ts +70 -0
  157. package/dist/utility/wrun/wrun-pack.util.js +301 -0
  158. package/dist/utility/wrun/wrun-pane-format.util.d.ts +180 -0
  159. package/dist/utility/wrun/wrun-pane-format.util.js +299 -0
  160. package/dist/utility/wrun/wrun-panel-style.lazy.d.ts +25 -0
  161. package/dist/utility/wrun/wrun-panel-style.lazy.js +15 -0
  162. package/dist/utility/wrun/wrun-panel-style.util.d.ts +174 -0
  163. package/dist/utility/wrun/wrun-panel-style.util.js +726 -0
  164. package/dist/utility/wrun/wrun-param-values.util.d.ts +69 -0
  165. package/dist/utility/wrun/wrun-param-values.util.js +230 -0
  166. package/dist/utility/wrun/wrun-refusal.util.d.ts +263 -0
  167. package/dist/utility/wrun/wrun-refusal.util.js +1259 -0
  168. package/dist/utility/wrun/wrun-registry-errors.util.d.ts +199 -0
  169. package/dist/utility/wrun/wrun-registry-errors.util.js +257 -0
  170. package/dist/utility/wrun/wrun-render-select.util.d.ts +336 -0
  171. package/dist/utility/wrun/wrun-render-select.util.js +1157 -0
  172. package/dist/utility/wrun/wrun-script-inputs.util.d.ts +434 -0
  173. package/dist/utility/wrun/wrun-script-inputs.util.js +1971 -0
  174. package/dist/utility/wrun/wrun-setting-words.lazy.d.ts +20 -0
  175. package/dist/utility/wrun/wrun-setting-words.lazy.js +9 -0
  176. package/dist/utility/wrun/wrun-setting-words.util.d.ts +79 -0
  177. package/dist/utility/wrun/wrun-setting-words.util.js +176 -0
  178. package/dist/utility/wrun/wrun-socket-row-store.d.ts +98 -0
  179. package/dist/utility/wrun/wrun-socket-row-store.js +417 -0
  180. package/dist/utility/wrun/wrun-style-flags.util.d.ts +18 -0
  181. package/dist/utility/wrun/wrun-style-flags.util.js +21 -0
  182. package/dist/utility/wrun/wrun-style-words.util.d.ts +148 -0
  183. package/dist/utility/wrun/wrun-style-words.util.js +439 -0
  184. package/dist/utility/wrun/wrun-table-look.util.d.ts +125 -0
  185. package/dist/utility/wrun/wrun-table-look.util.js +225 -0
  186. package/dist/utility/wrun/wrun-text-look.util.d.ts +51 -0
  187. package/dist/utility/wrun/wrun-text-look.util.js +227 -0
  188. package/dist/utility/wrun/wrun-text-params.util.d.ts +106 -0
  189. package/dist/utility/wrun/wrun-text-params.util.js +171 -0
  190. package/dist/utility/wrun/wrun-tpo-rows.util.d.ts +71 -0
  191. package/dist/utility/wrun/wrun-tpo-rows.util.js +438 -0
  192. package/dist/utility/wrun/wrun-twin-compute-inputs.util.d.ts +14 -0
  193. package/dist/utility/wrun/wrun-twin-compute-inputs.util.js +58 -0
  194. package/dist/utility/wrun/wrun-visibility-table.d.ts +437 -0
  195. package/dist/utility/wrun/wrun-visibility-table.js +237 -0
  196. package/dist/utility/wrun/wrun-volume-profile.util.d.ts +37 -0
  197. package/dist/utility/wrun/wrun-volume-profile.util.js +278 -0
  198. package/package.json +38 -0
@@ -0,0 +1,110 @@
1
+ /**
2
+ * The row-height multiplier tables behind every profile canvas (WRUN-STYLE
3
+ * g6 PT-footprint, PT-tpo, DL-time-anchored): the three `INTERVAL_TO_BARS`
4
+ * tables moved verbatim out of the native controls (aggregated volume
5
+ * footprint, TPO, session volume profile), which import them back through
6
+ * their unchanged `getBarsForInterval` exports. A leaf: it imports the
7
+ * interval registry only, so the wrun canvases never load a control module
8
+ * (stores, workers, dialogs) to size a row.
9
+ */
10
+ import { intervalLabelForMs, intervalMs, standardIntervalAtOrBelow, standardIntervalMsAtOrBelow, } from './interval-ladder.util.js';
11
+ /** The native footprint's table (aggregated-volume-footprint/index.ts). */
12
+ const FOOTPRINT_INTERVAL_TO_BARS = {
13
+ '1s': 1,
14
+ '1m': 2,
15
+ '5m': 5,
16
+ '15m': 8,
17
+ '30m': 10,
18
+ '1h': 15,
19
+ '4h': 25,
20
+ '1d': 50,
21
+ '1w': 250,
22
+ };
23
+ /** The native TPO's table (time-price-opportunity/index.ts). */
24
+ const TPO_INTERVAL_TO_BARS = {
25
+ '1s': 1,
26
+ '1m': 5,
27
+ '5m': 10,
28
+ '15m': 15,
29
+ '30m': 20,
30
+ '1h': 25,
31
+ '4h': 30,
32
+ '1d': 50,
33
+ '1w': 100,
34
+ };
35
+ /** The native session profile's table (session-volume-profile/index.ts). */
36
+ const SESSION_INTERVAL_TO_BARS = {
37
+ '1s': 1,
38
+ '1m': 5,
39
+ '5m': 10,
40
+ '15m': 15,
41
+ '30m': 20,
42
+ '1h': 25,
43
+ '4h': 50,
44
+ '1d': 100,
45
+ '1w': 200,
46
+ };
47
+ /** The TPO period's multiplier over its interval base (the native TPO's
48
+ * `SESSION_MULTIPLIERS`, keyed by the engine's session words). */
49
+ const TPO_PERIOD_MULTIPLIERS = {
50
+ Daily: 1,
51
+ Weekly: 1.5,
52
+ Monthly: 2,
53
+ };
54
+ const ROW_TABLES = {
55
+ footprint: FOOTPRINT_INTERVAL_TO_BARS,
56
+ tpo: TPO_INTERVAL_TO_BARS,
57
+ session: SESSION_INTERVAL_TO_BARS,
58
+ };
59
+ /** The tables' labels, ascending by span (the scan keeps the largest match). */
60
+ const TABLE_LABELS = ['1s', '1m', '5m', '15m', '30m', '1h', '4h', '1d', '1w'];
61
+ /** The table label of an interval given in milliseconds: the registry's
62
+ * label when the span is a known interval (a custom one folds to its
63
+ * standard, the tuning rule), else the largest table label no longer than
64
+ * the span. An unknown or non-positive span reads as '' (the tables'
65
+ * fallback of 1). */
66
+ export function profileRowIntervalLabel(interval) {
67
+ if (typeof interval === 'string')
68
+ return standardIntervalAtOrBelow(interval);
69
+ if (!Number.isFinite(interval) || interval <= 0)
70
+ return '';
71
+ const known = intervalLabelForMs(standardIntervalMsAtOrBelow(interval));
72
+ if (known !== undefined)
73
+ return standardIntervalAtOrBelow(known);
74
+ let label = '';
75
+ for (const candidate of TABLE_LABELS) {
76
+ const candidateMs = intervalMs(candidate);
77
+ if (candidateMs !== undefined && candidateMs <= interval)
78
+ label = candidate;
79
+ }
80
+ return label;
81
+ }
82
+ /**
83
+ * The row multiplier behind a profile canvas's `row_height: "auto"` (the
84
+ * native controls' `getBarsForInterval`): the kind's table at the chart
85
+ * interval (a label, or a span in milliseconds), 1 for an interval outside
86
+ * the table. A TPO period word (the engine's 'Daily' | 'Weekly' | 'Monthly',
87
+ * or the sheet's 'day' | 'week' | 'month') scales the TPO base by the native
88
+ * session multiplier, floored, exactly like the control.
89
+ */
90
+ export function profileRowMultiplier(kind, interval, period) {
91
+ const base = ROW_TABLES[kind][profileRowIntervalLabel(interval)] || 1;
92
+ if (kind !== 'tpo' || !period)
93
+ return base;
94
+ const multiplier = TPO_PERIOD_MULTIPLIERS[tpoPeriodWord(period)] || 1;
95
+ return Math.floor(base * multiplier);
96
+ }
97
+ /** The engine's TPO session word for a sheet period (`day` -> 'Daily'); an
98
+ * engine word passes through unchanged. */
99
+ export function tpoPeriodWord(period) {
100
+ switch (period) {
101
+ case 'day':
102
+ return 'Daily';
103
+ case 'week':
104
+ return 'Weekly';
105
+ case 'month':
106
+ return 'Monthly';
107
+ default:
108
+ return period;
109
+ }
110
+ }
@@ -0,0 +1 @@
1
+ export declare function getSessionInterval(sessionType: string, chartInterval: string): number | string;
@@ -0,0 +1,35 @@
1
+ import { Intervals } from '../../constants/interval.constants.js';
2
+ import { intervalMs, standardIntervalAtOrBelow } from './interval-ladder.util.js';
3
+ const SESSION_INTERVALS = {
4
+ '1s': { Footprint: Intervals.SECOND, Targeted: Intervals.SECOND5, Wide: Intervals.SECOND15 },
5
+ '1m': { Footprint: Intervals.MINUTE, Targeted: Intervals.MINUTE5, Wide: Intervals.MINUTE15 },
6
+ '5m': { Footprint: Intervals.MINUTE5, Targeted: Intervals.HOUR, Wide: Intervals.HOUR4 },
7
+ '15m': { Footprint: Intervals.MINUTE15, Targeted: Intervals.HOUR, Wide: Intervals.HOUR4 },
8
+ '30m': { Footprint: Intervals.MINUTE30, Targeted: Intervals.HOUR, Wide: Intervals.HOUR4 },
9
+ '1h': { Footprint: Intervals.HOUR, Targeted: Intervals.HOUR12, Wide: Intervals.DAY3 },
10
+ '4h': { Footprint: Intervals.HOUR4, Targeted: Intervals.DAY3, Wide: Intervals.WEEK },
11
+ '1d': { Footprint: Intervals.DAY, Targeted: Intervals.WEEK, Wide: Intervals.DAY30 },
12
+ '1w': { Footprint: Intervals.WEEK, Targeted: Intervals.WEEK4, Wide: Intervals.WEEK12 },
13
+ // Calendar bars: every session is the bar itself (one profile per month,
14
+ // quarter or year), never the DAY fallback.
15
+ '1M': { Footprint: Intervals.MONTH, Targeted: Intervals.MONTH, Wide: Intervals.MONTH },
16
+ '3M': { Footprint: Intervals.MONTH3, Targeted: Intervals.MONTH3, Wide: Intervals.MONTH3 },
17
+ '1Y': { Footprint: Intervals.YEAR, Targeted: Intervals.YEAR, Wide: Intervals.YEAR },
18
+ };
19
+ export function getSessionInterval(sessionType, chartInterval) {
20
+ if (['US', 'EU', 'Asia'].includes(sessionType)) {
21
+ return sessionType;
22
+ }
23
+ // A preset or an extended rung reads the row of its standard at or below
24
+ // (10m -> 5m, 30s -> 1s, 6M -> 3M), floored at its own bar: a session never
25
+ // splits a bar, so Footprint (one profile per chart bar) keeps the chart's
26
+ // length and a 30s chart never draws the 1s row's 5s sessions.
27
+ const intervalMapping = SESSION_INTERVALS[standardIntervalAtOrBelow(chartInterval)];
28
+ if (intervalMapping && intervalMapping[sessionType]) {
29
+ return Math.max(intervalMapping[sessionType], intervalMs(chartInterval) ?? 0);
30
+ }
31
+ if (Intervals.INTERVAL_ORDER.includes(sessionType)) {
32
+ return Intervals.map_unit[sessionType];
33
+ }
34
+ return Intervals.DAY;
35
+ }
@@ -0,0 +1,18 @@
1
+ /** The legacy fixed decimals every built-in legend printed (OverlayNumericPrecision.TechnicalScript). */
2
+ export declare const TECHNICAL_SCRIPT_LEGEND_MIN_DECIMALS = 2;
3
+ /**
4
+ * `value` on the instrument's tick lattice: the nearest tick, dust-free at the tick's decimals
5
+ * (7784.38 on 0.25 -> 7784.5, never 7784.500000000001). Unchanged without a usable tick (null,
6
+ * absent, zero, negative, non-finite), so a pane without a tick prints exactly as before. The
7
+ * same rounding the engine applies to the axis pills and the crosshair (titan `roundToTick`), so
8
+ * a price-pane legend value and the pill beside it read one number.
9
+ */
10
+ export declare function roundLegendValueToTick(value: number, tick: number | null | undefined): number;
11
+ /** Decimals for one legend value: at least 2, the chart's price digits for a price-pane line, and
12
+ * enough below 1 for two significant digits. */
13
+ export declare function technicalScriptLegendDecimals(value: number, priceDigits?: number): number;
14
+ /** The legend text of one built-in value. `priceDigits` is the chart's price precision for a line
15
+ * on the price pane (omit it for lower panes and volume-scaled lines); `priceTick` is the
16
+ * instrument tick that line's value rounds to first (the engine's tick on the main price scale,
17
+ * CME today), so an EMA on NQ reads 31134.25 like its axis pill, never 31134.13 beside it. */
18
+ export declare function formatTechnicalScriptLegendValue(value: number, priceDigits?: number, priceTick?: number | null): string;
@@ -0,0 +1,53 @@
1
+ /**
2
+ * A built-in (kScript) indicator's legend value, formatted the way TradingView inherits the
3
+ * symbol's price format: a line on the price pane prints at the chart's price precision (the
4
+ * symbol's tick), so a 0.0058 Tenkan on a sub-cent coin reads 0.005792, not "0.01". Every line
5
+ * keeps at least 2 decimals (the legacy TechnicalScript rule, K/M/B from 1M), and a value below 1
6
+ * gains decimals until two significant digits show, so a lower-pane 0.000012 never collapses to
7
+ * "0.00". Oscillators (RSI, Stochastic, ADX: values from 1 up, own axis) read exactly as before.
8
+ */
9
+ import { partiallyFormatNumbers } from '../number-format.util.js';
10
+ /** The legacy fixed decimals every built-in legend printed (OverlayNumericPrecision.TechnicalScript). */
11
+ export const TECHNICAL_SCRIPT_LEGEND_MIN_DECIMALS = 2;
12
+ const TECHNICAL_SCRIPT_LEGEND_MAX_DECIMALS = 10;
13
+ /** Decimals the tick is written with (0.25 -> 2, 1 -> 0, 0.000001 -> 6), tolerant of float dust. */
14
+ function priceTickDecimals(tick) {
15
+ for (let d = 0; d <= TECHNICAL_SCRIPT_LEGEND_MAX_DECIMALS; d++) {
16
+ if (Math.abs(tick - Number(tick.toFixed(d))) <= tick * 1e-9)
17
+ return d;
18
+ }
19
+ return TECHNICAL_SCRIPT_LEGEND_MAX_DECIMALS;
20
+ }
21
+ /**
22
+ * `value` on the instrument's tick lattice: the nearest tick, dust-free at the tick's decimals
23
+ * (7784.38 on 0.25 -> 7784.5, never 7784.500000000001). Unchanged without a usable tick (null,
24
+ * absent, zero, negative, non-finite), so a pane without a tick prints exactly as before. The
25
+ * same rounding the engine applies to the axis pills and the crosshair (titan `roundToTick`), so
26
+ * a price-pane legend value and the pill beside it read one number.
27
+ */
28
+ export function roundLegendValueToTick(value, tick) {
29
+ if (typeof tick !== 'number' || !Number.isFinite(tick) || tick <= 0 || !Number.isFinite(value))
30
+ return value;
31
+ return Number((Math.round(value / tick) * tick).toFixed(priceTickDecimals(tick)));
32
+ }
33
+ /** Decimals for one legend value: at least 2, the chart's price digits for a price-pane line, and
34
+ * enough below 1 for two significant digits. */
35
+ export function technicalScriptLegendDecimals(value, priceDigits) {
36
+ const abs = Math.abs(value);
37
+ const significant = abs > 0 && abs < 1 ? Math.min(TECHNICAL_SCRIPT_LEGEND_MAX_DECIMALS, -Math.floor(Math.log10(abs)) + 1) : 0;
38
+ const price = priceDigits !== undefined && Number.isFinite(priceDigits)
39
+ ? Math.min(TECHNICAL_SCRIPT_LEGEND_MAX_DECIMALS, Math.max(0, Math.round(priceDigits)))
40
+ : 0;
41
+ return Math.max(TECHNICAL_SCRIPT_LEGEND_MIN_DECIMALS, significant, price);
42
+ }
43
+ /** The legend text of one built-in value. `priceDigits` is the chart's price precision for a line
44
+ * on the price pane (omit it for lower panes and volume-scaled lines); `priceTick` is the
45
+ * instrument tick that line's value rounds to first (the engine's tick on the main price scale,
46
+ * CME today), so an EMA on NQ reads 31134.25 like its axis pill, never 31134.13 beside it. */
47
+ export function formatTechnicalScriptLegendValue(value, priceDigits, priceTick) {
48
+ const shown = roundLegendValueToTick(value, priceTick);
49
+ if (!Number.isFinite(shown) || shown === 0) {
50
+ return String(partiallyFormatNumbers(shown, TECHNICAL_SCRIPT_LEGEND_MIN_DECIMALS));
51
+ }
52
+ return String(partiallyFormatNumbers(shown, technicalScriptLegendDecimals(shown, priceDigits)));
53
+ }
@@ -0,0 +1,70 @@
1
+ /**
2
+ * A venue's trading-day anchor: an IANA time zone and the wall-clock minute of the day's open in it. Structurally
3
+ * the engine's `TradingDayAnchor` (titan's settings.tradingDayAnchor), declared here so this module imports no
4
+ * engine type; src/utility/wrun/wrun-chart-host-type-pins.ts pins the two equal.
5
+ */
6
+ export interface TradingDayAnchor {
7
+ /** IANA time zone name, e.g. 'America/Chicago'. */
8
+ timeZone: string;
9
+ /** Trading-day open as minutes past local midnight in `timeZone` (0..1439). */
10
+ openMinutes: number;
11
+ }
12
+ /** Structural shape of a TPO custom time range (tpo-session.util's TpoTimeRange). */
13
+ export interface TradingDayTpoTimeRange {
14
+ start_time: string;
15
+ end_time: string;
16
+ timezone: string;
17
+ }
18
+ /** CME Globex: trading day opens 17:00 exchange-local in Chicago. */
19
+ export declare const CME_TRADING_DAY_ANCHOR: Readonly<TradingDayAnchor>;
20
+ /**
21
+ * TPO wire projection of the CME anchor. The tsdb-gateway custom-time-range
22
+ * SQL path supports only the UTC and America/New_York ('ET') zones
23
+ * (sessionCustomTimeRange in tsdb-gateway pkg/tsdb/selects/tpo_agg.go
24
+ * degrades every other zone to plain UTC truncation), so the Chicago open is
25
+ * expressed in New York wall time: 17:00 America/Chicago is 18:00
26
+ * America/New_York at every session boundary, because both zones follow the
27
+ * same US DST schedule and their brief transition-window divergence sits in
28
+ * the 01:00-03:00 ET band, never at 18:00. The 18:00 -> 17:00 ET window is
29
+ * the full trading day; the excluded 17:00-18:00 ET hour is the CME
30
+ * maintenance halt, which carries no bars.
31
+ */
32
+ export declare const CME_TRADING_DAY_TPO_TIME_RANGE: Readonly<TradingDayTpoTimeRange>;
33
+ /** US equity and index options (OPRA): the trading day opens at the 09:30 New York open. */
34
+ export declare const US_OPTIONS_TRADING_DAY_ANCHOR: Readonly<TradingDayAnchor>;
35
+ /**
36
+ * TPO wire projection of the options anchor: the whole-day session window
37
+ * (us-options-session.util), expressed natively in America/New_York, one of
38
+ * the two zones the gateway's custom-time-range path supports. The window
39
+ * ends at the 16:15 late close; ordinary equity options stop printing at
40
+ * 16:00, so their last quarter hour carries no rows.
41
+ */
42
+ export declare const US_OPTIONS_TRADING_DAY_TPO_TIME_RANGE: Readonly<TradingDayTpoTimeRange>;
43
+ export declare function isTradingDayAnchor(value: unknown): value is TradingDayAnchor;
44
+ /**
45
+ * The trading-day anchor for a symbol's exchange, or undefined for venues
46
+ * that keep the legacy UTC-midnight day (all of crypto). This is the single
47
+ * venue gate both TPO and the session volume profile consume.
48
+ */
49
+ export declare function getTradingDayAnchor(exchange: string | undefined | null): TradingDayAnchor | undefined;
50
+ export declare function tradingDayStartMs(tsMs: number, anchor: TradingDayAnchor): number;
51
+ export type TradingDayPeriod = 'Session' | 'Week' | 'Month' | 'Year';
52
+ /**
53
+ * Anchored period start (in SECONDS, the indicator wire unit) for the period
54
+ * containing `timestampSec`. 'Session' is the trading-day open itself;
55
+ * 'Week' / 'Month' / 'Year' resolve the TRADING date the timestamp belongs
56
+ * to, floor it onto the ISO-Monday / first-of-month / first-of-year calendar
57
+ * date, and return the open instant that begins that trading date (Sunday
58
+ * 17:00 America/Chicago for a CME Monday). The value is a period identifier
59
+ * as much as a fetch edge: weekend calendar dates never label a bar, so all
60
+ * real sessions of one period share one start and the period flips exactly
61
+ * at the reopen print, with no venue holiday knowledge needed.
62
+ */
63
+ export declare function getTradingDayPeriodStartSec(timestampSec: number, period: TradingDayPeriod, anchor: TradingDayAnchor): number;
64
+ /**
65
+ * The TPO custom-time-range projection of an anchor, or undefined when the
66
+ * anchor is absent, invalid, or has no wire-expressible projection. The CME
67
+ * and the options anchors have one; a new session venue needs its own entry
68
+ * here (and a gateway-supported zone to express it in).
69
+ */
70
+ export declare function getTradingDayTpoTimeRange(anchor: unknown): TradingDayTpoTimeRange | undefined;
@@ -0,0 +1,238 @@
1
+ /**
2
+ * Trading-day anchoring for session venues (the CME family and the OPRA
3
+ * options plane).
4
+ *
5
+ * The FE owns all venue knowledge: titan-charts stays venue-agnostic and only
6
+ * consumes the generic `tradingDayAnchor` descriptor this module produces
7
+ * (the type is declared here, structurally titan's `TradingDayAnchor`, so
8
+ * worker-safe consumers keep one import site). CME Globex trading day: opens
9
+ * 17:00 America/Chicago
10
+ * the prior evening, halts 16:00-17:00, so the "day" of Monday runs Sunday
11
+ * 17:00 CT through Monday 16:00 CT; DST moves the UTC edge (22:00 UTC in
12
+ * summer, 23:00 UTC in winter) and Sunday evening belongs to Monday. US
13
+ * equity and index options (OPRA) trade one session a day that opens 09:30
14
+ * America/New_York (us-options-session.util), so their day is labeled by its
15
+ * own calendar date.
16
+ *
17
+ * Consumers of the SAME anchor:
18
+ * - Session volume profile passes it straight to titan, whose daily session
19
+ * grid floors onto the exchange-local open (titan src/utils/tradingDay.ts).
20
+ * - TPO projects it onto the tsdb-gateway custom-time-range wire vocabulary
21
+ * (getTradingDayTpoTimeRange below) for backend period bucketing and the
22
+ * FE live-merge window math.
23
+ * - Native VWAP floors its Session/Week/Month/Year periods with
24
+ * getTradingDayPeriodStartSec (via vwap-period-start.util, shared by the
25
+ * control and the worker twin).
26
+ * - The DOM session volume-at-price window (session-window.util) and the
27
+ * session-break / prev-close bucket walk (session-bucket.util) floor with
28
+ * tradingDayStartMs.
29
+ *
30
+ * Deliberately Vue/store/i18n free so worker code can import it.
31
+ */
32
+ import dayjs from 'dayjs';
33
+ import timezone from 'dayjs/plugin/timezone.js';
34
+ import utc from 'dayjs/plugin/utc.js';
35
+ import { isCmeGoverned } from './cme-realtime.util.js';
36
+ import { isOpraGoverned } from '../v2/opra-governed.util.js';
37
+ dayjs.extend(utc);
38
+ dayjs.extend(timezone);
39
+ /** CME Globex: trading day opens 17:00 exchange-local in Chicago. */
40
+ export const CME_TRADING_DAY_ANCHOR = Object.freeze({
41
+ timeZone: 'America/Chicago',
42
+ openMinutes: 17 * 60,
43
+ });
44
+ /**
45
+ * TPO wire projection of the CME anchor. The tsdb-gateway custom-time-range
46
+ * SQL path supports only the UTC and America/New_York ('ET') zones
47
+ * (sessionCustomTimeRange in tsdb-gateway pkg/tsdb/selects/tpo_agg.go
48
+ * degrades every other zone to plain UTC truncation), so the Chicago open is
49
+ * expressed in New York wall time: 17:00 America/Chicago is 18:00
50
+ * America/New_York at every session boundary, because both zones follow the
51
+ * same US DST schedule and their brief transition-window divergence sits in
52
+ * the 01:00-03:00 ET band, never at 18:00. The 18:00 -> 17:00 ET window is
53
+ * the full trading day; the excluded 17:00-18:00 ET hour is the CME
54
+ * maintenance halt, which carries no bars.
55
+ */
56
+ export const CME_TRADING_DAY_TPO_TIME_RANGE = Object.freeze({
57
+ start_time: '18:00',
58
+ end_time: '17:00',
59
+ timezone: 'America/New_York',
60
+ });
61
+ /** US equity and index options (OPRA): the trading day opens at the 09:30 New York open. */
62
+ export const US_OPTIONS_TRADING_DAY_ANCHOR = Object.freeze({
63
+ timeZone: 'America/New_York',
64
+ openMinutes: 9 * 60 + 30,
65
+ });
66
+ /**
67
+ * TPO wire projection of the options anchor: the whole-day session window
68
+ * (us-options-session.util), expressed natively in America/New_York, one of
69
+ * the two zones the gateway's custom-time-range path supports. The window
70
+ * ends at the 16:15 late close; ordinary equity options stop printing at
71
+ * 16:00, so their last quarter hour carries no rows.
72
+ */
73
+ export const US_OPTIONS_TRADING_DAY_TPO_TIME_RANGE = Object.freeze({
74
+ start_time: '09:30',
75
+ end_time: '16:15',
76
+ timezone: 'America/New_York',
77
+ });
78
+ export function isTradingDayAnchor(value) {
79
+ if (!value || typeof value !== 'object')
80
+ return false;
81
+ const { timeZone, openMinutes } = value;
82
+ return (typeof timeZone === 'string' &&
83
+ timeZone.length > 0 &&
84
+ typeof openMinutes === 'number' &&
85
+ Number.isInteger(openMinutes) &&
86
+ openMinutes >= 0 &&
87
+ openMinutes < 1440);
88
+ }
89
+ /**
90
+ * The trading-day anchor for a symbol's exchange, or undefined for venues
91
+ * that keep the legacy UTC-midnight day (all of crypto). This is the single
92
+ * venue gate both TPO and the session volume profile consume.
93
+ */
94
+ export function getTradingDayAnchor(exchange) {
95
+ if (isCmeGoverned(exchange))
96
+ return CME_TRADING_DAY_ANCHOR;
97
+ if (isOpraGoverned(exchange))
98
+ return US_OPTIONS_TRADING_DAY_ANCHOR;
99
+ return undefined;
100
+ }
101
+ // ── Anchored session / period floors ────────────────────────────────────────
102
+ const pad2 = (n) => String(n).padStart(2, '0');
103
+ /**
104
+ * The instant whose wall clock in `timeZone` reads `minutes` past midnight on
105
+ * the y-m-d calendar date. Parsing the wall string with dayjs.tz is DST-exact
106
+ * (mirrors rth-session.util's wallTimeOnDay): counting real minutes from
107
+ * midnight drifts by the offset delta on 23h/25h transition days. Memoized
108
+ * because period-floor consumers walk thousands of bar timestamps while the
109
+ * instant only changes once per calendar date; bounded, cleared wholesale on
110
+ * overflow (recomputation is cheap).
111
+ */
112
+ const wallInstantCache = new Map();
113
+ const WALL_INSTANT_CACHE_MAX = 2048;
114
+ function wallInstantMs(timeZone, date, minutes) {
115
+ const key = `${timeZone}|${minutes}|${date.y}-${date.m}-${date.d}`;
116
+ let ms = wallInstantCache.get(key);
117
+ if (ms === undefined) {
118
+ const wall = `${date.y}-${pad2(date.m)}-${pad2(date.d)} ${pad2(Math.floor(minutes / 60))}:${pad2(minutes % 60)}`;
119
+ try {
120
+ ms = dayjs.tz(wall, timeZone).valueOf();
121
+ }
122
+ catch {
123
+ ms = dayjs.utc(wall).valueOf();
124
+ }
125
+ if (wallInstantCache.size >= WALL_INSTANT_CACHE_MAX)
126
+ wallInstantCache.clear();
127
+ wallInstantCache.set(key, ms);
128
+ }
129
+ return ms;
130
+ }
131
+ /**
132
+ * The venue-local calendar date containing the instant. Memoized on the exact
133
+ * (zone, instant) key: with the trading-day window cache below, the raw
134
+ * per-bar stream never reaches here, so the entries that do land are the
135
+ * highly repeated ones (session open instants resolved by tradingDateOf once
136
+ * per bar). Bounded like wallInstantCache; recomputation is cheap.
137
+ */
138
+ const venueDateCache = new Map();
139
+ function venueDateOf(tsMs, timeZone) {
140
+ const key = `${timeZone}|${tsMs}`;
141
+ let date = venueDateCache.get(key);
142
+ if (date === undefined) {
143
+ let zoned;
144
+ try {
145
+ zoned = dayjs(tsMs).tz(timeZone);
146
+ }
147
+ catch {
148
+ zoned = dayjs.utc(tsMs);
149
+ }
150
+ date = { y: zoned.year(), m: zoned.month() + 1, d: zoned.date() };
151
+ if (venueDateCache.size >= WALL_INSTANT_CACHE_MAX)
152
+ venueDateCache.clear();
153
+ venueDateCache.set(key, date);
154
+ }
155
+ return date;
156
+ }
157
+ /** Pure calendar-date shift; Date.UTC normalizes day/month overflow. */
158
+ function shiftCalendarDate(date, days) {
159
+ const shifted = new Date(Date.UTC(date.y, date.m - 1, date.d + days));
160
+ return { y: shifted.getUTCFullYear(), m: shifted.getUTCMonth() + 1, d: shifted.getUTCDate() };
161
+ }
162
+ const tradingDayWindowByAnchor = new Map();
163
+ export function tradingDayStartMs(tsMs, anchor) {
164
+ const anchorKey = `${anchor.timeZone}|${anchor.openMinutes}`;
165
+ const cached = tradingDayWindowByAnchor.get(anchorKey);
166
+ if (cached && tsMs >= cached.openMs && tsMs < cached.nextOpenMs)
167
+ return cached.openMs;
168
+ const date = venueDateOf(tsMs, anchor.timeZone);
169
+ const todayOpen = wallInstantMs(anchor.timeZone, date, anchor.openMinutes);
170
+ const openDate = tsMs >= todayOpen ? date : shiftCalendarDate(date, -1);
171
+ const openMs = tsMs >= todayOpen ? todayOpen : wallInstantMs(anchor.timeZone, openDate, anchor.openMinutes);
172
+ // Opens are strictly increasing, exactly one per calendar date (the CME
173
+ // 17:00 wall time never sits inside the DST transition band), so the span
174
+ // [openMs, nextOpenMs) maps every contained instant to openMs.
175
+ const nextOpenMs = wallInstantMs(anchor.timeZone, shiftCalendarDate(openDate, 1), anchor.openMinutes);
176
+ tradingDayWindowByAnchor.set(anchorKey, { openMs, nextOpenMs });
177
+ return openMs;
178
+ }
179
+ /**
180
+ * The venue-local calendar date labeling `tsMs`'s trading day. Evening opens
181
+ * (openMinutes >= 720, e.g. CME's 17:00) label the session with the NEXT
182
+ * calendar date: the session opening Sunday 17:00 America/Chicago IS Monday's
183
+ * trading day, so Sunday-evening bars belong to Monday (and therefore to
184
+ * Monday's week, month, and year).
185
+ */
186
+ function tradingDateOf(tsMs, anchor) {
187
+ const openDate = venueDateOf(tradingDayStartMs(tsMs, anchor), anchor.timeZone);
188
+ return anchor.openMinutes >= 720 ? shiftCalendarDate(openDate, 1) : openDate;
189
+ }
190
+ /**
191
+ * Anchored period start (in SECONDS, the indicator wire unit) for the period
192
+ * containing `timestampSec`. 'Session' is the trading-day open itself;
193
+ * 'Week' / 'Month' / 'Year' resolve the TRADING date the timestamp belongs
194
+ * to, floor it onto the ISO-Monday / first-of-month / first-of-year calendar
195
+ * date, and return the open instant that begins that trading date (Sunday
196
+ * 17:00 America/Chicago for a CME Monday). The value is a period identifier
197
+ * as much as a fetch edge: weekend calendar dates never label a bar, so all
198
+ * real sessions of one period share one start and the period flips exactly
199
+ * at the reopen print, with no venue holiday knowledge needed.
200
+ */
201
+ export function getTradingDayPeriodStartSec(timestampSec, period, anchor) {
202
+ const tsMs = timestampSec * 1000;
203
+ if (period === 'Session')
204
+ return tradingDayStartMs(tsMs, anchor) / 1000;
205
+ const tradeDate = tradingDateOf(tsMs, anchor);
206
+ let firstTradeDate;
207
+ if (period === 'Week') {
208
+ const dow = new Date(Date.UTC(tradeDate.y, tradeDate.m - 1, tradeDate.d)).getUTCDay();
209
+ firstTradeDate = shiftCalendarDate(tradeDate, -((dow + 6) % 7));
210
+ }
211
+ else if (period === 'Month') {
212
+ firstTradeDate = { y: tradeDate.y, m: tradeDate.m, d: 1 };
213
+ }
214
+ else {
215
+ firstTradeDate = { y: tradeDate.y, m: 1, d: 1 };
216
+ }
217
+ const openDate = anchor.openMinutes >= 720 ? shiftCalendarDate(firstTradeDate, -1) : firstTradeDate;
218
+ return wallInstantMs(anchor.timeZone, openDate, anchor.openMinutes) / 1000;
219
+ }
220
+ /**
221
+ * The TPO custom-time-range projection of an anchor, or undefined when the
222
+ * anchor is absent, invalid, or has no wire-expressible projection. The CME
223
+ * and the options anchors have one; a new session venue needs its own entry
224
+ * here (and a gateway-supported zone to express it in).
225
+ */
226
+ export function getTradingDayTpoTimeRange(anchor) {
227
+ if (!isTradingDayAnchor(anchor))
228
+ return undefined;
229
+ if (anchor.timeZone === CME_TRADING_DAY_ANCHOR.timeZone &&
230
+ anchor.openMinutes === CME_TRADING_DAY_ANCHOR.openMinutes) {
231
+ return CME_TRADING_DAY_TPO_TIME_RANGE;
232
+ }
233
+ if (anchor.timeZone === US_OPTIONS_TRADING_DAY_ANCHOR.timeZone &&
234
+ anchor.openMinutes === US_OPTIONS_TRADING_DAY_ANCHOR.openMinutes) {
235
+ return US_OPTIONS_TRADING_DAY_TPO_TIME_RANGE;
236
+ }
237
+ return undefined;
238
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * The words a wrun legend prints for a sheet name. Sheet names are ids
3
+ * (`[a-z0-9][a-z0-9._-]*`: `odds_by_price`, `gex_by_strike`), so every place
4
+ * the chart turns a wrun output, level, pane, canvas or child name into a
5
+ * legend row, a pane title or a hover card's row name reads it through
6
+ * `wrunLegendName`, and a legend never prints a raw id:
7
+ *
8
+ * - a declared `label` wins, trimmed;
9
+ * - a name that is already words (it holds a space) prints as written;
10
+ * - else the name splits on `_` and `-` (and a lowercase camel hump) into
11
+ * words: the first letter is capitalized, every other word stays lower
12
+ * case, a word written with capitals keeps them, and the known market
13
+ * tokens keep their own spelling, a plural or a trailing length included
14
+ * (`etfs` -> "ETFs", `ema20` -> "EMA20");
15
+ * - a name with no word in it (empty, separators only) prints as written.
16
+ *
17
+ * `odds_by_price` -> "Odds by price", `gex_curve` -> "GEX curve",
18
+ * `iv_surface` -> "IV surface", `bid_line_1` -> "Bid line 1".
19
+ */
20
+ /** The tokens a legend name keeps in their own spelling, matched whole-word
21
+ * and case-blind. */
22
+ export declare const WRUN_LEGEND_NAME_TOKENS: ReadonlyArray<string>;
23
+ /** The legend text of a wrun name: the declared `label` when it has one,
24
+ * else the name read as words (see the file note). */
25
+ export declare function wrunLegendName(name: string, label?: string | null): string;
@@ -0,0 +1,87 @@
1
+ /**
2
+ * The words a wrun legend prints for a sheet name. Sheet names are ids
3
+ * (`[a-z0-9][a-z0-9._-]*`: `odds_by_price`, `gex_by_strike`), so every place
4
+ * the chart turns a wrun output, level, pane, canvas or child name into a
5
+ * legend row, a pane title or a hover card's row name reads it through
6
+ * `wrunLegendName`, and a legend never prints a raw id:
7
+ *
8
+ * - a declared `label` wins, trimmed;
9
+ * - a name that is already words (it holds a space) prints as written;
10
+ * - else the name splits on `_` and `-` (and a lowercase camel hump) into
11
+ * words: the first letter is capitalized, every other word stays lower
12
+ * case, a word written with capitals keeps them, and the known market
13
+ * tokens keep their own spelling, a plural or a trailing length included
14
+ * (`etfs` -> "ETFs", `ema20` -> "EMA20");
15
+ * - a name with no word in it (empty, separators only) prints as written.
16
+ *
17
+ * `odds_by_price` -> "Odds by price", `gex_curve` -> "GEX curve",
18
+ * `iv_surface` -> "IV surface", `bid_line_1` -> "Bid line 1".
19
+ */
20
+ /** The tokens a legend name keeps in their own spelling, matched whole-word
21
+ * and case-blind. */
22
+ export const WRUN_LEGEND_NAME_TOKENS = [
23
+ 'IV',
24
+ 'ATM',
25
+ 'GEX',
26
+ 'OI',
27
+ 'VWAP',
28
+ 'CVD',
29
+ 'USD',
30
+ 'BTC',
31
+ 'ETH',
32
+ 'RSI',
33
+ 'EMA',
34
+ 'SMA',
35
+ 'ATR',
36
+ 'POC',
37
+ 'VAH',
38
+ 'VAL',
39
+ 'TPO',
40
+ 'ETF',
41
+ '2s10s',
42
+ ];
43
+ const TOKEN_BY_LOWER = new Map(WRUN_LEGEND_NAME_TOKENS.map((token) => [token.toLowerCase(), token]));
44
+ /** A word's token spelling: the token itself, its plural (`etfs` -> "ETFs")
45
+ * or the token with a trailing length (`ema20` -> "EMA20"); undefined for
46
+ * every other word. */
47
+ function tokenSpelling(word) {
48
+ const lower = word.toLowerCase();
49
+ const exact = TOKEN_BY_LOWER.get(lower);
50
+ if (exact !== undefined)
51
+ return exact;
52
+ const plural = lower.endsWith('s') ? TOKEN_BY_LOWER.get(lower.slice(0, -1)) : undefined;
53
+ if (plural !== undefined)
54
+ return `${plural}s`;
55
+ const [, stem, length] = /^([a-z]+)(\d+)$/.exec(lower) ?? [];
56
+ const token = stem === undefined ? undefined : TOKEN_BY_LOWER.get(stem);
57
+ return token === undefined ? undefined : `${token}${length}`;
58
+ }
59
+ /** The words of a name: `_` / `-` pieces; a piece that opens lower case (an
60
+ * id piece) splits at a camel hump and reads lower case, a piece written
61
+ * with a capital first keeps its spelling. */
62
+ function nameWords(name) {
63
+ return name
64
+ .split(/[_-]+/)
65
+ .flatMap((piece) => /^[a-z0-9]/.test(piece)
66
+ ? piece
67
+ .replace(/([a-z0-9])([A-Z])/g, '$1 $2')
68
+ .toLowerCase()
69
+ .split(' ')
70
+ : [piece])
71
+ .filter((word) => word.length > 0);
72
+ }
73
+ /** The legend text of a wrun name: the declared `label` when it has one,
74
+ * else the name read as words (see the file note). */
75
+ export function wrunLegendName(name, label) {
76
+ const declared = typeof label === 'string' ? label.trim() : '';
77
+ if (declared !== '')
78
+ return declared;
79
+ const trimmed = name.trim();
80
+ if (/\s/.test(trimmed))
81
+ return trimmed;
82
+ const words = nameWords(trimmed).map((word) => tokenSpelling(word) ?? word);
83
+ if (words.length === 0)
84
+ return name;
85
+ const text = words.join(' ');
86
+ return text.charAt(0).toUpperCase() + text.slice(1);
87
+ }