gloomberb 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
@@ -1,4 +1,14 @@
1
- import { useCallback, useEffect, useId, useMemo, useRef, useState, useSyncExternalStore, type ReactNode } from "react";
1
+ import {
2
+ useCallback,
3
+ useEffect,
4
+ useId,
5
+ useMemo,
6
+ useRef,
7
+ useState,
8
+ useSyncExternalStore,
9
+ type ComponentProps,
10
+ type ReactNode,
11
+ } from "react";
2
12
  import { useCompositeChartKeyboard } from "./use-composite-chart-keyboard";
3
13
  import { useCompositeViewport } from "./use-composite-viewport";
4
14
  import { CompositePanelSurface } from "./panel-surface";
@@ -40,6 +50,12 @@ import { useChartViewResetListener } from "../core/view-reset";
40
50
  import { useShowChartTextFallback } from "../native/use-chart-text-fallback";
41
51
  import { StaticXAxisLabels, StaticXMarkerLabels, StaticXMarkerOverlay } from "./axis-overlays";
42
52
  import { formatCompositeCursorAxisDate } from "./format";
53
+ import {
54
+ createCompositeCursorSource,
55
+ createValueStore,
56
+ useCursorScene,
57
+ type CompositeCursorSource,
58
+ } from "./cursor-source";
43
59
  import {
44
60
  resolveCompositeWheelPan,
45
61
  resolveCompositeWheelZoom,
@@ -51,10 +67,8 @@ import { useCompositeValueScales } from "./use-composite-value-scales";
51
67
  import { COMPOSITE_RIGHT_OFFSET_RATIO } from "./time-scale";
52
68
  import {
53
69
  allocateCompositePanelHeights,
54
- applyCompositeChartCursor,
55
70
  buildCompositeChartScene,
56
71
  compositeCursorAsOf,
57
- compositeLinkedCursorTime,
58
72
  resizeCompositePanel,
59
73
  resolveAdjacentCompositeCursorDate,
60
74
  } from "./scene";
@@ -93,6 +107,11 @@ const NO_X_MARKERS: readonly CompositeChartXMarker[] = [];
93
107
  const subscribeToNothing = () => () => {};
94
108
  const holdsNothing = () => false;
95
109
 
110
+ function finiteTimestampOrNull(date: Date | null | undefined): number | null {
111
+ const timestamp = date?.getTime() ?? null;
112
+ return timestamp !== null && Number.isFinite(timestamp) ? timestamp : null;
113
+ }
114
+
96
115
  /**
97
116
  * Desktop: the rows below the plot span the chart's box and their labels the
98
117
  * width the gutters leave, so when a resize draws the box at a new size
@@ -215,7 +234,9 @@ function ThemedCompositeChart({
215
234
  const { cellWidthPx = 8, cellHeightPx = 18, pixelRatio = 1, fractionalViewport = false } = useUiCapabilities();
216
235
  const isDesktopWeb = useUiCapabilities().nativePaneChrome === true;
217
236
  const showTextFallback = useShowChartTextFallback();
218
- const [internalCursorDate, setInternalCursorDate] = useState<Date | null>(null);
237
+ // The chart's own cursor, in epoch ms. A pointer move sets it without
238
+ // rendering the chart: only what draws the crosshair renders (see `cursorSource`).
239
+ const [ownCursor] = useState(() => createValueStore<number | null>(null));
219
240
  const [toolSpan, setToolSpan] = useState<ChartToolSpan | null>(null);
220
241
  const [pointerDragging, setPointerDragging] = useState(false);
221
242
  const paneFocused = usePaneFocused();
@@ -255,8 +276,7 @@ function ThemedCompositeChart({
255
276
  // pointer moves it as on any chart, and the pointer leaving returns it.
256
277
  const restingCursor = cursorDate !== undefined && !onCursorDateChange;
257
278
  const ownsCursor = cursorDate === undefined || restingCursor;
258
- const resolvedCursorDate = cursorDate === undefined ? internalCursorDate
259
- : restingCursor ? internalCursorDate ?? cursorDate : cursorDate;
279
+ const ownerCursorTimestamp = finiteTimestampOrNull(cursorDate);
260
280
  const totalWidth = Math.max(1, Math.floor(width));
261
281
  const totalHeight = Math.max(1, Math.floor(height));
262
282
  const seriesIdentityRef = useRef<ResolvedSeries[]>([]);
@@ -483,10 +503,12 @@ function ThemedCompositeChart({
483
503
  };
484
504
  return downsampleCompositeChartScene(laidOut, downsampleWidth);
485
505
  }, [downsampleWidth, layoutPanels, maximizedPanelId, plotWidth, projectedScene]);
486
- const resolvedCursorTimestamp = resolvedCursorDate?.getTime() ?? null;
487
- const normalizedCursorTimestamp = resolvedCursorTimestamp !== null && Number.isFinite(resolvedCursorTimestamp)
488
- ? resolvedCursorTimestamp
489
- : null;
506
+ // The cursor shown: the chart's own, or else the owner's.
507
+ const currentCursorTimestamp = useCallback(
508
+ () => (ownsCursor ? ownCursor.get() : null) ?? ownerCursorTimestamp,
509
+ [ownCursor, ownerCursorTimestamp, ownsCursor],
510
+ );
511
+ const normalizedCursorTimestamp = currentCursorTimestamp();
490
512
  // A custom x axis is not time, so there is no time to share. Otherwise an
491
513
  // interactive chart in a pane shares its crosshair with every chart in the
492
514
  // pane's layout tab, its siblings in the pane included: each chart is its
@@ -506,43 +528,40 @@ function ThemedCompositeChart({
506
528
  const sharedTime = link?.time;
507
529
  // Charts sharing a cursor show one: another chart's while it holds it, in
508
530
  // place of this one's own. An owner's resting cursor, such as a table's
509
- // selected row, comes back when it clears. A chart renders again when the
510
- // bar the shared cursor lands on here changes, not on every move: a daily
511
- // chart under a 30-minute one's cursor moves once a session.
531
+ // selected row, comes back when it clears. Whether one shows renders the
532
+ // chart; where it is renders only what draws it (see `cursorSource`).
512
533
  const showsSharedCursor = useSyncExternalStore(subscribeToLink, useCallback(() => sharedTime?.() != null, [sharedTime]));
513
- const sharedCursorBar = useSyncExternalStore(subscribeToLink, useCallback(() => {
514
- const time = sharedTime?.() ?? null;
515
- return time === null || !baseScene ? null : compositeLinkedCursorTime(baseScene, time);
516
- }, [baseScene, sharedTime]));
517
534
  const holdsSharedCursor = useSyncExternalStore(subscribeToLink, link?.held ?? holdsNothing);
518
535
  const pinnedCursor = useSyncExternalStore(subscribeToLink, link?.pinned ?? holdsNothing);
519
536
  const publishCursor = link?.publish;
520
- const scene = useMemo(() => {
521
- if (!baseScene) return null;
522
- if (showsSharedCursor) {
523
- return applyCompositeChartCursor(baseScene, sharedCursorBar === null ? null : new Date(sharedCursorBar), "linked");
524
- }
525
- return applyCompositeChartCursor(
526
- baseScene,
527
- normalizedCursorTimestamp === null ? null : new Date(normalizedCursorTimestamp),
528
- );
529
- }, [baseScene, normalizedCursorTimestamp, sharedCursorBar, showsSharedCursor]);
537
+ const cursorSource = useMemo<CompositeCursorSource | null>(() => baseScene ? createCompositeCursorSource({
538
+ baseScene,
539
+ own: ownsCursor ? ownCursor : null,
540
+ fallback: ownerCursorTimestamp,
541
+ link,
542
+ }) : null, [baseScene, link, ownCursor, ownerCursorTimestamp, ownsCursor]);
530
543
  const lastCursorTimestampRef = useRef<number | null>(normalizedCursorTimestamp);
531
544
  const renderedCursorTimestampRef = useRef<number | null>(normalizedCursorTimestamp);
532
- if (renderedCursorTimestampRef.current !== normalizedCursorTimestamp) {
533
- renderedCursorTimestampRef.current = normalizedCursorTimestamp;
534
- lastCursorTimestampRef.current = normalizedCursorTimestamp;
535
- }
545
+ // The cursor last shown, which a move to the same time does not report
546
+ // again. It follows the chart's own cursor as it moves, between renders.
547
+ const syncShownCursor = useCallback(() => {
548
+ const shown = currentCursorTimestamp();
549
+ if (renderedCursorTimestampRef.current === shown) return;
550
+ renderedCursorTimestampRef.current = shown;
551
+ lastCursorTimestampRef.current = shown;
552
+ }, [currentCursorTimestamp]);
553
+ syncShownCursor();
554
+ useEffect(() => ownCursor.subscribe(syncShownCursor), [ownCursor, syncShownCursor]);
536
555
 
537
556
  const updateCursor = useCallback((date: Date | null) => {
538
557
  const timestamp = date?.getTime() ?? null;
539
558
  const nextTimestamp = timestamp !== null && Number.isFinite(timestamp) ? timestamp : null;
540
559
  if (lastCursorTimestampRef.current === nextTimestamp) return;
541
560
  lastCursorTimestampRef.current = nextTimestamp;
542
- if (ownsCursor) setInternalCursorDate(date);
561
+ if (ownsCursor) ownCursor.set(nextTimestamp);
543
562
  onCursorDateChange?.(date);
544
563
  publishCursor?.(date && baseScene && nextTimestamp !== null ? compositeCursorAsOf(baseScene, date) : null);
545
- }, [baseScene, onCursorDateChange, ownsCursor, publishCursor]);
564
+ }, [baseScene, onCursorDateChange, ownCursor, ownsCursor, publishCursor]);
546
565
  // Another chart taking the cursor, or clearing it, takes it from this one,
547
566
  // so it does not come back here later. Read live: a move since the render
548
567
  // makes this chart's cursor the shared one again.
@@ -570,12 +589,15 @@ function ThemedCompositeChart({
570
589
  // The last time sits in a ref, so a moving crosshair costs no extra render,
571
590
  // and the footer's pin is there from the start: a hint appearing mid-hover
572
591
  // would move the plot under the pointer.
573
- const cursorAt = scene?.cursorDate?.getTime() ?? null;
574
592
  const lastCursorAtRef = useRef<{ time: number; shared: boolean } | null>(null);
575
- if (cursorAt !== null) {
576
- const shared = showsSharedCursor ? sharedTime?.() ?? null : null;
593
+ const noteShownCursor = useCallback(() => {
594
+ const cursorAt = cursorSource?.scene().cursorDate?.getTime() ?? null;
595
+ if (cursorAt === null) return;
596
+ const shared = sharedTime?.() ?? null;
577
597
  lastCursorAtRef.current = shared !== null ? { time: shared, shared: true } : { time: cursorAt, shared: false };
578
- }
598
+ }, [cursorSource, sharedTime]);
599
+ noteShownCursor();
600
+ useEffect(() => cursorSource?.subscribe(noteShownCursor), [cursorSource, noteShownCursor]);
579
601
  const pinnable = !!link?.pin;
580
602
  const togglePin = useCallback(() => {
581
603
  if (!link?.pin) return;
@@ -702,7 +724,8 @@ function ThemedCompositeChart({
702
724
  interactive,
703
725
  navigable,
704
726
  showLegend,
705
- scene,
727
+ scene: baseScene,
728
+ cursor: cursorSource,
706
729
  cursorDate,
707
730
  updateCursor: updateKeyboardCursor,
708
731
  pin: pinnable ? { pinned: pinnedCursor, toggle: togglePin } : null,
@@ -882,7 +905,7 @@ function ThemedCompositeChart({
882
905
  () => baseScene && showTimeAxis ? buildCompositeTimeAxisLayout(baseScene, plotWidth) : null,
883
906
  [baseScene, plotWidth, showTimeAxis],
884
907
  );
885
- const emptyTimeAxisLayout = !scene && showTimeAxis && effectiveViewport
908
+ const emptyTimeAxisLayout = !baseScene && showTimeAxis && effectiveViewport
886
909
  ? buildCompositeViewportTimeAxisLayout(effectiveViewport, plotWidth)
887
910
  : null;
888
911
 
@@ -898,7 +921,7 @@ function ThemedCompositeChart({
898
921
  ? { width: "auto", height: "auto", right: `calc(${rightPadding} * var(--cell-w))`, bottom: `calc(${timeAxisRows + xMarkerRows} * var(--cell-h))` }
899
922
  : undefined;
900
923
 
901
- if (!scene) {
924
+ if (!baseScene || !cursorSource) {
902
925
  const emptyPlotHeight = Math.max(0, totalHeight - legendRows - timeAxisRows - xMarkerRows);
903
926
  return (
904
927
  <Box
@@ -985,29 +1008,18 @@ function ThemedCompositeChart({
985
1008
  // while a tool picked from the keys is in hand, so the plot says which one.
986
1009
  const toolbarFolded = showToolbar && chartLayout.toolbarHidden === true && armedTool === null;
987
1010
  // Bars shorter than a day carry a time of day the cursor reads out.
988
- const intradayBars = scene.timeZone !== undefined || visibleSeries.some((entry) => (
1011
+ const intradayBars = baseScene.timeZone !== undefined || visibleSeries.some((entry) => (
989
1012
  !!entry.historyResolution && isIntradayResolution(entry.historyResolution)
990
1013
  ));
991
- const timeAxisCursorColumn = scene.cursorXRatio === null
992
- ? null
993
- : scene.cursorXRatio * Math.max(plotWidth - 1, 0);
994
- const timeAxisCursorPixelX = timeAxisCursorColumn === null
995
- ? null
996
- : timeAxisCursorColumn * cellWidthPx;
997
- const timeAxisCursorLabel = xAxis?.formatCursor && scene.cursorXRatio !== null
998
- ? xAxis.formatCursor(scene.cursorXRatio)
999
- : scene.cursorDate
1000
- ? formatCompositeCursorAxisDate(scene.cursorDate, scene.startTime, scene.endTime, scene.timeZone, intradayBars)
1001
- : null;
1002
1014
  // The crosshair labels the moving end, so the axis only adds the anchor.
1003
1015
  const timeAxisMarkers = toolSpan
1004
1016
  ? [{
1005
1017
  ratio: toolSpan.startXRatio,
1006
1018
  label: formatCompositeCursorAxisDate(
1007
1019
  new Date(toolSpan.startTime),
1008
- scene.startTime,
1009
- scene.endTime,
1010
- scene.timeZone,
1020
+ baseScene.startTime,
1021
+ baseScene.endTime,
1022
+ baseScene.timeZone,
1011
1023
  intradayBars,
1012
1024
  ),
1013
1025
  color: toolSpan.color,
@@ -1028,10 +1040,10 @@ function ThemedCompositeChart({
1028
1040
  data-gloom-data={navigationFrame ? `${navigationFrame.dataStart}:${navigationFrame.dataEnd}` : undefined}
1029
1041
  >
1030
1042
  {showLegend ? (
1031
- <CompositeLegend
1043
+ <CursorLegend
1032
1044
  // Every series' value at the crosshair, the latest ones when the
1033
1045
  // pointer leaves; the price and the time under it sit on the axes.
1034
- scene={scene}
1046
+ cursor={cursorSource}
1035
1047
  series={visibleLegendSeries}
1036
1048
  visibleSeriesIds={visibleSeriesIds}
1037
1049
  lineCues={lineCues}
@@ -1122,11 +1134,12 @@ function ThemedCompositeChart({
1122
1134
  onRestore={setDrawings}
1123
1135
  />
1124
1136
  ) : null}
1125
- {scene.panels.map((panel, index) => (
1137
+ {baseScene.panels.map((panel, index) => (
1126
1138
  <CompositePanelSurface
1127
1139
  key={panel.id}
1128
1140
  panel={panel}
1129
- scene={scene}
1141
+ scene={baseScene}
1142
+ cursor={cursorSource}
1130
1143
  plotWidth={plotWidth}
1131
1144
  leftAxisWidth={leftAxisWidth}
1132
1145
  rightAxisWidth={rightAxisWidth}
@@ -1217,14 +1230,15 @@ function ThemedCompositeChart({
1217
1230
  data-gloom-role="composite-chart-time-scale"
1218
1231
  >
1219
1232
  {leftPadding > 0 ? <Box width={leftPadding} /> : null}
1220
- <StaticXAxisLabels
1233
+ <CursorTimeAxis
1234
+ cursor={cursorSource}
1235
+ formatCursor={xAxis?.formatCursor}
1236
+ intradayBars={intradayBars}
1237
+ cellWidthPx={cellWidthPx}
1221
1238
  labels={xAxis?.ticks ? [] : xAxis?.labels ? [...xAxis.labels] : [timeAxisLayout.text]}
1222
1239
  positionedLabels={xAxis?.ticks ?? (xAxis?.labels ? undefined : timeAxisLayout.ticks)}
1223
1240
  width={plotWidth}
1224
1241
  color={resolvedColors.textDim}
1225
- cursorColumn={timeAxisCursorColumn}
1226
- cursorPixelX={timeAxisCursorPixelX}
1227
- cursorLabel={timeAxisCursorLabel}
1228
1242
  cursorColor={resolvedColors.crosshair}
1229
1243
  cursorBackgroundColor={resolvedColors.background}
1230
1244
  extraMarkers={timeAxisMarkers}
@@ -1246,3 +1260,44 @@ function ThemedCompositeChart({
1246
1260
  </Box>
1247
1261
  );
1248
1262
  }
1263
+
1264
+ /** The legend, rendering with the crosshair: its values are the series' at the cursor. */
1265
+ function CursorLegend({ cursor, ...props }: Omit<ComponentProps<typeof CompositeLegend>, "scene"> & {
1266
+ cursor: CompositeCursorSource;
1267
+ }) {
1268
+ return <CompositeLegend {...props} scene={useCursorScene(cursor)} />;
1269
+ }
1270
+
1271
+ /** The time axis, rendering with the crosshair: its label sits at the cursor, and the ticks under it step aside. */
1272
+ function CursorTimeAxis({
1273
+ cursor,
1274
+ formatCursor,
1275
+ intradayBars,
1276
+ cellWidthPx,
1277
+ width,
1278
+ ...props
1279
+ }: Omit<ComponentProps<typeof StaticXAxisLabels>, "cursorColumn" | "cursorPixelX" | "cursorLabel"> & {
1280
+ cursor: CompositeCursorSource;
1281
+ formatCursor?: (ratio: number) => string;
1282
+ intradayBars: boolean;
1283
+ cellWidthPx: number;
1284
+ }) {
1285
+ const scene = useCursorScene(cursor);
1286
+ const cursorColumn = scene.cursorXRatio === null
1287
+ ? null
1288
+ : scene.cursorXRatio * Math.max(width - 1, 0);
1289
+ const cursorLabel = formatCursor && scene.cursorXRatio !== null
1290
+ ? formatCursor(scene.cursorXRatio)
1291
+ : scene.cursorDate
1292
+ ? formatCompositeCursorAxisDate(scene.cursorDate, scene.startTime, scene.endTime, scene.timeZone, intradayBars)
1293
+ : null;
1294
+ return (
1295
+ <StaticXAxisLabels
1296
+ {...props}
1297
+ width={width}
1298
+ cursorColumn={cursorColumn}
1299
+ cursorPixelX={cursorColumn === null ? null : cursorColumn * cellWidthPx}
1300
+ cursorLabel={cursorLabel}
1301
+ />
1302
+ );
1303
+ }
@@ -0,0 +1,111 @@
1
+ import { useSyncExternalStore } from "react";
2
+ import { applyCompositeChartCursor, compositeLinkedCursorTime } from "./scene";
3
+ import type { CompositeChartScene } from "./types";
4
+
5
+ type Listener = () => void;
6
+
7
+ /** A value that changes without rendering what holds it: only its readers render. */
8
+ export interface ValueStore<T> {
9
+ get(): T;
10
+ set(value: T): void;
11
+ subscribe(listener: Listener): () => void;
12
+ }
13
+
14
+ export function createValueStore<T>(initial: T): ValueStore<T> {
15
+ let value = initial;
16
+ const listeners = new Set<Listener>();
17
+ return {
18
+ get: () => value,
19
+ set(next) {
20
+ if (Object.is(next, value)) return;
21
+ value = next;
22
+ for (const listener of [...listeners]) listener();
23
+ },
24
+ subscribe(listener) {
25
+ listeners.add(listener);
26
+ return () => {
27
+ listeners.delete(listener);
28
+ };
29
+ },
30
+ };
31
+ }
32
+
33
+ /** The cursor charts in one tab share: the time another chart's crosshair is at. */
34
+ interface SharedCursorTime {
35
+ subscribe(listener: Listener): () => void;
36
+ time(): number | null;
37
+ }
38
+
39
+ /**
40
+ * The chart's scene with its crosshair applied, for the parts that draw the
41
+ * crosshair: the legend's values, the value and time axes' cursor labels and
42
+ * the plot's crosshair. A pointer move renders those alone; the chart, its
43
+ * series and its axes stay as they are.
44
+ */
45
+ export interface CompositeCursorSource {
46
+ /** The scene with the cursor, the same object until the cursor moves to another bar. */
47
+ scene(): CompositeChartScene;
48
+ subscribe(listener: Listener): () => void;
49
+ }
50
+
51
+ export interface CompositeCursorSourceOptions {
52
+ /** The scene the cursor is applied to, which has none of its own. */
53
+ baseScene: CompositeChartScene;
54
+ /** The chart's own cursor, in epoch ms, which the pointer and the keys move. Null when the owner holds it. */
55
+ own: ValueStore<number | null> | null;
56
+ /** The owner's cursor, in epoch ms: the one shown while the chart has none of its own. */
57
+ fallback: number | null;
58
+ /** Another chart's cursor, which shows in place of this one's while it is set. */
59
+ link?: SharedCursorTime;
60
+ }
61
+
62
+ export function createCompositeCursorSource({
63
+ baseScene,
64
+ own,
65
+ fallback,
66
+ link,
67
+ }: CompositeCursorSourceOptions): CompositeCursorSource {
68
+ let cachedKey: string | null = null;
69
+ let cached = baseScene;
70
+ const scene = () => {
71
+ const sharedTime = link?.time() ?? null;
72
+ let key: string;
73
+ let next: () => CompositeChartScene;
74
+ if (sharedTime !== null) {
75
+ // A chart renders again when the bar the shared cursor lands on here
76
+ // changes, not on every move: a daily chart under a 30-minute one's
77
+ // cursor moves once a session.
78
+ const bar = compositeLinkedCursorTime(baseScene, sharedTime);
79
+ key = `linked:${bar}`;
80
+ next = () => applyCompositeChartCursor(baseScene, bar === null ? null : new Date(bar), "linked");
81
+ } else {
82
+ const time = own?.get() ?? fallback;
83
+ key = `own:${time}`;
84
+ next = () => applyCompositeChartCursor(baseScene, time === null ? null : new Date(time));
85
+ }
86
+ if (key !== cachedKey) {
87
+ cachedKey = key;
88
+ cached = next();
89
+ }
90
+ return cached;
91
+ };
92
+ const subscribe = (listener: Listener) => {
93
+ const stopOwn = own?.subscribe(listener);
94
+ const stopLink = link?.subscribe(listener);
95
+ return () => {
96
+ stopOwn?.();
97
+ stopLink?.();
98
+ };
99
+ };
100
+ return { scene, subscribe };
101
+ }
102
+
103
+ /** The scene with the cursor, rendering again when the cursor moves to another bar. */
104
+ export function useCursorScene(source: CompositeCursorSource): CompositeChartScene {
105
+ return useSyncExternalStore(source.subscribe, source.scene, source.scene);
106
+ }
107
+
108
+ /** A store's value, rendering again when it changes. */
109
+ export function useValueStore<T>(store: ValueStore<T>): T {
110
+ return useSyncExternalStore(store.subscribe, store.get, store.get);
111
+ }
@@ -191,13 +191,27 @@ function ticksFitRows(domain: CompositeAxisDomain, values: number[]): boolean {
191
191
  return true;
192
192
  }
193
193
 
194
+ // Every label on an axis reads its ticks again (see `compactAxisNumber`).
195
+ const tickValues = new WeakMap<CompositeAxisDomain, readonly number[]>();
196
+
194
197
  /** Round values inside a linear domain, so every gridline carries a readable
195
198
  * value. A log axis, or a short terminal panel no round step fits, keeps its
196
199
  * top, middle and bottom values. */
197
- function axisTickValues(domain: CompositeAxisDomain): number[] {
200
+ function axisTickValues(domain: CompositeAxisDomain): readonly number[] {
201
+ let values = tickValues.get(domain);
202
+ if (!values) {
203
+ values = computeAxisTickValues(domain);
204
+ tickValues.set(domain, values);
205
+ }
206
+ return values;
207
+ }
208
+
209
+ function computeAxisTickValues(domain: CompositeAxisDomain): number[] {
198
210
  const span = domain.max - domain.min;
199
211
  if (domain.scale === "log" || !Number.isFinite(span) || span <= 0) return edgeTickValues(domain);
200
212
  const maxTicks = Math.max(2, domain.maxTicks ?? DEFAULT_AXIS_MAX_TICKS);
213
+ const grid = axisTickGrid(domain);
214
+ if (grid) return gridAxisTickValues(domain, grid, span, maxTicks);
201
215
  // Walk the 1-2-5 ladder around the target spacing and keep the step whose
202
216
  // tick count lands nearest the target, one extra tick allowed.
203
217
  let step = adjacentNiceStep(adjacentNiceStep(niceCeilStep(span / (maxTicks - 1)), -1), -1);
@@ -216,6 +230,66 @@ function axisTickValues(domain: CompositeAxisDomain): number[] {
216
230
  return best.length >= Math.max(2, edges.length) ? best : edges;
217
231
  }
218
232
 
233
+ // Half a 32nd: the finest step a 32nds axis ticks on when its series name no grid of their own.
234
+ const HALF_THIRTY_SECOND = 1 / 64;
235
+
236
+ /**
237
+ * The grid a linear axis's ticks fall on: its series' own (a Treasury
238
+ * future's fraction of a 32nd), else half a 32nd on an axis quoted in 32nds.
239
+ * None on a decimal axis.
240
+ */
241
+ function axisTickGrid(domain: CompositeAxisDomain): number | undefined {
242
+ if (domain.scale === "log") return undefined;
243
+ const grid = domain.tickGrid ?? (domain.unit.trim() === "32nds" ? HALF_THIRTY_SECOND : undefined);
244
+ return grid !== undefined && Number.isFinite(grid) && grid > 0 ? grid : undefined;
245
+ }
246
+
247
+ // Steps a 32nds axis takes, in 32nds, between its finest grid and a whole point.
248
+ const THIRTY_SECONDS_STEPS = [1, 2, 3, 4, 6, 8, 12, 16];
249
+
250
+ /**
251
+ * Steps on a fractional grid, as a Treasury price reads: the grid doubled up
252
+ * to a 32nd, then 1, 2, 3, 4, 6, 8, 12 and 16 32nds, then whole points on the
253
+ * 1-2-5 ladder. Each is a multiple of the grid and no wider than the axis.
254
+ */
255
+ function gridSteps(grid: number, span: number): number[] {
256
+ const steps: number[] = [];
257
+ for (let step = grid; step < 1 / 32 - 1e-12; step *= 2) steps.push(step);
258
+ steps.push(...THIRTY_SECONDS_STEPS.map((count) => count / 32));
259
+ for (let step = 1; step <= span * (1 + 1e-9); step = adjacentNiceStep(step, 1)) steps.push(step);
260
+ return steps.filter((step) => step >= grid * (1 - 1e-9) && step <= span * (1 + 1e-9)
261
+ && Math.abs(step / grid - Math.round(step / grid)) < 1e-9);
262
+ }
263
+
264
+ /**
265
+ * Ticks on a fractional grid (`gridSteps`), keeping the step whose count
266
+ * lands nearest the target, as the decimal ladder does. Where no step gives
267
+ * as many as the top, middle and bottom, those are kept instead, each moved
268
+ * onto the grid: no label reads 104-25.60.
269
+ */
270
+ function gridAxisTickValues(domain: CompositeAxisDomain, grid: number, span: number, maxTicks: number): number[] {
271
+ let best: number[] = [];
272
+ for (const step of gridSteps(grid, span)) {
273
+ const values = stepMultiples(domain.min, domain.max, step);
274
+ if (values.length >= 2 && values.length <= maxTicks + 1
275
+ && (best.length === 0 || Math.abs(values.length - maxTicks) < Math.abs(best.length - maxTicks))
276
+ && ticksFitRows(domain, values)) {
277
+ best = values;
278
+ }
279
+ }
280
+ const edges = edgeTickValues(domain);
281
+ if (best.length >= Math.max(2, edges.length)) return best;
282
+ const onGrid = edges.map((value, index) => {
283
+ // The top rounds down and the bottom up, so neither leaves the axis.
284
+ const units = value / grid;
285
+ const whole = index === 0 ? Math.floor(units + 1e-9) : index === edges.length - 1 ? Math.ceil(units - 1e-9) : Math.round(units);
286
+ return Number((whole * grid).toPrecision(12));
287
+ }).filter((value) => value >= domain.min - grid * 1e-9 && value <= domain.max + grid * 1e-9);
288
+ const snapped = [...new Set(onGrid)];
289
+ return snapped.length >= best.length && snapped.length > 0 ? snapped
290
+ : best.length > 0 ? best : [Number((Math.round((domain.min + domain.max) / 2 / grid) * grid).toPrecision(12))];
291
+ }
292
+
219
293
  /** The narrowest distance between neighbouring ticks. A log axis bunches its
220
294
  * lowest ticks together, so the tightest pair is what every label has to stay
221
295
  * legible against. */
@@ -397,6 +471,12 @@ export function formatCompositeCursorValue(value: number, domain: CompositeAxisD
397
471
  return formatCompositeAxisValue(value, domain);
398
472
  }
399
473
 
474
+ /**
475
+ * An axis label for a value. It must read only the value and the axis: the
476
+ * ticks and gutter widths it labels are kept per formatter and axis (see
477
+ * `axisResultCache`), so one that reads anything else (a currency, a setting)
478
+ * is a new function whenever that changes.
479
+ */
400
480
  export type CompositeAxisValueFormatter = (value: number, domain: CompositeAxisDomain) => string;
401
481
 
402
482
  type LabeledTick = { value: number; label: string };
@@ -409,10 +489,11 @@ function repeatsLabel(ticks: LabeledTick[]): boolean {
409
489
  * (2k 2k 1.9k). The axis then climbs the 1-2-5 ladder until its labels
410
490
  * differ, and failing that keeps its top and bottom, or the top alone. */
411
491
  function distinctAxisTicks(domain: CompositeAxisDomain, format: CompositeAxisValueFormatter): LabeledTick[] {
412
- const label = (values: number[]) => values.map((value) => ({ value, label: format(value, domain) }));
492
+ const label = (values: readonly number[]) => values.map((value) => ({ value, label: format(value, domain) }));
413
493
  const ticks = label(axisTickValues(domain));
414
494
  if (ticks.length < 2 || !repeatsLabel(ticks)) return ticks;
415
- if (domain.scale !== "log") {
495
+ // A grid's ticks are already its coarsest that fit; a coarser decimal step would leave the grid.
496
+ if (domain.scale !== "log" && !axisTickGrid(domain)) {
416
497
  const gap = Math.abs(ticks[0]!.value - ticks[1]!.value);
417
498
  let step = niceCeilStep(gap);
418
499
  if (step <= gap * (1 + 1e-9)) step = adjacentNiceStep(step, 1);
@@ -429,15 +510,96 @@ function distinctAxisTicks(domain: CompositeAxisDomain, format: CompositeAxisVal
429
510
  return top.label !== bottom.label ? [top, bottom] : [top];
430
511
  }
431
512
 
513
+ /** Whether two records hold equal values under every key either has; a key set to undefined reads as absent. */
514
+ function sameFields(
515
+ left: Record<string, unknown>,
516
+ right: Record<string, unknown>,
517
+ same: (left: unknown, right: unknown) => boolean,
518
+ ): boolean {
519
+ for (const key of Object.keys(left)) {
520
+ if (!same(left[key], right[key])) return false;
521
+ }
522
+ for (const key of Object.keys(right)) {
523
+ if (!Object.hasOwn(left, key) && !same(undefined, right[key])) return false;
524
+ }
525
+ return true;
526
+ }
527
+
528
+ function sameAxisDomainValue(left: unknown, right: unknown): boolean {
529
+ if (Object.is(left, right)) return true;
530
+ if (Array.isArray(left) && Array.isArray(right)) {
531
+ return left.length === right.length && left.every((value, index) => Object.is(value, right[index]));
532
+ }
533
+ if (!left || !right || typeof left !== "object" || typeof right !== "object") return false;
534
+ if (Array.isArray(left) || Array.isArray(right)) return false;
535
+ return sameFields(left as Record<string, unknown>, right as Record<string, unknown>, Object.is);
536
+ }
537
+
538
+ /**
539
+ * Whether two axes read the same: every field either has equal, its lists
540
+ * and records one level down. A chart builds its axes again on every tick,
541
+ * and they come out the same until the price leaves the range.
542
+ */
543
+ export function sameCompositeAxisDomain(left: CompositeAxisDomain, right: CompositeAxisDomain): boolean {
544
+ if (left === right) return true;
545
+ return sameFields(
546
+ left as unknown as Record<string, unknown>,
547
+ right as unknown as Record<string, unknown>,
548
+ sameAxisDomainValue,
549
+ );
550
+ }
551
+
552
+ export type CompositeAxisTick = { ratio: number; value: number; label: string };
553
+
554
+ /**
555
+ * The last results worked out for an axis under each formatter, kept for the
556
+ * next scene's equal axes. They hold while the formatter reads only the value
557
+ * and the axis (see `CompositeAxisValueFormatter`). Each hit labels the axis's
558
+ * top once more and works the result out again when that label changed, so a
559
+ * formatter that reads something else and kept its identity cannot keep
560
+ * stale labels past a change that moves its top label.
561
+ */
562
+ export function axisResultCache<Value>(size = 8): (
563
+ domain: CompositeAxisDomain,
564
+ format: CompositeAxisValueFormatter,
565
+ key: string,
566
+ compute: () => Value,
567
+ ) => Value {
568
+ type Entry = { domain: CompositeAxisDomain; key: string; probe: string; value: Value };
569
+ const byFormat = new WeakMap<CompositeAxisValueFormatter, Entry[]>();
570
+ return (domain, format, key, compute) => {
571
+ let entries = byFormat.get(format);
572
+ if (!entries) {
573
+ entries = [];
574
+ byFormat.set(format, entries);
575
+ }
576
+ const probe = format(domain.max, domain);
577
+ const index = entries.findIndex((entry) => entry.key === key && sameCompositeAxisDomain(entry.domain, domain));
578
+ if (index >= 0) {
579
+ const [entry] = entries.splice(index, 1);
580
+ if (entry!.probe === probe) {
581
+ entries.unshift(entry!);
582
+ return entry!.value;
583
+ }
584
+ }
585
+ const value = compute();
586
+ entries.unshift({ domain, key, probe, value });
587
+ if (entries.length > size) entries.length = size;
588
+ return value;
589
+ };
590
+ }
591
+
592
+ const cachedAxisTicks = axisResultCache<readonly CompositeAxisTick[]>();
593
+
432
594
  export function compositeAxisTicks(
433
595
  domain: CompositeAxisDomain,
434
596
  format: CompositeAxisValueFormatter = formatCompositeAxisValue,
435
- ): Array<{ ratio: number; value: number; label: string }> {
436
- return distinctAxisTicks(domain, format).map(({ value, label }) => ({
597
+ ): readonly CompositeAxisTick[] {
598
+ return cachedAxisTicks(domain, format, "", () => distinctAxisTicks(domain, format).map(({ value, label }) => ({
437
599
  ratio: axisTickRatio(domain, value),
438
600
  value,
439
601
  label,
440
- }));
602
+ })));
441
603
  }
442
604
 
443
605
  /** Gridlines follow the ticks of the panel's labeled axis, left first. The