@gloom-sh/terminal 0.19.5 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (318) hide show
  1. package/LICENSE +0 -4
  2. package/package.json +6 -5
  3. package/patches/@opentui%2Fcore@0.3.2.patch +86 -25
  4. package/patches/electrobun-devkit@2.0.5.patch +148 -0
  5. package/src/api-client/bond-trades.ts +59 -0
  6. package/src/api-client/data.ts +21 -0
  7. package/src/api-client/equity-screener.ts +23 -0
  8. package/src/api-client/index.ts +2 -0
  9. package/src/api-client/types/account.ts +86 -0
  10. package/src/api-client/types/assist.ts +32 -0
  11. package/src/api-client/types/auth.ts +63 -0
  12. package/src/api-client/types/billing.ts +54 -0
  13. package/src/api-client/types/chat.ts +180 -0
  14. package/src/api-client/types/congress.ts +107 -0
  15. package/src/api-client/types/credit.ts +110 -0
  16. package/src/api-client/types/econ.ts +158 -0
  17. package/src/api-client/types/equity-diagnostic.ts +73 -0
  18. package/src/api-client/types/filings-and-calls.ts +350 -0
  19. package/src/api-client/types/index.ts +25 -0
  20. package/src/api-client/types/jobs.ts +147 -0
  21. package/src/api-client/types/market.ts +122 -0
  22. package/src/api-client/types/news.ts +91 -0
  23. package/src/api-client/types/notes-and-theses.ts +172 -0
  24. package/src/api-client/types/quotes.ts +28 -0
  25. package/src/api-client/types/scanners.ts +125 -0
  26. package/src/api-client/types/screener.ts +65 -0
  27. package/src/api-client/types/search.ts +107 -0
  28. package/src/api-client/types/sync.ts +14 -0
  29. package/src/api-client/types/team-collections.ts +43 -0
  30. package/src/api-client/types/team-views.ts +32 -0
  31. package/src/api-client/types/teams.ts +135 -0
  32. package/src/api-client/types/ticker-data.ts +57 -0
  33. package/src/api-client/types/tweets.ts +59 -0
  34. package/src/api-client/types/world-venues.ts +23 -0
  35. package/src/app/pane-runtime/index.tsx +2 -0
  36. package/src/app/pane-runtime/plugin-bindings.ts +10 -1
  37. package/src/app/runtime/desktop-deeplink.ts +41 -6
  38. package/src/app/star-prompt/status-line.tsx +1 -1
  39. package/src/app.tsx +64 -23
  40. package/src/architecture/ui-tokens-allowlist.json +0 -8
  41. package/src/cli/commands/market.ts +149 -10
  42. package/src/cli/commands/search.ts +21 -3
  43. package/src/cli/commands/ticker.ts +90 -36
  44. package/src/cli/desktop-pane-shot-browser.ts +69 -3
  45. package/src/cli/glossary.ts +3 -3
  46. package/src/cli/known-gaps.ts +8 -0
  47. package/src/cli/listing-arg.ts +12 -0
  48. package/src/cli/pane-functions/capabilities.ts +2 -0
  49. package/src/cli/pane-functions/catalog.ts +25 -5
  50. package/src/cli/pane-functions/function-help.ts +8 -5
  51. package/src/cli/pane-functions/headless.ts +4 -3
  52. package/src/cli/pane-functions/resolver.ts +75 -2
  53. package/src/cli/quote-answer.ts +9 -0
  54. package/src/cli/symbol-list.ts +54 -2
  55. package/src/cli/symbol-rows.ts +14 -2
  56. package/src/cli/ticker-resolution.ts +89 -20
  57. package/src/components/chart/composite/axis-overlays.tsx +60 -27
  58. package/src/components/chart/composite/composite-chart.tsx +118 -63
  59. package/src/components/chart/composite/cursor-source.ts +111 -0
  60. package/src/components/chart/composite/format.ts +168 -6
  61. package/src/components/chart/composite/legend.tsx +8 -4
  62. package/src/components/chart/composite/panel-labels.ts +20 -1
  63. package/src/components/chart/composite/panel-surface.tsx +201 -92
  64. package/src/components/chart/composite/price-axis-labels.tsx +92 -46
  65. package/src/components/chart/composite/price-series.ts +31 -8
  66. package/src/components/chart/composite/scene.ts +154 -59
  67. package/src/components/chart/composite/series-axis-tags.tsx +4 -2
  68. package/src/components/chart/composite/time-axis.ts +13 -5
  69. package/src/components/chart/composite/time-scale.ts +211 -56
  70. package/src/components/chart/composite/types.ts +11 -1
  71. package/src/components/chart/composite/use-composite-chart-keyboard.ts +43 -14
  72. package/src/components/chart/curve/curve-surface.tsx +5 -2
  73. package/src/components/chart/curve/model.ts +4 -1
  74. package/src/components/chart/native/use-bitmap-metrics.ts +81 -0
  75. package/src/components/chart/static/series.ts +3 -0
  76. package/src/components/command-bar/commands/collection-list.ts +81 -0
  77. package/src/components/command-bar/commands/direct/index.ts +6 -0
  78. package/src/components/command-bar/commands/registry.ts +8 -0
  79. package/src/components/command-bar/layout-items/current-layout.ts +22 -1
  80. package/src/components/command-bar/layout-items/focused-pane.ts +22 -1
  81. package/src/components/command-bar/pane-templates/items.ts +19 -3
  82. package/src/components/command-bar/pane-templates/workflow.ts +5 -0
  83. package/src/components/command-bar/routes/root/results.ts +23 -3
  84. package/src/components/command-bar/routes/root/selection.ts +4 -2
  85. package/src/components/command-bar/routes/root/shortcut-feedback.ts +1 -1
  86. package/src/components/command-bar/routes/root/shortcut-items.ts +3 -4
  87. package/src/components/command-bar/routes/root/shortcuts.ts +58 -14
  88. package/src/components/command-bar/routes/root/ticker-first.ts +32 -0
  89. package/src/components/command-bar/surface/environment.ts +2 -0
  90. package/src/components/command-bar/view-model.ts +7 -0
  91. package/src/components/command-bar/workflow/ops.ts +2 -1
  92. package/src/components/command-bar/workflow/tickers.ts +20 -0
  93. package/src/components/data-table/export.ts +4 -1
  94. package/src/components/layout/detached-pane-shell.tsx +10 -37
  95. package/src/components/layout/double-escape-close.ts +90 -0
  96. package/src/components/layout/header.tsx +3 -2
  97. package/src/components/layout/market-summary.ts +6 -3
  98. package/src/components/layout/pane/footer/index.tsx +2 -6
  99. package/src/components/layout/pane/footer/model.ts +6 -12
  100. package/src/components/layout/shell/active-drag.ts +53 -11
  101. package/src/components/layout/shell/drag/magnets.ts +128 -19
  102. package/src/components/layout/shell/menu.ts +15 -1
  103. package/src/components/layout/shell/pane/actions.ts +10 -2
  104. package/src/components/layout/shell/pane/management-shortcuts.ts +13 -51
  105. package/src/components/layout/shell/ticker-link-menu.ts +12 -3
  106. package/src/components/layout/status-bar.tsx +24 -78
  107. package/src/components/layout/status-widget-space.ts +5 -5
  108. package/src/components/onboarding/onboarding-keyboard.ts +5 -1
  109. package/src/components/onboarding/onboarding-wizard.tsx +15 -4
  110. package/src/components/onboarding/portfolio-step/positions-panel.tsx +9 -6
  111. package/src/components/onboarding/use-onboarding-progress.ts +20 -1
  112. package/src/components/price-sparkline/view.tsx +14 -6
  113. package/src/components/ticker/badge/index.tsx +8 -4
  114. package/src/components/ticker/badge/list.tsx +23 -7
  115. package/src/components/ui/column-grid.tsx +8 -2
  116. package/src/components/ui/data-table/index.tsx +5 -1
  117. package/src/components/ui/data-table/opentui/model.ts +4 -1
  118. package/src/components/ui/data-table/render-cell.ts +19 -0
  119. package/src/components/ui/delayed-mark.tsx +59 -7
  120. package/src/components/ui/icon.tsx +1 -8
  121. package/src/components/ui/menu.tsx +6 -1
  122. package/src/components/ui/tabs.tsx +5 -2
  123. package/src/core/state/app/layout.ts +18 -3
  124. package/src/core/state/app/state.ts +2 -0
  125. package/src/core/state/app/types.ts +5 -0
  126. package/src/data/config/layout.ts +3 -0
  127. package/src/data/config/store/normalize.ts +39 -4
  128. package/src/i18n/es.ts +13 -3
  129. package/src/i18n/ja.ts +13 -3
  130. package/src/i18n/ko.ts +13 -3
  131. package/src/i18n/zh-cn.ts +13 -3
  132. package/src/i18n/zh-tw.ts +13 -3
  133. package/src/layout/pane-manager/floating-placement.ts +7 -4
  134. package/src/layout/pane-manager/floating.ts +5 -2
  135. package/src/market-data/bond-funds.ts +19 -0
  136. package/src/market-data/futures-contract.ts +14 -3
  137. package/src/market-data/market/freshness.ts +18 -0
  138. package/src/market-data/market/status.ts +15 -2
  139. package/src/plugins/builtin/bond-calculator/headless.ts +2 -1
  140. package/src/plugins/builtin/bond-calculator/index.tsx +1 -1
  141. package/src/plugins/builtin/bond-calculator/model.ts +14 -5
  142. package/src/plugins/builtin/bond-calculator/pane.tsx +1 -1
  143. package/src/plugins/builtin/buildout/cells.tsx +25 -45
  144. package/src/plugins/builtin/buildout/detail/company.tsx +3 -3
  145. package/src/plugins/builtin/buildout/detail/index.tsx +1 -1
  146. package/src/plugins/builtin/buildout/detail/intel.tsx +4 -7
  147. package/src/plugins/builtin/buildout/detail/site.tsx +4 -4
  148. package/src/plugins/builtin/buildout/detail/ui.tsx +39 -38
  149. package/src/plugins/builtin/buildout/format.ts +23 -1
  150. package/src/plugins/builtin/buildout/model/types.ts +1 -0
  151. package/src/plugins/builtin/buildout/pane/index.tsx +2 -8
  152. package/src/plugins/builtin/buildout/table-model.ts +12 -4
  153. package/src/plugins/builtin/cds/headless.ts +1 -0
  154. package/src/plugins/builtin/cds/index.tsx +1 -1
  155. package/src/plugins/builtin/chat/content/composer.tsx +21 -27
  156. package/src/plugins/builtin/chat/content/index.tsx +31 -3
  157. package/src/plugins/builtin/chat/content/shortcuts.ts +4 -2
  158. package/src/plugins/builtin/chat/content/snapshot.ts +0 -3
  159. package/src/plugins/builtin/cloud/auth-actions.tsx +51 -23
  160. package/src/plugins/builtin/cloud/plugin.tsx +2 -0
  161. package/src/plugins/builtin/cloud/trial-offer-status-widget.tsx +3 -3
  162. package/src/plugins/builtin/cloud/upgrade-status-widget.tsx +44 -12
  163. package/src/plugins/builtin/congress-trades/model.ts +2 -1
  164. package/src/plugins/builtin/congress-trades/pane.tsx +3 -0
  165. package/src/plugins/builtin/correlation/headless.ts +3 -2
  166. package/src/plugins/builtin/crypto-board/pane.tsx +5 -4
  167. package/src/plugins/builtin/custom-view/index.tsx +1 -1
  168. package/src/plugins/builtin/custom-view/loader.ts +85 -8
  169. package/src/plugins/builtin/custom-view/view-spec.ts +28 -0
  170. package/src/plugins/builtin/debt-maturities/headless.ts +11 -2
  171. package/src/plugins/builtin/debt-maturities/model.ts +66 -0
  172. package/src/plugins/builtin/debt-maturities/pane.tsx +23 -4
  173. package/src/plugins/builtin/earnings-ripple/pane.tsx +1 -1
  174. package/src/plugins/builtin/econ/calendar-model.ts +28 -6
  175. package/src/plugins/builtin/equity-screener/client.ts +1 -1
  176. package/src/plugins/builtin/equity-screener/criterion-editor.tsx +16 -19
  177. package/src/plugins/builtin/equity-screener/headless.ts +37 -3
  178. package/src/plugins/builtin/equity-screener/ideas.ts +67 -3
  179. package/src/plugins/builtin/equity-screener/model.ts +238 -27
  180. package/src/plugins/builtin/equity-screener/pane.tsx +88 -18
  181. package/src/plugins/builtin/equity-screener/screen-check.ts +7 -4
  182. package/src/plugins/builtin/equity-screener/watchlist.ts +33 -0
  183. package/src/plugins/builtin/executives/format.ts +5 -4
  184. package/src/plugins/builtin/executives/pane.tsx +1 -1
  185. package/src/plugins/builtin/futures-curve/client.ts +19 -0
  186. package/src/plugins/builtin/futures-curve/headless.ts +52 -13
  187. package/src/plugins/builtin/futures-curve/index.tsx +1 -1
  188. package/src/plugins/builtin/futures-curve/model.ts +77 -6
  189. package/src/plugins/builtin/futures-curve/pane.tsx +19 -3
  190. package/src/plugins/builtin/help/index.tsx +55 -1
  191. package/src/plugins/builtin/insider/model.ts +30 -2
  192. package/src/plugins/builtin/jobs/model.ts +2 -2
  193. package/src/plugins/builtin/macro-day/client.ts +41 -0
  194. package/src/plugins/builtin/macro-day/headless.ts +19 -9
  195. package/src/plugins/builtin/macro-day/model.ts +3 -1
  196. package/src/plugins/builtin/market-movers/index.tsx +4 -3
  197. package/src/plugins/builtin/mna/distress/headless.ts +1 -0
  198. package/src/plugins/builtin/mna/model.ts +2 -2
  199. package/src/plugins/builtin/notes/files.ts +2 -0
  200. package/src/plugins/builtin/notes/owner.tsx +20 -1
  201. package/src/plugins/builtin/notes/quick-notes-pane.tsx +22 -4
  202. package/src/plugins/builtin/notes/store.ts +6 -1
  203. package/src/plugins/builtin/perps/pane.tsx +3 -1
  204. package/src/plugins/builtin/portfolio-list/cli/bulk-symbols.ts +17 -0
  205. package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +2 -1
  206. package/src/plugins/builtin/portfolio-list/cli/watchlist-command.ts +2 -1
  207. package/src/plugins/builtin/portfolio-list/header.tsx +1 -1
  208. package/src/plugins/builtin/rate-path/headless.ts +24 -10
  209. package/src/plugins/builtin/research/corporate-actions-pane.tsx +29 -25
  210. package/src/plugins/builtin/research/event-model.ts +10 -3
  211. package/src/plugins/builtin/research/events-headless.ts +20 -2
  212. package/src/plugins/builtin/sec/fund-facts.ts +17 -1
  213. package/src/plugins/builtin/sec/index.tsx +1 -1
  214. package/src/plugins/builtin/series-inventory.ts +1 -0
  215. package/src/plugins/builtin/shared/earnings-report.ts +7 -2
  216. package/src/plugins/builtin/shared/members-menu.tsx +103 -38
  217. package/src/plugins/builtin/shared/use-quote-board.ts +85 -46
  218. package/src/plugins/builtin/short-interest/headless.ts +1 -1
  219. package/src/plugins/builtin/short-interest/model.ts +15 -6
  220. package/src/plugins/builtin/short-interest/publications-model.ts +22 -1
  221. package/src/plugins/builtin/short-interest/publications-pane.tsx +13 -4
  222. package/src/plugins/builtin/short-interest/types.ts +2 -0
  223. package/src/plugins/builtin/short-interest/watch-model.ts +1 -1
  224. package/src/plugins/builtin/thirteenf/overlap-pane.tsx +3 -0
  225. package/src/plugins/builtin/thirteenf/pane.tsx +3 -0
  226. package/src/plugins/builtin/ticker-detail/overview/model.ts +5 -3
  227. package/src/plugins/builtin/ticker-detail/overview-tab.tsx +4 -4
  228. package/src/plugins/builtin/time-sales/pane.tsx +3 -2
  229. package/src/plugins/builtin/trace-bonds/client.ts +7 -4
  230. package/src/plugins/builtin/trace-bonds/detail.tsx +198 -0
  231. package/src/plugins/builtin/trace-bonds/headless.ts +62 -4
  232. package/src/plugins/builtin/trace-bonds/history.ts +155 -0
  233. package/src/plugins/builtin/trace-bonds/index.tsx +1 -1
  234. package/src/plugins/builtin/trace-bonds/pane.tsx +64 -5
  235. package/src/plugins/builtin/volatility/client.ts +6 -1
  236. package/src/plugins/builtin/volatility/headless.ts +0 -1
  237. package/src/plugins/builtin/yield-curve/curves.ts +15 -0
  238. package/src/plugins/builtin/yield-curve/headless.ts +6 -1
  239. package/src/plugins/builtin/yield-curve/index.tsx +5 -8
  240. package/src/plugins/host-modules.ts +22 -3
  241. package/src/plugins/host-smoke.ts +6 -3
  242. package/src/plugins/installer.ts +16 -3
  243. package/src/plugins/plugin-names.ts +11 -2
  244. package/src/portfolio/collection-name.ts +19 -0
  245. package/src/remote/controller.ts +9 -2
  246. package/src/remote/schema.ts +2 -1
  247. package/src/renderers/browser/http-proxy-transport.ts +78 -8
  248. package/src/renderers/cloudflare/http-proxy.ts +73 -3
  249. package/src/renderers/cloudflare/proxy-session.ts +47 -24
  250. package/src/renderers/cloudflare/worker.ts +44 -4
  251. package/src/renderers/desktop/geometry.ts +279 -0
  252. package/src/renderers/desktop/screen-setup.ts +246 -0
  253. package/src/renderers/desktop/sequential-window-host.ts +179 -0
  254. package/src/renderers/desktop/test-utils.ts +71 -0
  255. package/src/renderers/desktop/window-controller.ts +433 -0
  256. package/src/renderers/desktop/window-host.ts +70 -0
  257. package/src/renderers/desktop/window-layouts.ts +630 -0
  258. package/src/renderers/dom/data-frames.ts +15 -4
  259. package/src/renderers/dom/desktop/icons.tsx +0 -2
  260. package/src/renderers/dom/styles.css +0 -3
  261. package/src/renderers/electrobun/bun/application-menu/click.ts +1 -0
  262. package/src/renderers/electrobun/bun/application-menu/index.ts +4 -1
  263. package/src/renderers/electrobun/bun/desktop/backend-requests.ts +19 -8
  264. package/src/renderers/electrobun/bun/desktop/backend.ts +320 -19
  265. package/src/renderers/electrobun/bun/desktop/detached-windows.ts +83 -61
  266. package/src/renderers/electrobun/bun/desktop/host-requests.ts +4 -14
  267. package/src/renderers/electrobun/bun/desktop/initialization.ts +30 -11
  268. package/src/renderers/electrobun/bun/desktop/install-records.ts +59 -0
  269. package/src/renderers/electrobun/bun/desktop/installer-folder.ts +208 -592
  270. package/src/renderers/electrobun/bun/desktop/macos-objc.ts +14 -0
  271. package/src/renderers/electrobun/bun/desktop/screen-setup-file.ts +55 -0
  272. package/src/renderers/electrobun/bun/desktop/state-broadcaster.ts +44 -8
  273. package/src/renderers/electrobun/bun/desktop/update.ts +1 -1
  274. package/src/renderers/electrobun/bun/desktop/workspace/index.ts +298 -97
  275. package/src/renderers/electrobun/bun/desktop/workspace/requests.ts +44 -6
  276. package/src/renderers/electrobun/bun/index.ts +22 -109
  277. package/src/renderers/electrobun/bun/window/create.ts +23 -3
  278. package/src/renderers/electrobun/bun/window/electrobun-window-host.ts +306 -0
  279. package/src/renderers/electrobun/bun/window/events.ts +4 -4
  280. package/src/renderers/electrobun/bun/window/focus.ts +0 -25
  281. package/src/renderers/electrobun/bun/window/frame.ts +2 -1
  282. package/src/renderers/electrobun/bun/window/native-min-size.ts +322 -0
  283. package/src/renderers/electrobun/bun/window/remembered-frame.ts +4 -82
  284. package/src/renderers/electrobun/shared/protocol.ts +44 -2
  285. package/src/renderers/electrobun/view/backend-rpc.ts +16 -1
  286. package/src/renderers/electrobun/view/desktop/window/bridge.ts +63 -3
  287. package/src/renderers/electrobun/view/main.tsx +13 -7
  288. package/src/series/fred-argument.ts +17 -0
  289. package/src/sources/gloomberb-cloud/index.ts +5 -7
  290. package/src/sources/provider-router/batches.ts +18 -3
  291. package/src/sources/provider-router/financial-routes.ts +7 -1
  292. package/src/sources/provider-router/financials.ts +18 -4
  293. package/src/state/app/context/index.tsx +16 -2
  294. package/src/state/desktop-windows.ts +63 -0
  295. package/src/sync/other-window-tabs.ts +62 -0
  296. package/src/tickers/company-name-listing.ts +23 -3
  297. package/src/tickers/listing-fate.ts +147 -1
  298. package/src/tickers/terminal-codes.ts +5 -0
  299. package/src/time-series/types.ts +6 -0
  300. package/src/types/config.ts +10 -1
  301. package/src/types/data-provider.ts +14 -0
  302. package/src/types/desktop-window.ts +71 -2
  303. package/src/types/financials.ts +19 -3
  304. package/src/types/headless.ts +21 -0
  305. package/src/types/plugin.ts +6 -0
  306. package/src/ui/index.tsx +14 -13
  307. package/src/ui/same-props.ts +58 -0
  308. package/src/utils/cli-output.ts +33 -4
  309. package/src/utils/double-escape-close.ts +38 -16
  310. package/src/utils/format.ts +30 -5
  311. package/src/utils/futures-generic.ts +12 -0
  312. package/src/utils/http-proxy-upstream.ts +6 -2
  313. package/src/utils/plugin-proxy-hosts.json +0 -4
  314. package/src/utils/plugin-proxy-hosts.ts +22 -0
  315. package/src/utils/price-earnings.ts +18 -0
  316. package/src/utils/sec-filings.ts +7 -1
  317. package/patches/electrobun@1.18.1.patch +0 -633
  318. package/src/api-client/types.ts +0 -2441
