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
@@ -1,4 +1,4 @@
1
- import { useCallback, useEffect, useMemo, useRef, useState } from "react";
1
+ import { useCallback, useEffect, useMemo, useRef, useState, type ComponentProps, type ReactNode, type RefObject } from "react";
2
2
  import {
3
3
  Box,
4
4
  ChartSurface,
@@ -83,6 +83,7 @@ import {
83
83
  } from "./panel-gestures";
84
84
  import { resolvePanelCrosshair, axisLabelRows, cursorAxisLabel, resolveSeriesCursorYRatio, resolveSeriesAxisTags } from "./panel-labels";
85
85
  import type { KeyboardToolDrag } from "./use-composite-chart-keyboard";
86
+ import { createValueStore, useCursorScene, useValueStore, type CompositeCursorSource, type ValueStore } from "./cursor-source";
86
87
 
87
88
  const webFrame = globalThis as typeof globalThis & {
88
89
  requestAnimationFrame?: (callback: () => void) => number;
@@ -98,7 +99,9 @@ function pointerRow(event: ChartMouseEvent): number {
98
99
 
99
100
  interface CompositePanelSurfaceProps {
100
101
  panel: CompositePanelScene;
102
+ /** The chart's scene, without its cursor: the crosshair comes from `cursor`. */
101
103
  scene: CompositeChartScene;
104
+ cursor: CompositeCursorSource;
102
105
  plotWidth: number;
103
106
  leftAxisWidth: number;
104
107
  rightAxisWidth: number;
@@ -178,6 +181,7 @@ const PANEL_DIVIDER_STYLE = {
178
181
  export function CompositePanelSurface({
179
182
  panel,
180
183
  scene,
184
+ cursor,
181
185
  plotWidth,
182
186
  leftAxisWidth,
183
187
  rightAxisWidth,
@@ -222,22 +226,16 @@ export function CompositePanelSurface({
222
226
  const { cellHeightPx = 18, cellWidthPx = 8, fractionalViewport = false } = useUiCapabilities();
223
227
  const renderer = useNativeRenderer();
224
228
  const plotRef = useRef<BoxRenderable | null>(null);
225
- const [cursorYRatio, setCursorYRatio] = useState<number | null>(null);
229
+ // The pointer's height over the plot, 0 at the top and 1 at the bottom. It
230
+ // moves with the pointer without rendering the panel: only what draws the
231
+ // crosshair reads it.
232
+ const [pointerY] = useState(() => createValueStore<number | null>(null));
226
233
  const [toolDrag, setToolDrag] = useState<ChartToolDrag | null>(null);
227
234
  // A pointer drag owns the plot while it lasts; otherwise a tool placed from
228
235
  // the keyboard draws and reads out exactly like one.
229
236
  const keyboardDrag = toolDrag ? null : keyboardToolDrag;
230
237
  const activeDrag = toolDrag ?? keyboardDrag?.drag ?? null;
231
- // A keyboard placement's end sits at the level the user put it, so it
232
- // draws a level line where otherwise only the pointer would.
233
- const heldCursorYRatio = keyboardDrag ? keyboardDrag.drag.endYRatio : sharedCursor ? null : cursorYRatio;
234
- const seriesCursorYRatio = useMemo(
235
- () => resolveSeriesCursorYRatio(panel, scene),
236
- [panel, scene],
237
- );
238
- const activeCursorYRatio = scene.cursorXRatio === null
239
- ? null
240
- : heldCursorYRatio ?? seriesCursorYRatio;
238
+ const cursorView = { panel, cursor, pointerY, keyboardDrag, sharedCursor };
241
239
  // The last press on bare plot, for a double press where the host does not count clicks.
242
240
  const lastPlotPressRef = useRef<{ at: number; x: number; y: number } | null>(null);
243
241
  const dragRef = useRef<
@@ -265,16 +263,6 @@ export function CompositePanelSurface({
265
263
  const plotSpanFactor = 1 + compositeRightOffsetRatio(scene.timeScale);
266
264
  const bitmapSize = useStaticChartBitmapSize(plotSize.width, plotSize.height);
267
265
  const bitmap = useCompositePanelBitmap({ panel, bitmapSize, colors, isDesktopWeb, revealed: plotSize.revealed === true });
268
- // The chart under the pointer draws both lines: the level line follows the
269
- // pointer, and its value sits on the axes, beside each series' own tag on
270
- // the desktop and the web. A keyboard or shared cursor knows its column
271
- // only, so a chart following another chart's cursor draws the time line
272
- // alone. A tool placed from the keyboard is the exception: its end is a level.
273
- const pointerCursorYRatio = scene.cursorXRatio === null ? null : heldCursorYRatio;
274
- const crosshair = useMemo(
275
- () => resolvePanelCrosshair(panel, bitmap, scene, pointerCursorYRatio, colors.crosshair),
276
- [bitmap, colors.crosshair, panel, pointerCursorYRatio, scene],
277
- );
278
266
  const measureDomain = useMemo(() => resolveMeasureAxisDomain(panel), [panel]);
279
267
  const toolReadout = useMemo(() => {
280
268
  if (!activeDrag) return null;
@@ -356,13 +344,16 @@ export function CompositePanelSurface({
356
344
  () => levels && levelDomain ? projectLevels(levels.items, levelDomain, levelDraft) : NO_LEVELS,
357
345
  [levelDomain, levelDraft, levels],
358
346
  );
359
- // Over a line a plain drag moves, and while one moves, the pointer says it goes up and down.
360
- const levelGrab = useMemo(() => {
347
+ // Over a line a plain drag moves, and while one moves, the pointer says it
348
+ // goes up and down. Where the pointer is, the plot reads (see `PanelPlotSurface`).
349
+ const levelGrab = useMemo<LevelGrab>(() => {
361
350
  if (levelDraft) return true;
362
- if (!levels?.onEdit || cursorYRatio === null || onPickTime || onPickPrice || (armedTool && armedTool !== "level")) return false;
363
- const hit = hitTestLevel(projectedLevels, cursorYRatio, levelGrabRatio(panel.height));
364
- return !!hit?.editable && !!hit.draggable;
365
- }, [armedTool, cursorYRatio, levelDraft, levels?.onEdit, onPickPrice, onPickTime, panel.height, projectedLevels]);
351
+ if (!levels?.onEdit || onPickTime || onPickPrice || (armedTool && armedTool !== "level")) return false;
352
+ return (cursorYRatio) => {
353
+ const hit = hitTestLevel(projectedLevels, cursorYRatio, levelGrabRatio(panel.height));
354
+ return !!hit?.editable && !!hit.draggable;
355
+ };
356
+ }, [armedTool, levelDraft, levels?.onEdit, onPickPrice, onPickTime, panel.height, projectedLevels]);
366
357
  // Drawings project through the time scale alone: the crosshair moving,
367
358
  // here or on a linked chart, must not repaint the plot, which the terminal's
368
359
  // kitty surface would upload whole again.
@@ -432,16 +423,6 @@ export function CompositePanelSurface({
432
423
  selectedLevelId,
433
424
  toolReadout?.direction,
434
425
  ]);
435
- const textLines = useMemo(
436
- () => isDesktopWeb || !showTextFallback
437
- ? []
438
- : writeLevelText(
439
- renderCompositePanelText(panel, plotWidth, scene.cursorXRatio, pointerCursorYRatio),
440
- projectedLevels,
441
- selectedLevelId,
442
- ),
443
- [isDesktopWeb, panel, plotWidth, pointerCursorYRatio, projectedLevels, scene.cursorXRatio, selectedLevelId, showTextFallback],
444
- );
445
426
  const leftAxisLabels = useMemo(
446
427
  () => axisLabelRows(
447
428
  renderCompositeAxisText(panel.axes.left, panel.height, leftAxisWidth, "left", formatAxisValue),
@@ -462,17 +443,6 @@ export function CompositePanelSurface({
462
443
  () => compositeAxisTickLabels(panel.axes.right, rightAxisWidth, formatAxisValue),
463
444
  [formatAxisValue, panel, rightAxisWidth],
464
445
  );
465
- const cursorRow = activeCursorYRatio === null
466
- ? null
467
- : Math.round(activeCursorYRatio * Math.max(panel.height - 1, 0));
468
- const cursorPixelY = activeCursorYRatio === null
469
- ? null
470
- : activeCursorYRatio * Math.max(panel.height * cellHeightPx - 1, 0);
471
- // The pointer's value on the axes follows the level line it belongs to.
472
- const axisCursorYRatio = isDesktopWeb ? pointerCursorYRatio : activeCursorYRatio;
473
- const leftCursorLabel = cursorAxisLabel(panel, "left", axisCursorYRatio, formatAxisValue);
474
- const rightCursorLabel = cursorAxisLabel(panel, "right", axisCursorYRatio, formatAxisValue);
475
- const seriesAxisTags = useMemo(() => isDesktopWeb ? resolveSeriesAxisTags(panel, scene, formatAxisValue) : [], [formatAxisValue, isDesktopWeb, panel, scene]);
476
446
  const measureReadout = useMemo(() => {
477
447
  if (!activeDrag || !toolReadout?.summary) return null;
478
448
  const text = toolReadout.summary;
@@ -614,15 +584,15 @@ export function CompositePanelSurface({
614
584
  const nextYRatio = panel.height <= 1
615
585
  ? 0.5
616
586
  : Math.max(0, Math.min(1, pointer.cellY / (panel.height - 1)));
617
- setCursorYRatio((current) => current === nextYRatio ? current : nextYRatio);
587
+ pointerY.set(nextYRatio);
618
588
  onCursorDateChange(nextDate);
619
589
  consumeChartMouseEvent(event);
620
590
  return true;
621
- }, [onCursorDateChange, panel.height, plotPointer, scene]);
591
+ }, [onCursorDateChange, panel.height, plotPointer, pointerY, scene]);
622
592
  const clearCursor = useCallback(() => {
623
- setCursorYRatio(null);
593
+ pointerY.set(null);
624
594
  onCursorDateChange(null);
625
- }, [onCursorDateChange]);
595
+ }, [onCursorDateChange, pointerY]);
626
596
  const startDrag = useCallback((event: ChartMouseEvent) => {
627
597
  onActivate?.();
628
598
  onPointerPress();
@@ -1196,21 +1166,19 @@ export function CompositePanelSurface({
1196
1166
  ) : null}
1197
1167
  {leftAxisWidth > 0 ? (
1198
1168
  <>
1199
- <PriceAxisLabels
1169
+ <PanelValueAxis
1170
+ view={cursorView}
1171
+ formatAxisValue={formatAxisValue}
1200
1172
  axisLabels={leftAxisLabels}
1201
1173
  axisTicks={leftAxisTicks}
1202
1174
  axisWidth={leftAxisWidth}
1203
1175
  axisSectionWidth={leftAxisWidth}
1204
1176
  side="left"
1205
1177
  height={panel.height}
1206
- cursorRow={cursorRow}
1207
- cursorPixelY={cursorPixelY}
1208
- cursorLabel={leftCursorLabel}
1209
1178
  cursorColor={colors.crosshair}
1210
1179
  cursorBackgroundColor={colors.background}
1211
1180
  axisColor={colors.textDim}
1212
1181
  extraMarkers={leftAxisMarkers}
1213
- seriesTags={isDesktopWeb ? seriesAxisTags.filter((tag) => tag.side === "left") : undefined}
1214
1182
  measuredPixelHeight={plotSize.height * cellHeightPx}
1215
1183
  gestures={leftAxisGestures}
1216
1184
  footButton={manualSide === "left"}
@@ -1218,16 +1186,24 @@ export function CompositePanelSurface({
1218
1186
  <Box width={axisGap} />
1219
1187
  </>
1220
1188
  ) : null}
1221
- <ChartSurface
1222
- ref={plotRef}
1189
+ <PanelPlotSurface
1190
+ view={cursorView}
1191
+ plotRef={plotRef}
1192
+ bitmap={bitmap}
1193
+ crosshairColor={colors.crosshair}
1194
+ textColor={colors.text}
1195
+ textFallback={!isDesktopWeb && showTextFallback}
1196
+ plotWidth={plotWidth}
1197
+ projectedLevels={projectedLevels}
1198
+ selectedLevelId={selectedLevelId}
1199
+ levelGrab={levelGrab}
1223
1200
  // Its measured box on the desktop, where pointer bounds read it; CSS lays it out.
1224
1201
  width={plotSize.width}
1225
1202
  height={plotSize.height}
1226
1203
  // Desktop: the width the axes leave, and the row's height.
1227
- style={isDesktopWeb ? levelGrab ? DESKTOP_PLOT_LEVEL_STYLE : onPickPrice ? DESKTOP_PLOT_PICK_STYLE : DESKTOP_PLOT_STYLE : undefined}
1204
+ style={isDesktopWeb ? onPickPrice ? DESKTOP_PLOT_PICK_STYLE : DESKTOP_PLOT_STYLE : undefined}
1228
1205
  flexDirection="column"
1229
1206
  bitmaps={bitmapLayers}
1230
- crosshair={crosshair}
1231
1207
  vectors={vectors}
1232
1208
  onMouseMove={interactive ? handleMouseMove : undefined}
1233
1209
  onMouseDown={interactive ? navigable ? pressPlot : pressCursor : undefined}
@@ -1236,54 +1212,55 @@ export function CompositePanelSurface({
1236
1212
  onMouseDragEnd={interactive && navigable ? releasePlot : undefined}
1237
1213
  onMouseScroll={interactive && navigable ? panFromWheel : undefined}
1238
1214
  onMouseOut={interactive ? clearCursor : undefined}
1239
- cursor={interactive ? levelGrab ? "ns-resize" : toolDrag || !navigable || onPickTime || onPickPrice ? "crosshair" : "grab" : undefined}
1215
+ cursor={interactive ? toolDrag || !navigable || onPickTime || onPickPrice ? "crosshair" : "grab" : undefined}
1240
1216
  data-gloom-interactive={interactive ? "true" : undefined}
1241
1217
  data-gloom-role={COMPOSITE_PANEL_ROLE}
1242
1218
  data-gloom-remote-kind={remoteKind}
1243
1219
  data-gloom-label={panel.label ?? panel.id}
1244
1220
  data-gloom-value-scale={manuallyScaled ? "manual" : undefined}
1245
- >
1246
- {textLines.map((line, index) => <Text key={index} fg={colors.text}>{line}</Text>)}
1247
- </ChartSurface>
1248
- {(isDesktopWeb
1249
- ? layoutLevelLabels(projectedLevels, plotSize.height * cellHeightPx, cellHeightPx)
1250
- : fitAxisLabels(projectedLevels.filter((entry) => entry.level.label), [], (entry) => entry.yRatio * Math.max(1, panel.height - 1))
1251
- ).map((entry) => {
1252
- const { level, yRatio } = entry;
1253
- const axisWidth = levelDomain?.side === "left" ? leftAxisWidth : rightAxisWidth;
1254
- const axisMarkers = levelDomain?.side === "left" ? leftAxisMarkers : rightAxisMarkers;
1255
- const cursorCovers = activeCursorYRatio !== null && Math.abs(activeCursorYRatio - yRatio) * panel.height < 1;
1256
- const axisVisible = !cursorCovers && (level.axisLabel?.length ?? 0) <= axisWidth && !!axisMarkers?.some((marker) => marker.id === level.id);
1257
- const label = levelLabelText(level, axisVisible);
1258
- const labelStyle = isDesktopWeb ? {
1259
- ...levelLabelStyle(entry, colors.background), left: "auto", right: (rightAxisWidth + (rightAxisWidth ? axisGap : 0) + 1) * cellWidthPx,
1260
- maxWidth: Math.max(1, plotWidth - 2) * cellWidthPx,
1261
- } : undefined;
1262
- const labelWidth = Math.min(plotWidth - 2, label.length + 2);
1263
- return <Box key={`annotation:${level.id}`} position="absolute" left={leftAxisWidth + (leftAxisWidth ? axisGap : 0) + plotWidth - labelWidth - 1} top={yRatio * Math.max(0, panel.height - 1)} height={1}
1264
- width={labelWidth} flexDirection="row" justifyContent="flex-end" backgroundColor={colors.background} zIndex={20}
1265
- style={labelStyle} data-gloom-role="chart-level-label">
1266
- <Text fg={labelStyle?.color ?? level.color} wrapMode="none" style={isDesktopWeb ? { lineHeight: 1 } : undefined}>{label}</Text>
1267
- </Box>;
1268
- })}
1221
+ />
1222
+ {projectedLevels.length > 0 ? (
1223
+ // A level's label leaves its value to the axis, unless the cursor's covers it there.
1224
+ <PanelLevelLabels view={cursorView}>
1225
+ {(activeCursorYRatio) => (isDesktopWeb
1226
+ ? layoutLevelLabels(projectedLevels, plotSize.height * cellHeightPx, cellHeightPx)
1227
+ : fitAxisLabels(projectedLevels.filter((entry) => entry.level.label), [], (entry) => entry.yRatio * Math.max(1, panel.height - 1))
1228
+ ).map((entry) => {
1229
+ const { level, yRatio } = entry;
1230
+ const axisWidth = levelDomain?.side === "left" ? leftAxisWidth : rightAxisWidth;
1231
+ const axisMarkers = levelDomain?.side === "left" ? leftAxisMarkers : rightAxisMarkers;
1232
+ const cursorCovers = activeCursorYRatio !== null && Math.abs(activeCursorYRatio - yRatio) * panel.height < 1;
1233
+ const axisVisible = !cursorCovers && (level.axisLabel?.length ?? 0) <= axisWidth && !!axisMarkers?.some((marker) => marker.id === level.id);
1234
+ const label = levelLabelText(level, axisVisible);
1235
+ const labelStyle = isDesktopWeb ? {
1236
+ ...levelLabelStyle(entry, colors.background), left: "auto", right: (rightAxisWidth + (rightAxisWidth ? axisGap : 0) + 1) * cellWidthPx,
1237
+ maxWidth: Math.max(1, plotWidth - 2) * cellWidthPx,
1238
+ } : undefined;
1239
+ const labelWidth = Math.min(plotWidth - 2, label.length + 2);
1240
+ return <Box key={`annotation:${level.id}`} position="absolute" left={leftAxisWidth + (leftAxisWidth ? axisGap : 0) + plotWidth - labelWidth - 1} top={yRatio * Math.max(0, panel.height - 1)} height={1}
1241
+ width={labelWidth} flexDirection="row" justifyContent="flex-end" backgroundColor={colors.background} zIndex={20}
1242
+ style={labelStyle} data-gloom-role="chart-level-label">
1243
+ <Text fg={labelStyle?.color ?? level.color} wrapMode="none" style={isDesktopWeb ? { lineHeight: 1 } : undefined}>{label}</Text>
1244
+ </Box>;
1245
+ })}
1246
+ </PanelLevelLabels>
1247
+ ) : null}
1269
1248
  {rightAxisWidth > 0 ? (
1270
1249
  <>
1271
1250
  <Box width={axisGap} />
1272
- <PriceAxisLabels
1251
+ <PanelValueAxis
1252
+ view={cursorView}
1253
+ formatAxisValue={formatAxisValue}
1273
1254
  axisLabels={rightAxisLabels}
1274
1255
  axisTicks={rightAxisTicks}
1275
1256
  axisWidth={rightAxisWidth}
1276
1257
  axisSectionWidth={rightAxisWidth}
1277
1258
  side="right"
1278
1259
  height={panel.height}
1279
- cursorRow={cursorRow}
1280
- cursorPixelY={cursorPixelY}
1281
- cursorLabel={rightCursorLabel}
1282
1260
  cursorColor={colors.crosshair}
1283
1261
  cursorBackgroundColor={colors.background}
1284
1262
  axisColor={colors.textDim}
1285
1263
  extraMarkers={rightAxisMarkers}
1286
- seriesTags={isDesktopWeb ? seriesAxisTags.filter((tag) => tag.side === "right") : undefined}
1287
1264
  measuredPixelHeight={plotSize.height * cellHeightPx}
1288
1265
  gestures={rightAxisGestures}
1289
1266
  footButton={manualSide === "right"}
@@ -1326,3 +1303,135 @@ export function CompositePanelSurface({
1326
1303
  </Box>
1327
1304
  );
1328
1305
  }
1306
+
1307
+ /** Over a level a drag moves: always while one moves, never, or at the pointer's height. */
1308
+ type LevelGrab = boolean | ((cursorYRatio: number) => boolean);
1309
+
1310
+ /** What a panel's crosshair is read from: everything else in the panel holds still while it moves. */
1311
+ interface PanelCursorView {
1312
+ panel: CompositePanelScene;
1313
+ cursor: CompositeCursorSource;
1314
+ pointerY: ValueStore<number | null>;
1315
+ keyboardDrag: KeyboardToolDrag | null;
1316
+ sharedCursor: boolean;
1317
+ }
1318
+
1319
+ /** The crosshair over a panel, read by the parts that draw it, so a pointer move renders only them. */
1320
+ function usePanelCursor({ panel, cursor, pointerY, keyboardDrag, sharedCursor }: PanelCursorView) {
1321
+ const scene = useCursorScene(cursor);
1322
+ const cursorYRatio = useValueStore(pointerY);
1323
+ // A keyboard placement's end sits at the level the user put it, so it
1324
+ // draws a level line where otherwise only the pointer would.
1325
+ const heldCursorYRatio = keyboardDrag ? keyboardDrag.drag.endYRatio : sharedCursor ? null : cursorYRatio;
1326
+ const seriesCursorYRatio = useMemo(
1327
+ () => resolveSeriesCursorYRatio(panel, scene),
1328
+ [panel, scene],
1329
+ );
1330
+ return {
1331
+ scene,
1332
+ cursorYRatio,
1333
+ activeCursorYRatio: scene.cursorXRatio === null ? null : heldCursorYRatio ?? seriesCursorYRatio,
1334
+ // The chart under the pointer draws both lines: the level line follows the
1335
+ // pointer, and its value sits on the axes, beside each series' own tag on
1336
+ // the desktop and the web. A keyboard or shared cursor knows its column
1337
+ // only, so a chart following another chart's cursor draws the time line
1338
+ // alone. A tool placed from the keyboard is the exception: its end is a level.
1339
+ pointerCursorYRatio: scene.cursorXRatio === null ? null : heldCursorYRatio,
1340
+ };
1341
+ }
1342
+
1343
+ /** The plot, with the crosshair over it and, in a terminal without graphics, the text that draws both. */
1344
+ function PanelPlotSurface({
1345
+ view,
1346
+ plotRef,
1347
+ bitmap,
1348
+ crosshairColor,
1349
+ textColor,
1350
+ textFallback,
1351
+ plotWidth,
1352
+ projectedLevels,
1353
+ selectedLevelId,
1354
+ levelGrab,
1355
+ ...surface
1356
+ }: Omit<ComponentProps<typeof ChartSurface>, "ref" | "crosshair" | "children"> & {
1357
+ view: PanelCursorView;
1358
+ plotRef: RefObject<BoxRenderable | null>;
1359
+ bitmap: ReturnType<typeof useCompositePanelBitmap>;
1360
+ crosshairColor: string;
1361
+ textColor: string;
1362
+ textFallback: boolean;
1363
+ plotWidth: number;
1364
+ projectedLevels: readonly ProjectedLevel[];
1365
+ selectedLevelId: string | null;
1366
+ levelGrab: LevelGrab;
1367
+ }) {
1368
+ const { panel } = view;
1369
+ const { scene, cursorYRatio, pointerCursorYRatio } = usePanelCursor(view);
1370
+ const crosshair = useMemo(
1371
+ () => resolvePanelCrosshair(panel, bitmap, scene, pointerCursorYRatio, crosshairColor),
1372
+ [bitmap, crosshairColor, panel, pointerCursorYRatio, scene],
1373
+ );
1374
+ const textLines = useMemo(
1375
+ () => textFallback
1376
+ ? writeLevelText(
1377
+ renderCompositePanelText(panel, plotWidth, scene.cursorXRatio, pointerCursorYRatio),
1378
+ projectedLevels,
1379
+ selectedLevelId,
1380
+ )
1381
+ : [],
1382
+ [panel, plotWidth, pointerCursorYRatio, projectedLevels, scene.cursorXRatio, selectedLevelId, textFallback],
1383
+ );
1384
+ const grab = typeof levelGrab === "function" ? cursorYRatio !== null && levelGrab(cursorYRatio) : levelGrab;
1385
+ return (
1386
+ <ChartSurface
1387
+ ref={plotRef}
1388
+ {...surface}
1389
+ style={grab && surface.style ? DESKTOP_PLOT_LEVEL_STYLE : surface.style}
1390
+ cursor={grab && surface.cursor ? "ns-resize" : surface.cursor}
1391
+ crosshair={crosshair}
1392
+ >
1393
+ {textLines.map((line, index) => <Text key={index} fg={textColor}>{line}</Text>)}
1394
+ </ChartSurface>
1395
+ );
1396
+ }
1397
+
1398
+ /** A value axis, with the cursor's value on it and, on the desktop, each series' value at the cursor. */
1399
+ function PanelValueAxis({
1400
+ view,
1401
+ formatAxisValue,
1402
+ side,
1403
+ ...axis
1404
+ }: Omit<ComponentProps<typeof PriceAxisLabels>, "cursorRow" | "cursorPixelY" | "cursorLabel" | "seriesTags" | "side"> & {
1405
+ view: PanelCursorView;
1406
+ formatAxisValue?: CompositeAxisValueFormatter;
1407
+ side: CompositeAxisSide;
1408
+ }) {
1409
+ const { panel } = view;
1410
+ const isDesktopWeb = useUiCapabilities().nativePaneChrome === true;
1411
+ const { cellHeightPx = 18 } = useUiCapabilities();
1412
+ const { scene, activeCursorYRatio, pointerCursorYRatio } = usePanelCursor(view);
1413
+ // The pointer's value on the axes follows the level line it belongs to.
1414
+ const axisCursorYRatio = isDesktopWeb ? pointerCursorYRatio : activeCursorYRatio;
1415
+ const seriesTags = useMemo(
1416
+ () => isDesktopWeb ? resolveSeriesAxisTags(panel, scene, formatAxisValue).filter((tag) => tag.side === side) : undefined,
1417
+ [formatAxisValue, isDesktopWeb, panel, scene, side],
1418
+ );
1419
+ return (
1420
+ <PriceAxisLabels
1421
+ {...axis}
1422
+ side={side}
1423
+ cursorRow={activeCursorYRatio === null ? null : Math.round(activeCursorYRatio * Math.max(panel.height - 1, 0))}
1424
+ cursorPixelY={activeCursorYRatio === null ? null : activeCursorYRatio * Math.max(panel.height * cellHeightPx - 1, 0)}
1425
+ cursorLabel={cursorAxisLabel(panel, side, axisCursorYRatio, formatAxisValue)}
1426
+ seriesTags={seriesTags}
1427
+ />
1428
+ );
1429
+ }
1430
+
1431
+ /** A panel's level labels, which step aside where the cursor's label covers theirs on the axis. */
1432
+ function PanelLevelLabels({ view, children }: {
1433
+ view: PanelCursorView;
1434
+ children: (activeCursorYRatio: number | null) => ReactNode;
1435
+ }) {
1436
+ return <>{children(usePanelCursor(view).activeCursorYRatio)}</>;
1437
+ }
@@ -1,4 +1,4 @@
1
- import { useMemo } from "react";
1
+ import { memo, useMemo } from "react";
2
2
  import { Box, Text, useUiCapabilities } from "../../../ui";
3
3
  import { colors } from "../../../theme/colors";
4
4
  import { clamp } from "../../../utils/math";
@@ -173,7 +173,10 @@ export function PriceAxisLabels({
173
173
  // Row-snapped labels drift up to a row off the gridlines they name.
174
174
  const usePixelTicks = fractionalViewport && axisTicks !== undefined;
175
175
  const pixelHeight = Math.max(measuredPixelHeight ?? height * cellHeightPx, 1);
176
- const placedSeriesTags = seriesTags ? placeSeriesAxisTags(seriesTags, pixelHeight, cellHeightPx) : [];
176
+ const placedSeriesTags = useMemo(
177
+ () => seriesTags ? placeSeriesAxisTags(seriesTags, pixelHeight, cellHeightPx) : [],
178
+ [cellHeightPx, pixelHeight, seriesTags],
179
+ );
177
180
  const lanes = Math.max(1, ...placedSeriesTags.map((tag) => tag.lane + 1));
178
181
  // Fixed reference labels yield to observations, never the other way round.
179
182
  const visibleMarkers = extraMarkers?.filter((marker) => placedSeriesTags.every((tag) => Math.abs(tag.centerY - marker.pixelY) >= cellHeightPx));
@@ -198,22 +201,6 @@ export function PriceAxisLabels({
198
201
  : fractionalViewport
199
202
  ? "flex-start"
200
203
  : "flex-end";
201
- const formatLabel = (label: string | null) => {
202
- const formatted = formatAxisCell(label, axisWidth);
203
- return side === "right" ? formatted.trimStart().padEnd(axisWidth) : formatted;
204
- };
205
- const renderAxisLabel = (label: string | null, fg: string) => (
206
- fractionalViewport ? (
207
- <Box flexDirection="row" width={axisSectionWidth} height={1}>
208
- <Box flexDirection="row" width={axisWidth} justifyContent={axisLabelJustify} overflow="hidden">
209
- {label ? <Text fg={fg} selectable={false}>{formatLabel(label).trim()}</Text> : null}
210
- </Box>
211
- {axisPaddingWidth > 0 ? <Box width={axisPaddingWidth} /> : null}
212
- </Box>
213
- ) : (
214
- <Text fg={fg} selectable={false}>{formatLabel(label).padEnd(axisSectionWidth)}</Text>
215
- )
216
- );
217
204
 
218
205
  const placedStyle = usePixelOverlay || usePixelTicks ? { position: "relative", height: "auto", alignSelf: "stretch" } : undefined;
219
206
  return (
@@ -239,36 +226,29 @@ export function PriceAxisLabels({
239
226
  ? cursorLabel
240
227
  : marker?.label ?? (usePixelTicks || (footButton && row === height - 1) ? null : axisLabels.get(row) ?? null);
241
228
  return (
242
- <Box key={row} height={1}>
243
- {renderAxisLabel(
244
- label,
245
- isCursorRow ? cursorColor : marker ? marker.color : axisColor,
246
- )}
247
- </Box>
229
+ <AxisRow
230
+ key={row}
231
+ label={label}
232
+ fg={isCursorRow ? cursorColor : marker ? marker.color : axisColor}
233
+ side={side}
234
+ axisWidth={axisWidth}
235
+ axisSectionWidth={axisSectionWidth}
236
+ fractional={fractionalViewport}
237
+ justify={axisLabelJustify}
238
+ />
248
239
  );
249
240
  })}
250
- {placedTicks ? placedTicks.map((tick) => {
251
- return (
252
- <Box
253
- key={`${tick.label}:${tick.ratio}`}
254
- width={axisSectionWidth}
255
- flexDirection="row"
256
- style={{
257
- position: "absolute",
258
- left: 0,
259
- top: `${tick.topPercent}%`,
260
- transform: "translateY(-50%)",
261
- whiteSpace: "pre",
262
- pointerEvents: "none",
263
- }}
264
- >
265
- <Box flexDirection="row" width={axisWidth} justifyContent={axisLabelJustify} overflow="hidden">
266
- <Text fg={axisColor} selectable={false}>{tick.label}</Text>
267
- </Box>
268
- {axisPaddingWidth > 0 ? <Box width={axisPaddingWidth} /> : null}
269
- </Box>
270
- );
271
- }) : null}
241
+ {placedTicks ? placedTicks.map((tick) => (
242
+ <AxisTick
243
+ key={`${tick.label}:${tick.ratio}`}
244
+ label={tick.label}
245
+ topPercent={tick.topPercent}
246
+ color={axisColor}
247
+ axisWidth={axisWidth}
248
+ axisSectionWidth={axisSectionWidth}
249
+ justify={axisLabelJustify}
250
+ />
251
+ )) : null}
272
252
  {usePixelOverlay || usePixelTicks ? visibleMarkers?.map((marker) => (
273
253
  <Box
274
254
  key={`${marker.label}:${marker.pixelY}`}
@@ -318,3 +298,69 @@ export function PriceAxisLabels({
318
298
  </Box>
319
299
  );
320
300
  }
301
+
302
+ type AxisLabelJustify = "flex-start" | "flex-end";
303
+
304
+ /**
305
+ * One row of the axis, with its label or none. A row only renders when its
306
+ * label does: the cursor's moving down the axis renders the rows it leaves
307
+ * and lands on, not the column.
308
+ */
309
+ const AxisRow = memo(function AxisRow({ label, fg, side, axisWidth, axisSectionWidth, fractional, justify }: {
310
+ label: string | null;
311
+ fg: string;
312
+ side: "left" | "right" | undefined;
313
+ axisWidth: number;
314
+ axisSectionWidth: number;
315
+ fractional: boolean;
316
+ justify: AxisLabelJustify;
317
+ }) {
318
+ const formatted = formatAxisCell(label, axisWidth);
319
+ const text = side === "right" ? formatted.trimStart().padEnd(axisWidth) : formatted;
320
+ const axisPaddingWidth = Math.max(0, axisSectionWidth - axisWidth);
321
+ return (
322
+ <Box height={1}>
323
+ {fractional ? (
324
+ <Box flexDirection="row" width={axisSectionWidth} height={1}>
325
+ <Box flexDirection="row" width={axisWidth} justifyContent={justify} overflow="hidden">
326
+ {label ? <Text fg={fg} selectable={false}>{text.trim()}</Text> : null}
327
+ </Box>
328
+ {axisPaddingWidth > 0 ? <Box width={axisPaddingWidth} /> : null}
329
+ </Box>
330
+ ) : (
331
+ <Text fg={fg} selectable={false}>{text.padEnd(axisSectionWidth)}</Text>
332
+ )}
333
+ </Box>
334
+ );
335
+ });
336
+
337
+ /** A tick label at its exact height, which holds still while the cursor moves past. */
338
+ const AxisTick = memo(function AxisTick({ label, topPercent, color, axisWidth, axisSectionWidth, justify }: {
339
+ label: string;
340
+ topPercent: number;
341
+ color: string;
342
+ axisWidth: number;
343
+ axisSectionWidth: number;
344
+ justify: AxisLabelJustify;
345
+ }) {
346
+ const axisPaddingWidth = Math.max(0, axisSectionWidth - axisWidth);
347
+ return (
348
+ <Box
349
+ width={axisSectionWidth}
350
+ flexDirection="row"
351
+ style={{
352
+ position: "absolute",
353
+ left: 0,
354
+ top: `${topPercent}%`,
355
+ transform: "translateY(-50%)",
356
+ whiteSpace: "pre",
357
+ pointerEvents: "none",
358
+ }}
359
+ >
360
+ <Box flexDirection="row" width={axisWidth} justifyContent={justify} overflow="hidden">
361
+ <Text fg={color} selectable={false}>{label}</Text>
362
+ </Box>
363
+ {axisPaddingWidth > 0 ? <Box width={axisPaddingWidth} /> : null}
364
+ </Box>
365
+ );
366
+ });
@@ -51,17 +51,40 @@ function normalizePricePointUncached(point: PricePoint, providerId?: string): Ti
51
51
  };
52
52
  }
53
53
 
54
- /** Converts the app's canonical price history into the generic chart-series boundary. */
55
- export function pricePointsToResolvedSeries(
56
- points: readonly PricePoint[],
57
- options: PricePointsToResolvedSeriesOptions,
58
- ): ResolvedSeries {
54
+ /** The points one per instant in time order, the later of two at one instant kept. */
55
+ function uniqueTimeOrderedPoints(points: readonly PricePoint[], providerId: string | undefined): TimeSeriesPoint[] {
56
+ // A history comes in time order: kept as it is, it needs no keyed sort.
57
+ const ordered: TimeSeriesPoint[] = [];
58
+ let previous = Number.NEGATIVE_INFINITY;
59
+ for (const point of points) {
60
+ const normalized = normalizePricePoint(point, providerId);
61
+ if (!normalized) continue;
62
+ const time = normalized.date.getTime();
63
+ if (time <= previous) return keyedTimeOrderedPoints(points, providerId);
64
+ previous = time;
65
+ ordered.push(normalized);
66
+ }
67
+ return ordered;
68
+ }
69
+
70
+ function keyedTimeOrderedPoints(points: readonly PricePoint[], providerId: string | undefined): TimeSeriesPoint[] {
59
71
  const byTimestamp = new Map<number, TimeSeriesPoint>();
60
72
  for (const point of points) {
61
- const normalized = normalizePricePoint(point, options.providerId);
73
+ const normalized = normalizePricePoint(point, providerId);
62
74
  if (!normalized) continue;
63
75
  byTimestamp.set(normalized.date.getTime(), normalized);
64
76
  }
77
+ return [...byTimestamp.values()].sort((left, right) => left.date.getTime() - right.date.getTime());
78
+ }
79
+
80
+ /** Converts the app's canonical price history into the generic chart-series boundary. */
81
+ export function pricePointsToResolvedSeries(
82
+ points: readonly PricePoint[],
83
+ options: PricePointsToResolvedSeriesOptions,
84
+ ): ResolvedSeries {
85
+ const resolved = uniqueTimeOrderedPoints(points, options.providerId);
86
+ let rejected = 0;
87
+ for (const point of resolved) if (point.provenance?.priceHistoryIntegrity) rejected += 1;
65
88
 
66
89
  return {
67
90
  id: options.id,
@@ -77,7 +100,7 @@ export function pricePointsToResolvedSeries(
77
100
  panelId: options.panelId ?? "main",
78
101
  interpolation: "none",
79
102
  timeBasis: options.timeBasis,
80
- points: [...byTimestamp.values()].sort((left, right) => left.date.getTime() - right.date.getTime()),
81
- warning: [options.warning, priceHistoryIntegrityNotice([...byTimestamp.values()].filter((point) => point.provenance?.priceHistoryIntegrity).length)].filter(Boolean).join(" ") || undefined,
103
+ points: resolved,
104
+ warning: [options.warning, priceHistoryIntegrityNotice(rejected)].filter(Boolean).join(" ") || undefined,
82
105
  };
83
106
  }