gloomberb 0.20.7 → 0.20.9

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 (632) hide show
  1. package/README.ja.md +74 -0
  2. package/README.md +2 -0
  3. package/README.zh-CN.md +2 -0
  4. package/package.json +6 -1
  5. package/src/account/auth-model.ts +22 -0
  6. package/src/api-client/auth.ts +7 -2
  7. package/src/api-client/awards.ts +5 -0
  8. package/src/api-client/bond-trades.ts +22 -0
  9. package/src/api-client/catalysts.ts +11 -1
  10. package/src/api-client/data.ts +30 -6
  11. package/src/api-client/debt-maturities.ts +7 -0
  12. package/src/api-client/equity-screener.ts +17 -0
  13. package/src/api-client/errors.ts +2 -0
  14. package/src/api-client/exchange-announcements.ts +14 -7
  15. package/src/api-client/fund-facts.ts +21 -3
  16. package/src/api-client/futures-curve.ts +19 -2
  17. package/src/api-client/geo.ts +10 -0
  18. package/src/api-client/hiring.ts +2 -0
  19. package/src/api-client/index.ts +3 -0
  20. package/src/api-client/insider-signals.ts +14 -0
  21. package/src/api-client/members.ts +30 -2
  22. package/src/api-client/money-markets.ts +11 -1
  23. package/src/api-client/paths.ts +6 -1
  24. package/src/api-client/perps.ts +2 -0
  25. package/src/api-client/request.ts +2 -1
  26. package/src/api-client/socket.ts +7 -0
  27. package/src/api-client/types/econ.ts +2 -1
  28. package/src/api-client/types/filings-and-calls.ts +6 -0
  29. package/src/api-client/types/market.ts +4 -0
  30. package/src/api-client/web-experiments.ts +5 -6
  31. package/src/app/runtime/update.ts +2 -1
  32. package/src/architecture/floating-promise-allowlist.json +33 -106
  33. package/src/capabilities/asset-data-inputs.ts +183 -0
  34. package/src/capabilities/factories.ts +8 -2
  35. package/src/cli/base-converter.ts +36 -2
  36. package/src/cli/commands/api.ts +2 -2
  37. package/src/cli/commands/command-utils.ts +18 -0
  38. package/src/cli/commands/hong-kong-movers.ts +50 -0
  39. package/src/cli/commands/market.ts +539 -130
  40. package/src/cli/commands/options-chain.ts +7 -1
  41. package/src/cli/commands/overview.ts +76 -14
  42. package/src/cli/commands/plugins.ts +7 -6
  43. package/src/cli/commands/search.ts +52 -9
  44. package/src/cli/commands/system.ts +15 -10
  45. package/src/cli/commands/ticker.ts +97 -44
  46. package/src/cli/content-figures.ts +45 -0
  47. package/src/cli/context.ts +5 -0
  48. package/src/cli/desktop-pane-shot-routes.ts +13 -4
  49. package/src/cli/desktop-pane-shot.ts +86 -12
  50. package/src/cli/earnings-calendar.ts +36 -5
  51. package/src/cli/export-source.ts +17 -3
  52. package/src/cli/fx-pair.ts +111 -11
  53. package/src/cli/glossary.ts +36 -2
  54. package/src/cli/help.ts +1 -1
  55. package/src/cli/history-export.ts +29 -11
  56. package/src/cli/history-rows.ts +130 -21
  57. package/src/cli/index.ts +8 -5
  58. package/src/cli/known-gaps.ts +45 -1
  59. package/src/cli/listing-arg.ts +366 -19
  60. package/src/cli/pane-functions/capabilities.ts +2 -2
  61. package/src/cli/pane-functions/catalog.ts +105 -9
  62. package/src/cli/pane-functions/data.ts +3 -2
  63. package/src/cli/pane-functions/discovery.ts +2 -0
  64. package/src/cli/pane-functions/dom.ts +46 -9
  65. package/src/cli/pane-functions/freshness.ts +7 -3
  66. package/src/cli/pane-functions/function-help.ts +9 -6
  67. package/src/cli/pane-functions/headless.ts +78 -6
  68. package/src/cli/pane-functions/index.ts +141 -23
  69. package/src/cli/pane-functions/options.ts +1 -3
  70. package/src/cli/pane-functions/plugin-code.ts +169 -0
  71. package/src/cli/pane-functions/report.ts +10 -0
  72. package/src/cli/pane-functions/resolver.ts +69 -21
  73. package/src/cli/pane-functions/screenshot-assessment.ts +82 -3
  74. package/src/cli/pane-functions/screenshot-data-evidence.ts +3 -1
  75. package/src/cli/pane-functions/screenshot-types.ts +6 -0
  76. package/src/cli/quote-answer.ts +49 -2
  77. package/src/cli/registry.ts +42 -4
  78. package/src/cli/report-tables.ts +26 -6
  79. package/src/cli/result.ts +13 -2
  80. package/src/cli/series-search.ts +17 -7
  81. package/src/cli/statement-filings.ts +22 -8
  82. package/src/cli/symbol-args.ts +9 -0
  83. package/src/cli/symbol-cells.ts +6 -0
  84. package/src/cli/symbol-list.ts +14 -6
  85. package/src/cli/symbol-rows.ts +12 -5
  86. package/src/cli/ticker-resolution.ts +3 -2
  87. package/src/cli/unknown-command.ts +111 -14
  88. package/src/components/chart/composite/format.ts +15 -1
  89. package/src/components/chart/composite/legend.tsx +101 -47
  90. package/src/components/chart/composite/panel-labels.ts +4 -4
  91. package/src/components/chart/composite/panel-surface.tsx +4 -6
  92. package/src/components/chart/composite/scene/build.ts +180 -0
  93. package/src/components/chart/composite/scene/cursor.ts +226 -0
  94. package/src/components/chart/composite/scene/domain.ts +170 -0
  95. package/src/components/chart/composite/scene/markers.ts +115 -0
  96. package/src/components/chart/composite/scene/panels.ts +85 -0
  97. package/src/components/chart/composite/scene/points.ts +169 -0
  98. package/src/components/chart/composite/scene/projection.ts +105 -0
  99. package/src/components/chart/composite/scene/timeline.ts +71 -0
  100. package/src/components/chart/composite/scene.ts +12 -1066
  101. package/src/components/chart/composite/types.ts +4 -2
  102. package/src/components/chart/curve/model.ts +2 -2
  103. package/src/components/chart-table/axis.ts +18 -6
  104. package/src/components/command-bar/layout-items/focused-pane.ts +3 -0
  105. package/src/components/command-bar/list/model.ts +9 -0
  106. package/src/components/command-bar/pane-templates/items.ts +61 -15
  107. package/src/components/command-bar/pane-templates/workflow.ts +16 -5
  108. package/src/components/command-bar/routes/root/plugin-install.ts +7 -46
  109. package/src/components/command-bar/routes/root/provider-search.ts +8 -5
  110. package/src/components/command-bar/routes/root/results.ts +6 -1
  111. package/src/components/command-bar/routes/root/runtime.ts +1 -0
  112. package/src/components/command-bar/routes/root/shortcut-feedback.ts +4 -1
  113. package/src/components/command-bar/routes/ticker-search/actions.ts +7 -5
  114. package/src/components/command-bar/routes/ticker-search/results.ts +51 -3
  115. package/src/components/command-bar/view-model.ts +12 -0
  116. package/src/components/command-bar/workflow/ops.ts +21 -4
  117. package/src/components/command-bar/workflow/ticker-listing-picker.ts +3 -1
  118. package/src/components/command-bar/workflow/tickers.ts +6 -2
  119. package/src/components/data-table/view.tsx +46 -1
  120. package/src/components/form-modal/confirm.tsx +3 -2
  121. package/src/components/form-modal/content.tsx +3 -2
  122. package/src/components/form-modal/field-row.tsx +2 -0
  123. package/src/components/form-modal/host.tsx +18 -3
  124. package/src/components/form-modal/remote-reads.test-helpers.ts +34 -0
  125. package/src/components/index.ts +1 -1
  126. package/src/components/layout/pane/title.ts +21 -5
  127. package/src/components/layout/shell/pane/layers.tsx +20 -14
  128. package/src/components/layout/shell/pane-occlusion.ts +21 -0
  129. package/src/components/onboarding/desks-step.tsx +7 -1
  130. package/src/components/onboarding/onboarding-keyboard.ts +48 -6
  131. package/src/components/onboarding/onboarding-wizard.tsx +47 -8
  132. package/src/components/onboarding/portfolio-step/positions-panel.tsx +17 -3
  133. package/src/components/onboarding/use-onboarding-progress.ts +57 -14
  134. package/src/components/onboarding/wizard-positions.ts +2 -0
  135. package/src/components/paged-rows.ts +11 -5
  136. package/src/components/ticker/list-table-view.tsx +24 -5
  137. package/src/components/toggle-list.tsx +44 -1
  138. package/src/components/ui/data-table/opentui/index.tsx +7 -6
  139. package/src/components/ui/data-table/opentui/model.ts +7 -3
  140. package/src/components/ui/data-table/types.ts +13 -2
  141. package/src/components/ui/fields.tsx +16 -4
  142. package/src/components/ui/page-stack-view.tsx +24 -6
  143. package/src/components/ui/query-bar.tsx +43 -9
  144. package/src/components/ui/table-layout.ts +56 -2
  145. package/src/core/app-services.ts +7 -2
  146. package/src/core/connection-health.ts +26 -0
  147. package/src/core/state/app/layout.ts +12 -4
  148. package/src/data/config/layout.ts +3 -1
  149. package/src/data/config/store/node.ts +4 -2
  150. package/src/docs/snapshot.json +756 -216
  151. package/src/i18n/es.ts +4 -1
  152. package/src/i18n/ja.ts +4 -1
  153. package/src/i18n/ko.ts +4 -1
  154. package/src/i18n/zh-cn.ts +4 -1
  155. package/src/i18n/zh-tw.ts +4 -1
  156. package/src/layout/pane-follow.ts +1 -1
  157. package/src/layout/pane-manager/gridlock.ts +18 -5
  158. package/src/layout/pane-manager/index.ts +1 -0
  159. package/src/layout/pane-manager/transient.ts +56 -0
  160. package/src/layout-marketplace/gallery.tsx +2 -1
  161. package/src/layout-marketplace/model.ts +4 -10
  162. package/src/market-data/commodity-names.ts +24 -0
  163. package/src/market-data/connection-follow.ts +9 -7
  164. package/src/market-data/coordinator/auxiliary.ts +4 -3
  165. package/src/market-data/coordinator/entries.ts +22 -1
  166. package/src/market-data/coordinator/financials.ts +2 -3
  167. package/src/market-data/coordinator/index.ts +67 -12
  168. package/src/market-data/coordinator/quotes.ts +2 -3
  169. package/src/market-data/fund-facts.ts +7 -1
  170. package/src/market-data/futures-board.ts +38 -4
  171. package/src/market-data/futures-contract.ts +5 -2
  172. package/src/market-data/futures-roll-returns.ts +226 -0
  173. package/src/market-data/fx-closes.ts +4 -1
  174. package/src/market-data/market/bar-period.ts +15 -0
  175. package/src/market-data/market/format.ts +4 -2
  176. package/src/market-data/market/freshness.ts +4 -0
  177. package/src/market-data/market/session-close-note.ts +41 -4
  178. package/src/market-data/market/status.ts +23 -3
  179. package/src/market-data/options-alternatives.ts +21 -9
  180. package/src/market-data/published-futures-sessions.ts +9 -0
  181. package/src/market-data/quotes/balance-sheet-rate.ts +34 -0
  182. package/src/market-data/quotes/delisting.ts +26 -2
  183. package/src/market-data/quotes/freshness.ts +62 -0
  184. package/src/market-data/quotes/listing-enterprise-value.ts +254 -19
  185. package/src/market-data/quotes/regular-session-valuation.ts +8 -0
  186. package/src/market-data/realized-volatility.ts +3 -1
  187. package/src/market-data/request-types.ts +2 -0
  188. package/src/market-data/selectors.ts +1 -0
  189. package/src/news/aggregator.ts +3 -3
  190. package/src/plugins/builtin/account-management/delete-account.ts +78 -0
  191. package/src/plugins/builtin/account-management/pane.tsx +22 -19
  192. package/src/plugins/builtin/account-management/password-dialog.tsx +75 -0
  193. package/src/plugins/builtin/alerts/alert-log.ts +3 -2
  194. package/src/plugins/builtin/alerts/cli-forms.ts +1 -1
  195. package/src/plugins/builtin/alerts/cli.ts +72 -4
  196. package/src/plugins/builtin/alerts/format.ts +8 -2
  197. package/src/plugins/builtin/alerts/index.tsx +8 -5
  198. package/src/plugins/builtin/alerts/pane.tsx +5 -3
  199. package/src/plugins/builtin/alerts/research-builder.ts +12 -0
  200. package/src/plugins/builtin/analytics/index.tsx +3 -3
  201. package/src/plugins/builtin/analytics/risk-client.ts +14 -3
  202. package/src/plugins/builtin/analytics/risk-pane.tsx +3 -3
  203. package/src/plugins/builtin/attention/pane.tsx +1 -1
  204. package/src/plugins/builtin/attention/trending.tsx +1 -1
  205. package/src/plugins/builtin/awards/detail.tsx +4 -1
  206. package/src/plugins/builtin/awards/headless.ts +7 -3
  207. package/src/plugins/builtin/awards/model.ts +11 -0
  208. package/src/plugins/builtin/awards/pane.tsx +12 -5
  209. package/src/plugins/builtin/backtest/client.ts +16 -4
  210. package/src/plugins/builtin/backtest/headless.ts +2 -1
  211. package/src/plugins/builtin/backtest/pane.tsx +5 -3
  212. package/src/plugins/builtin/backtest/report.ts +22 -6
  213. package/src/plugins/builtin/backtest/window.ts +17 -9
  214. package/src/plugins/builtin/bond-calculator/pane.tsx +1 -1
  215. package/src/plugins/builtin/broker-manager/sign-in-end.ts +1 -1
  216. package/src/plugins/builtin/broker-trading/orders.tsx +2 -2
  217. package/src/plugins/builtin/buildout/company/pane.tsx +1 -1
  218. package/src/plugins/builtin/buildout/model/index.ts +2 -2
  219. package/src/plugins/builtin/catalysts/headless.ts +9 -6
  220. package/src/plugins/builtin/catalysts/model.ts +72 -10
  221. package/src/plugins/builtin/catalysts/pane.tsx +10 -7
  222. package/src/plugins/builtin/cds/pane.tsx +5 -3
  223. package/src/plugins/builtin/central-bank-rates/pane.tsx +3 -2
  224. package/src/plugins/builtin/chart-composer/catalog-series.ts +59 -0
  225. package/src/plugins/builtin/chart-composer/headless-schema.ts +2 -1
  226. package/src/plugins/builtin/chart-composer/headless.ts +104 -23
  227. package/src/plugins/builtin/chart-composer/index.tsx +6 -3
  228. package/src/plugins/builtin/chart-composer/legend-names.ts +19 -0
  229. package/src/plugins/builtin/chart-composer/pane.tsx +37 -10
  230. package/src/plugins/builtin/chart-composer/presets.ts +63 -6
  231. package/src/plugins/builtin/chart-composer/roll-events.ts +38 -0
  232. package/src/plugins/builtin/chart-composer/series-catalog.ts +12 -5
  233. package/src/plugins/builtin/chart-composer/series-expression.ts +8 -4
  234. package/src/plugins/builtin/chart-composer/series-listings.ts +33 -9
  235. package/src/plugins/builtin/chart-composer/use-series-catalog.ts +2 -2
  236. package/src/plugins/builtin/clinical-trials/client.ts +13 -0
  237. package/src/plugins/builtin/clinical-trials/index.tsx +1 -1
  238. package/src/plugins/builtin/clinical-trials/pane.tsx +77 -27
  239. package/src/plugins/builtin/clinical-trials/search.ts +117 -0
  240. package/src/plugins/builtin/cloud/askg/conversation-store.ts +17 -6
  241. package/src/plugins/builtin/cloud/askg/lock-note.ts +4 -2
  242. package/src/plugins/builtin/cloud/askg/manifest.ts +3 -2
  243. package/src/plugins/builtin/cloud/askg/pane.tsx +2 -2
  244. package/src/plugins/builtin/cloud/askg/sources.ts +3 -3
  245. package/src/plugins/builtin/cloud/one-tap/one-tap-prompt.tsx +7 -3
  246. package/src/plugins/builtin/cloud/team/acm-tab.tsx +1 -1
  247. package/src/plugins/builtin/cloud/team/pane.tsx +17 -10
  248. package/src/plugins/builtin/cloud/team/views.ts +15 -3
  249. package/src/plugins/builtin/cloud/terminal-relay/redact.ts +105 -16
  250. package/src/plugins/builtin/cloud/thesis/board-pane.tsx +17 -2
  251. package/src/plugins/builtin/cloud/thesis/module.tsx +3 -2
  252. package/src/plugins/builtin/cloud/thesis/store.ts +17 -3
  253. package/src/plugins/builtin/commodities-energy/index.tsx +35 -3
  254. package/src/plugins/builtin/commodity-balances/index.tsx +1 -1
  255. package/src/plugins/builtin/company-attention/app-rank.tsx +1 -1
  256. package/src/plugins/builtin/company-attention/building.tsx +1 -1
  257. package/src/plugins/builtin/company-attention/model.ts +2 -1
  258. package/src/plugins/builtin/company-attention/moves.tsx +1 -1
  259. package/src/plugins/builtin/company-attention/pane.tsx +1 -1
  260. package/src/plugins/builtin/company-attention/signals.tsx +1 -1
  261. package/src/plugins/builtin/company-kpis/pane.tsx +1 -1
  262. package/src/plugins/builtin/correlation/headless.ts +13 -7
  263. package/src/plugins/builtin/correlation/history.ts +17 -6
  264. package/src/plugins/builtin/correlation/index.tsx +8 -4
  265. package/src/plugins/builtin/correlation/matrix/model.ts +15 -1
  266. package/src/plugins/builtin/correlation/relationship/history.ts +1 -1
  267. package/src/plugins/builtin/correlation/relationship/model.ts +15 -1
  268. package/src/plugins/builtin/correlation/relationship/pane.tsx +5 -3
  269. package/src/plugins/builtin/cot/headless.ts +10 -3
  270. package/src/plugins/builtin/cot/pane.tsx +2 -2
  271. package/src/plugins/builtin/cpi/pane.tsx +1 -1
  272. package/src/plugins/builtin/credit-boards/model.ts +1 -1
  273. package/src/plugins/builtin/credit-documents/pane.tsx +1 -1
  274. package/src/plugins/builtin/crypto-board/defi-view.tsx +2 -2
  275. package/src/plugins/builtin/crypto-board/defi.ts +9 -3
  276. package/src/plugins/builtin/crypto-board/headless.ts +19 -10
  277. package/src/plugins/builtin/crypto-board/model.ts +8 -0
  278. package/src/plugins/builtin/crypto-board/pane.tsx +11 -5
  279. package/src/plugins/builtin/crypto-board/series.ts +17 -3
  280. package/src/plugins/builtin/crypto-board/supply.ts +26 -3
  281. package/src/plugins/builtin/crypto-etf-flows/headless.ts +3 -2
  282. package/src/plugins/builtin/crypto-etf-flows/model.ts +13 -3
  283. package/src/plugins/builtin/crypto-etf-flows/pane.tsx +6 -3
  284. package/src/plugins/builtin/custom-view/pane.tsx +5 -5
  285. package/src/plugins/builtin/debt-maturities/client.ts +5 -0
  286. package/src/plugins/builtin/debt-maturities/headless.ts +3 -1
  287. package/src/plugins/builtin/debt-maturities/model.ts +1 -0
  288. package/src/plugins/builtin/debt-maturities/pane.tsx +1 -1
  289. package/src/plugins/builtin/dividend-yield/pane.tsx +1 -1
  290. package/src/plugins/builtin/doe/model.ts +1 -1
  291. package/src/plugins/builtin/doe/pane.tsx +1 -1
  292. package/src/plugins/builtin/earnings/board.tsx +2 -2
  293. package/src/plugins/builtin/earnings/history.tsx +1 -1
  294. package/src/plugins/builtin/earnings-calls/calendar.tsx +1 -1
  295. package/src/plugins/builtin/earnings-calls/data.ts +2 -1
  296. package/src/plugins/builtin/earnings-calls/headless.ts +15 -0
  297. package/src/plugins/builtin/earnings-calls/model.ts +68 -8
  298. package/src/plugins/builtin/earnings-calls/pane.tsx +29 -8
  299. package/src/plugins/builtin/earnings-calls/transcript-view.tsx +32 -2
  300. package/src/plugins/builtin/earnings-ripple/pane.tsx +1 -1
  301. package/src/plugins/builtin/econ/calendar-model.ts +94 -2
  302. package/src/plugins/builtin/econ/detail-view.tsx +15 -11
  303. package/src/plugins/builtin/econ/index.tsx +25 -9
  304. package/src/plugins/builtin/econ/types.ts +4 -1
  305. package/src/plugins/builtin/equity-screener/headless.ts +23 -7
  306. package/src/plugins/builtin/equity-screener/index.tsx +3 -0
  307. package/src/plugins/builtin/equity-screener/live.ts +39 -12
  308. package/src/plugins/builtin/equity-screener/model.ts +86 -5
  309. package/src/plugins/builtin/equity-screener/pane.tsx +20 -21
  310. package/src/plugins/builtin/equity-screener/results.ts +12 -3
  311. package/src/plugins/builtin/equity-screener/ticker-check.tsx +2 -2
  312. package/src/plugins/builtin/estimate-revisions/pane.tsx +2 -2
  313. package/src/plugins/builtin/executives/pane.tsx +2 -2
  314. package/src/plugins/builtin/exposure/pane.tsx +1 -1
  315. package/src/plugins/builtin/fear-greed/data.ts +3 -1
  316. package/src/plugins/builtin/fear-greed/headless.ts +8 -2
  317. package/src/plugins/builtin/fear-greed/pane.tsx +8 -4
  318. package/src/plugins/builtin/filing-events/pane.tsx +1 -1
  319. package/src/plugins/builtin/futures/index.tsx +5 -4
  320. package/src/plugins/builtin/futures/model.ts +17 -9
  321. package/src/plugins/builtin/futures/returns.ts +2 -0
  322. package/src/plugins/builtin/futures/series.ts +44 -8
  323. package/src/plugins/builtin/futures/table.tsx +3 -3
  324. package/src/plugins/builtin/futures-curve/client.ts +1 -0
  325. package/src/plugins/builtin/futures-curve/headless.ts +17 -12
  326. package/src/plugins/builtin/futures-curve/index.tsx +7 -4
  327. package/src/plugins/builtin/futures-curve/model.ts +117 -7
  328. package/src/plugins/builtin/futures-curve/pane.tsx +18 -7
  329. package/src/plugins/builtin/fx-matrix/amount.ts +2 -1
  330. package/src/plugins/builtin/fx-matrix/index.tsx +9 -0
  331. package/src/plugins/builtin/gpu/changes.tsx +1 -1
  332. package/src/plugins/builtin/gpu/equities.tsx +1 -1
  333. package/src/plugins/builtin/gpu/pane.tsx +2 -2
  334. package/src/plugins/builtin/help/function-card.tsx +4 -2
  335. package/src/plugins/builtin/help/function-index.ts +12 -6
  336. package/src/plugins/builtin/help/index.tsx +1 -1
  337. package/src/plugins/builtin/holders/beneficial-view.tsx +1 -1
  338. package/src/plugins/builtin/holders/pane.tsx +1 -1
  339. package/src/plugins/builtin/insider/base-values.ts +55 -0
  340. package/src/plugins/builtin/insider/headless.ts +307 -83
  341. package/src/plugins/builtin/insider/index.tsx +65 -23
  342. package/src/plugins/builtin/insider/insiders.tsx +26 -16
  343. package/src/plugins/builtin/insider/model.ts +2 -2
  344. package/src/plugins/builtin/insider/signals-cells.tsx +4 -1
  345. package/src/plugins/builtin/insider/signals-model.ts +13 -5
  346. package/src/plugins/builtin/insider/signals.tsx +5 -3
  347. package/src/plugins/builtin/insider/tickers.tsx +466 -0
  348. package/src/plugins/builtin/ipo-calendar/pane.tsx +1 -1
  349. package/src/plugins/builtin/iv-history/client.ts +35 -4
  350. package/src/plugins/builtin/iv-history/headless.ts +10 -4
  351. package/src/plugins/builtin/iv-history/model.ts +85 -16
  352. package/src/plugins/builtin/iv-history/pane.tsx +2 -2
  353. package/src/plugins/builtin/iv-history/screen-pane.tsx +6 -3
  354. package/src/plugins/builtin/jobs/pane.tsx +5 -5
  355. package/src/plugins/builtin/kelly-sizer/headless.ts +2 -2
  356. package/src/plugins/builtin/kelly-sizer/history.ts +10 -3
  357. package/src/plugins/builtin/kelly-sizer/pane.tsx +2 -2
  358. package/src/plugins/builtin/kelly-sizer/sections.tsx +1 -1
  359. package/src/plugins/builtin/macro-day/pane.tsx +1 -1
  360. package/src/plugins/builtin/macro-day/release-table.ts +5 -5
  361. package/src/plugins/builtin/macro-day/releases.ts +11 -9
  362. package/src/plugins/builtin/market-movers/headless.ts +6 -2
  363. package/src/plugins/builtin/market-movers/screener.ts +18 -4
  364. package/src/plugins/builtin/members/breadth-pane.tsx +3 -3
  365. package/src/plugins/builtin/members/client.ts +24 -2
  366. package/src/plugins/builtin/members/headless.ts +66 -9
  367. package/src/plugins/builtin/members/index.tsx +7 -6
  368. package/src/plugins/builtin/members/model.ts +89 -5
  369. package/src/plugins/builtin/members/pane.tsx +70 -21
  370. package/src/plugins/builtin/mna/distress/pane.tsx +2 -1
  371. package/src/plugins/builtin/mna/pane.tsx +1 -1
  372. package/src/plugins/builtin/money-markets/client.ts +43 -15
  373. package/src/plugins/builtin/money-markets/headless.ts +18 -11
  374. package/src/plugins/builtin/money-markets/index.tsx +7 -6
  375. package/src/plugins/builtin/money-markets/model.ts +20 -5
  376. package/src/plugins/builtin/money-markets/pane.tsx +28 -17
  377. package/src/plugins/builtin/news/wire/news/footer.ts +11 -1
  378. package/src/plugins/builtin/news/wire/news/table.tsx +15 -5
  379. package/src/plugins/builtin/notes/headless.ts +94 -0
  380. package/src/plugins/builtin/notes/index.tsx +3 -1
  381. package/src/plugins/builtin/notes/store.ts +10 -3
  382. package/src/plugins/builtin/options/footer.ts +8 -2
  383. package/src/plugins/builtin/options/open-interest-as-of.ts +12 -3
  384. package/src/plugins/builtin/options/view.tsx +10 -1
  385. package/src/plugins/builtin/options-calculator/pane.tsx +1 -1
  386. package/src/plugins/builtin/options-positioning/client.ts +35 -8
  387. package/src/plugins/builtin/options-positioning/headless.ts +17 -7
  388. package/src/plugins/builtin/options-positioning/index.tsx +10 -0
  389. package/src/plugins/builtin/options-positioning/pane.tsx +16 -7
  390. package/src/plugins/builtin/options-scenario/csp-screen-pane.tsx +1 -1
  391. package/src/plugins/builtin/options-scenario/pane.tsx +1 -1
  392. package/src/plugins/builtin/pe-band/pane.tsx +2 -2
  393. package/src/plugins/builtin/perps/cascade-tabs.tsx +2 -2
  394. package/src/plugins/builtin/perps/client.ts +54 -15
  395. package/src/plugins/builtin/perps/headless.ts +39 -13
  396. package/src/plugins/builtin/perps/index.tsx +2 -1
  397. package/src/plugins/builtin/perps/model.ts +43 -1
  398. package/src/plugins/builtin/perps/pane.tsx +35 -18
  399. package/src/plugins/builtin/portfolio-list/allocation-rows.ts +74 -0
  400. package/src/plugins/builtin/portfolio-list/cell-version.ts +1 -0
  401. package/src/plugins/builtin/portfolio-list/cli/period-report.ts +7 -3
  402. package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +33 -3
  403. package/src/plugins/builtin/portfolio-list/cli/render.ts +149 -24
  404. package/src/plugins/builtin/portfolio-list/headless.ts +30 -9
  405. package/src/plugins/builtin/portfolio-list/income.ts +17 -8
  406. package/src/plugins/builtin/portfolio-list/index.tsx +4 -4
  407. package/src/plugins/builtin/portfolio-list/pane/fx-day-moves.ts +52 -0
  408. package/src/plugins/builtin/portfolio-list/pane/index.tsx +76 -9
  409. package/src/plugins/builtin/portfolio-list/pane/target-weights.tsx +178 -0
  410. package/src/plugins/builtin/portfolio-list/period-pnl.ts +44 -5
  411. package/src/plugins/builtin/portfolio-list/settings.ts +12 -6
  412. package/src/plugins/builtin/portfolio-list/summary/index.tsx +9 -4
  413. package/src/plugins/builtin/portfolio-list/summary/totals.ts +21 -2
  414. package/src/plugins/builtin/portfolio-list/table.tsx +33 -25
  415. package/src/plugins/builtin/power/gas.tsx +2 -2
  416. package/src/plugins/builtin/power/prices.tsx +2 -2
  417. package/src/plugins/builtin/primary-dealers/pane.tsx +10 -11
  418. package/src/plugins/builtin/rate-path/model.ts +9 -0
  419. package/src/plugins/builtin/rate-path/pane.tsx +6 -5
  420. package/src/plugins/builtin/realized-vol/fx-proxy.ts +27 -0
  421. package/src/plugins/builtin/realized-vol/headless.ts +19 -12
  422. package/src/plugins/builtin/realized-vol/model.ts +14 -6
  423. package/src/plugins/builtin/realized-vol/pane.tsx +15 -8
  424. package/src/plugins/builtin/realized-vol/settings.ts +2 -1
  425. package/src/plugins/builtin/relative-rotation/pane.tsx +1 -1
  426. package/src/plugins/builtin/research/analyst-headless.ts +5 -1
  427. package/src/plugins/builtin/research/analyst-model.ts +7 -1
  428. package/src/plugins/builtin/research/analyst-pane.tsx +1 -1
  429. package/src/plugins/builtin/research/relative-valuation-basis.ts +44 -4
  430. package/src/plugins/builtin/research/relative-valuation-headless.ts +59 -14
  431. package/src/plugins/builtin/research/relative-valuation-model.ts +65 -26
  432. package/src/plugins/builtin/research/relative-valuation-pane.tsx +42 -17
  433. package/src/plugins/builtin/revenue-breakdown/pane.tsx +1 -1
  434. package/src/plugins/builtin/reverse-dcf/client.ts +34 -4
  435. package/src/plugins/builtin/reverse-dcf/headless.ts +30 -15
  436. package/src/plugins/builtin/reverse-dcf/model.ts +190 -29
  437. package/src/plugins/builtin/reverse-dcf/pane.tsx +35 -13
  438. package/src/plugins/builtin/risk-factors/pane.tsx +2 -2
  439. package/src/plugins/builtin/roadmap/pane.tsx +2 -2
  440. package/src/plugins/builtin/scanner/flow-pane.tsx +4 -4
  441. package/src/plugins/builtin/scanner/headless.ts +15 -1
  442. package/src/plugins/builtin/seasonality/client.ts +66 -17
  443. package/src/plugins/builtin/seasonality/headless.ts +7 -2
  444. package/src/plugins/builtin/seasonality/model.ts +12 -3
  445. package/src/plugins/builtin/seasonality/pane.tsx +5 -3
  446. package/src/plugins/builtin/sec/fund-facts-view.tsx +5 -2
  447. package/src/plugins/builtin/sec/fund-facts.ts +41 -1
  448. package/src/plugins/builtin/sec/headless.ts +8 -4
  449. package/src/plugins/builtin/sec/index.tsx +41 -13
  450. package/src/plugins/builtin/shared/ticker-company.ts +111 -0
  451. package/src/plugins/builtin/shared/use-quote-board.ts +65 -8
  452. package/src/plugins/builtin/shared/volatility/live-session.ts +23 -0
  453. package/src/plugins/builtin/shared/volatility-indices.ts +2 -0
  454. package/src/plugins/builtin/short-interest/publications-pane.tsx +1 -1
  455. package/src/plugins/builtin/short-volume/pane.tsx +1 -1
  456. package/src/plugins/builtin/social-mentions/outliers.tsx +3 -3
  457. package/src/plugins/builtin/social-mentions/pane.tsx +2 -2
  458. package/src/plugins/builtin/supply-chain/graph-pane.tsx +1 -1
  459. package/src/plugins/builtin/supply-chain/pane.tsx +1 -1
  460. package/src/plugins/builtin/themes/pane.tsx +4 -4
  461. package/src/plugins/builtin/thirteenf/api.ts +1 -0
  462. package/src/plugins/builtin/thirteenf/format.ts +5 -0
  463. package/src/plugins/builtin/thirteenf/headless.ts +2 -2
  464. package/src/plugins/builtin/thirteenf/model.ts +128 -5
  465. package/src/plugins/builtin/thirteenf/overlap-pane.tsx +1 -1
  466. package/src/plugins/builtin/thirteenf/report-notes.ts +10 -3
  467. package/src/plugins/builtin/thirteenf/signals-pane.tsx +1 -1
  468. package/src/plugins/builtin/thirteenf/table.ts +2 -2
  469. package/src/plugins/builtin/thirteenf/types.ts +12 -0
  470. package/src/plugins/builtin/ticker-detail/data-panes/historical-prices.tsx +27 -14
  471. package/src/plugins/builtin/ticker-detail/data-panes/returns-history.ts +6 -3
  472. package/src/plugins/builtin/ticker-detail/data-panes/returns-model.ts +14 -0
  473. package/src/plugins/builtin/ticker-detail/data-panes/returns-pane.tsx +4 -1
  474. package/src/plugins/builtin/ticker-detail/financials/aggregation.ts +87 -19
  475. package/src/plugins/builtin/ticker-detail/financials/exchange-results.ts +54 -0
  476. package/src/plugins/builtin/ticker-detail/financials/model.ts +114 -9
  477. package/src/plugins/builtin/ticker-detail/financials/ratios.ts +37 -20
  478. package/src/plugins/builtin/ticker-detail/financials/tab.tsx +42 -19
  479. package/src/plugins/builtin/ticker-detail/headless-schema.ts +3 -2
  480. package/src/plugins/builtin/ticker-detail/headless.ts +90 -31
  481. package/src/plugins/builtin/ticker-detail/overview/model.ts +22 -15
  482. package/src/plugins/builtin/ticker-detail/overview-tab.tsx +5 -2
  483. package/src/plugins/builtin/ticker-detail/quote-monitor/card.tsx +12 -7
  484. package/src/plugins/builtin/ticker-detail/quote-monitor/index.tsx +21 -0
  485. package/src/plugins/builtin/trace-bonds/client.ts +107 -10
  486. package/src/plugins/builtin/trace-bonds/detail.tsx +1 -1
  487. package/src/plugins/builtin/trace-bonds/headless.ts +20 -5
  488. package/src/plugins/builtin/trace-bonds/pane.tsx +15 -4
  489. package/src/plugins/builtin/treasury-auctions/hk-view.tsx +1 -1
  490. package/src/plugins/builtin/treasury-auctions/pane.tsx +1 -1
  491. package/src/plugins/builtin/treasury-daily/pane.tsx +2 -2
  492. package/src/plugins/builtin/vol-surface/charts.tsx +30 -5
  493. package/src/plugins/builtin/vol-surface/client.ts +40 -12
  494. package/src/plugins/builtin/vol-surface/events.ts +213 -0
  495. package/src/plugins/builtin/vol-surface/headless.ts +82 -13
  496. package/src/plugins/builtin/vol-surface/index.tsx +5 -1
  497. package/src/plugins/builtin/vol-surface/model.ts +42 -6
  498. package/src/plugins/builtin/vol-surface/pane.tsx +95 -23
  499. package/src/plugins/builtin/volatility/dvol.ts +14 -2
  500. package/src/plugins/builtin/volatility/headless.ts +3 -2
  501. package/src/plugins/builtin/volatility/index.tsx +1 -1
  502. package/src/plugins/builtin/volatility/pane.tsx +1 -1
  503. package/src/plugins/builtin/volatility/series.ts +7 -3
  504. package/src/plugins/builtin/world-venue-map/activity-series.ts +89 -0
  505. package/src/plugins/builtin/world-venue-map/chokepoint-report.ts +123 -0
  506. package/src/plugins/builtin/world-venue-map/evidence.ts +2 -0
  507. package/src/plugins/builtin/world-venue-map/geo-series.ts +35 -1
  508. package/src/plugins/builtin/world-venue-map/headless.ts +58 -9
  509. package/src/plugins/builtin/world-venue-map/index.ts +6 -3
  510. package/src/plugins/builtin/world-venue-map/layered-pane.tsx +6 -1
  511. package/src/plugins/builtin/world-venue-map/pane.tsx +4 -3
  512. package/src/plugins/builtin/yield-curve/index.tsx +12 -10
  513. package/src/plugins/builtin/yield-curve/swaps.tsx +1 -1
  514. package/src/plugins/extracted-plugins.ts +14 -10
  515. package/src/plugins/installer.ts +17 -1
  516. package/src/plugins/marketplace/feed.ts +14 -0
  517. package/src/plugins/marketplace/install-offer.ts +64 -0
  518. package/src/plugins/registry/contributions.ts +46 -8
  519. package/src/plugins/registry/index.ts +5 -0
  520. package/src/portfolio/collection-name.ts +38 -4
  521. package/src/portfolio/column-values.ts +32 -4
  522. package/src/portfolio/period-pnl.ts +4 -2
  523. package/src/react/async-resource.ts +24 -8
  524. package/src/remote/endpoint.ts +38 -12
  525. package/src/remote/secrets.ts +22 -6
  526. package/src/remote/server.ts +20 -4
  527. package/src/renderers/dom/data-table/index.tsx +2 -1
  528. package/src/renderers/dom/data-table/row.tsx +49 -7
  529. package/src/renderers/dom/desktop/controls.tsx +3 -1
  530. package/src/renderers/dom/desktop/query-bar.tsx +57 -7
  531. package/src/renderers/dom/host/surface-3d.tsx +46 -5
  532. package/src/renderers/dom/styles.css +24 -4
  533. package/src/renderers/electrobun/view/backend-rpc.ts +15 -21
  534. package/src/renderers/electrobun/view/cli-pane-shot-entry.tsx +16 -61
  535. package/src/renderers/electrobun/view/cli-pane-shot-socket.ts +134 -0
  536. package/src/renderers/electrobun/view/host-route.ts +119 -0
  537. package/src/renderers/electrobun/view/rpc-timeout.ts +6 -5
  538. package/src/renderers/opentui/box-width.ts +30 -0
  539. package/src/renderers/opentui/toast-host.tsx +6 -3
  540. package/src/renderers/opentui/ui-host.tsx +29 -5
  541. package/src/series/registry.ts +1 -0
  542. package/src/series/standalone-catalog.ts +40 -0
  543. package/src/series/types.ts +10 -0
  544. package/src/series/validate.ts +5 -0
  545. package/src/shares/portable-layout.ts +2 -7
  546. package/src/sources/gloomberb-cloud/dated-chunks.ts +133 -0
  547. package/src/sources/gloomberb-cloud/index.ts +46 -5
  548. package/src/sources/gloomberb-cloud/news.ts +15 -9
  549. package/src/sources/gloomberb-cloud/normalizers.ts +17 -0
  550. package/src/sources/history-coverage.ts +13 -0
  551. package/src/sources/history-result.ts +1 -0
  552. package/src/sources/provider-errors.ts +9 -0
  553. package/src/sources/provider-router/batches.ts +7 -3
  554. package/src/sources/provider-router/financial-routes.ts +3 -1
  555. package/src/sources/provider-router/history.ts +6 -4
  556. package/src/sources/provider-router/index.ts +5 -1
  557. package/src/sources/provider-router/primary.ts +4 -3
  558. package/src/sources/provider-router/retrieved-at.ts +12 -0
  559. package/src/team/store.ts +17 -4
  560. package/src/telemetry/crash-reports.ts +3 -1
  561. package/src/test-support/cli-context.ts +3 -2
  562. package/src/test-support/test-env.ts +7 -0
  563. package/src/theme/themes.ts +16 -9
  564. package/src/theme/tone-contrast.ts +29 -5
  565. package/src/tickers/company-name-listing.ts +31 -3
  566. package/src/tickers/company-name.ts +9 -0
  567. package/src/tickers/index-roots.ts +56 -4
  568. package/src/tickers/listing-name.ts +7 -2
  569. package/src/tickers/listing-venues.ts +17 -2
  570. package/src/tickers/search/home-listing.ts +2 -0
  571. package/src/tickers/search/index.ts +64 -11
  572. package/src/tickers/search/major-listings.json +595 -592
  573. package/src/tickers/search/ranking.ts +19 -1
  574. package/src/tickers/terminal-codes.ts +5 -3
  575. package/src/time-series/bar-aggregation.ts +3 -2
  576. package/src/time-series/base-series.ts +18 -1
  577. package/src/time-series/chart-data.ts +9 -6
  578. package/src/time-series/chart-seed.ts +11 -3
  579. package/src/time-series/currency-conversion.ts +1 -0
  580. package/src/time-series/date-window.ts +8 -0
  581. package/src/time-series/formula-months.ts +57 -0
  582. package/src/time-series/fundamentals/period-points.ts +3 -3
  583. package/src/time-series/fundamentals/source-statements.ts +5 -4
  584. package/src/time-series/leverage.ts +12 -4
  585. package/src/time-series/live-bars.ts +12 -7
  586. package/src/time-series/live-quotes.ts +6 -2
  587. package/src/time-series/market.ts +10 -3
  588. package/src/time-series/price-comparison.ts +106 -0
  589. package/src/time-series/range.ts +10 -0
  590. package/src/time-series/resolve-context.ts +7 -2
  591. package/src/time-series/resolve.ts +61 -5
  592. package/src/time-series/series-name.ts +2 -2
  593. package/src/time-series/series-presentation.ts +91 -2
  594. package/src/time-series/session-bar.ts +13 -7
  595. package/src/time-series/spec.ts +21 -2
  596. package/src/time-series/studies/formula.ts +262 -36
  597. package/src/time-series/studies/leverage.ts +9 -3
  598. package/src/time-series/studies/resolve.ts +7 -2
  599. package/src/time-series/types.ts +34 -0
  600. package/src/time-series/use-chart-resolution.ts +18 -1
  601. package/src/types/data-provider.ts +7 -0
  602. package/src/types/financials.ts +117 -2
  603. package/src/types/headless.ts +70 -3
  604. package/src/types/instrument.ts +6 -0
  605. package/src/types/plugin-context.ts +9 -0
  606. package/src/types/plugin-pane-templates.ts +6 -0
  607. package/src/types/plugin-panes.ts +7 -0
  608. package/src/types/price-history.ts +6 -0
  609. package/src/ui/host.tsx +3 -1
  610. package/src/ui/index.tsx +7 -2
  611. package/src/utils/cli-output.ts +21 -1
  612. package/src/utils/currency-units.ts +14 -0
  613. package/src/utils/datetime-format.ts +11 -0
  614. package/src/utils/exchange-announcements.ts +26 -3
  615. package/src/utils/exchange-notation.generated.ts +3 -4
  616. package/src/utils/exchange-results.ts +144 -0
  617. package/src/utils/exchanges.ts +10 -0
  618. package/src/utils/financial-statements.ts +212 -22
  619. package/src/utils/fire-and-forget.ts +1 -1
  620. package/src/utils/fiscal-period.ts +41 -3
  621. package/src/utils/format.ts +10 -6
  622. package/src/utils/fundamentals.ts +223 -15
  623. package/src/utils/futures-generic.ts +26 -0
  624. package/src/utils/lease-liabilities.ts +15 -5
  625. package/src/utils/lookup-token.ts +22 -0
  626. package/src/utils/max-drawdown.ts +25 -4
  627. package/src/utils/price-history-integrity.ts +56 -8
  628. package/src/utils/price-history.ts +6 -2
  629. package/src/utils/price-window.ts +38 -2
  630. package/src/utils/replace-file.ts +47 -0
  631. package/src/utils/rpc-timeout-error.ts +16 -2
  632. package/src/utils/untrusted-text.ts +14 -0
