gloomberb 0.19.4 → 0.19.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (321) hide show
  1. package/package.json +3 -1
  2. package/patches/@opentui%2Fcore@0.3.2.patch +86 -25
  3. package/src/api-client/equity-screener.ts +23 -0
  4. package/src/app/pane-runtime/index.tsx +2 -0
  5. package/src/app/pane-runtime/plugin-bindings.ts +10 -1
  6. package/src/app.tsx +63 -16
  7. package/src/cli/commands/command-utils.ts +4 -0
  8. package/src/cli/commands/market.ts +264 -33
  9. package/src/cli/commands/search.ts +22 -4
  10. package/src/cli/commands/ticker.ts +84 -39
  11. package/src/cli/currency-name-hint.ts +60 -0
  12. package/src/cli/glossary.ts +3 -3
  13. package/src/cli/history-rows.ts +18 -1
  14. package/src/cli/known-gaps.ts +25 -2
  15. package/src/cli/listing-arg.ts +12 -0
  16. package/src/cli/not-a-ticker.ts +5 -3
  17. package/src/cli/pane-functions/capabilities.ts +2 -0
  18. package/src/cli/pane-functions/catalog.ts +31 -5
  19. package/src/cli/pane-functions/function-help.ts +8 -5
  20. package/src/cli/pane-functions/headless.ts +11 -6
  21. package/src/cli/pane-functions/market-session.ts +6 -7
  22. package/src/cli/pane-functions/resolver.ts +75 -2
  23. package/src/cli/quote-answer.ts +9 -0
  24. package/src/cli/series-search.ts +4 -5
  25. package/src/cli/symbol-list.ts +54 -2
  26. package/src/cli/symbol-rows.ts +14 -2
  27. package/src/cli/ticker-resolution.ts +89 -20
  28. package/src/components/chart/composite/axis-overlays.tsx +60 -27
  29. package/src/components/chart/composite/composite-chart.tsx +118 -63
  30. package/src/components/chart/composite/cursor-source.ts +111 -0
  31. package/src/components/chart/composite/format.ts +168 -6
  32. package/src/components/chart/composite/legend.tsx +8 -4
  33. package/src/components/chart/composite/panel-bitmap.ts +28 -2
  34. package/src/components/chart/composite/panel-labels.ts +20 -1
  35. package/src/components/chart/composite/panel-surface.tsx +201 -92
  36. package/src/components/chart/composite/price-axis-labels.tsx +92 -46
  37. package/src/components/chart/composite/price-series.ts +31 -8
  38. package/src/components/chart/composite/scene.ts +154 -59
  39. package/src/components/chart/composite/series-axis-tags.tsx +4 -2
  40. package/src/components/chart/composite/time-axis.ts +30 -7
  41. package/src/components/chart/composite/time-scale.ts +211 -56
  42. package/src/components/chart/composite/types.ts +11 -1
  43. package/src/components/chart/composite/use-composite-chart-keyboard.ts +32 -12
  44. package/src/components/chart/curve/curve-surface.tsx +5 -2
  45. package/src/components/chart/curve/model.ts +4 -1
  46. package/src/components/chart/native/use-bitmap-metrics.ts +81 -0
  47. package/src/components/chart/static/series.ts +3 -0
  48. package/src/components/command-bar/commands/collection-list.ts +81 -0
  49. package/src/components/command-bar/commands/direct/index.ts +6 -0
  50. package/src/components/command-bar/commands/registry.ts +8 -0
  51. package/src/components/command-bar/layout-items/current-layout.ts +22 -1
  52. package/src/components/command-bar/layout-items/focused-pane.ts +22 -1
  53. package/src/components/command-bar/pane-templates/items.ts +19 -3
  54. package/src/components/command-bar/pane-templates/workflow.ts +5 -0
  55. package/src/components/command-bar/routes/root/results.ts +23 -3
  56. package/src/components/command-bar/routes/root/selection.ts +4 -2
  57. package/src/components/command-bar/routes/root/shortcut-feedback.ts +1 -1
  58. package/src/components/command-bar/routes/root/shortcut-items.ts +3 -4
  59. package/src/components/command-bar/routes/root/shortcuts.ts +58 -14
  60. package/src/components/command-bar/routes/root/ticker-first.ts +32 -0
  61. package/src/components/command-bar/surface/environment.ts +2 -0
  62. package/src/components/command-bar/view-model.ts +7 -0
  63. package/src/components/command-bar/workflow/ops.ts +2 -1
  64. package/src/components/command-bar/workflow/tickers.ts +20 -0
  65. package/src/components/layout/shell/active-drag.ts +38 -7
  66. package/src/components/layout/shell/drag/magnets.ts +106 -0
  67. package/src/components/layout/shell/menu.ts +15 -1
  68. package/src/components/layout/shell/pane/actions.ts +4 -0
  69. package/src/components/layout/shell/ticker-link-menu.ts +12 -3
  70. package/src/components/layout/status-bar.tsx +20 -0
  71. package/src/components/layout/window-controls.tsx +96 -35
  72. package/src/components/layout/window-fullscreen.ts +20 -0
  73. package/src/components/onboarding/onboarding-keyboard.ts +5 -1
  74. package/src/components/onboarding/onboarding-wizard.tsx +15 -4
  75. package/src/components/onboarding/portfolio-step/positions-panel.tsx +8 -5
  76. package/src/components/onboarding/use-onboarding-progress.ts +20 -1
  77. package/src/components/price-sparkline/view.tsx +14 -6
  78. package/src/components/quote-flash.ts +36 -32
  79. package/src/components/ticker/badge/index.tsx +8 -4
  80. package/src/components/ticker/badge/list.tsx +23 -7
  81. package/src/components/ui/column-grid.tsx +8 -2
  82. package/src/components/ui/data-table/opentui/model.ts +4 -1
  83. package/src/components/ui/tabs.tsx +5 -2
  84. package/src/core/state/app/layout.ts +18 -3
  85. package/src/core/state/app/state.ts +2 -0
  86. package/src/core/state/app/types.ts +5 -0
  87. package/src/data/config/layout.ts +3 -0
  88. package/src/data/config/store/normalize.ts +39 -4
  89. package/src/i18n/es.ts +10 -0
  90. package/src/i18n/ja.ts +10 -0
  91. package/src/i18n/ko.ts +10 -0
  92. package/src/i18n/zh-cn.ts +10 -0
  93. package/src/i18n/zh-tw.ts +10 -0
  94. package/src/layout/pane-manager/floating-placement.ts +7 -4
  95. package/src/layout/pane-manager/floating.ts +5 -2
  96. package/src/market-data/bond-funds.ts +19 -0
  97. package/src/market-data/coordinator/events.ts +17 -1
  98. package/src/market-data/frame-scheduler.ts +47 -10
  99. package/src/market-data/frame-wake.ts +74 -0
  100. package/src/market-data/futures-board.ts +7 -6
  101. package/src/market-data/futures-contract.ts +14 -3
  102. package/src/market-data/hooks.tsx +12 -3
  103. package/src/market-data/market/freshness.ts +18 -0
  104. package/src/market-data/market/status.ts +15 -2
  105. package/src/market-data/performance.ts +78 -9
  106. package/src/market-data/request-types.ts +6 -3
  107. package/src/plugins/builtin/alerts/cli.ts +2 -1
  108. package/src/plugins/builtin/analytics/risk-evidence.ts +1 -0
  109. package/src/plugins/builtin/attention/evidence.ts +1 -1
  110. package/src/plugins/builtin/awards/client.ts +1 -1
  111. package/src/plugins/builtin/awards/evidence.ts +1 -1
  112. package/src/plugins/builtin/awards/pane.tsx +2 -1
  113. package/src/plugins/builtin/bond-calculator/headless.ts +2 -1
  114. package/src/plugins/builtin/bond-calculator/index.tsx +1 -1
  115. package/src/plugins/builtin/bond-calculator/math.ts +1 -1
  116. package/src/plugins/builtin/bond-calculator/model.ts +14 -5
  117. package/src/plugins/builtin/bond-calculator/pane.tsx +1 -1
  118. package/src/plugins/builtin/broker-manager/footer.ts +3 -2
  119. package/src/plugins/builtin/broker-manager/index.tsx +2 -1
  120. package/src/plugins/builtin/broker-manager/keyboard.ts +2 -1
  121. package/src/plugins/builtin/buildout/cells.tsx +25 -45
  122. package/src/plugins/builtin/buildout/detail/company.tsx +3 -3
  123. package/src/plugins/builtin/buildout/detail/index.tsx +1 -1
  124. package/src/plugins/builtin/buildout/detail/intel.tsx +4 -7
  125. package/src/plugins/builtin/buildout/detail/site.tsx +4 -4
  126. package/src/plugins/builtin/buildout/detail/ui.tsx +39 -38
  127. package/src/plugins/builtin/buildout/format.ts +23 -1
  128. package/src/plugins/builtin/buildout/model/types.ts +1 -0
  129. package/src/plugins/builtin/buildout/pane/index.tsx +2 -8
  130. package/src/plugins/builtin/buildout/table-model.ts +12 -4
  131. package/src/plugins/builtin/catalysts/evidence.ts +1 -1
  132. package/src/plugins/builtin/catalysts/pane.tsx +2 -1
  133. package/src/plugins/builtin/cds/headless.ts +1 -0
  134. package/src/plugins/builtin/cds/index.tsx +1 -1
  135. package/src/plugins/builtin/chart-composer/headless.ts +40 -1
  136. package/src/plugins/builtin/cloud/plugin.tsx +2 -0
  137. package/src/plugins/builtin/cloud/upgrade-status-widget.tsx +28 -3
  138. package/src/plugins/builtin/cloud-tweets/table.tsx +3 -2
  139. package/src/plugins/builtin/comment-letters/client.ts +2 -1
  140. package/src/plugins/builtin/company-kpis/client.ts +1 -1
  141. package/src/plugins/builtin/company-kpis/pane.tsx +2 -1
  142. package/src/plugins/builtin/company-kpis/screenshot-evidence.ts +3 -2
  143. package/src/plugins/builtin/correlation/headless.ts +3 -2
  144. package/src/plugins/builtin/cot/headless.ts +9 -3
  145. package/src/plugins/builtin/cot/model.ts +44 -3
  146. package/src/plugins/builtin/credit-documents/client.ts +1 -1
  147. package/src/plugins/builtin/credit-documents/evidence.ts +1 -1
  148. package/src/plugins/builtin/credit-documents/pane.tsx +2 -1
  149. package/src/plugins/builtin/crypto-board/pane.tsx +5 -4
  150. package/src/plugins/builtin/debt-maturities/headless.ts +11 -2
  151. package/src/plugins/builtin/debt-maturities/model.ts +66 -0
  152. package/src/plugins/builtin/debt-maturities/pane.tsx +23 -4
  153. package/src/plugins/builtin/earnings-calls/pane.tsx +1 -1
  154. package/src/plugins/builtin/earnings-ripple/index.tsx +6 -1
  155. package/src/plugins/builtin/earnings-ripple/pane.tsx +1 -1
  156. package/src/plugins/builtin/econ/calendar-model.ts +30 -6
  157. package/src/plugins/builtin/econ/fred-catalog.ts +5 -5
  158. package/src/plugins/builtin/econ/print-watch.ts +3 -1
  159. package/src/plugins/builtin/equity-screener/client.ts +1 -1
  160. package/src/plugins/builtin/equity-screener/criterion-editor.tsx +4 -16
  161. package/src/plugins/builtin/equity-screener/headless.ts +4 -2
  162. package/src/plugins/builtin/equity-screener/ideas.ts +67 -3
  163. package/src/plugins/builtin/equity-screener/model.ts +180 -12
  164. package/src/plugins/builtin/equity-screener/pane.tsx +52 -12
  165. package/src/plugins/builtin/equity-screener/screen-check.ts +7 -4
  166. package/src/plugins/builtin/equity-screener/watchlist.ts +33 -0
  167. package/src/plugins/builtin/futures/series.ts +16 -1
  168. package/src/plugins/builtin/futures-curve/client.ts +19 -0
  169. package/src/plugins/builtin/futures-curve/headless.ts +52 -13
  170. package/src/plugins/builtin/futures-curve/index.tsx +1 -1
  171. package/src/plugins/builtin/futures-curve/model.ts +77 -6
  172. package/src/plugins/builtin/futures-curve/pane.tsx +19 -3
  173. package/src/plugins/builtin/fx-matrix/headless.ts +4 -2
  174. package/src/plugins/builtin/fx-matrix/index.tsx +37 -3
  175. package/src/plugins/builtin/fx-matrix/pairs.ts +15 -0
  176. package/src/plugins/builtin/gpu/headless.ts +2 -1
  177. package/src/plugins/builtin/help/function-card.tsx +2 -1
  178. package/src/plugins/builtin/help/index.tsx +2 -1
  179. package/src/plugins/builtin/insider/display.ts +45 -6
  180. package/src/plugins/builtin/ipo-calendar/model.ts +2 -0
  181. package/src/plugins/builtin/iv-history/client.ts +2 -1
  182. package/src/plugins/builtin/iv-history/headless.ts +2 -1
  183. package/src/plugins/builtin/jobs/pages.ts +4 -4
  184. package/src/plugins/builtin/kelly-sizer/headless.ts +2 -1
  185. package/src/plugins/builtin/macro-day/client.ts +41 -0
  186. package/src/plugins/builtin/macro-day/headless.ts +19 -9
  187. package/src/plugins/builtin/macro-day/model.ts +3 -1
  188. package/src/plugins/builtin/market-heatmap/index.tsx +2 -1
  189. package/src/plugins/builtin/market-movers/index.tsx +4 -3
  190. package/src/plugins/builtin/members/client.ts +1 -1
  191. package/src/plugins/builtin/mna/distress/client.ts +1 -0
  192. package/src/plugins/builtin/mna/distress/headless.ts +1 -0
  193. package/src/plugins/builtin/mna/pane.tsx +4 -1
  194. package/src/plugins/builtin/options/market-reference.ts +1 -1
  195. package/src/plugins/builtin/options/open-interest-as-of.ts +3 -1
  196. package/src/plugins/builtin/options/view.tsx +2 -1
  197. package/src/plugins/builtin/options-calculator/evidence.ts +1 -1
  198. package/src/plugins/builtin/options-scenario/csp-screen-pane.tsx +1 -1
  199. package/src/plugins/builtin/options-scenario/csp-screen.ts +8 -4
  200. package/src/plugins/builtin/options-scenario/csp.ts +28 -9
  201. package/src/plugins/builtin/options-scenario/evidence.ts +5 -4
  202. package/src/plugins/builtin/options-scenario/pane.tsx +2 -1
  203. package/src/plugins/builtin/perps/client.ts +1 -1
  204. package/src/plugins/builtin/perps/pane.tsx +3 -1
  205. package/src/plugins/builtin/portfolio-list/cli/bulk-symbols.ts +17 -0
  206. package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +2 -1
  207. package/src/plugins/builtin/portfolio-list/cli/watchlist-command.ts +4 -2
  208. package/src/plugins/builtin/portfolio-list/pane/index.tsx +7 -3
  209. package/src/plugins/builtin/portfolio-list/use-throttled-memo.ts +10 -19
  210. package/src/plugins/builtin/rate-path/headless.ts +24 -10
  211. package/src/plugins/builtin/research/analyst-model.ts +1 -0
  212. package/src/plugins/builtin/research/equity-diagnostic-pane.tsx +2 -1
  213. package/src/plugins/builtin/research/event-model.ts +10 -3
  214. package/src/plugins/builtin/research/events-headless.ts +20 -2
  215. package/src/plugins/builtin/research/index.tsx +1 -0
  216. package/src/plugins/builtin/research/relative-valuation-currency.ts +1 -1
  217. package/src/plugins/builtin/research/relative-valuation-peers.ts +2 -1
  218. package/src/plugins/builtin/research-search/command-bar-search.ts +3 -1
  219. package/src/plugins/builtin/research-search/snippet.ts +1 -0
  220. package/src/plugins/builtin/revenue-breakdown/client.ts +3 -2
  221. package/src/plugins/builtin/seasonality/headless.ts +2 -1
  222. package/src/plugins/builtin/sec/command-bar-search.ts +3 -2
  223. package/src/plugins/builtin/sec/fund-facts.ts +17 -1
  224. package/src/plugins/builtin/sec/index.tsx +8 -5
  225. package/src/plugins/builtin/sec/row-summaries.ts +28 -12
  226. package/src/plugins/builtin/shared/members-menu.tsx +103 -38
  227. package/src/plugins/builtin/short-interest/publications-model.ts +22 -1
  228. package/src/plugins/builtin/short-interest/publications-pane.tsx +13 -4
  229. package/src/plugins/builtin/short-interest/watch-client.ts +2 -1
  230. package/src/plugins/builtin/short-interest/watch-model.ts +1 -1
  231. package/src/plugins/builtin/social-mentions/client.ts +2 -1
  232. package/src/plugins/builtin/supply-chain/client.ts +1 -1
  233. package/src/plugins/builtin/supply-chain/evidence.ts +1 -1
  234. package/src/plugins/builtin/supply-chain/graph-pane.tsx +2 -1
  235. package/src/plugins/builtin/supply-chain/pane.tsx +2 -1
  236. package/src/plugins/builtin/ticker-detail/adr-pair/headless.ts +1 -1
  237. package/src/plugins/builtin/ticker-detail/adr-pair/model.ts +24 -4
  238. package/src/plugins/builtin/ticker-detail/adr-pair/tab.tsx +1 -1
  239. package/src/plugins/builtin/time-sales/client.ts +1 -0
  240. package/src/plugins/builtin/time-sales/pane.tsx +3 -2
  241. package/src/plugins/builtin/trace-bonds/client.ts +7 -4
  242. package/src/plugins/builtin/trace-bonds/index.tsx +1 -1
  243. package/src/plugins/builtin/vol-surface/client.ts +2 -1
  244. package/src/plugins/builtin/volatility/client.ts +6 -1
  245. package/src/plugins/builtin/volatility/headless.ts +0 -1
  246. package/src/plugins/builtin/yield-curve/curves.ts +15 -0
  247. package/src/plugins/builtin/yield-curve/headless.ts +9 -2
  248. package/src/plugins/builtin/yield-curve/index.tsx +5 -8
  249. package/src/plugins/host-modules.ts +22 -3
  250. package/src/plugins/host-smoke.ts +6 -3
  251. package/src/portfolio/collection-name.ts +19 -0
  252. package/src/portfolio/column-values.ts +76 -10
  253. package/src/renderers/browser/http-proxy-transport.ts +78 -8
  254. package/src/renderers/cloudflare/http-proxy.ts +13 -2
  255. package/src/renderers/cloudflare/proxy-session.ts +47 -24
  256. package/src/renderers/cloudflare/worker.ts +15 -2
  257. package/src/renderers/desktop/geometry.ts +279 -0
  258. package/src/renderers/desktop/screen-setup.ts +246 -0
  259. package/src/renderers/desktop/sequential-window-host.ts +179 -0
  260. package/src/renderers/desktop/test-utils.ts +71 -0
  261. package/src/renderers/desktop/window-controller.ts +433 -0
  262. package/src/renderers/desktop/window-host.ts +70 -0
  263. package/src/renderers/desktop/window-layouts.ts +630 -0
  264. package/src/renderers/dom/data-frames.ts +15 -4
  265. package/src/renderers/dom/host/box.tsx +204 -176
  266. package/src/renderers/dom/host/style.ts +49 -20
  267. package/src/renderers/dom/host/text.tsx +3 -2
  268. package/src/renderers/electrobun/bun/application-menu/click.ts +1 -0
  269. package/src/renderers/electrobun/bun/application-menu/index.ts +4 -1
  270. package/src/renderers/electrobun/bun/desktop/backend-requests.ts +19 -8
  271. package/src/renderers/electrobun/bun/desktop/backend.ts +322 -19
  272. package/src/renderers/electrobun/bun/desktop/detached-windows.ts +83 -61
  273. package/src/renderers/electrobun/bun/desktop/host-requests.ts +29 -15
  274. package/src/renderers/electrobun/bun/desktop/initialization.ts +30 -11
  275. package/src/renderers/electrobun/bun/desktop/relaunch.ts +9 -1
  276. package/src/renderers/electrobun/bun/desktop/screen-setup-file.ts +55 -0
  277. package/src/renderers/electrobun/bun/desktop/state-broadcaster.ts +44 -8
  278. package/src/renderers/electrobun/bun/desktop/windows-script.ts +9 -6
  279. package/src/renderers/electrobun/bun/desktop/workspace/index.ts +298 -97
  280. package/src/renderers/electrobun/bun/desktop/workspace/requests.ts +44 -6
  281. package/src/renderers/electrobun/bun/index.ts +4 -97
  282. package/src/renderers/electrobun/bun/window/electrobun-window-host.ts +306 -0
  283. package/src/renderers/electrobun/bun/window/focus.ts +0 -25
  284. package/src/renderers/electrobun/bun/window/remembered-frame.ts +4 -82
  285. package/src/renderers/electrobun/bun/window/windows-native.ts +26 -1
  286. package/src/renderers/electrobun/shared/protocol.ts +50 -2
  287. package/src/renderers/electrobun/view/backend-rpc.ts +15 -0
  288. package/src/renderers/electrobun/view/desktop/window/bridge.ts +63 -3
  289. package/src/renderers/electrobun/view/main.tsx +13 -7
  290. package/src/renderers/electrobun/view/ui-host.tsx +7 -0
  291. package/src/renderers/electrobun/view/window-fullscreen.ts +10 -3
  292. package/src/series/fred-argument.ts +17 -0
  293. package/src/sources/provider-router/financial-routes.ts +7 -1
  294. package/src/sources/provider-router/index.ts +7 -1
  295. package/src/state/app/context/index.tsx +16 -2
  296. package/src/state/desktop-windows.ts +63 -0
  297. package/src/sync/other-window-tabs.ts +62 -0
  298. package/src/tickers/company-name-listing.ts +23 -3
  299. package/src/tickers/listing-fate.ts +147 -1
  300. package/src/tickers/terminal-codes.ts +5 -0
  301. package/src/time-series/price-units.ts +11 -0
  302. package/src/time-series/types.ts +6 -0
  303. package/src/types/config.ts +10 -1
  304. package/src/types/desktop-window.ts +71 -2
  305. package/src/types/financials.ts +4 -0
  306. package/src/types/headless.ts +19 -0
  307. package/src/types/plugin.ts +6 -0
  308. package/src/ui/host.tsx +2 -0
  309. package/src/ui/index.tsx +14 -13
  310. package/src/ui/same-props.ts +58 -0
  311. package/src/utils/cli-output.ts +33 -4
  312. package/src/utils/currency-names.ts +20 -0
  313. package/src/utils/currency-pair.ts +6 -0
  314. package/src/utils/exchange-rate-snapshot.ts +20 -2
  315. package/src/utils/format.ts +7 -2
  316. package/src/utils/futures-generic.ts +12 -0
  317. package/src/utils/fx-market-hours.ts +43 -0
  318. package/src/utils/http-proxy-upstream.ts +6 -2
  319. package/src/utils/plugin-proxy-hosts.json +0 -4
  320. package/src/utils/plugin-proxy-hosts.ts +22 -0
  321. package/src/utils/sec-filings.ts +7 -1
