gloomberb 0.19.4 → 0.19.6

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 (321) hide show
  1. package/package.json +3 -1
  2. package/patches/@opentui%2Fcore@0.3.2.patch +86 -25
  3. package/src/api-client/equity-screener.ts +23 -0
  4. package/src/app/pane-runtime/index.tsx +2 -0
  5. package/src/app/pane-runtime/plugin-bindings.ts +10 -1
  6. package/src/app.tsx +63 -16
  7. package/src/cli/commands/command-utils.ts +4 -0
  8. package/src/cli/commands/market.ts +264 -33
  9. package/src/cli/commands/search.ts +22 -4
  10. package/src/cli/commands/ticker.ts +84 -39
  11. package/src/cli/currency-name-hint.ts +60 -0
  12. package/src/cli/glossary.ts +3 -3
  13. package/src/cli/history-rows.ts +18 -1
  14. package/src/cli/known-gaps.ts +25 -2
  15. package/src/cli/listing-arg.ts +12 -0
  16. package/src/cli/not-a-ticker.ts +5 -3
  17. package/src/cli/pane-functions/capabilities.ts +2 -0
  18. package/src/cli/pane-functions/catalog.ts +31 -5
  19. package/src/cli/pane-functions/function-help.ts +8 -5
  20. package/src/cli/pane-functions/headless.ts +11 -6
  21. package/src/cli/pane-functions/market-session.ts +6 -7
  22. package/src/cli/pane-functions/resolver.ts +75 -2
  23. package/src/cli/quote-answer.ts +9 -0
  24. package/src/cli/series-search.ts +4 -5
  25. package/src/cli/symbol-list.ts +54 -2
  26. package/src/cli/symbol-rows.ts +14 -2
  27. package/src/cli/ticker-resolution.ts +89 -20
  28. package/src/components/chart/composite/axis-overlays.tsx +60 -27
  29. package/src/components/chart/composite/composite-chart.tsx +118 -63
  30. package/src/components/chart/composite/cursor-source.ts +111 -0
  31. package/src/components/chart/composite/format.ts +168 -6
  32. package/src/components/chart/composite/legend.tsx +8 -4
  33. package/src/components/chart/composite/panel-bitmap.ts +28 -2
  34. package/src/components/chart/composite/panel-labels.ts +20 -1
  35. package/src/components/chart/composite/panel-surface.tsx +201 -92
  36. package/src/components/chart/composite/price-axis-labels.tsx +92 -46
  37. package/src/components/chart/composite/price-series.ts +31 -8
  38. package/src/components/chart/composite/scene.ts +154 -59
  39. package/src/components/chart/composite/series-axis-tags.tsx +4 -2
  40. package/src/components/chart/composite/time-axis.ts +30 -7
  41. package/src/components/chart/composite/time-scale.ts +211 -56
  42. package/src/components/chart/composite/types.ts +11 -1
  43. package/src/components/chart/composite/use-composite-chart-keyboard.ts +32 -12
  44. package/src/components/chart/curve/curve-surface.tsx +5 -2
  45. package/src/components/chart/curve/model.ts +4 -1
  46. package/src/components/chart/native/use-bitmap-metrics.ts +81 -0
  47. package/src/components/chart/static/series.ts +3 -0
  48. package/src/components/command-bar/commands/collection-list.ts +81 -0
  49. package/src/components/command-bar/commands/direct/index.ts +6 -0
  50. package/src/components/command-bar/commands/registry.ts +8 -0
  51. package/src/components/command-bar/layout-items/current-layout.ts +22 -1
  52. package/src/components/command-bar/layout-items/focused-pane.ts +22 -1
  53. package/src/components/command-bar/pane-templates/items.ts +19 -3
  54. package/src/components/command-bar/pane-templates/workflow.ts +5 -0
  55. package/src/components/command-bar/routes/root/results.ts +23 -3
  56. package/src/components/command-bar/routes/root/selection.ts +4 -2
  57. package/src/components/command-bar/routes/root/shortcut-feedback.ts +1 -1
  58. package/src/components/command-bar/routes/root/shortcut-items.ts +3 -4
  59. package/src/components/command-bar/routes/root/shortcuts.ts +58 -14
  60. package/src/components/command-bar/routes/root/ticker-first.ts +32 -0
  61. package/src/components/command-bar/surface/environment.ts +2 -0
  62. package/src/components/command-bar/view-model.ts +7 -0
  63. package/src/components/command-bar/workflow/ops.ts +2 -1
  64. package/src/components/command-bar/workflow/tickers.ts +20 -0
  65. package/src/components/layout/shell/active-drag.ts +38 -7
  66. package/src/components/layout/shell/drag/magnets.ts +106 -0
  67. package/src/components/layout/shell/menu.ts +15 -1
  68. package/src/components/layout/shell/pane/actions.ts +4 -0
  69. package/src/components/layout/shell/ticker-link-menu.ts +12 -3
  70. package/src/components/layout/status-bar.tsx +20 -0
  71. package/src/components/layout/window-controls.tsx +96 -35
  72. package/src/components/layout/window-fullscreen.ts +20 -0
  73. package/src/components/onboarding/onboarding-keyboard.ts +5 -1
  74. package/src/components/onboarding/onboarding-wizard.tsx +15 -4
  75. package/src/components/onboarding/portfolio-step/positions-panel.tsx +8 -5
  76. package/src/components/onboarding/use-onboarding-progress.ts +20 -1
  77. package/src/components/price-sparkline/view.tsx +14 -6
  78. package/src/components/quote-flash.ts +36 -32
  79. package/src/components/ticker/badge/index.tsx +8 -4
  80. package/src/components/ticker/badge/list.tsx +23 -7
  81. package/src/components/ui/column-grid.tsx +8 -2
  82. package/src/components/ui/data-table/opentui/model.ts +4 -1
  83. package/src/components/ui/tabs.tsx +5 -2
  84. package/src/core/state/app/layout.ts +18 -3
  85. package/src/core/state/app/state.ts +2 -0
  86. package/src/core/state/app/types.ts +5 -0
  87. package/src/data/config/layout.ts +3 -0
  88. package/src/data/config/store/normalize.ts +39 -4
  89. package/src/i18n/es.ts +10 -0
  90. package/src/i18n/ja.ts +10 -0
  91. package/src/i18n/ko.ts +10 -0
  92. package/src/i18n/zh-cn.ts +10 -0
  93. package/src/i18n/zh-tw.ts +10 -0
  94. package/src/layout/pane-manager/floating-placement.ts +7 -4
  95. package/src/layout/pane-manager/floating.ts +5 -2
  96. package/src/market-data/bond-funds.ts +19 -0
  97. package/src/market-data/coordinator/events.ts +17 -1
  98. package/src/market-data/frame-scheduler.ts +47 -10
  99. package/src/market-data/frame-wake.ts +74 -0
  100. package/src/market-data/futures-board.ts +7 -6
  101. package/src/market-data/futures-contract.ts +14 -3
  102. package/src/market-data/hooks.tsx +12 -3
  103. package/src/market-data/market/freshness.ts +18 -0
  104. package/src/market-data/market/status.ts +15 -2
  105. package/src/market-data/performance.ts +78 -9
  106. package/src/market-data/request-types.ts +6 -3
  107. package/src/plugins/builtin/alerts/cli.ts +2 -1
  108. package/src/plugins/builtin/analytics/risk-evidence.ts +1 -0
  109. package/src/plugins/builtin/attention/evidence.ts +1 -1
  110. package/src/plugins/builtin/awards/client.ts +1 -1
  111. package/src/plugins/builtin/awards/evidence.ts +1 -1
  112. package/src/plugins/builtin/awards/pane.tsx +2 -1
  113. package/src/plugins/builtin/bond-calculator/headless.ts +2 -1
  114. package/src/plugins/builtin/bond-calculator/index.tsx +1 -1
  115. package/src/plugins/builtin/bond-calculator/math.ts +1 -1
  116. package/src/plugins/builtin/bond-calculator/model.ts +14 -5
  117. package/src/plugins/builtin/bond-calculator/pane.tsx +1 -1
  118. package/src/plugins/builtin/broker-manager/footer.ts +3 -2
  119. package/src/plugins/builtin/broker-manager/index.tsx +2 -1
  120. package/src/plugins/builtin/broker-manager/keyboard.ts +2 -1
  121. package/src/plugins/builtin/buildout/cells.tsx +25 -45
  122. package/src/plugins/builtin/buildout/detail/company.tsx +3 -3
  123. package/src/plugins/builtin/buildout/detail/index.tsx +1 -1
  124. package/src/plugins/builtin/buildout/detail/intel.tsx +4 -7
  125. package/src/plugins/builtin/buildout/detail/site.tsx +4 -4
  126. package/src/plugins/builtin/buildout/detail/ui.tsx +39 -38
  127. package/src/plugins/builtin/buildout/format.ts +23 -1
  128. package/src/plugins/builtin/buildout/model/types.ts +1 -0
  129. package/src/plugins/builtin/buildout/pane/index.tsx +2 -8
  130. package/src/plugins/builtin/buildout/table-model.ts +12 -4
  131. package/src/plugins/builtin/catalysts/evidence.ts +1 -1
  132. package/src/plugins/builtin/catalysts/pane.tsx +2 -1
  133. package/src/plugins/builtin/cds/headless.ts +1 -0
  134. package/src/plugins/builtin/cds/index.tsx +1 -1
  135. package/src/plugins/builtin/chart-composer/headless.ts +40 -1
  136. package/src/plugins/builtin/cloud/plugin.tsx +2 -0
  137. package/src/plugins/builtin/cloud/upgrade-status-widget.tsx +28 -3
  138. package/src/plugins/builtin/cloud-tweets/table.tsx +3 -2
  139. package/src/plugins/builtin/comment-letters/client.ts +2 -1
  140. package/src/plugins/builtin/company-kpis/client.ts +1 -1
  141. package/src/plugins/builtin/company-kpis/pane.tsx +2 -1
  142. package/src/plugins/builtin/company-kpis/screenshot-evidence.ts +3 -2
  143. package/src/plugins/builtin/correlation/headless.ts +3 -2
  144. package/src/plugins/builtin/cot/headless.ts +9 -3
  145. package/src/plugins/builtin/cot/model.ts +44 -3
  146. package/src/plugins/builtin/credit-documents/client.ts +1 -1
  147. package/src/plugins/builtin/credit-documents/evidence.ts +1 -1
  148. package/src/plugins/builtin/credit-documents/pane.tsx +2 -1
  149. package/src/plugins/builtin/crypto-board/pane.tsx +5 -4
  150. package/src/plugins/builtin/debt-maturities/headless.ts +11 -2
  151. package/src/plugins/builtin/debt-maturities/model.ts +66 -0
  152. package/src/plugins/builtin/debt-maturities/pane.tsx +23 -4
  153. package/src/plugins/builtin/earnings-calls/pane.tsx +1 -1
  154. package/src/plugins/builtin/earnings-ripple/index.tsx +6 -1
  155. package/src/plugins/builtin/earnings-ripple/pane.tsx +1 -1
  156. package/src/plugins/builtin/econ/calendar-model.ts +30 -6
  157. package/src/plugins/builtin/econ/fred-catalog.ts +5 -5
  158. package/src/plugins/builtin/econ/print-watch.ts +3 -1
  159. package/src/plugins/builtin/equity-screener/client.ts +1 -1
  160. package/src/plugins/builtin/equity-screener/criterion-editor.tsx +4 -16
  161. package/src/plugins/builtin/equity-screener/headless.ts +4 -2
  162. package/src/plugins/builtin/equity-screener/ideas.ts +67 -3
  163. package/src/plugins/builtin/equity-screener/model.ts +180 -12
  164. package/src/plugins/builtin/equity-screener/pane.tsx +52 -12
  165. package/src/plugins/builtin/equity-screener/screen-check.ts +7 -4
  166. package/src/plugins/builtin/equity-screener/watchlist.ts +33 -0
  167. package/src/plugins/builtin/futures/series.ts +16 -1
  168. package/src/plugins/builtin/futures-curve/client.ts +19 -0
  169. package/src/plugins/builtin/futures-curve/headless.ts +52 -13
  170. package/src/plugins/builtin/futures-curve/index.tsx +1 -1
  171. package/src/plugins/builtin/futures-curve/model.ts +77 -6
  172. package/src/plugins/builtin/futures-curve/pane.tsx +19 -3
  173. package/src/plugins/builtin/fx-matrix/headless.ts +4 -2
  174. package/src/plugins/builtin/fx-matrix/index.tsx +37 -3
  175. package/src/plugins/builtin/fx-matrix/pairs.ts +15 -0
  176. package/src/plugins/builtin/gpu/headless.ts +2 -1
  177. package/src/plugins/builtin/help/function-card.tsx +2 -1
  178. package/src/plugins/builtin/help/index.tsx +2 -1
  179. package/src/plugins/builtin/insider/display.ts +45 -6
  180. package/src/plugins/builtin/ipo-calendar/model.ts +2 -0
  181. package/src/plugins/builtin/iv-history/client.ts +2 -1
  182. package/src/plugins/builtin/iv-history/headless.ts +2 -1
  183. package/src/plugins/builtin/jobs/pages.ts +4 -4
  184. package/src/plugins/builtin/kelly-sizer/headless.ts +2 -1
  185. package/src/plugins/builtin/macro-day/client.ts +41 -0
  186. package/src/plugins/builtin/macro-day/headless.ts +19 -9
  187. package/src/plugins/builtin/macro-day/model.ts +3 -1
  188. package/src/plugins/builtin/market-heatmap/index.tsx +2 -1
  189. package/src/plugins/builtin/market-movers/index.tsx +4 -3
  190. package/src/plugins/builtin/members/client.ts +1 -1
  191. package/src/plugins/builtin/mna/distress/client.ts +1 -0
  192. package/src/plugins/builtin/mna/distress/headless.ts +1 -0
  193. package/src/plugins/builtin/mna/pane.tsx +4 -1
  194. package/src/plugins/builtin/options/market-reference.ts +1 -1
  195. package/src/plugins/builtin/options/open-interest-as-of.ts +3 -1
  196. package/src/plugins/builtin/options/view.tsx +2 -1
  197. package/src/plugins/builtin/options-calculator/evidence.ts +1 -1
  198. package/src/plugins/builtin/options-scenario/csp-screen-pane.tsx +1 -1
  199. package/src/plugins/builtin/options-scenario/csp-screen.ts +8 -4
  200. package/src/plugins/builtin/options-scenario/csp.ts +28 -9
  201. package/src/plugins/builtin/options-scenario/evidence.ts +5 -4
  202. package/src/plugins/builtin/options-scenario/pane.tsx +2 -1
  203. package/src/plugins/builtin/perps/client.ts +1 -1
  204. package/src/plugins/builtin/perps/pane.tsx +3 -1
  205. package/src/plugins/builtin/portfolio-list/cli/bulk-symbols.ts +17 -0
  206. package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +2 -1
  207. package/src/plugins/builtin/portfolio-list/cli/watchlist-command.ts +4 -2
  208. package/src/plugins/builtin/portfolio-list/pane/index.tsx +7 -3
  209. package/src/plugins/builtin/portfolio-list/use-throttled-memo.ts +10 -19
  210. package/src/plugins/builtin/rate-path/headless.ts +24 -10
  211. package/src/plugins/builtin/research/analyst-model.ts +1 -0
  212. package/src/plugins/builtin/research/equity-diagnostic-pane.tsx +2 -1
  213. package/src/plugins/builtin/research/event-model.ts +10 -3
  214. package/src/plugins/builtin/research/events-headless.ts +20 -2
  215. package/src/plugins/builtin/research/index.tsx +1 -0
  216. package/src/plugins/builtin/research/relative-valuation-currency.ts +1 -1
  217. package/src/plugins/builtin/research/relative-valuation-peers.ts +2 -1
  218. package/src/plugins/builtin/research-search/command-bar-search.ts +3 -1
  219. package/src/plugins/builtin/research-search/snippet.ts +1 -0
  220. package/src/plugins/builtin/revenue-breakdown/client.ts +3 -2
  221. package/src/plugins/builtin/seasonality/headless.ts +2 -1
  222. package/src/plugins/builtin/sec/command-bar-search.ts +3 -2
  223. package/src/plugins/builtin/sec/fund-facts.ts +17 -1
  224. package/src/plugins/builtin/sec/index.tsx +8 -5
  225. package/src/plugins/builtin/sec/row-summaries.ts +28 -12
  226. package/src/plugins/builtin/shared/members-menu.tsx +103 -38
  227. package/src/plugins/builtin/short-interest/publications-model.ts +22 -1
  228. package/src/plugins/builtin/short-interest/publications-pane.tsx +13 -4
  229. package/src/plugins/builtin/short-interest/watch-client.ts +2 -1
  230. package/src/plugins/builtin/short-interest/watch-model.ts +1 -1
  231. package/src/plugins/builtin/social-mentions/client.ts +2 -1
  232. package/src/plugins/builtin/supply-chain/client.ts +1 -1
  233. package/src/plugins/builtin/supply-chain/evidence.ts +1 -1
  234. package/src/plugins/builtin/supply-chain/graph-pane.tsx +2 -1
  235. package/src/plugins/builtin/supply-chain/pane.tsx +2 -1
  236. package/src/plugins/builtin/ticker-detail/adr-pair/headless.ts +1 -1
  237. package/src/plugins/builtin/ticker-detail/adr-pair/model.ts +24 -4
  238. package/src/plugins/builtin/ticker-detail/adr-pair/tab.tsx +1 -1
  239. package/src/plugins/builtin/time-sales/client.ts +1 -0
  240. package/src/plugins/builtin/time-sales/pane.tsx +3 -2
  241. package/src/plugins/builtin/trace-bonds/client.ts +7 -4
  242. package/src/plugins/builtin/trace-bonds/index.tsx +1 -1
  243. package/src/plugins/builtin/vol-surface/client.ts +2 -1
  244. package/src/plugins/builtin/volatility/client.ts +6 -1
  245. package/src/plugins/builtin/volatility/headless.ts +0 -1
  246. package/src/plugins/builtin/yield-curve/curves.ts +15 -0
  247. package/src/plugins/builtin/yield-curve/headless.ts +9 -2
  248. package/src/plugins/builtin/yield-curve/index.tsx +5 -8
  249. package/src/plugins/host-modules.ts +22 -3
  250. package/src/plugins/host-smoke.ts +6 -3
  251. package/src/portfolio/collection-name.ts +19 -0
  252. package/src/portfolio/column-values.ts +76 -10
  253. package/src/renderers/browser/http-proxy-transport.ts +78 -8
  254. package/src/renderers/cloudflare/http-proxy.ts +13 -2
  255. package/src/renderers/cloudflare/proxy-session.ts +47 -24
  256. package/src/renderers/cloudflare/worker.ts +15 -2
  257. package/src/renderers/desktop/geometry.ts +279 -0
  258. package/src/renderers/desktop/screen-setup.ts +246 -0
  259. package/src/renderers/desktop/sequential-window-host.ts +179 -0
  260. package/src/renderers/desktop/test-utils.ts +71 -0
  261. package/src/renderers/desktop/window-controller.ts +433 -0
  262. package/src/renderers/desktop/window-host.ts +70 -0
  263. package/src/renderers/desktop/window-layouts.ts +630 -0
  264. package/src/renderers/dom/data-frames.ts +15 -4
  265. package/src/renderers/dom/host/box.tsx +204 -176
  266. package/src/renderers/dom/host/style.ts +49 -20
  267. package/src/renderers/dom/host/text.tsx +3 -2
  268. package/src/renderers/electrobun/bun/application-menu/click.ts +1 -0
  269. package/src/renderers/electrobun/bun/application-menu/index.ts +4 -1
  270. package/src/renderers/electrobun/bun/desktop/backend-requests.ts +19 -8
  271. package/src/renderers/electrobun/bun/desktop/backend.ts +322 -19
  272. package/src/renderers/electrobun/bun/desktop/detached-windows.ts +83 -61
  273. package/src/renderers/electrobun/bun/desktop/host-requests.ts +29 -15
  274. package/src/renderers/electrobun/bun/desktop/initialization.ts +30 -11
  275. package/src/renderers/electrobun/bun/desktop/relaunch.ts +9 -1
  276. package/src/renderers/electrobun/bun/desktop/screen-setup-file.ts +55 -0
  277. package/src/renderers/electrobun/bun/desktop/state-broadcaster.ts +44 -8
  278. package/src/renderers/electrobun/bun/desktop/windows-script.ts +9 -6
  279. package/src/renderers/electrobun/bun/desktop/workspace/index.ts +298 -97
  280. package/src/renderers/electrobun/bun/desktop/workspace/requests.ts +44 -6
  281. package/src/renderers/electrobun/bun/index.ts +4 -97
  282. package/src/renderers/electrobun/bun/window/electrobun-window-host.ts +306 -0
  283. package/src/renderers/electrobun/bun/window/focus.ts +0 -25
  284. package/src/renderers/electrobun/bun/window/remembered-frame.ts +4 -82
  285. package/src/renderers/electrobun/bun/window/windows-native.ts +26 -1
  286. package/src/renderers/electrobun/shared/protocol.ts +50 -2
  287. package/src/renderers/electrobun/view/backend-rpc.ts +15 -0
  288. package/src/renderers/electrobun/view/desktop/window/bridge.ts +63 -3
  289. package/src/renderers/electrobun/view/main.tsx +13 -7
  290. package/src/renderers/electrobun/view/ui-host.tsx +7 -0
  291. package/src/renderers/electrobun/view/window-fullscreen.ts +10 -3
  292. package/src/series/fred-argument.ts +17 -0
  293. package/src/sources/provider-router/financial-routes.ts +7 -1
  294. package/src/sources/provider-router/index.ts +7 -1
  295. package/src/state/app/context/index.tsx +16 -2
  296. package/src/state/desktop-windows.ts +63 -0
  297. package/src/sync/other-window-tabs.ts +62 -0
  298. package/src/tickers/company-name-listing.ts +23 -3
  299. package/src/tickers/listing-fate.ts +147 -1
  300. package/src/tickers/terminal-codes.ts +5 -0
  301. package/src/time-series/price-units.ts +11 -0
  302. package/src/time-series/types.ts +6 -0
  303. package/src/types/config.ts +10 -1
  304. package/src/types/desktop-window.ts +71 -2
  305. package/src/types/financials.ts +4 -0
  306. package/src/types/headless.ts +19 -0
  307. package/src/types/plugin.ts +6 -0
  308. package/src/ui/host.tsx +2 -0
  309. package/src/ui/index.tsx +14 -13
  310. package/src/ui/same-props.ts +58 -0
  311. package/src/utils/cli-output.ts +33 -4
  312. package/src/utils/currency-names.ts +20 -0
  313. package/src/utils/currency-pair.ts +6 -0
  314. package/src/utils/exchange-rate-snapshot.ts +20 -2
  315. package/src/utils/format.ts +7 -2
  316. package/src/utils/futures-generic.ts +12 -0
  317. package/src/utils/fx-market-hours.ts +43 -0
  318. package/src/utils/http-proxy-upstream.ts +6 -2
  319. package/src/utils/plugin-proxy-hosts.json +0 -4
  320. package/src/utils/plugin-proxy-hosts.ts +22 -0
  321. package/src/utils/sec-filings.ts +7 -1