@@ -1,1066 +1,12 @@
1
- import type {
2
- ChartPanelSpec,
3
- PanelScale,
4
- ResolvedSeries,
5
- TimeSeriesPoint,
6
- } from "../../../time-series/types";
7
- import { effectiveTimeSeriesPointTime, sortedUniquePoints, timeSeriesObservationKey } from "../../../time-series/alignment";
8
- import type {
9
- BuildCompositeChartSceneOptions,
10
- CompositeAxisDomain,
11
- CompositeAxisSide,
12
- CompositeChartScene,
13
- CompositeCursorValue,
14
- CompositePanelScene,
15
- CompositeProjectedPoint,
16
- } from "./types";
17
- import {
18
- buildCompositeTimeScale,
19
- COMPOSITE_RIGHT_OFFSET_RATIO,
20
- compositeTimeProjector,
21
- projectCompositeTimestamp,
22
- unprojectCompositeTimestamp,
23
- } from "./time-scale";
24
- import { compositeAxisMaxTicks, seriesPriceReference } from "./format";
25
- import type { CompositeTimeScale } from "./types";
26
- import { isFiniteNumber } from "../../../utils/guards";
27
- import { volumeProfile } from "../../../time-series/trader-studies";
28
- import { extendedHoursSpans, isIntradaySeries } from "./session-shading";
29
- import { listingTimeZone } from "../../../market-data/market/trading-sessions";
30
- import { manualValueRangeApplies, valueScaleKey, valueScaleSlot, type CompositeManualValueScale } from "./value-scale";
31
-
32
- const DAY_MS = 24 * 60 * 60 * 1000;
33
-
34
- function resolveTimeSeriesPointValue(point: TimeSeriesPoint): number | null {
35
- if (isFiniteNumber(point.value)) return point.value;
36
- if (isFiniteNumber(point.close)) return point.close;
37
- return null;
38
- }
39
-
40
- /**
41
- * Heikin Ashi bars in place of a series' own: each close averages the bar's
42
- * four prices and each open sits halfway along the previous Heikin Ashi body,
43
- * so the chain runs from the first loaded bar, before any viewport cut. The
44
- * real close stays in `rawValue` for the last price marker.
45
- */
46
- export function heikinAshiPoints(points: readonly TimeSeriesPoint[]): TimeSeriesPoint[] {
47
- let previous: { open: number; close: number } | null = null;
48
- // Chain over the bars the chart draws: one per observation, in time order,
49
- // so a superseded copy of a bar never feeds the next open.
50
- return sortedUniquePoints(points).map((point) => {
51
- const close = point.close ?? point.value;
52
- if (!isFiniteNumber(close)) return point;
53
- const open = isFiniteNumber(point.open) ? point.open : close;
54
- const high = isFiniteNumber(point.high) ? point.high : Math.max(open, close);
55
- const low = isFiniteNumber(point.low) ? point.low : Math.min(open, close);
56
- const haClose = (open + high + low + close) / 4;
57
- const haOpen = previous ? (previous.open + previous.close) / 2 : (open + close) / 2;
58
- previous = { open: haOpen, close: haClose };
59
- return {
60
- ...point,
61
- value: haClose,
62
- rawValue: close,
63
- open: haOpen,
64
- high: Math.max(high, haOpen, haClose),
65
- low: Math.min(low, haOpen, haClose),
66
- close: haClose,
67
- };
68
- });
69
- }
70
-
71
- function pointTime(point: TimeSeriesPoint): number | null {
72
- const time = point.date instanceof Date ? point.date.getTime() : new Date(point.date).getTime();
73
- return Number.isFinite(time) ? time : null;
74
- }
75
-
76
- function isMarketObservationSeries(series: ResolvedSeries): boolean {
77
- return series.observationKind === "market" || series.timeBasis?.kind === "market";
78
- }
79
-
80
- function pointTimestampForScale(
81
- series: ResolvedSeries,
82
- point: TimeSeriesPoint,
83
- timeScale?: CompositeTimeScale,
84
- ): number | null {
85
- const timestamp = pointTime(point);
86
- if (timestamp === null) return null;
87
- return timeScale?.kind === "market" && !isMarketObservationSeries(series)
88
- ? effectiveTimeSeriesPointTime(point)
89
- : timestamp;
90
- }
91
-
92
- interface NormalizedSourcePoint {
93
- point: TimeSeriesPoint;
94
- timestamp: number;
95
- value: number | null;
96
- }
97
-
98
- interface NormalizedPointsCache {
99
- points: readonly TimeSeriesPoint[];
100
- pointCount: number;
101
- last: TimeSeriesPoint | undefined;
102
- lastTimestamp: number | null;
103
- lastValue: number | null;
104
- byPlacement: Map<boolean, NormalizedSourcePoint[]>;
105
- }
106
-
107
- // Every scene build normalises each series several times over; a viewport
108
- // change must not re-sort thousands of unchanged points. Live ticks mutate
109
- // the last point in place, so the cache also keys on its time and value.
110
- const normalizedPointsCache = new WeakMap<ResolvedSeries, NormalizedPointsCache>();
111
-
112
- /**
113
- * Points already in time order, one per instant and with no fiscal period,
114
- * normalise in order: each is its own observation, at its own date. Null for
115
- * anything else, which goes through the keyed sort.
116
- */
117
- function orderedSourcePoints(points: readonly TimeSeriesPoint[]): NormalizedSourcePoint[] | null {
118
- const normalized: NormalizedSourcePoint[] = [];
119
- let previous = Number.NEGATIVE_INFINITY;
120
- for (const point of points) {
121
- if (point.periodLabel !== undefined) return null;
122
- const timestamp = pointTime(point);
123
- if (timestamp === null || timestamp <= previous) return null;
124
- previous = timestamp;
125
- normalized.push({ point, timestamp, value: resolveTimeSeriesPointValue(point) });
126
- }
127
- return normalized;
128
- }
129
-
130
- function computeNormalizedSourcePoints(
131
- series: ResolvedSeries,
132
- timeScale?: CompositeTimeScale,
133
- ): NormalizedSourcePoint[] {
134
- // Placed at their own dates, points in time order are already normalised;
135
- // a live chart re-resolves its series on every tick.
136
- const effectiveTimes = timeScale?.kind === "market" && !isMarketObservationSeries(series);
137
- const ordered = effectiveTimes ? null : orderedSourcePoints(series.points);
138
- if (ordered) return ordered;
139
- const byObservation = new Map<string, NormalizedSourcePoint>();
140
- for (const point of series.points) {
141
- const sourceTimestamp = pointTime(point);
142
- const timestamp = pointTimestampForScale(series, point, timeScale);
143
- if (sourceTimestamp === null || timestamp === null || !Number.isFinite(timestamp)) continue;
144
- byObservation.set(timeSeriesObservationKey(point), {
145
- point,
146
- timestamp,
147
- value: resolveTimeSeriesPointValue(point),
148
- });
149
- }
150
- return [...byObservation.values()].sort((left, right) => (
151
- left.timestamp - right.timestamp
152
- || left.point.date.getTime() - right.point.date.getTime()
153
- || left.point.observedAt.getTime() - right.point.observedAt.getTime()
154
- ));
155
- }
156
-
157
- function normalizedSourcePoints(
158
- series: ResolvedSeries,
159
- timeScale?: CompositeTimeScale,
160
- ): NormalizedSourcePoint[] {
161
- const effectiveTimes = timeScale?.kind === "market" && !isMarketObservationSeries(series);
162
- const last = series.points[series.points.length - 1];
163
- const lastTimestamp = last ? pointTime(last) : null;
164
- const lastValue = last ? resolveTimeSeriesPointValue(last) : null;
165
- let cached = normalizedPointsCache.get(series);
166
- if (
167
- !cached
168
- || cached.points !== series.points
169
- || cached.pointCount !== series.points.length
170
- || cached.last !== last
171
- || cached.lastTimestamp !== lastTimestamp
172
- || cached.lastValue !== lastValue
173
- ) {
174
- cached = {
175
- points: series.points,
176
- pointCount: series.points.length,
177
- last,
178
- lastTimestamp,
179
- lastValue,
180
- byPlacement: new Map(),
181
- };
182
- normalizedPointsCache.set(series, cached);
183
- }
184
- let normalized = cached.byPlacement.get(effectiveTimes);
185
- if (!normalized) {
186
- normalized = computeNormalizedSourcePoints(series, timeScale);
187
- cached.byPlacement.set(effectiveTimes, normalized);
188
- }
189
- return normalized;
190
- }
191
-
192
- function hasDrawableValue(series: ResolvedSeries): boolean {
193
- return normalizedSourcePoints(series).some((entry) => entry.value !== null);
194
- }
195
-
196
- /**
197
- * The sorted union of timestamp lists that are each sorted, as
198
- * `[...new Set(lists.flat())].sort()` gives it, merged in one pass.
199
- */
200
- function mergeSortedTimestamps(lists: readonly (readonly number[])[]): number[] {
201
- let merged: number[] = [];
202
- for (const list of lists) {
203
- const next: number[] = [];
204
- let left = 0;
205
- let right = 0;
206
- while (left < merged.length || right < list.length) {
207
- const fromLeft = right >= list.length || (left < merged.length && merged[left]! <= list[right]!);
208
- const value = fromLeft ? merged[left++]! : list[right++]!;
209
- if (next.length === 0 || next[next.length - 1] !== value) next.push(value);
210
- }
211
- merged = next;
212
- }
213
- return merged;
214
- }
215
-
216
- function timestampsOf(points: readonly NormalizedSourcePoint[]): number[] {
217
- const timestamps = new Array<number>(points.length);
218
- for (let index = 0; index < points.length; index += 1) timestamps[index] = points[index]!.timestamp;
219
- return timestamps;
220
- }
221
-
222
- function explicitViewport(
223
- options: BuildCompositeChartSceneOptions,
224
- ): { startTime: number; endTime: number } | null {
225
- const startTime = options.viewport?.start.getTime();
226
- const endTime = options.viewport?.end.getTime();
227
- return isFiniteNumber(startTime) && isFiniteNumber(endTime) && startTime <= endTime
228
- ? { startTime, endTime }
229
- : null;
230
- }
231
-
232
- function scopeSeriesToViewport(
233
- series: ResolvedSeries,
234
- startTime: number,
235
- endTime: number,
236
- timeScale: CompositeTimeScale,
237
- clipToViewport: boolean,
238
- ): ResolvedSeries | null {
239
- const points = normalizedSourcePoints(series, timeScale);
240
- const placement = timeScale.kind === "market" && !isMarketObservationSeries(series)
241
- ? "next-market-slot" as const
242
- : "timestamp" as const;
243
- const project = compositeTimeProjector(timeScale, placement);
244
- const visible = points.filter(({ timestamp }) => {
245
- if (timestamp >= startTime && timestamp <= endTime) return true;
246
- if (clipToViewport) return false;
247
- const projected = project(timestamp);
248
- return !!projected && projected.ratio >= 0 && projected.ratio <= 1;
249
- });
250
- if (series.interpolation === "step-after" || series.style === "step") {
251
- const anchor = points.some(({ timestamp }) => timestamp === startTime) ? undefined
252
- : [...points].reverse().find(({ timestamp }) => timestamp < startTime);
253
- if (anchor && !visible.includes(anchor)) visible.unshift(anchor);
254
- }
255
- return visible.some(({ value }) => value !== null)
256
- ? { ...series, points: visible.map(({ point }) => point) }
257
- : null;
258
- }
259
-
260
- function panelSpecsForSeries(series: ResolvedSeries[], panels: ChartPanelSpec[]): ChartPanelSpec[] {
261
- const visiblePanelIds = new Set(series.map((entry) => entry.panelId));
262
- const ordered = panels.filter((panel) => visiblePanelIds.has(panel.id));
263
- const knownIds = new Set(ordered.map((panel) => panel.id));
264
- for (const entry of series) {
265
- if (knownIds.has(entry.panelId)) continue;
266
- knownIds.add(entry.panelId);
267
- ordered.push({ id: entry.panelId });
268
- }
269
- return ordered;
270
- }
271
-
272
- export function allocateCompositePanelHeights(
273
- panels: ChartPanelSpec[],
274
- availableHeight: number,
275
- ): Map<string, number> {
276
- const heights = new Map<string, number>();
277
- if (panels.length === 0) return heights;
278
-
279
- const totalHeight = Math.max(panels.length, Math.floor(availableHeight));
280
- const weights = panels.map((panel) => (
281
- isFiniteNumber(panel.height) && panel.height > 0 ? panel.height : 1
282
- ));
283
- const totalWeight = weights.reduce((sum, weight) => sum + weight, 0) || panels.length;
284
- const quotas = weights.map((weight) => (weight / totalWeight) * totalHeight);
285
- const allocations = quotas.map((quota) => Math.max(1, Math.floor(quota)));
286
- let allocated = allocations.reduce((sum, value) => sum + value, 0);
287
-
288
- while (allocated < totalHeight) {
289
- let index = 0;
290
- for (let candidate = 1; candidate < allocations.length; candidate += 1) {
291
- if (quotas[candidate]! - allocations[candidate]!
292
- > quotas[index]! - allocations[index]!) {
293
- index = candidate;
294
- }
295
- }
296
- allocations[index] = (allocations[index] ?? 0) + 1;
297
- allocated += 1;
298
- }
299
- while (allocated > totalHeight) {
300
- let index = -1;
301
- for (let candidate = 0; candidate < allocations.length; candidate += 1) {
302
- if (allocations[candidate]! <= 1) continue;
303
- if (index < 0 || allocations[candidate]! - quotas[candidate]!
304
- > allocations[index]! - quotas[index]!) {
305
- index = candidate;
306
- }
307
- }
308
- if (index < 0) break;
309
- allocations[index] = allocations[index]! - 1;
310
- allocated -= 1;
311
- }
312
-
313
- panels.forEach((panel, index) => heights.set(panel.id, allocations[index] ?? 1));
314
- return heights;
315
- }
316
-
317
- /**
318
- * The extremes of a set of values, of all of them and of the positive ones a
319
- * log axis can show, gathered without keeping the values.
320
- */
321
- interface DomainExtent {
322
- count: number;
323
- min: number;
324
- max: number;
325
- positiveCount: number;
326
- positiveMin: number;
327
- positiveMax: number;
328
- }
329
-
330
- function emptyDomainExtent(): DomainExtent {
331
- return {
332
- count: 0,
333
- min: Number.POSITIVE_INFINITY,
334
- max: Number.NEGATIVE_INFINITY,
335
- positiveCount: 0,
336
- positiveMin: Number.POSITIVE_INFINITY,
337
- positiveMax: Number.NEGATIVE_INFINITY,
338
- };
339
- }
340
-
341
- function addDomainValue(extent: DomainExtent, value: number): void {
342
- extent.count += 1;
343
- extent.min = Math.min(extent.min, value);
344
- extent.max = Math.max(extent.max, value);
345
- if (value > 0) {
346
- extent.positiveCount += 1;
347
- extent.positiveMin = Math.min(extent.positiveMin, value);
348
- extent.positiveMax = Math.max(extent.positiveMax, value);
349
- }
350
- }
351
-
352
- /** Every value a series holds its axis open for: its points, their bar extremes or band, and zero under columns. */
353
- function addSeriesDomainValues(extent: DomainExtent, series: ResolvedSeries): void {
354
- const ohlc = series.dataShape === "ohlcv";
355
- const band = !ohlc && series.style === "band";
356
- for (const point of series.points) {
357
- const scalar = resolveTimeSeriesPointValue(point);
358
- if (scalar !== null) addDomainValue(extent, scalar);
359
- if (ohlc) {
360
- if (isFiniteNumber(point.open)) addDomainValue(extent, point.open);
361
- if (isFiniteNumber(point.high)) addDomainValue(extent, point.high);
362
- if (isFiniteNumber(point.low)) addDomainValue(extent, point.low);
363
- if (isFiniteNumber(point.close)) addDomainValue(extent, point.close);
364
- } else if (band) {
365
- if (isFiniteNumber(point.high)) addDomainValue(extent, point.high);
366
- if (isFiniteNumber(point.low)) addDomainValue(extent, point.low);
367
- }
368
- }
369
- if (series.style === "columns") addDomainValue(extent, 0);
370
- }
371
-
372
- function paddedDomain(extent: DomainExtent, scale: PanelScale): { min: number; max: number } {
373
- const usable = scale === "log" ? extent.positiveCount : extent.count;
374
- if (usable === 0) return scale === "log" ? { min: 1, max: 10 } : { min: 0, max: 1 };
375
-
376
- const rawMin = scale === "log" ? extent.positiveMin : extent.min;
377
- const rawMax = scale === "log" ? extent.positiveMax : extent.max;
378
- if (rawMin === rawMax) {
379
- if (scale === "log") {
380
- return { min: rawMin / 1.1, max: rawMax * 1.1 };
381
- }
382
- // All zero, as in a session without reported volume, sits on the floor.
383
- if (rawMin === 0) return { min: 0, max: 1 };
384
- const delta = Math.max(Math.abs(rawMin) * 0.08, 1);
385
- return signBounded(rawMin, rawMax, { min: rawMin - delta, max: rawMax + delta });
386
- }
387
-
388
- if (scale === "log") {
389
- const logMin = Math.log(rawMin);
390
- const logMax = Math.log(rawMax);
391
- const padding = (logMax - logMin) * 0.06;
392
- return { min: Math.exp(logMin - padding), max: Math.exp(logMax + padding) };
393
- }
394
-
395
- const padding = (rawMax - rawMin) * 0.06;
396
- return signBounded(rawMin, rawMax, { min: rawMin - padding, max: rawMax + padding });
397
- }
398
-
399
- /** Headroom never pushes one-signed values across zero: a price or volume
400
- * axis does not reach below 0. */
401
- function signBounded(rawMin: number, rawMax: number, padded: { min: number; max: number }): { min: number; max: number } {
402
- return {
403
- min: rawMin >= 0 ? Math.max(0, padded.min) : padded.min,
404
- max: rawMax <= 0 ? Math.min(0, padded.max) : padded.max,
405
- };
406
- }
407
-
408
- function axisPriceReferences(axisSeries: ResolvedSeries[]): Record<string, number> {
409
- const references: Record<string, number> = {};
410
- for (const entry of axisSeries) {
411
- const key = entry.priceAssetCategory ?? "";
412
- if (key in references) continue;
413
- const value = seriesPriceReference(entry);
414
- if (value !== undefined) references[key] = value;
415
- }
416
- return references;
417
- }
418
-
419
- /**
420
- * A one-day chart's previous close joins the axis when it lies within one
421
- * session range of the bars, so a quiet session still shows where it opened
422
- * from; a far gap leaves the bars their full height.
423
- */
424
- function priorCloseInReach(series: readonly ResolvedSeries[], values: DomainExtent): number[] {
425
- const reference = series.find((entry) => isFiniteNumber(entry.priorClose) && entry.points.length > 0)?.priorClose;
426
- if (reference === undefined || values.count === 0) return [];
427
- const low = values.min;
428
- const high = values.max;
429
- const span = high - low;
430
- return reference >= low - span && reference <= high + span ? [reference] : [];
431
- }
432
-
433
- function buildAxisDomain(
434
- side: CompositeAxisSide,
435
- series: ResolvedSeries[],
436
- scale: PanelScale,
437
- rows: number,
438
- manualScale?: CompositeManualValueScale,
439
- referenceLevels?: BuildCompositeChartSceneOptions["referenceLevels"],
440
- ): CompositeAxisDomain | undefined {
441
- const axisSeries = series.filter((entry) => entry.axis === side);
442
- if (axisSeries.length === 0) return undefined;
443
- const values = emptyDomainExtent();
444
- for (const entry of axisSeries) addSeriesDomainValues(values, entry);
445
- const references = referenceLevels && axisSeries.some((entry) => entry.id === referenceLevels.seriesId)
446
- ? referenceLevels.items.map((level) => level.value).filter(Number.isFinite)
447
- : [];
448
- const extra = [...priorCloseInReach(axisSeries, values), ...references];
449
- const fitted = paddedDomain(extra.length === 0 ? values : extra.reduce((extent, value) => {
450
- addDomainValue(extent, value);
451
- return extent;
452
- }, { ...values }), scale);
453
- const scaleKey = valueScaleKey(scale, axisSeries);
454
- // A range set by hand holds while the axis plots the same series and some
455
- // of their data is in it; otherwise the axis fits the data again.
456
- const manual = manualScale && manualScale.key === scaleKey && manualValueRangeApplies(manualScale, fitted, scale)
457
- ? manualScale
458
- : null;
459
- const { min, max } = manual ?? fitted;
460
- const first = axisSeries[0]!;
461
- return {
462
- side,
463
- min,
464
- max,
465
- scale,
466
- unit: first.unit,
467
- unitGroup: first.unitGroup,
468
- priceAssetCategories: [...new Set(axisSeries.flatMap((entry) => entry.priceAssetCategory ? [entry.priceAssetCategory] : []))],
469
- priceReferences: axisPriceReferences(axisSeries),
470
- seriesIds: axisSeries.map((entry) => entry.id),
471
- maxTicks: compositeAxisMaxTicks(rows),
472
- tickRows: rows,
473
- ...(first.tickGrid ? { tickGrid: first.tickGrid } : {}),
474
- scaleKey,
475
- ...(manual ? { manual: true } : {}),
476
- };
477
- }
478
-
479
- /** A panel laid out at another height keeps as many axis ticks as it can
480
- * label. Hosts that place labels at exact heights drop the row snapping. */
481
- export function resizeCompositePanel(
482
- panel: CompositePanelScene,
483
- height: number,
484
- snapTicksToRows = true,
485
- ): CompositePanelScene {
486
- const maxTicks = compositeAxisMaxTicks(height);
487
- const tickRows = snapTicksToRows ? height : undefined;
488
- const fits = (domain: CompositeAxisDomain) => domain.maxTicks === maxTicks && domain.tickRows === tickRows;
489
- if (panel.height === height && (["left", "right"] as const).every((side) => !panel.axes[side] || fits(panel.axes[side]!))) {
490
- return panel;
491
- }
492
- const axes: CompositePanelScene["axes"] = {};
493
- for (const side of ["left", "right"] as const) {
494
- const domain = panel.axes[side];
495
- if (domain) axes[side] = fits(domain) ? domain : { ...domain, maxTicks, tickRows };
496
- }
497
- return { ...panel, height, axes };
498
- }
499
-
500
- export function projectCompositeValue(value: number, domain: CompositeAxisDomain): number | null {
501
- if (!Number.isFinite(value)) return null;
502
- if (domain.scale === "log") {
503
- if (value <= 0 || domain.min <= 0 || domain.max <= 0) return null;
504
- const span = Math.log(domain.max) - Math.log(domain.min);
505
- return span === 0 ? 0.5 : 1 - (Math.log(value) - Math.log(domain.min)) / span;
506
- }
507
- const span = domain.max - domain.min;
508
- return span === 0 ? 0.5 : 1 - (value - domain.min) / span;
509
- }
510
-
511
- export function unprojectCompositeValue(
512
- yRatio: number,
513
- domain: CompositeAxisDomain,
514
- ): number | null {
515
- if (
516
- !Number.isFinite(yRatio)
517
- || !Number.isFinite(domain.min)
518
- || !Number.isFinite(domain.max)
519
- ) {
520
- return null;
521
- }
522
- const ratio = Math.max(0, Math.min(1, yRatio));
523
- if (domain.scale === "log") {
524
- if (domain.min <= 0 || domain.max <= 0) return null;
525
- return Math.exp(
526
- Math.log(domain.max)
527
- + (Math.log(domain.min) - Math.log(domain.max)) * ratio,
528
- );
529
- }
530
- return domain.max + (domain.min - domain.max) * ratio;
531
- }
532
-
533
- function projectSeries(
534
- series: ResolvedSeries,
535
- domain: CompositeAxisDomain,
536
- startTime: number,
537
- /** Where a step series holds its last level to, never past the newest bar. */
538
- stepEndTime: number,
539
- timeScale: CompositeTimeScale,
540
- ): CompositeProjectedPoint[] {
541
- const projected: CompositeProjectedPoint[] = [];
542
- let breakBefore = true;
543
- const placement = timeScale.kind === "market" && !isMarketObservationSeries(series)
544
- ? "next-market-slot" as const
545
- : "timestamp" as const;
546
- const stepSeries = series.interpolation === "step-after" || series.style === "step";
547
- const project = compositeTimeProjector(timeScale, placement);
548
- for (const { point, timestamp, value } of normalizedSourcePoints(series, timeScale)) {
549
- if (value === null) {
550
- breakBefore = true;
551
- continue;
552
- }
553
- const yRatio = projectCompositeValue(value, domain);
554
- if (yRatio === null) {
555
- breakBefore = true;
556
- continue;
557
- }
558
- const projectedTime = project(timestamp);
559
- if (!projectedTime) continue;
560
- const beforeViewportStepAnchor = stepSeries
561
- && timestamp < startTime
562
- && projectedTime.ratio < 0;
563
- if (!beforeViewportStepAnchor && (projectedTime.ratio < 0 || projectedTime.ratio > 1)) {
564
- continue;
565
- }
566
- projected.push({
567
- point,
568
- timestamp: beforeViewportStepAnchor ? startTime : timestamp,
569
- value,
570
- xRatio: beforeViewportStepAnchor ? 0 : projectedTime.ratio,
571
- xSlot: beforeViewportStepAnchor ? undefined : projectedTime.xSlot,
572
- yRatio,
573
- breakBefore,
574
- });
575
- breakBefore = false;
576
- }
577
- if (stepSeries && projected.length > 0) {
578
- const last = projected.at(-1)!;
579
- const trailingGap = normalizedSourcePoints(series, timeScale).some(({ timestamp, value }) => (
580
- timestamp > last.timestamp && timestamp <= stepEndTime
581
- && (value === null || projectCompositeValue(value, domain) === null)
582
- ));
583
- // The synthetic tail is a level, not an observation, so it lands on its own
584
- // timestamp rather than snapping forward to the next trading slot.
585
- const trailingRatio = projectCompositeTimestamp(timeScale, stepEndTime)?.ratio;
586
- if (last.timestamp < stepEndTime && !trailingGap && trailingRatio !== undefined) {
587
- projected.push({
588
- ...last,
589
- timestamp: stepEndTime,
590
- xRatio: Math.min(trailingRatio, 1),
591
- xSlot: undefined,
592
- breakBefore: false,
593
- });
594
- }
595
- }
596
- return projected;
597
- }
598
-
599
- /**
600
- * Unit groups a price can wear, raw or transformed. Volume, oscillators and
601
- * other derived study outputs are deliberately absent: a level line there
602
- * would mark a quantity that has no last price to read.
603
- */
604
- const PRICE_UNIT_GROUPS = /^(?:price|currency|percent|index|log)(?::|$)/;
605
-
606
- /**
607
- * The chart's primary price series: the first exchange-traded price, in
608
- * authored order. Study outputs are appended after the series they derive
609
- * from, so an overlay indicator never wins over the price it follows.
610
- */
611
- function primaryPriceSeries(series: readonly ResolvedSeries[]): ResolvedSeries | null {
612
- return series.find((entry) => (
613
- entry.timeBasis?.kind === "market"
614
- && PRICE_UNIT_GROUPS.test(entry.unitGroup.toLowerCase())
615
- )) ?? null;
616
- }
617
-
618
- function lastCloseOf(points: readonly CompositeProjectedPoint[], heikinAshi = false): number | null {
619
- const last = points.at(-1);
620
- if (!last) return null;
621
- // A Heikin Ashi close is an average; the marker names the price that traded.
622
- if (heikinAshi && isFiniteNumber(last.point.rawValue)) return last.point.rawValue;
623
- return isFiniteNumber(last.point.close) ? last.point.close : last.value;
624
- }
625
-
626
- /** Marks the newest close of the primary price series on the panel that draws it. */
627
- function attachLastPriceMarker(
628
- panels: CompositePanelScene[],
629
- series: readonly ResolvedSeries[],
630
- ): void {
631
- const primary = primaryPriceSeries(series);
632
- if (!primary) return;
633
- const panel = panels.find((entry) => entry.id === primary.panelId);
634
- const projected = panel?.series.find((entry) => entry.source.id === primary.id);
635
- const domain = panel?.axes[primary.axis];
636
- if (!panel || !projected || !domain) return;
637
- // A rejected or missing latest bar cannot make an older close current.
638
- const latest = normalizedSourcePoints(primary).at(-1);
639
- if (latest?.point.provenance?.priceHistoryIntegrity || latest?.value === null) return;
640
- const value = lastCloseOf(projected.points, primary.style === "heikin-ashi");
641
- if (value === null) return;
642
- const yRatio = projectCompositeValue(value, domain);
643
- // An axis scaled by hand can leave the last close off the panel.
644
- if (yRatio === null || (domain.manual && (yRatio < 0 || yRatio > 1))) return;
645
- panel.lastPrice = {
646
- seriesId: primary.id,
647
- color: primary.color,
648
- axis: primary.axis,
649
- value,
650
- yRatio,
651
- };
652
- }
653
-
654
- /** Marks the previous session's close a one-day chart carries on its price series. */
655
- function attachPriorClose(panels: CompositePanelScene[], series: readonly ResolvedSeries[]): void {
656
- const entry = series.find((candidate) => isFiniteNumber(candidate.priorClose));
657
- const panel = entry ? panels.find((candidate) => candidate.id === entry.panelId) : undefined;
658
- const domain = entry ? panel?.axes[entry.axis] : undefined;
659
- if (!entry || !panel || !domain || !panel.series.some((candidate) => candidate.source.id === entry.id)) return;
660
- const yRatio = projectCompositeValue(entry.priorClose!, domain);
661
- // Off the axis it marks nothing; the axis follows the session's own bars.
662
- if (yRatio === null || yRatio < 0 || yRatio > 1) return;
663
- panel.priorClose = { axis: entry.axis, value: entry.priorClose!, yRatio };
664
- }
665
-
666
- /**
667
- * The zone intraday market bars read in: the venue's own clock, as the tape
668
- * does. Daily and longer bars carry dates, which stay in UTC.
669
- */
670
- function sceneTimeZone(anchor: ResolvedSeries | undefined, series: readonly ResolvedSeries[]): string | undefined {
671
- const market = anchor ?? series.find((entry) => entry.observationKind === "market");
672
- if (!market || !isIntradaySeries(market)) return undefined;
673
- const zone = market.timeBasis?.timeZone
674
- ?? (market.listing ? listingTimeZone(market.listing.symbol, market.listing.exchange) : null);
675
- return zone && zone !== "UTC" ? zone : undefined;
676
- }
677
-
678
- /**
679
- * Profiles a volume-profile study over its bars in view and takes its points
680
- * off the panel, so it draws as a histogram rather than a line or cursor dots.
681
- */
682
- function attachVolumeProfile(panel: CompositePanelScene): void {
683
- const entry = panel.series.find((series) => series.source.profile);
684
- const domain = entry ? panel.axes[entry.source.axis] : undefined;
685
- if (!entry || !domain) return;
686
- const bars = entry.points.flatMap(({ point, value }) => {
687
- const close = isFiniteNumber(point.close) ? point.close : value;
688
- const volume = point.volume;
689
- if (!isFiniteNumber(volume)) return [];
690
- return [{
691
- time: point.date.getTime(),
692
- high: isFiniteNumber(point.high) ? point.high : close,
693
- low: isFiniteNumber(point.low) ? point.low : close,
694
- close,
695
- volume,
696
- }];
697
- });
698
- entry.points = [];
699
- const profile = volumeProfile(bars, entry.source.profile!.rows);
700
- const pocRatio = profile ? projectCompositeValue(profile.poc, domain) : null;
701
- if (!profile || pocRatio === null) return;
702
- panel.volumeProfile = {
703
- seriesId: entry.source.id,
704
- color: entry.source.color,
705
- rows: profile.rows.flatMap((row) => {
706
- const lowRatio = projectCompositeValue(row.low, domain);
707
- const highRatio = projectCompositeValue(row.high, domain);
708
- return lowRatio === null || highRatio === null
709
- ? []
710
- : [{ lowRatio, highRatio, volume: row.volume, valueArea: row.valueArea }];
711
- }),
712
- maxVolume: profile.maxVolume,
713
- poc: profile.poc,
714
- pocRatio,
715
- };
716
- }
717
-
718
- function nearestDate(dates: Date[], requested: Date): Date | null {
719
- const target = requested.getTime();
720
- if (!Number.isFinite(target) || dates.length === 0) return null;
721
- let low = 0;
722
- let high = dates.length;
723
- while (low < high) {
724
- const middle = low + Math.floor((high - low) / 2);
725
- if (dates[middle]!.getTime() < target) low = middle + 1;
726
- else high = middle;
727
- }
728
- const next = dates[low] ?? null;
729
- const previous = dates[low - 1] ?? null;
730
- if (!previous) return next;
731
- if (!next) return previous;
732
- return target - previous.getTime() <= next.getTime() - target ? previous : next;
733
- }
734
-
735
- function cursorPointForSeries(
736
- series: CompositePanelScene["series"][number],
737
- cursorTime: number,
738
- ): CompositeProjectedPoint | null {
739
- const points = series.points;
740
- if (points.length === 0) return null;
741
-
742
- let low = 0;
743
- let high = points.length;
744
- while (low < high) {
745
- const middle = low + Math.floor((high - low) / 2);
746
- if (points[middle]!.timestamp <= cursorTime) low = middle + 1;
747
- else high = middle;
748
- }
749
- return points[low - 1] ?? null;
750
- }
751
-
752
- /**
753
- * The latest unavailable observation at or before the cursor and after the
754
- * value it reads there, which ends that value. Points are in time order, so
755
- * the search stops at the first one older than that value.
756
- */
757
- function gapAfterCursorValue(
758
- points: readonly NormalizedSourcePoint[],
759
- cursorTime: number,
760
- projected: CompositeProjectedPoint | null,
761
- ): NormalizedSourcePoint | undefined {
762
- const after = projected?.timestamp ?? Number.NEGATIVE_INFINITY;
763
- for (let index = points.length - 1; index >= 0; index -= 1) {
764
- const entry = points[index]!;
765
- const { timestamp, point, value } = entry;
766
- if (timestamp < after) return undefined;
767
- if (timestamp > cursorTime) continue;
768
- const later = timestamp > after || (timestamp === projected?.timestamp && point.observedAt > projected.point.observedAt);
769
- if (later && (point.provenance?.priceHistoryIntegrity || value === null)) return entry;
770
- }
771
- return undefined;
772
- }
773
-
774
- function buildCursorValues(
775
- panels: CompositePanelScene[],
776
- cursorDate: Date | null,
777
- viewport: Pick<CompositeChartScene, "startTime" | "endTime" | "timeScale">,
778
- ): CompositeCursorValue[] {
779
- const cursorTime = cursorDate?.getTime() ?? viewport.endTime;
780
- return panels.flatMap((panel) => panel.series.map((entry) => {
781
- // A profile reads the same wherever the cursor is: its point of control.
782
- if (entry.source.profile) {
783
- return {
784
- seriesId: entry.source.id,
785
- label: entry.source.label,
786
- color: entry.source.color,
787
- unit: entry.source.unit,
788
- value: panel.volumeProfile?.seriesId === entry.source.id ? panel.volumeProfile.poc : null,
789
- point: null,
790
- };
791
- }
792
- let projected = cursorPointForSeries(entry, cursorTime);
793
- // Sparse observations can carry forward, but an explicitly unavailable
794
- // observation ends that value at its date, including the idle legend.
795
- const gap = gapAfterCursorValue(normalizedSourcePoints(entry.source, viewport.timeScale), cursorTime, projected);
796
- if (gap) projected = null;
797
- // The drawn navigation buffer can include observations after the chosen
798
- // end. An unarmed legend describes the active window, including when the
799
- // pointer leaves; explicitly inspected cursor dates keep their own behavior.
800
- if (!cursorDate && projected && projected.timestamp < viewport.startTime) projected = null;
801
- return {
802
- seriesId: entry.source.id,
803
- label: entry.source.label,
804
- color: entry.source.color,
805
- unit: entry.source.unit,
806
- value: projected?.value ?? null,
807
- point: projected?.point ?? gap?.point ?? null,
808
- ...(cursorDate && projected && projected.timestamp < cursorTime ? { carried: true } : {}),
809
- };
810
- }));
811
- }
812
-
813
- /**
814
- * The bar a time from another chart lands on: the last one at or before it,
815
- * as a bar stands for the time from its open until the next. A time before
816
- * the first bar in view lands on none, and so does one past the plot's right
817
- * edge while the chart is panned back from its newest bar, rather than
818
- * pinning the cursor to an edge the time is not at. A chart showing its
819
- * newest bar lands any later time on it, so a monthly series still reads its
820
- * latest month on a day after it.
821
- */
822
- function linkedCursorDate(scene: CompositeChartScene, requested: Date): Date | null {
823
- const target = requested.getTime();
824
- const { dates, timeScale } = scene;
825
- if (!Number.isFinite(target) || dates.length === 0) return null;
826
- const plotEnd = unprojectCompositeTimestamp(timeScale, 1);
827
- const newest = timeScale.kind === "market" ? timeScale.anchors.at(-1)?.timestamp : scene.newestTime;
828
- if (target > plotEnd && (newest === undefined || newest > plotEnd)) return null;
829
- let low = 0;
830
- let high = dates.length;
831
- while (low < high) {
832
- const middle = low + Math.floor((high - low) / 2);
833
- if (dates[middle]!.getTime() <= target) low = middle + 1;
834
- else high = middle;
835
- }
836
- return dates[low - 1] ?? null;
837
- }
838
-
839
- /** The bar another chart's cursor time lands on (see `linkedCursorDate`), as its timestamp. */
840
- export function compositeLinkedCursorTime(scene: CompositeChartScene, time: number): number | null {
841
- return linkedCursorDate(scene, new Date(time))?.getTime() ?? null;
842
- }
843
-
844
- /**
845
- * The last instant of the bar a cursor is on, which is the time it is shared
846
- * at: a bar stands until the next one or its own interval ends, whichever is
847
- * first. Another chart then lands on its last bar at or before it, so a daily
848
- * cursor shows the day's last intraday bar, whose close is the day's, and an
849
- * intraday cursor shows its own day's bar rather than the next one's. On
850
- * calendar time the newest bar, with no next one, stands as long as the one
851
- * before it did, so a series' latest month lands a daily chart on that
852
- * month's latest day rather than its first.
853
- */
854
- export function compositeCursorAsOf(scene: CompositeChartScene, date: Date): number {
855
- const start = date.getTime();
856
- const next = scene.dates.find((entry) => entry.getTime() > start)?.getTime() ?? Number.POSITIVE_INFINITY;
857
- const previous = scene.dates.findLast((entry) => entry.getTime() < start)?.getTime();
858
- const intervalEnd = scene.timeScale.kind === "market" ? start + scene.timeScale.cadenceMs
859
- : next === Number.POSITIVE_INFINITY && previous !== undefined ? start + (start - previous)
860
- : Number.POSITIVE_INFINITY;
861
- const end = Math.min(next, intervalEnd);
862
- return Number.isFinite(end) ? end - 1 : start;
863
- }
864
-
865
- /**
866
- * Applies cursor-only state without rebuilding panel domains or projected
867
- * series. Keeping those references stable lets renderers reuse the expensive
868
- * base chart while the cursor moves. `linked` places a time another chart's
869
- * cursor is at (see `linkedCursorDate`); otherwise the cursor goes to the
870
- * nearest bar.
871
- */
872
- export function applyCompositeChartCursor(
873
- scene: CompositeChartScene,
874
- requestedCursor: Date | null,
875
- snap: "nearest" | "linked" = "nearest",
876
- ): CompositeChartScene {
877
- const cursorDate = !requestedCursor ? null
878
- : snap === "linked" ? linkedCursorDate(scene, requestedCursor)
879
- : nearestDate(scene.dates, requestedCursor);
880
- const currentTimestamp = scene.cursorDate?.getTime() ?? null;
881
- const nextTimestamp = cursorDate?.getTime() ?? null;
882
- if (currentTimestamp === nextTimestamp) return scene;
883
-
884
- const cursorXRatio = cursorDate
885
- ? projectCompositeTimestamp(scene.timeScale, cursorDate.getTime())?.ratio ?? null
886
- : null;
887
- return {
888
- ...scene,
889
- cursorDate,
890
- cursorXRatio,
891
- cursorValues: buildCursorValues(scene.cursorPanels ?? scene.panels, cursorDate, scene),
892
- };
893
- }
894
-
895
- export function buildCompositeChartScene(
896
- series: ResolvedSeries[],
897
- panels: ChartPanelSpec[],
898
- options: BuildCompositeChartSceneOptions,
899
- ): CompositeChartScene | null {
900
- const dataSeries = series
901
- .map((entry) => entry.style === "heikin-ashi" ? { ...entry, points: heikinAshiPoints(entry.points) } : entry)
902
- .filter(hasDrawableValue);
903
- if (dataSeries.length === 0) return null;
904
-
905
- // A known missing observation owns a date even though it has no drawable
906
- // value. Retain it in the window and cursor timeline, including trailing gaps.
907
- const uniqueTimes = mergeSortedTimestamps(dataSeries.map((entry) => timestampsOf(normalizedSourcePoints(entry))));
908
- if (uniqueTimes.length === 0) return null;
909
- const firstTime = uniqueTimes[0]!;
910
- const lastTime = uniqueTimes.at(-1)!;
911
- const viewport = explicitViewport(options);
912
- const startTime = viewport?.startTime ?? (firstTime === lastTime ? firstTime - DAY_MS / 2 : firstTime);
913
- const endTime = viewport?.endTime ?? (firstTime === lastTime ? lastTime + DAY_MS / 2 : lastTime);
914
- const timelineSeries = options.timelineSeries?.some((entry) => (
915
- entry.timeBasis?.kind === "market" && entry.points.length > 0
916
- )) ? options.timelineSeries : dataSeries;
917
- const timeScale = buildCompositeTimeScale(
918
- timelineSeries,
919
- startTime,
920
- endTime,
921
- options.rightOffsetRatio ?? COMPOSITE_RIGHT_OFFSET_RATIO,
922
- );
923
- // The plot reaches past the viewport by the reserved right offset. Panned
924
- // back into history that space holds real observations, so navigation and
925
- // the cursor follow the drawn edge rather than the viewport end.
926
- const plotEndTime = options.clipToViewport ? endTime : Math.max(endTime, unprojectCompositeTimestamp(timeScale, 1));
927
- // A step holds its level to the newest observation and no further: the space
928
- // reserved after it stays empty. With data still ahead of the window, the
929
- // level runs to the drawn edge instead.
930
- const stepTrailingTime = Math.min(plotEndTime, Math.max(lastTime, endTime));
931
- const scopedSeries = viewport
932
- ? dataSeries.flatMap((entry) => scopeSeriesToViewport(entry, startTime, endTime, timeScale, options.clipToViewport === true) ?? [])
933
- : dataSeries;
934
- // A range without observations still has a chart: keep the panels, axes and
935
- // grid and simply draw no points, instead of blanking the whole surface.
936
- const emptyRange = scopedSeries.length === 0;
937
- const usableSeries = emptyRange
938
- ? dataSeries.map((entry) => ({ ...entry, points: [] }))
939
- : scopedSeries;
940
- const visibleTimes = uniqueTimes.filter((time) => time >= startTime && time <= plotEndTime);
941
- const marketTimes = timeScale.kind === "market"
942
- // The first market controls session spacing, but every plotted market
943
- // observation must remain inspectable. Other exchanges can trade before
944
- // or after its anchors. Nonmarket source dates stay excluded: filings
945
- // retain their availability-based placement on eligible market slots.
946
- ? mergeSortedTimestamps([
947
- timeScale.anchors.map(({ timestamp }) => timestamp),
948
- ...scopedSeries.filter(isMarketObservationSeries)
949
- .map((entry) => timestampsOf(normalizedSourcePoints(entry)
950
- .filter(({ value, point }) => value !== null || point.provenance?.priceHistoryIntegrity))),
951
- ]).filter((time) => time >= startTime && time <= plotEndTime)
952
- : [];
953
- const cursorTimes = timeScale.kind === "market" ? marketTimes : visibleTimes;
954
- const dates = (cursorTimes.length > 0
955
- ? cursorTimes
956
- : viewport
957
- ? [...new Set([startTime, endTime])]
958
- : uniqueTimes
959
- ).map((time) => new Date(time));
960
- const projectDate = compositeTimeProjector(timeScale);
961
- const dateRatios = dates.map((date) => projectDate(date.getTime())?.ratio ?? 0);
962
- const requestedCursor = options.cursorDate ?? null;
963
- const cursorDate = requestedCursor ? nearestDate(dates, requestedCursor) : null;
964
- const cursorXRatio = cursorDate
965
- ? projectCompositeTimestamp(timeScale, cursorDate.getTime())?.ratio ?? null
966
- : null;
967
- // Panels belong to the authored series, not to whichever of them happen to
968
- // hold observations right now. A panel that disappears while its data loads
969
- // reflows every other panel, and the chart jumps again when it comes back.
970
- const anchor = timeScale.kind === "market"
971
- ? timelineSeries.find((entry) => entry.id === timeScale.anchorSeriesId)
972
- : timelineSeries.find((entry) => entry.timeBasis?.kind === "market");
973
- const extendedHours = extendedHoursSpans(anchor, dates, dateRatios);
974
- const orderedPanels = panelSpecsForSeries(series, panels);
975
- const panelHeights = allocateCompositePanelHeights(orderedPanels, options.height);
976
-
977
- const panelScenes: CompositePanelScene[] = orderedPanels.map((panel) => {
978
- const panelSeries = usableSeries.filter((entry) => entry.panelId === panel.id);
979
- const scale = panel.scale ?? "linear";
980
- // With no in-view values, scale the axes to the loaded history rather than
981
- // the meaningless 0..1 fallback, so the panel keeps its gutter and grid.
982
- const domainSeries = emptyRange || panelSeries.length === 0
983
- ? dataSeries.filter((entry) => entry.panelId === panel.id)
984
- : panelSeries;
985
- const rows = panelHeights.get(panel.id) ?? 1;
986
- const left = buildAxisDomain("left", domainSeries, scale, rows, options.valueScales?.[valueScaleSlot(panel.id, "left")], options.referenceLevels);
987
- const right = buildAxisDomain("right", domainSeries, scale, rows, options.valueScales?.[valueScaleSlot(panel.id, "right")], options.referenceLevels);
988
- const axes: Partial<Record<CompositeAxisSide, CompositeAxisDomain>> = { left, right };
989
- return {
990
- id: panel.id,
991
- label: panel.label,
992
- height: panelHeights.get(panel.id) ?? 1,
993
- scale,
994
- axes,
995
- ...(extendedHours.length > 0 ? { extendedHours } : {}),
996
- series: panelSeries.flatMap((entry) => {
997
- const domain = axes[entry.axis];
998
- return domain
999
- ? [{
1000
- source: entry,
1001
- points: projectSeries(entry, domain, startTime, stepTrailingTime, timeScale),
1002
- }]
1003
- : [];
1004
- }),
1005
- };
1006
- });
1007
- panelScenes.forEach(attachVolumeProfile);
1008
- attachLastPriceMarker(panelScenes, usableSeries);
1009
- attachPriorClose(panelScenes, usableSeries);
1010
- const timeZone = sceneTimeZone(anchor, timelineSeries);
1011
-
1012
- return {
1013
- width: Math.max(1, Math.floor(options.width)),
1014
- height: panelScenes.reduce((sum, panel) => sum + panel.height, 0),
1015
- startTime,
1016
- endTime,
1017
- timeScale,
1018
- dates,
1019
- dateRatios,
1020
- panels: panelScenes,
1021
- cursorDate,
1022
- cursorXRatio,
1023
- cursorValues: buildCursorValues(panelScenes, cursorDate, { startTime, endTime, timeScale }),
1024
- newestTime: lastTime,
1025
- ...(timeZone ? { timeZone } : {}),
1026
- };
1027
- }
1028
-
1029
- export function resolveCompositeCursorDate(scene: CompositeChartScene, localX: number): Date | null {
1030
- if (scene.dates.length === 0) return null;
1031
- const ratio = scene.width <= 1
1032
- ? 0
1033
- : Math.max(0, Math.min(1, localX / Math.max(scene.width - 1, 1)));
1034
- let nearestIndex = 0;
1035
- let nearestDistance = Number.POSITIVE_INFINITY;
1036
- scene.dateRatios.forEach((candidate, index) => {
1037
- const distance = Math.abs(candidate - ratio);
1038
- if (distance < nearestDistance) {
1039
- nearestIndex = index;
1040
- nearestDistance = distance;
1041
- }
1042
- });
1043
- return scene.dates[nearestIndex] ?? null;
1044
- }
1045
-
1046
- export function resolveAdjacentCompositeCursorDate(
1047
- scene: CompositeChartScene,
1048
- current: Date | null,
1049
- step: -1 | 1,
1050
- ): Date | null {
1051
- if (scene.dates.length === 0) return null;
1052
- if (!current || !Number.isFinite(current.getTime())) {
1053
- return step < 0 ? scene.dates.at(-1) ?? null : scene.dates[0] ?? null;
1054
- }
1055
-
1056
- const currentTime = current.getTime();
1057
- let currentIndex = scene.dates.findIndex((date) => date.getTime() === currentTime);
1058
- if (currentIndex < 0) {
1059
- const snapped = nearestDate(scene.dates, current);
1060
- currentIndex = snapped
1061
- ? scene.dates.findIndex((date) => date.getTime() === snapped.getTime())
1062
- : 0;
1063
- }
1064
- const nextIndex = Math.max(0, Math.min(scene.dates.length - 1, currentIndex + step));
1065
- return scene.dates[nextIndex] ?? null;
1066
- }
1
+ // Entry point of the composite chart scene; the work lives in the modules under ./scene.
2
+ export { heikinAshiPoints } from "./scene/points";
3
+ export { allocateCompositePanelHeights, resizeCompositePanel } from "./scene/panels";
4
+ export { projectCompositeValue, unprojectCompositeValue } from "./scene/projection";
5
+ export {
6
+ applyCompositeChartCursor,
7
+ compositeCursorAsOf,
8
+ compositeLinkedCursorTime,
9
+ resolveAdjacentCompositeCursorDate,
10
+ resolveCompositeCursorDate,
11
+ } from "./scene/cursor";
12
+ export { buildCompositeChartScene } from "./scene/build";