@@ -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
@@ -1,4 +1,4 @@
1
- import { useEffect, useRef } from "react";
1
+ import { memo, useEffect, useRef } from "react";
2
2
  import { Box, ScrollBox, Span, Text, useUiCapabilities, type ScrollBoxRenderable } from "../../../ui";
3
3
  import { colors as themeColors, hoverBg } from "../../../theme/colors";
4
4
  import { CANONICAL_EXCHANGE_ALIASES } from "../../../utils/exchanges";
@@ -14,7 +14,7 @@ import {
14
14
  } from "./format";
15
15
  import type { CompositeChartProps, CompositeChartScene } from "./types";
16
16
  import { DIRECTION_MARKER, seriesColorsDirection, seriesCueCssBackground, type SeriesLineCue } from "./series-cues";
17
- import { DisclosureMarker } from "../../ui/disclosure-marker";
17
+ import { DisclosureMarker as KitDisclosureMarker } from "../../ui/disclosure-marker";
18
18
 
19
19
  const LEGEND_WHEEL_DELTA_PER_CELL = 8;
20
20
  const NO_LINE_CUES: ReadonlyMap<string, SeriesLineCue> = new Map();
@@ -126,8 +126,12 @@ const DIRECTION_TRIANGLES = {
126
126
  down: "polygon(0 0, 100% 0, 50% 100%)",
127
127
  } as const;