@@ -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. */
@@ -10,6 +10,7 @@ import type { PaneHint } from "../../layout/pane/footer/model";
10
10
  import type { ContextMenuItem } from "../../../types/context-menu";
11
11
  import type { ResolvedSeries } from "../../../time-series/types";
12
12
  import { isPlainKey } from "../../../utils/keyboard";
13
+ import { keepEscapeFromClosing } from "../../../utils/double-escape-close";
13
14
  import { nextDrawingId, nextLevelId } from "./drawing-store";
14
15
  import { CHART_TOOL_MENU, KEYBOARD_TOOL_HINTS, ARMED_TOOL_BY_INTERACTION } from "./tool-catalog";
15
16
  import {
@@ -35,6 +36,7 @@ import {
35
36
  import { projectCompositeTimestamp } from "./time-scale";
36
37
  import { projectCompositeValue, resolveAdjacentCompositeCursorDate, unprojectCompositeValue } from "./scene";
37
38
  import type { CompositeChartProps, CompositeChartScene } from "./types";
39
+ import type { CompositeCursorSource } from "./cursor-source";
38
40
 
39
41
  /**
40
42
  * A tool placed from the keyboard: Enter anchors it at the cursor, the arrows
@@ -97,6 +99,7 @@ export function useCompositeChartKeyboard({
97
99
  navigable,
98
100
  showLegend,
99
101
  scene,
102
+ cursor,
100
103
  cursorDate,
101
104
  updateCursor,
102
105
  pin,
@@ -128,7 +131,10 @@ export function useCompositeChartKeyboard({
128
131
  interactive: boolean;
129
132
  navigable: boolean;
130
133
  showLegend: boolean;
134
+ /** The chart's scene, without its cursor. */
131
135
  scene: CompositeChartScene | null;
136
+ /** Where the crosshair is, which moves without rendering the chart. */
137
+ cursor: CompositeCursorSource | null;
132
138
  cursorDate: CompositeChartProps["cursorDate"];
133
139
  updateCursor: (date: Date | null) => void;
134
140
  /** The tab's crosshair pin, when there is a cursor to pin or a pin to lift. */
@@ -162,7 +168,14 @@ export function useCompositeChartKeyboard({
162
168
  const [armedTool, setArmedTool] = useState<ChartToolKind | null>(null);
163
169
  const [keyboardPlacement, setKeyboardPlacement] = useState<KeyboardToolPlacement | null>(null);
164
170
  // Whether the user moved into the chart from the pane's tab strip; see `inside`.
165
- const [entered, setEntered] = useState(false);
171
+ const [entered, setEnteredState] = useState(false);
172
+ // Follows every change as it is made, not the next render: a step out (Esc,
173
+ // Up, focus leaving) and a wheel step in one batch must still enter again.
174
+ const enteredRef = useRef(entered);
175
+ const setEntered = useCallback((next: boolean) => {
176
+ enteredRef.current = next;
177
+ setEnteredState(next);
178
+ }, []);
166
179
  const keyboardId = `composite-chart:${useId()}`;
167
180
  const [selectedLevelId, setSelectedLevelId] = useState<string | null>(null);
168
181
  useEffect(() => {
@@ -181,13 +194,16 @@ export function useCompositeChartKeyboard({
181
194
  setKeyboardPlacement(null);
182
195
  if (tool === null) setSelectedDrawingId(null);
183
196
  if (tool !== "level") setSelectedLevelId(null);
184
- }, []);
197
+ }, [setEntered]);
185
198
  const cancelKeyboardPlacement = useCallback(() => setKeyboardPlacement(null), []);
186
199
  // A press, drag or wheel on the chart moves into it, as Down or Enter do.
200
+ // Once inside, a wheel step sets nothing: setting the same state right
201
+ // after the chart rendered still costs React a render of the chart that
202
+ // bails out, and a pan or zoom renders it on every step.
187
203
  const activateFromPointer = useCallback(() => {
188
- setEntered(true);
204
+ if (!enteredRef.current) setEntered(true);
189
205
  onActivate?.();
190
- }, [onActivate]);
206
+ }, [onActivate, setEntered]);
191
207
  const levelHost = useMemo(
192
208
  () => scene && levels ? levelPanel(scene, levels.seriesId) : null,
193
209
  [levels, scene],
@@ -198,8 +214,13 @@ export function useCompositeChartKeyboard({
198
214
  useEffect(() => {
199
215
  if (selectedLevelId && !selectedLevel) setSelectedLevelId(null);
200
216
  }, [selectedLevel, selectedLevelId]);
201
- const keyboardCursorDateRef = useRef<Date | null>(scene?.cursorDate ?? null);
202
- keyboardCursorDateRef.current = scene?.cursorDate ?? null;
217
+ // The keys step on from the crosshair wherever the pointer or another chart
218
+ // left it, read as it moves: a move does not render the chart.
219
+ const keyboardCursorDateRef = useRef<Date | null>(null);
220
+ keyboardCursorDateRef.current = cursor?.scene().cursorDate ?? null;
221
+ useEffect(() => cursor?.subscribe(() => {
222
+ keyboardCursorDateRef.current = cursor.scene().cursorDate;
223
+ }), [cursor]);
203
224
 
204
225
  // The cursor keys belong to every focused chart; pan, zoom, the tools and
205
226
  // their keys only to one that navigates.
@@ -219,12 +240,12 @@ export function useCompositeChartKeyboard({
219
240
  useEffect(() => {
220
241
  if (wasFocusedRef.current && !focused) setEntered(false);
221
242
  wasFocusedRef.current = focused;
222
- }, [focused]);
243
+ }, [focused, setEntered]);
223
244
  // A time or a price is picked with the arrows and Enter.
224
245
  const picking = !!timePick || !!pricePick;
225
246
  useEffect(() => {
226
247
  if (picking) setEntered(true);
227
- }, [picking]);
248
+ }, [picking, setEntered]);
228
249
  useEffect(() => {
229
250
  if (!toolsActive) setKeyboardPlacement(null);
230
251
  }, [toolsActive]);
@@ -240,7 +261,7 @@ export function useCompositeChartKeyboard({
240
261
  // pane's back key.
241
262
  const canDeleteDrawing = toolsActive && drawings.length > 0 && (!!selectedDrawingId || isDrawingTool(armedTool));
242
263
  // An owner that holds the cursor decides when it goes, so Esc stays the pane's.
243
- const clearableCursor = !!scene?.cursorDate && cursorDate === undefined;
264
+ const clearableCursor = () => !!cursor?.scene().cursorDate && cursorDate === undefined;
244
265
 
245
266
  const enterChart = () => {
246
267
  setEntered(true);
@@ -254,7 +275,7 @@ export function useCompositeChartKeyboard({
254
275
  setEntered(false);
255
276
  setLegendKeyboardIndex(null);
256
277
  // Stepping out to the strip leaves a pinned crosshair where it is.
257
- if (!clearableCursor || pin?.pinned) return;
278
+ if (!clearableCursor() || pin?.pinned) return;
258
279
  keyboardCursorDateRef.current = null;
259
280
  updateCursor(null);
260
281
  };
@@ -440,14 +461,21 @@ export function useCompositeChartKeyboard({
440
461
  };
441
462
  if (timePick && scene && isPlainKey(event, "return", "enter", "escape")) {
442
463
  consume();
443
- if (event.name === "escape") timePick.onCancel();
464
+ // A pick, like a placement below, is unfinished input: ending it is no half of a close.
465
+ if (event.name === "escape") {
466
+ keepEscapeFromClosing(event);
467
+ timePick.onCancel();
468
+ }
444
469
  else chartActionsRef.current.pick();
445
470
  return;
446
471
  }
447
472
  // Esc ends a price pick even with nothing drawn yet; Enter needs a price at the cursor.
448
473
  if (pricePick && (scene || isPlainKey(event, "escape")) && isPlainKey(event, "return", "enter", "escape")) {
449
474
  consume();
450
- if (event.name === "escape") pricePick.onCancel();
475
+ if (event.name === "escape") {
476
+ keepEscapeFromClosing(event);
477
+ pricePick.onCancel();
478
+ }
451
479
  else chartActionsRef.current.pickPrice();
452
480
  return;
453
481
  }
@@ -492,6 +520,7 @@ export function useCompositeChartKeyboard({
492
520
  }
493
521
  if (keyboardPlacement && (isPlainKey(event, "escape") || isPlainKey(event, "backspace"))) {
494
522
  consume();
523
+ keepEscapeFromClosing(event);
495
524
  setKeyboardPlacement(null);
496
525
  return;
497
526
  }
@@ -535,7 +564,7 @@ export function useCompositeChartKeyboard({
535
564
  setSelectedLevelId(null);
536
565
  return;
537
566
  }
538
- if (isPlainKey(event, "escape") && legendKeysActive && legendKeyboardIndex !== null && !clearableCursor) {
567
+ if (isPlainKey(event, "escape") && legendKeysActive && legendKeyboardIndex !== null && !clearableCursor()) {
539
568
  consume();
540
569
  setLegendKeyboardIndex(null);
541
570
  return;
@@ -563,7 +592,7 @@ export function useCompositeChartKeyboard({
563
592
  || interaction === "clear-cursor";
564
593
  if (!cursorInteraction && !toolsActive) return;
565
594
  if (
566
- (interaction === "clear-cursor" && !clearableCursor)
595
+ (interaction === "clear-cursor" && !clearableCursor())
567
596
  || ((interaction === "arm-measure"
568
597
  || interaction === "arm-zoom"
569
598
  || 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)