@@ -20,18 +20,36 @@ const SESSION_DATE_BUCKET_LIMIT = 200_000;
20
20
 
21
21
  type MarketAnchors = Extract<CompositeTimeScale, { kind: "market" }>["anchors"];
22
22
 
23
- interface CachedMarketAnchors {
24
- points: readonly ResolvedSeries["points"][number][];
25
- pointCount: number;
26
- lastTimestamp: number | null;
23
+ /** A series' anchors, and what they were worked out from, so the next tick redoes only its tail. */
24
+ interface MarketAnchorBuild {
27
25
  timeZone: string;
28
26
  configuredCadence: number | undefined;
27
+ timestamps: number[];
28
+ sessionDates: string[];
29
+ /** The gaps between consecutive anchors, in ascending order: the cadence is their median. */
30
+ sameSessionGaps: number[];
31
+ allGaps: number[];
29
32
  cadenceMs: number;
30
33
  historyMsPerSlot: number;
31
34
  anchors: MarketAnchors;
32
35
  }
33
36
 
37
+ interface CachedMarketAnchors {
38
+ points: readonly ResolvedSeries["points"][number][];
39
+ pointCount: number;
40
+ lastTimestamp: number | null;
41
+ build: MarketAnchorBuild;
42
+ }
43
+
34
44
  const anchorCache = new WeakMap<ResolvedSeries, CachedMarketAnchors>();
45
+ /**
46
+ * The last anchors built over a history, by its first point: a live chart
47
+ * resolves a new series around the same history points on a tick that adds
48
+ * a bar, and its anchors differ from the last ones only at the end.
49
+ */
50
+ const anchorsByFirstPoint = new WeakMap<ResolvedSeries["points"][number], MarketAnchorBuild>();
51
+ /** Past this many changed anchors, building them again costs less than patching. */
52
+ const MAX_PATCHED_ANCHORS = 32;
35
53
 
36
54
  function finiteTimestamp(value: Date): number | null {
37
55
  const timestamp = value.getTime();
@@ -39,6 +57,20 @@ function finiteTimestamp(value: Date): number | null {
39
57
  }
40
58
 
41
59
  function uniqueSeriesTimestamps(series: ResolvedSeries): number[] {
60
+ // A market series comes in time order: its timestamps are already unique and sorted.
61
+ const ordered: number[] = [];
62
+ let previous = Number.NEGATIVE_INFINITY;
63
+ for (const point of series.points) {
64
+ const timestamp = finiteTimestamp(point.date);
65
+ if (timestamp === null) continue;
66
+ if (timestamp <= previous) return sortedUniqueSeriesTimestamps(series);
67
+ ordered.push(timestamp);
68
+ previous = timestamp;
69
+ }
70
+ return ordered;
71
+ }
72
+
73
+ function sortedUniqueSeriesTimestamps(series: ResolvedSeries): number[] {
42
74
  return [...new Set(series.points.flatMap((point) => {
43
75
  const timestamp = finiteTimestamp(point.date);
44
76
  return timestamp === null ? [] : [timestamp];
@@ -89,9 +121,8 @@ function sessionDate(timestamp: number, timeZone: string): string {
89
121
  return date;
90
122
  }
91
123
 
92
- function median(values: readonly number[]): number | null {
93
- const sorted = values.filter((value) => Number.isFinite(value) && value > 0)
94
- .sort((left, right) => left - right);
124
+ /** The median of positive gaps already in ascending order. */
125
+ function sortedMedian(sorted: readonly number[]): number | null {
95
126
  if (sorted.length === 0) return null;
96
127
  const middle = Math.floor(sorted.length / 2);
97
128
  return sorted.length % 2 === 1
@@ -99,6 +130,26 @@ function median(values: readonly number[]): number | null {
99
130
  : (sorted[middle - 1]! + sorted[middle]!) / 2;
100
131
  }
101
132
 
133
+ function sortedIndex(sorted: readonly number[], value: number): number {
134
+ let low = 0;
135
+ let high = sorted.length;
136
+ while (low < high) {
137
+ const middle = low + Math.floor((high - low) / 2);
138
+ if (sorted[middle]! < value) low = middle + 1;
139
+ else high = middle;
140
+ }
141
+ return low;
142
+ }
143
+
144
+ function insertSorted(sorted: number[], value: number): void {
145
+ sorted.splice(sortedIndex(sorted, value), 0, value);
146
+ }
147
+
148
+ function removeSorted(sorted: number[], value: number): void {
149
+ const index = sortedIndex(sorted, value);
150
+ if (sorted[index] === value) sorted.splice(index, 1);
151
+ }
152
+
102
153
  function lowerBoundAnchor(
103
154
  anchors: MarketAnchors,
104
155
  timestamp: number,
@@ -113,12 +164,42 @@ function lowerBoundAnchor(
113
164
  return low;
114
165
  }
115
166
 
116
- function positionForTimestamp(
117
- scale: Pick<Extract<CompositeTimeScale, { kind: "market" }>, "anchors" | "cadenceMs" | "historyMsPerSlot">,
167
+ /**
168
+ * `lowerBoundAnchor` for a timestamp no earlier than the one `hint` was found
169
+ * for: a run of timestamps in time order steps on from the last anchor rather
170
+ * than searching again.
171
+ */
172
+ function lowerBoundAnchorFrom(
173
+ anchors: MarketAnchors,
118
174
  timestamp: number,
175
+ hint: number,
119
176
  ): number {
177
+ if (hint > anchors.length || (hint > 0 && anchors[hint - 1]!.timestamp >= timestamp)) {
178
+ return lowerBoundAnchor(anchors, timestamp);
179
+ }
180
+ let low = hint;
181
+ for (let step = 0; step < 4; step += 1) {
182
+ if (low >= anchors.length || anchors[low]!.timestamp >= timestamp) return low;
183
+ low += 1;
184
+ }
185
+ let high = anchors.length;
186
+ while (low < high) {
187
+ const middle = low + Math.floor((high - low) / 2);
188
+ if (anchors[middle]!.timestamp < timestamp) low = middle + 1;
189
+ else high = middle;
190
+ }
191
+ return low;
192
+ }
193
+
194
+ type MarketScaleSlots = Pick<Extract<CompositeTimeScale, { kind: "market" }>, "anchors" | "cadenceMs" | "historyMsPerSlot">;
195
+
196
+ function positionForTimestamp(scale: MarketScaleSlots, timestamp: number): number {
197
+ return positionAtAnchor(scale, timestamp, lowerBoundAnchor(scale.anchors, timestamp));
198
+ }
199
+
200
+ /** The slot position of `timestamp`, given `index`, its lower bound among the anchors. */
201
+ function positionAtAnchor(scale: MarketScaleSlots, timestamp: number, index: number): number {
120
202
  const { anchors, cadenceMs } = scale;
121
- const index = lowerBoundAnchor(anchors, timestamp);
122
203
  const next = anchors[index];
123
204
  if (next?.timestamp === timestamp) return next.position;
124
205
  const previous = anchors[index - 1];
@@ -148,46 +229,90 @@ function averageMsPerSlot(anchors: MarketAnchors, cadenceMs: number): number {
148
229
  return Math.max(cadenceMs, (last.timestamp - first.timestamp) / (last.position - first.position));
149
230
  }
150
231
 
151
- function buildMarketAnchors(series: ResolvedSeries, timeZone: string): {
152
- cadenceMs: number;
153
- historyMsPerSlot: number;
154
- anchors: MarketAnchors;
155
- } {
156
- const anchorTimestamps = uniqueSeriesTimestamps(series);
157
- const sessionDates = anchorTimestamps.map((timestamp) => sessionDate(timestamp, timeZone));
158
- const sameSessionGaps: number[] = [];
159
- const allGaps: number[] = [];
160
- for (let index = 1; index < anchorTimestamps.length; index += 1) {
161
- const gap = anchorTimestamps[index]! - anchorTimestamps[index - 1]!;
232
+ function buildMarketAnchors(
233
+ series: ResolvedSeries,
234
+ timeZone: string,
235
+ previous: MarketAnchorBuild | undefined,
236
+ ): MarketAnchorBuild {
237
+ const timestamps = uniqueSeriesTimestamps(series);
238
+ const configuredCadence = series.timeBasis?.cadenceMs;
239
+ // The anchors a tick leaves alone: those before the first timestamp it moved
240
+ // or added. Their session dates are the zone's, so another zone keeps none;
241
+ // their gaps hold under any cadence, and their places only under the same
242
+ // one (below). Past MAX_PATCHED_ANCHORS changed bars, sorting the gaps
243
+ // afresh costs less than patching them one by one.
244
+ let shared = 0;
245
+ if (previous && previous.timeZone === timeZone) {
246
+ const limit = Math.min(previous.timestamps.length, timestamps.length);
247
+ while (shared < limit && previous.timestamps[shared] === timestamps[shared]) shared += 1;
248
+ if (previous.timestamps.length - shared + timestamps.length - shared > MAX_PATCHED_ANCHORS) shared = 0;
249
+ }
250
+ const base = shared > 0 ? previous! : null;
251
+ const sessionDates = base ? base.sessionDates.slice(0, shared) : [];
252
+ for (let index = sessionDates.length; index < timestamps.length; index += 1) {
253
+ sessionDates.push(sessionDate(timestamps[index]!, timeZone));
254
+ }
255
+ const sameSessionGaps = base ? base.sameSessionGaps.slice() : [];
256
+ const allGaps = base ? base.allGaps.slice() : [];
257
+ if (base) {
258
+ for (let index = shared; index < base.timestamps.length; index += 1) {
259
+ const gap = base.timestamps[index]! - base.timestamps[index - 1]!;
260
+ if (gap <= 0) continue;
261
+ removeSorted(allGaps, gap);
262
+ if (base.sessionDates[index - 1] === base.sessionDates[index]) removeSorted(sameSessionGaps, gap);
263
+ }
264
+ }
265
+ for (let index = Math.max(shared, 1); index < timestamps.length; index += 1) {
266
+ const gap = timestamps[index]! - timestamps[index - 1]!;
162
267
  if (gap <= 0) continue;
163
- allGaps.push(gap);
164
- if (sessionDates[index - 1] === sessionDates[index]) sameSessionGaps.push(gap);
268
+ if (base) insertSorted(allGaps, gap);
269
+ else allGaps.push(gap);
270
+ if (sessionDates[index - 1] === sessionDates[index]) {
271
+ if (base) insertSorted(sameSessionGaps, gap);
272
+ else sameSessionGaps.push(gap);
273
+ }
274
+ }
275
+ if (!base) {
276
+ allGaps.sort((left, right) => left - right);
277
+ sameSessionGaps.sort((left, right) => left - right);
165
278
  }
166
- const configuredCadence = series.timeBasis?.cadenceMs;
167
279
  const cadenceMs = typeof configuredCadence === "number"
168
280
  && Number.isFinite(configuredCadence)
169
281
  && configuredCadence > 0
170
282
  ? configuredCadence
171
- : median(sameSessionGaps) ?? median(allGaps) ?? DAY_MS;
283
+ : sortedMedian(sameSessionGaps) ?? sortedMedian(allGaps) ?? DAY_MS;
172
284
 
173
- const anchors: MarketAnchors = [];
174
- let position = 0;
175
- anchorTimestamps.forEach((timestamp, index) => {
285
+ // Each slot follows from the one before it, so with the cadence unchanged
286
+ // the shared anchors keep their places.
287
+ const anchors: MarketAnchors = base && base.cadenceMs === cadenceMs ? base.anchors.slice(0, shared) : [];
288
+ let position = anchors.at(-1)?.position ?? 0;
289
+ for (let index = anchors.length; index < timestamps.length; index += 1) {
290
+ const timestamp = timestamps[index]!;
176
291
  if (index > 0) {
177
- const previous = anchorTimestamps[index - 1]!;
292
+ const previousTimestamp = timestamps[index - 1]!;
178
293
  position += sessionDates[index - 1] === sessionDates[index]
179
- ? Math.max((timestamp - previous) / cadenceMs, MINIMUM_SLOT_FRACTION)
294
+ ? Math.max((timestamp - previousTimestamp) / cadenceMs, MINIMUM_SLOT_FRACTION)
180
295
  : 1;
181
296
  }
182
297
  anchors.push({ timestamp, position });
183
- });
184
- return { cadenceMs, historyMsPerSlot: averageMsPerSlot(anchors, cadenceMs), anchors };
298
+ }
299
+ return {
300
+ timeZone,
301
+ configuredCadence,
302
+ timestamps,
303
+ sessionDates,
304
+ sameSessionGaps,
305
+ allGaps,
306
+ cadenceMs,
307
+ historyMsPerSlot: averageMsPerSlot(anchors, cadenceMs),
308
+ anchors,
309
+ };
185
310
  }
186
311
 
187
312
  /**
188
313
  * Anchor slots for a market series, cached on the series object. Live ticks
189
314
  * mutate the last point in place, so the cache also keys on the point count
190
- * and the last timestamp.
315
+ * and the last timestamp; a tick then redoes only the anchors it moved.
191
316
  */
192
317
  function resolveMarketAnchors(
193
318
  series: ResolvedSeries,
@@ -203,23 +328,22 @@ function resolveMarketAnchors(
203
328
  && cached.points === series.points
204
329
  && cached.pointCount === series.points.length
205
330
  && cached.lastTimestamp === lastTimestamp
206
- && cached.timeZone === timeZone
207
- && cached.configuredCadence === configuredCadence
331
+ && cached.build.timeZone === timeZone
332
+ && cached.build.configuredCadence === configuredCadence
208
333
  ) {
209
- return { cadenceMs: cached.cadenceMs, historyMsPerSlot: cached.historyMsPerSlot, anchors: cached.anchors, timeZone };
334
+ const { cadenceMs, historyMsPerSlot, anchors } = cached.build;
335
+ return { cadenceMs, historyMsPerSlot, anchors, timeZone };
210
336
  }
211
- const built = buildMarketAnchors(series, timeZone);
337
+ const firstPoint = series.points[0];
338
+ const build = buildMarketAnchors(series, timeZone, cached?.build ?? (firstPoint ? anchorsByFirstPoint.get(firstPoint) : undefined));
212
339
  anchorCache.set(series, {
213
340
  points: series.points,
214
341
  pointCount: series.points.length,
215
342
  lastTimestamp,
216
- timeZone,
217
- configuredCadence,
218
- cadenceMs: built.cadenceMs,
219
- historyMsPerSlot: built.historyMsPerSlot,
220
- anchors: built.anchors,
343
+ build,
221
344
  });
222
- return { ...built, timeZone };
345
+ if (firstPoint) anchorsByFirstPoint.set(firstPoint, build);
346
+ return { cadenceMs: build.cadenceMs, historyMsPerSlot: build.historyMsPerSlot, anchors: build.anchors, timeZone };
223
347
  }
224
348
 
225
349
  export function buildCompositeTimeScale(
@@ -296,31 +420,62 @@ export function compositeTimeAtPosition(scale: CompositeTimeScale, position: num
296
420
  + (next.timestamp - previous.timestamp) * ((position - previous.position) / positionSpan);
297
421
  }
298
422
 
299
- export function projectCompositeTimestamp(
300
- scale: CompositeTimeScale,
301
- timestamp: number,
302
- placement: "timestamp" | "next-market-slot" = "timestamp",
303
- ): { ratio: number; xSlot?: number } | null {
304
- if (!Number.isFinite(timestamp)) return null;
305
- if (scale.kind === "calendar") {
306
- return { ratio: (timestamp - scale.startTime) / projectionSpan(scale) };
307
- }
423
+ type CompositeTimePlacement = "timestamp" | "next-market-slot";
424
+ type ProjectedTimestamp = { ratio: number; xSlot?: number };
308
425
 
426
+ function projectMarketTimestamp(
427
+ scale: Extract<CompositeTimeScale, { kind: "market" }>,
428
+ timestamp: number,
429
+ placement: CompositeTimePlacement,
430
+ index: number,
431
+ span: number,
432
+ ): ProjectedTimestamp | null {
309
433
  let position: number;
310
434
  let xSlot: number | undefined;
311
435
  if (placement === "next-market-slot") {
312
- const index = lowerBoundAnchor(scale.anchors, timestamp);
313
436
  const anchor = scale.anchors[index];
314
437
  if (!anchor) return null;
315
438
  position = anchor.position;
316
439
  xSlot = index;
317
440
  } else {
318
- const index = lowerBoundAnchor(scale.anchors, timestamp);
319
441
  const exact = scale.anchors[index];
320
- position = positionForTimestamp(scale, timestamp);
442
+ position = positionAtAnchor(scale, timestamp, index);
321
443
  if (exact?.timestamp === timestamp) xSlot = index;
322
444
  }
323
- return { ratio: (position - scale.startPosition) / projectionSpan(scale), xSlot };
445
+ return { ratio: (position - scale.startPosition) / span, xSlot };
446
+ }
447
+
448
+ export function projectCompositeTimestamp(
449
+ scale: CompositeTimeScale,
450
+ timestamp: number,
451
+ placement: CompositeTimePlacement = "timestamp",
452
+ ): ProjectedTimestamp | null {
453
+ if (!Number.isFinite(timestamp)) return null;
454
+ if (scale.kind === "calendar") {
455
+ return { ratio: (timestamp - scale.startTime) / projectionSpan(scale) };
456
+ }
457
+ return projectMarketTimestamp(scale, timestamp, placement, lowerBoundAnchor(scale.anchors, timestamp), projectionSpan(scale));
458
+ }
459
+
460
+ /**
461
+ * `projectCompositeTimestamp` for many timestamps on one scale. Fed in time
462
+ * order, as a series' points and a scene's dates are, each finds its anchor
463
+ * by stepping on from the last one's instead of searching the scale again.
464
+ */
465
+ export function compositeTimeProjector(
466
+ scale: CompositeTimeScale,
467
+ placement: CompositeTimePlacement = "timestamp",
468
+ ): (timestamp: number) => ProjectedTimestamp | null {
469
+ const span = projectionSpan(scale);
470
+ if (scale.kind === "calendar") {
471
+ return (timestamp) => Number.isFinite(timestamp) ? { ratio: (timestamp - scale.startTime) / span } : null;
472
+ }
473
+ let hint = 0;
474
+ return (timestamp) => {
475
+ if (!Number.isFinite(timestamp)) return null;
476
+ hint = lowerBoundAnchorFrom(scale.anchors, timestamp, hint);
477
+ return projectMarketTimestamp(scale, timestamp, placement, hint, span);
478
+ };
324
479
  }
325
480
 
326
481
  export function unprojectCompositeTimestamp(
@@ -36,6 +36,11 @@ export interface CompositeAxisDomain {
36
36
  seriesIds: string[];
37
37
  /** Most labeled ticks the axis shows, sized to the panel height. */
38
38
  maxTicks?: number;
39
+ /**
40
+ * The grid its ticks fall on, for prices quoted in fractions of a point: a
41
+ * Treasury future's 32nds (`ResolvedSeries.tickGrid`). Unset on a decimal axis.
42
+ */
43
+ tickGrid?: number;
39
44
  /** Rows the labels snap to, one per row, in the terminal. Unset where labels
40
45
  * sit at their exact heights. */
41
46
  tickRows?: number;
@@ -276,7 +281,12 @@ export interface CompositeChartProps {
276
281
  interactive?: boolean;
277
282
  /** False keeps the hover and keyboard cursor but removes pan, zoom, tools, and their keys. */
278
283
  navigable?: boolean;
279
- /** Overrides the unit-derived tick and cursor labels on both value axes. */
284
+ /**
285
+ * Overrides the unit-derived tick and cursor labels on both value axes. It
286
+ * reads only the value and the axis: what it labels is kept per formatter
287
+ * and axis, so one that reads anything else (a currency, a setting) is a new
288
+ * function whenever that changes.
289
+ */
280
290
  formatAxisValue?: (value: number, domain: CompositeAxisDomain) => string;
281
291
  xAxis?: CompositeChartXAxis;
282
292
  /** Tagged onto the plot's semantic node so remote clients can find this chart. */
@@ -35,6 +35,7 @@ import {
35
35
  import { projectCompositeTimestamp } from "./time-scale";
36
36
  import { projectCompositeValue, resolveAdjacentCompositeCursorDate, unprojectCompositeValue } from "./scene";
37
37
  import type { CompositeChartProps, CompositeChartScene } from "./types";
38
+ import type { CompositeCursorSource } from "./cursor-source";
38
39
 
39
40
  /**
40
41
  * A tool placed from the keyboard: Enter anchors it at the cursor, the arrows
@@ -97,6 +98,7 @@ export function useCompositeChartKeyboard({
97
98
  navigable,
98
99
  showLegend,
99
100
  scene,
101
+ cursor,
100
102
  cursorDate,
101
103
  updateCursor,
102
104
  pin,
@@ -128,7 +130,10 @@ export function useCompositeChartKeyboard({
128
130
  interactive: boolean;
129
131
  navigable: boolean;
130
132
  showLegend: boolean;
133
+ /** The chart's scene, without its cursor. */
131
134
  scene: CompositeChartScene | null;
135
+ /** Where the crosshair is, which moves without rendering the chart. */
136
+ cursor: CompositeCursorSource | null;
132
137
  cursorDate: CompositeChartProps["cursorDate"];
133
138
  updateCursor: (date: Date | null) => void;
134
139
  /** The tab's crosshair pin, when there is a cursor to pin or a pin to lift. */
@@ -162,7 +167,14 @@ export function useCompositeChartKeyboard({
162
167
  const [armedTool, setArmedTool] = useState<ChartToolKind | null>(null);
163
168
  const [keyboardPlacement, setKeyboardPlacement] = useState<KeyboardToolPlacement | null>(null);
164
169
  // Whether the user moved into the chart from the pane's tab strip; see `inside`.
165
- const [entered, setEntered] = useState(false);
170
+ const [entered, setEnteredState] = useState(false);
171
+ // Follows every change as it is made, not the next render: a step out (Esc,
172
+ // Up, focus leaving) and a wheel step in one batch must still enter again.
173
+ const enteredRef = useRef(entered);
174
+ const setEntered = useCallback((next: boolean) => {
175
+ enteredRef.current = next;
176
+ setEnteredState(next);
177
+ }, []);
166
178
  const keyboardId = `composite-chart:${useId()}`;
167
179
  const [selectedLevelId, setSelectedLevelId] = useState<string | null>(null);
168
180
  useEffect(() => {
@@ -181,13 +193,16 @@ export function useCompositeChartKeyboard({
181
193
  setKeyboardPlacement(null);
182
194
  if (tool === null) setSelectedDrawingId(null);
183
195
  if (tool !== "level") setSelectedLevelId(null);
184
- }, []);
196
+ }, [setEntered]);
185
197
  const cancelKeyboardPlacement = useCallback(() => setKeyboardPlacement(null), []);
186
198
  // A press, drag or wheel on the chart moves into it, as Down or Enter do.
199
+ // Once inside, a wheel step sets nothing: setting the same state right
200
+ // after the chart rendered still costs React a render of the chart that
201
+ // bails out, and a pan or zoom renders it on every step.
187
202
  const activateFromPointer = useCallback(() => {
188
- setEntered(true);
203
+ if (!enteredRef.current) setEntered(true);
189
204
  onActivate?.();
190
- }, [onActivate]);
205
+ }, [onActivate, setEntered]);
191
206
  const levelHost = useMemo(
192
207
  () => scene && levels ? levelPanel(scene, levels.seriesId) : null,
193
208
  [levels, scene],
@@ -198,8 +213,13 @@ export function useCompositeChartKeyboard({
198
213
  useEffect(() => {
199
214
  if (selectedLevelId && !selectedLevel) setSelectedLevelId(null);
200
215
  }, [selectedLevel, selectedLevelId]);
201
- const keyboardCursorDateRef = useRef<Date | null>(scene?.cursorDate ?? null);
202
- keyboardCursorDateRef.current = scene?.cursorDate ?? null;
216
+ // The keys step on from the crosshair wherever the pointer or another chart
217
+ // left it, read as it moves: a move does not render the chart.
218
+ const keyboardCursorDateRef = useRef<Date | null>(null);
219
+ keyboardCursorDateRef.current = cursor?.scene().cursorDate ?? null;
220
+ useEffect(() => cursor?.subscribe(() => {
221
+ keyboardCursorDateRef.current = cursor.scene().cursorDate;
222
+ }), [cursor]);
203
223
 
204
224
  // The cursor keys belong to every focused chart; pan, zoom, the tools and
205
225
  // their keys only to one that navigates.
@@ -219,12 +239,12 @@ export function useCompositeChartKeyboard({
219
239
  useEffect(() => {
220
240
  if (wasFocusedRef.current && !focused) setEntered(false);
221
241
  wasFocusedRef.current = focused;
222
- }, [focused]);
242
+ }, [focused, setEntered]);
223
243
  // A time or a price is picked with the arrows and Enter.
224
244
  const picking = !!timePick || !!pricePick;
225
245
  useEffect(() => {
226
246
  if (picking) setEntered(true);
227
- }, [picking]);
247
+ }, [picking, setEntered]);
228
248
  useEffect(() => {
229
249
  if (!toolsActive) setKeyboardPlacement(null);
230
250
  }, [toolsActive]);
@@ -240,7 +260,7 @@ export function useCompositeChartKeyboard({
240
260
  // pane's back key.
241
261
  const canDeleteDrawing = toolsActive && drawings.length > 0 && (!!selectedDrawingId || isDrawingTool(armedTool));
242
262
  // An owner that holds the cursor decides when it goes, so Esc stays the pane's.
243
- const clearableCursor = !!scene?.cursorDate && cursorDate === undefined;
263
+ const clearableCursor = () => !!cursor?.scene().cursorDate && cursorDate === undefined;
244
264
 
245
265
  const enterChart = () => {
246
266
  setEntered(true);
@@ -254,7 +274,7 @@ export function useCompositeChartKeyboard({
254
274
  setEntered(false);
255
275
  setLegendKeyboardIndex(null);
256
276
  // Stepping out to the strip leaves a pinned crosshair where it is.
257
- if (!clearableCursor || pin?.pinned) return;
277
+ if (!clearableCursor() || pin?.pinned) return;
258
278
  keyboardCursorDateRef.current = null;
259
279
  updateCursor(null);
260
280
  };
@@ -535,7 +555,7 @@ export function useCompositeChartKeyboard({
535
555
  setSelectedLevelId(null);
536
556
  return;
537
557
  }
538
- if (isPlainKey(event, "escape") && legendKeysActive && legendKeyboardIndex !== null && !clearableCursor) {
558
+ if (isPlainKey(event, "escape") && legendKeysActive && legendKeyboardIndex !== null && !clearableCursor()) {
539
559
  consume();
540
560
  setLegendKeyboardIndex(null);
541
561
  return;
@@ -563,7 +583,7 @@ export function useCompositeChartKeyboard({
563
583
  || interaction === "clear-cursor";
564
584
  if (!cursorInteraction && !toolsActive) return;
565
585
  if (
566
- (interaction === "clear-cursor" && !clearableCursor)
586
+ (interaction === "clear-cursor" && !clearableCursor())
567
587
  || ((interaction === "arm-measure"
568
588
  || interaction === "arm-zoom"
569
589
  || interaction === "arm-line"
@@ -41,6 +41,8 @@ export interface CurveSurfaceProps {
41
41
  formatChange?: (change: number) => string;
42
42
  /** Gridline labels; defaults to formatValue. */
43
43
  formatAxisValue?: CompositeAxisValueFormatter;
44
+ /** The grid the value axis ticks on, for prices quoted in fractions of a point: a Treasury future's 32nds. */
45
+ valueGrid?: number;
44
46
  /** @deprecated The cursor badge shows the row label. */
45
47
  formatX?: (value: number) => string;
46
48
  valueLabel?: string;
@@ -65,7 +67,7 @@ function isConstant(entry: CurveSeries): boolean {
65
67
  * Each ghost owns its coordinates and nulls, so missing months stay gaps. */
66
68
  export function CurveSurface({ series, width, height, focused = false, primarySeriesId, selectedPointId,
67
69
  onSelectedPointChange, display = "auto", caption, xScale, formatValue = formatNumber, formatChange, formatAxisValue,
68
- slope }: CurveSurfaceProps) {
70
+ valueGrid, slope }: CurveSurfaceProps) {
69
71
  const colors = useThemeColors();
70
72
  const { nativePaneChrome } = useUiCapabilities();
71
73
  const [localSelection, setLocalSelection] = useState<string | null>(null);
@@ -76,7 +78,8 @@ export function CurveSurface({ series, width, height, focused = false, primarySe
76
78
  const totalHeight = Math.max(1, Math.floor(height));
77
79
  const primary = curvePrimarySeries(series, primarySeriesId);
78
80
  const palette = useMemo(() => [colors.positive, colors.textMuted, colors.warning, colors.textDim], [colors]);
79
- const chart = useMemo(() => buildCurveChart(series, totalWidth, palette, { xScale }), [series, totalWidth, palette, xScale]);
81
+ const chart = useMemo(() => buildCurveChart(series, totalWidth, palette, { xScale, valueGrid }),
82
+ [series, totalWidth, palette, xScale, valueGrid]);
80
83
  const rows = useMemo(() => curveTableRows(series), [series]);
81
84
  const activeId = selectedPointId === undefined ? localSelection : selectedPointId;
82
85
  const selected = rows.find((row) => row.id === activeId);
@@ -221,6 +221,8 @@ function curveScale(coordinates: readonly number[], rowCoordinates: readonly num
221
221
 
222
222
  export interface CurveChartOptions {
223
223
  xScale?: CurveXScale;
224
+ /** The grid the value axis ticks on, for prices quoted in fractions of a point (`ResolvedSeries.tickGrid`). */
225
+ valueGrid?: number;
224
226
  }
225
227
 
226
228
  export function buildCurveChart(series: readonly CurveSeries[], width: number, colors: readonly string[], options: CurveChartOptions = {}) {
@@ -238,7 +240,8 @@ export function buildCurveChart(series: readonly CurveSeries[], width: number, c
238
240
  value: point.value != null && Number.isFinite(point.value) ? point.value : null,
239
241
  })),
240
242
  { id: entry.id, label: entry.label, color: entry.color ?? colors[index % Math.max(1, colors.length)] ?? "#ffffff",
241
- style: entry.role === "marker" ? "points" : entry.style, calendarSpaced: true, negativeColor: entry.negativeColor },
243
+ style: entry.role === "marker" ? "points" : entry.style, calendarSpaced: true, negativeColor: entry.negativeColor,
244
+ tickGrid: options.valueGrid },
242
245
  ));
243
246
  // References and markers are not maturities of the curve, so they never label the axis.
244
247
  const candidates = [...new Map((rowSeries.length ? rowSeries : plotted).flatMap((entry) => entry.points)
@@ -0,0 +1,81 @@
1
+ import { useCallback, useSyncExternalStore } from "react";
2
+ import type { NativeRendererHost, PixelResolution } from "../../../ui";
3
+
4
+ /** What a bitmap's pixel size and kitty support are worked out from. */
5
+ export interface NativeBitmapMetrics {
6
+ resolution: PixelResolution | null;
7
+ terminalWidth: number;
8
+ terminalHeight: number;
9
+ capabilities: unknown;
10
+ }
11
+
12
+ interface MetricsHub {
13
+ snapshot: NativeBitmapMetrics | null;
14
+ consumers: Set<() => void>;
15
+ notify: () => void;
16
+ }
17
+
18
+ const hubs = new WeakMap<NativeRendererHost, MetricsHub>();
19
+
20
+ function hubFor(renderer: NativeRendererHost): MetricsHub {
21
+ let hub = hubs.get(renderer);
22
+ if (!hub) {
23
+ const created: MetricsHub = {
24
+ snapshot: null,
25
+ consumers: new Set(),
26
+ notify: () => {
27
+ for (const consumer of created.consumers) consumer();
28
+ },
29
+ };
30
+ hubs.set(renderer, created);
31
+ hub = created;
32
+ }
33
+ return hub;
34
+ }
35
+
36
+ function readMetrics(renderer: NativeRendererHost): NativeBitmapMetrics {
37
+ const hub = hubFor(renderer);
38
+ const last = hub.snapshot;
39
+ const resolution = renderer.resolution ?? null;
40
+ const { terminalWidth, terminalHeight, capabilities } = renderer;
41
+ if (
42
+ last
43
+ && last.terminalWidth === terminalWidth
44
+ && last.terminalHeight === terminalHeight
45
+ && last.capabilities === capabilities
46
+ && (last.resolution === resolution || (!!last.resolution && !!resolution
47
+ && last.resolution.width === resolution.width && last.resolution.height === resolution.height))
48
+ ) return last;
49
+ hub.snapshot = { resolution, terminalWidth, terminalHeight, capabilities };
50
+ return hub.snapshot;
51
+ }
52
+
53
+ // One listener trio per renderer however many bitmaps watch it, as in renderer-selection.
54
+ function subscribe(renderer: NativeRendererHost, onChange: () => void): () => void {
55
+ const hub = hubFor(renderer);
56
+ if (hub.consumers.size === 0) {
57
+ renderer.on("resize", hub.notify);
58
+ renderer.on("resolution", hub.notify);
59
+ renderer.on("capabilities", hub.notify);
60
+ }
61
+ hub.consumers.add(onChange);
62
+ return () => {
63
+ hub.consumers.delete(onChange);
64
+ if (hub.consumers.size > 0) return;
65
+ renderer.off("resize", hub.notify);
66
+ renderer.off("resolution", hub.notify);
67
+ renderer.off("capabilities", hub.notify);
68
+ };
69
+ }
70
+
71
+ /**
72
+ * The renderer's pixel resolution, cell grid and capabilities, re-rendering the
73
+ * caller when a resize, a font zoom or a late terminal reply changes them. A
74
+ * bitmap sized from these during render needs this rather than reading them off
75
+ * the renderer, or a parent that stops re-rendering leaves it at its old size.
76
+ */
77
+ export function useNativeBitmapMetrics(renderer: NativeRendererHost): NativeBitmapMetrics {
78
+ const subscribeToRenderer = useCallback((onChange: () => void) => subscribe(renderer, onChange), [renderer]);
79
+ const getSnapshot = useCallback(() => readMetrics(renderer), [renderer]);
80
+ return useSyncExternalStore(subscribeToRenderer, getSnapshot, getSnapshot);
81
+ }
@@ -25,6 +25,8 @@ export interface StaticSeriesOptions {
25
25
  calendarSpaced?: boolean;
26
26
  /** Columns below zero in this colour. */
27
27
  negativeColor?: string;
28
+ /** The grid its axis ticks fall on (`ResolvedSeries.tickGrid`). */
29
+ tickGrid?: number;
28
30
  }
29
31
 
30
32
  export function staticSeries(points: TimeSeriesPoint[], options: StaticSeriesOptions): ResolvedSeries {
@@ -43,6 +45,7 @@ export function staticSeries(points: TimeSeriesPoint[], options: StaticSeriesOpt
43
45
  interpolation: "none",
44
46
  ...(options.calendarSpaced ? {} : { timeBasis: INDEX_SPACED_TIME_BASIS }),
45
47
  ...(options.negativeColor ? { negativeColor: options.negativeColor } : {}),
48
+ ...(options.tickGrid ? { tickGrid: options.tickGrid } : {}),
46
49
  points,
47
50
  };
48
51
  }