128
128
 
129
+ // The legend renders with the crosshair, its values the series' at the
130
+ // cursor; its markers and chevron hold still, so they render only when they change.
131
+ const DisclosureMarker = memo(KitDisclosureMarker);
132
+
129
133
  /** The legend's marker for a series on the desktop: its line as the plot strokes it, its up and down colors, or a dot. */
130
- function CompositeSeriesSwatch({ series, cue, downColor = null, filled = true }: {
134
+ const CompositeSeriesSwatch = memo(function CompositeSeriesSwatch({ series, cue, downColor = null, filled = true }: {
131
135
  series: ResolvedSeries;
132
136
  cue: SeriesLineCue | null;
133
137
  /** The down color, for a series keyed by direction: an up triangle in its color, then a down one in this. */
@@ -177,7 +181,7 @@ function CompositeSeriesSwatch({ series, cue, downColor = null, filled = true }:
177
181
  data-gloom-role="composite-chart-legend-marker"
178
182
  />
179
183
  );
180
- }
184
+ });
181
185
 
182
186
  export function CompositeLegend({
183
187
  scene,
@@ -77,6 +77,13 @@ export function useCompositePanelBitmap({
77
77
  const desktopRenderedSizeRef = useRef<{ pixelWidth: number; pixelHeight: number } | null>(null);
78
78
  const desktopCancelRenderRef = useRef<(() => void) | null>(null);
79
79
  const desktopActiveRef = useRef(false);
80
+ /** What the current desktop bitmap was drawn from. */
81
+ const desktopDrawnRef = useRef<{
82
+ panel: CompositePanelScene;
83
+ pixelWidth: number;
84
+ pixelHeight: number;
85
+ colors: CompositeChartColors;
86
+ } | null>(null);
80
87
  const pixelWidth = bitmapSize?.pixelWidth ?? null;
81
88
  const pixelHeight = bitmapSize?.pixelHeight ?? null;
82
89
 
@@ -84,6 +91,18 @@ export function useCompositePanelBitmap({
84
91
  ? { panel, pixelWidth, pixelHeight, colors }
85
92
  : null;
86
93
 
94
+ // New data at the size and palette already drawn (a live quote moving the
95
+ // last bar) is drawn in this render. Drawn in the layout effect, its state
96
+ // update would render the panel a second time, a commit per tick; the paint
97
+ // is the same either way, since the effect also draws before it.
98
+ const drawn = desktopDrawnRef.current;
99
+ if (isDesktopWeb && desktopActiveRef.current && desktopBitmapRef.current && drawn && drawn.panel !== panel
100
+ && drawn.pixelWidth === pixelWidth && drawn.pixelHeight === pixelHeight && drawn.colors === colors
101
+ && desktopCancelRenderRef.current === null && !desktopUnpaintedRef.current && !revealed) {
102
+ desktopBitmapRef.current = renderPanelBitmap(panel, { pixelWidth, pixelHeight }, colors);
103
+ desktopDrawnRef.current = { panel, pixelWidth, pixelHeight, colors };
104
+ }
105
+
87
106
  // The cursor is drawn as a separate overlay, so the plot raster stays cached
88
107
  // (and resident in the terminal) while the crosshair moves.
89
108
  const terminalBitmap = useMemo(() => {
@@ -114,6 +133,7 @@ export function useCompositePanelBitmap({
114
133
  };
115
134
  desktopRenderedColorsRef.current = input.colors;
116
135
  desktopBitmapRef.current = next;
136
+ desktopDrawnRef.current = input;
117
137
  setDesktopBitmap(next);
118
138
  // A chart that fills its box when it opens takes its measured size
119
139
  // before its first paint, by the end of the frame after next. Later
@@ -140,6 +160,7 @@ export function useCompositePanelBitmap({
140
160
  desktopRequestedSizeRef.current = null;
141
161
  desktopRenderedSizeRef.current = null;
142
162
  desktopBitmapRef.current = null;
163
+ desktopDrawnRef.current = null;
143
164
  setDesktopBitmap((current) => current === null ? current : null);
144
165
  return;
145
166
  }
@@ -158,7 +179,11 @@ export function useCompositePanelBitmap({
158
179
 
159
180
  if (!desktopBitmapRef.current || sizeAlreadyRendered || desktopRenderedColorsRef.current !== colors || desktopUnpaintedRef.current || revealed) {
160
181
  cancelRender();
161
- render();
182
+ const current = desktopDrawnRef.current;
183
+ // The render drew this data already.
184
+ const drawnNow = !!desktopBitmapRef.current && current?.panel === panel && current.colors === colors
185
+ && current.pixelWidth === pixelWidth && current.pixelHeight === pixelHeight;
186
+ if (!drawnNow) render();
162
187
  return;
163
188
  }
164
189
 
@@ -176,5 +201,6 @@ export function useCompositePanelBitmap({
176
201
  }, []);
177
202
 
178
203
  if (!bitmapSize) return null;
179
- return isDesktopWeb ? desktopBitmap : terminalBitmap;
204
+ // The state only renders the panel again; the ref also holds what this render drew.
205
+ return isDesktopWeb ? desktopBitmapRef.current ?? desktopBitmap : terminalBitmap;
180
206
  }
@@ -1,6 +1,12 @@
1
1
  import type { ChartSurfaceProps } from "../../../ui";
2
2
  import type { NativeChartBitmap } from "../native/chart-rasterizer";
3
- import { compositeAxisTicks, formatCompositeCursorValue, type CompositeAxisValueFormatter } from "./format";
3
+ import {
4
+ axisResultCache,
5
+ compositeAxisTicks,
6
+ formatCompositeAxisValue,
7
+ formatCompositeCursorValue,
8
+ type CompositeAxisValueFormatter,
9
+ } from "./format";
4
10
  import { projectCompositeValue, unprojectCompositeValue } from "./scene";
5
11
  import type { CompositeAxisDomain, CompositeChartScene, CompositePanelScene } from "./types";
6
12
 
@@ -110,6 +116,19 @@ export function compositeAxisLabelWidth(
110
116
  includeCursor: boolean,
111
117
  ): number {
112
118
  if (!domain) return 0;
119
+ // With no formatter of its own the cursor reads in cursor precision, so
120
+ // the default formatter is not the same as no formatter.
121
+ const key = `${includeCursor ? "cursor" : ""}:${format ? "" : "default"}`;
122
+ return cachedLabelWidths(domain, format ?? formatCompositeAxisValue, key, () => axisLabelWidth(domain, format, includeCursor));
123
+ }
124
+
125
+ const cachedLabelWidths = axisResultCache<number>();
126
+
127
+ function axisLabelWidth(
128
+ domain: CompositeAxisDomain,
129
+ format: CompositeAxisValueFormatter | undefined,
130
+ includeCursor: boolean,
131
+ ): number {
113
132
  const ticks = compositeAxisTicks(domain, format);
114
133
  const labels = ticks.map((tick) => tick.label);
115
134
  if (includeCursor) {