gloomberb 0.19.5 → 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 (208) hide show
  1. package/package.json +1 -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/market.ts +149 -10
  8. package/src/cli/commands/search.ts +21 -3
  9. package/src/cli/commands/ticker.ts +74 -33
  10. package/src/cli/glossary.ts +3 -3
  11. package/src/cli/known-gaps.ts +8 -0
  12. package/src/cli/listing-arg.ts +12 -0
  13. package/src/cli/pane-functions/capabilities.ts +2 -0
  14. package/src/cli/pane-functions/catalog.ts +22 -4
  15. package/src/cli/pane-functions/function-help.ts +8 -5
  16. package/src/cli/pane-functions/headless.ts +4 -3
  17. package/src/cli/pane-functions/resolver.ts +75 -2
  18. package/src/cli/quote-answer.ts +9 -0
  19. package/src/cli/symbol-list.ts +54 -2
  20. package/src/cli/symbol-rows.ts +14 -2
  21. package/src/cli/ticker-resolution.ts +89 -20
  22. package/src/components/chart/composite/axis-overlays.tsx +60 -27
  23. package/src/components/chart/composite/composite-chart.tsx +118 -63
  24. package/src/components/chart/composite/cursor-source.ts +111 -0
  25. package/src/components/chart/composite/format.ts +168 -6
  26. package/src/components/chart/composite/legend.tsx +8 -4
  27. package/src/components/chart/composite/panel-labels.ts +20 -1
  28. package/src/components/chart/composite/panel-surface.tsx +201 -92
  29. package/src/components/chart/composite/price-axis-labels.tsx +92 -46
  30. package/src/components/chart/composite/price-series.ts +31 -8
  31. package/src/components/chart/composite/scene.ts +154 -59
  32. package/src/components/chart/composite/series-axis-tags.tsx +4 -2
  33. package/src/components/chart/composite/time-axis.ts +13 -5
  34. package/src/components/chart/composite/time-scale.ts +211 -56
  35. package/src/components/chart/composite/types.ts +11 -1
  36. package/src/components/chart/composite/use-composite-chart-keyboard.ts +32 -12
  37. package/src/components/chart/curve/curve-surface.tsx +5 -2
  38. package/src/components/chart/curve/model.ts +4 -1
  39. package/src/components/chart/native/use-bitmap-metrics.ts +81 -0
  40. package/src/components/chart/static/series.ts +3 -0
  41. package/src/components/command-bar/commands/collection-list.ts +81 -0
  42. package/src/components/command-bar/commands/direct/index.ts +6 -0
  43. package/src/components/command-bar/commands/registry.ts +8 -0
  44. package/src/components/command-bar/layout-items/current-layout.ts +22 -1
  45. package/src/components/command-bar/layout-items/focused-pane.ts +22 -1
  46. package/src/components/command-bar/pane-templates/items.ts +19 -3
  47. package/src/components/command-bar/pane-templates/workflow.ts +5 -0
  48. package/src/components/command-bar/routes/root/results.ts +23 -3
  49. package/src/components/command-bar/routes/root/selection.ts +4 -2
  50. package/src/components/command-bar/routes/root/shortcut-feedback.ts +1 -1
  51. package/src/components/command-bar/routes/root/shortcut-items.ts +3 -4
  52. package/src/components/command-bar/routes/root/shortcuts.ts +58 -14
  53. package/src/components/command-bar/routes/root/ticker-first.ts +32 -0
  54. package/src/components/command-bar/surface/environment.ts +2 -0
  55. package/src/components/command-bar/view-model.ts +7 -0
  56. package/src/components/command-bar/workflow/ops.ts +2 -1
  57. package/src/components/command-bar/workflow/tickers.ts +20 -0
  58. package/src/components/layout/shell/menu.ts +15 -1
  59. package/src/components/layout/shell/pane/actions.ts +4 -0
  60. package/src/components/layout/shell/ticker-link-menu.ts +12 -3
  61. package/src/components/layout/status-bar.tsx +20 -0
  62. package/src/components/onboarding/onboarding-keyboard.ts +5 -1
  63. package/src/components/onboarding/onboarding-wizard.tsx +15 -4
  64. package/src/components/onboarding/portfolio-step/positions-panel.tsx +8 -5
  65. package/src/components/onboarding/use-onboarding-progress.ts +20 -1
  66. package/src/components/price-sparkline/view.tsx +14 -6
  67. package/src/components/ticker/badge/index.tsx +8 -4
  68. package/src/components/ticker/badge/list.tsx +23 -7
  69. package/src/components/ui/column-grid.tsx +8 -2
  70. package/src/components/ui/data-table/opentui/model.ts +4 -1
  71. package/src/components/ui/tabs.tsx +5 -2
  72. package/src/core/state/app/layout.ts +18 -3
  73. package/src/core/state/app/state.ts +2 -0
  74. package/src/core/state/app/types.ts +5 -0
  75. package/src/data/config/layout.ts +3 -0
  76. package/src/data/config/store/normalize.ts +39 -4
  77. package/src/i18n/es.ts +10 -0
  78. package/src/i18n/ja.ts +10 -0
  79. package/src/i18n/ko.ts +10 -0
  80. package/src/i18n/zh-cn.ts +10 -0
  81. package/src/i18n/zh-tw.ts +10 -0
  82. package/src/layout/pane-manager/floating-placement.ts +7 -4
  83. package/src/layout/pane-manager/floating.ts +5 -2
  84. package/src/market-data/bond-funds.ts +19 -0
  85. package/src/market-data/futures-contract.ts +14 -3
  86. package/src/market-data/market/freshness.ts +18 -0
  87. package/src/market-data/market/status.ts +15 -2
  88. package/src/plugins/builtin/bond-calculator/headless.ts +2 -1
  89. package/src/plugins/builtin/bond-calculator/index.tsx +1 -1
  90. package/src/plugins/builtin/bond-calculator/model.ts +14 -5
  91. package/src/plugins/builtin/bond-calculator/pane.tsx +1 -1
  92. package/src/plugins/builtin/buildout/cells.tsx +25 -45
  93. package/src/plugins/builtin/buildout/detail/company.tsx +3 -3
  94. package/src/plugins/builtin/buildout/detail/index.tsx +1 -1
  95. package/src/plugins/builtin/buildout/detail/intel.tsx +4 -7
  96. package/src/plugins/builtin/buildout/detail/site.tsx +4 -4
  97. package/src/plugins/builtin/buildout/detail/ui.tsx +39 -38
  98. package/src/plugins/builtin/buildout/format.ts +23 -1
  99. package/src/plugins/builtin/buildout/model/types.ts +1 -0
  100. package/src/plugins/builtin/buildout/pane/index.tsx +2 -8
  101. package/src/plugins/builtin/buildout/table-model.ts +12 -4
  102. package/src/plugins/builtin/cds/headless.ts +1 -0
  103. package/src/plugins/builtin/cds/index.tsx +1 -1
  104. package/src/plugins/builtin/cloud/plugin.tsx +2 -0
  105. package/src/plugins/builtin/cloud/upgrade-status-widget.tsx +28 -3
  106. package/src/plugins/builtin/correlation/headless.ts +3 -2
  107. package/src/plugins/builtin/crypto-board/pane.tsx +5 -4
  108. package/src/plugins/builtin/debt-maturities/headless.ts +11 -2
  109. package/src/plugins/builtin/debt-maturities/model.ts +66 -0
  110. package/src/plugins/builtin/debt-maturities/pane.tsx +23 -4
  111. package/src/plugins/builtin/earnings-ripple/pane.tsx +1 -1
  112. package/src/plugins/builtin/econ/calendar-model.ts +28 -6
  113. package/src/plugins/builtin/equity-screener/client.ts +1 -1
  114. package/src/plugins/builtin/equity-screener/criterion-editor.tsx +4 -16
  115. package/src/plugins/builtin/equity-screener/headless.ts +4 -2
  116. package/src/plugins/builtin/equity-screener/ideas.ts +67 -3
  117. package/src/plugins/builtin/equity-screener/model.ts +180 -12
  118. package/src/plugins/builtin/equity-screener/pane.tsx +52 -12
  119. package/src/plugins/builtin/equity-screener/screen-check.ts +7 -4
  120. package/src/plugins/builtin/equity-screener/watchlist.ts +33 -0
  121. package/src/plugins/builtin/futures-curve/client.ts +19 -0
  122. package/src/plugins/builtin/futures-curve/headless.ts +52 -13
  123. package/src/plugins/builtin/futures-curve/index.tsx +1 -1
  124. package/src/plugins/builtin/futures-curve/model.ts +77 -6
  125. package/src/plugins/builtin/futures-curve/pane.tsx +19 -3
  126. package/src/plugins/builtin/macro-day/client.ts +41 -0
  127. package/src/plugins/builtin/macro-day/headless.ts +19 -9
  128. package/src/plugins/builtin/macro-day/model.ts +3 -1
  129. package/src/plugins/builtin/market-movers/index.tsx +4 -3
  130. package/src/plugins/builtin/mna/distress/headless.ts +1 -0
  131. package/src/plugins/builtin/perps/pane.tsx +3 -1
  132. package/src/plugins/builtin/portfolio-list/cli/bulk-symbols.ts +17 -0
  133. package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +2 -1
  134. package/src/plugins/builtin/portfolio-list/cli/watchlist-command.ts +2 -1
  135. package/src/plugins/builtin/rate-path/headless.ts +24 -10
  136. package/src/plugins/builtin/research/event-model.ts +10 -3
  137. package/src/plugins/builtin/research/events-headless.ts +20 -2
  138. package/src/plugins/builtin/sec/fund-facts.ts +17 -1
  139. package/src/plugins/builtin/sec/index.tsx +1 -1
  140. package/src/plugins/builtin/shared/members-menu.tsx +103 -38
  141. package/src/plugins/builtin/short-interest/publications-model.ts +22 -1
  142. package/src/plugins/builtin/short-interest/publications-pane.tsx +13 -4
  143. package/src/plugins/builtin/short-interest/watch-model.ts +1 -1
  144. package/src/plugins/builtin/time-sales/pane.tsx +3 -2
  145. package/src/plugins/builtin/trace-bonds/client.ts +7 -4
  146. package/src/plugins/builtin/trace-bonds/index.tsx +1 -1
  147. package/src/plugins/builtin/volatility/client.ts +6 -1
  148. package/src/plugins/builtin/volatility/headless.ts +0 -1
  149. package/src/plugins/builtin/yield-curve/curves.ts +15 -0
  150. package/src/plugins/builtin/yield-curve/headless.ts +6 -1
  151. package/src/plugins/builtin/yield-curve/index.tsx +5 -8
  152. package/src/plugins/host-modules.ts +22 -3
  153. package/src/plugins/host-smoke.ts +6 -3
  154. package/src/portfolio/collection-name.ts +19 -0
  155. package/src/renderers/browser/http-proxy-transport.ts +78 -8
  156. package/src/renderers/cloudflare/http-proxy.ts +13 -2
  157. package/src/renderers/cloudflare/proxy-session.ts +47 -24
  158. package/src/renderers/cloudflare/worker.ts +15 -2
  159. package/src/renderers/desktop/geometry.ts +279 -0
  160. package/src/renderers/desktop/screen-setup.ts +246 -0
  161. package/src/renderers/desktop/sequential-window-host.ts +179 -0
  162. package/src/renderers/desktop/test-utils.ts +71 -0
  163. package/src/renderers/desktop/window-controller.ts +433 -0
  164. package/src/renderers/desktop/window-host.ts +70 -0
  165. package/src/renderers/desktop/window-layouts.ts +630 -0
  166. package/src/renderers/dom/data-frames.ts +15 -4
  167. package/src/renderers/electrobun/bun/application-menu/click.ts +1 -0
  168. package/src/renderers/electrobun/bun/application-menu/index.ts +4 -1
  169. package/src/renderers/electrobun/bun/desktop/backend-requests.ts +19 -8
  170. package/src/renderers/electrobun/bun/desktop/backend.ts +320 -19
  171. package/src/renderers/electrobun/bun/desktop/detached-windows.ts +83 -61
  172. package/src/renderers/electrobun/bun/desktop/host-requests.ts +4 -14
  173. package/src/renderers/electrobun/bun/desktop/initialization.ts +30 -11
  174. package/src/renderers/electrobun/bun/desktop/screen-setup-file.ts +55 -0
  175. package/src/renderers/electrobun/bun/desktop/state-broadcaster.ts +44 -8
  176. package/src/renderers/electrobun/bun/desktop/workspace/index.ts +298 -97
  177. package/src/renderers/electrobun/bun/desktop/workspace/requests.ts +44 -6
  178. package/src/renderers/electrobun/bun/index.ts +4 -97
  179. package/src/renderers/electrobun/bun/window/electrobun-window-host.ts +306 -0
  180. package/src/renderers/electrobun/bun/window/focus.ts +0 -25
  181. package/src/renderers/electrobun/bun/window/remembered-frame.ts +4 -82
  182. package/src/renderers/electrobun/shared/protocol.ts +44 -2
  183. package/src/renderers/electrobun/view/backend-rpc.ts +15 -0
  184. package/src/renderers/electrobun/view/desktop/window/bridge.ts +63 -3
  185. package/src/renderers/electrobun/view/main.tsx +13 -7
  186. package/src/series/fred-argument.ts +17 -0
  187. package/src/sources/provider-router/financial-routes.ts +7 -1
  188. package/src/state/app/context/index.tsx +16 -2
  189. package/src/state/desktop-windows.ts +63 -0
  190. package/src/sync/other-window-tabs.ts +62 -0
  191. package/src/tickers/company-name-listing.ts +23 -3
  192. package/src/tickers/listing-fate.ts +147 -1
  193. package/src/tickers/terminal-codes.ts +5 -0
  194. package/src/time-series/types.ts +6 -0
  195. package/src/types/config.ts +10 -1
  196. package/src/types/desktop-window.ts +71 -2
  197. package/src/types/financials.ts +4 -0
  198. package/src/types/headless.ts +19 -0
  199. package/src/types/plugin.ts +6 -0
  200. package/src/ui/index.tsx +14 -13
  201. package/src/ui/same-props.ts +58 -0
  202. package/src/utils/cli-output.ts +33 -4
  203. package/src/utils/format.ts +7 -2
  204. package/src/utils/futures-generic.ts +12 -0
  205. package/src/utils/http-proxy-upstream.ts +6 -2
  206. package/src/utils/plugin-proxy-hosts.json +0 -4
  207. package/src/utils/plugin-proxy-hosts.ts +22 -0
  208. package/src/utils/sec-filings.ts +7 -1
@@ -1,3 +1,4 @@
1
+ import { memo } from "react";
1
2
  import { Box, Text, useUiCapabilities } from "../../../ui";
2
3
  import type { CompositeChartXMarker } from "./types";
3
4
 
@@ -102,6 +103,49 @@ export interface StaticXAxisMarker {
102
103
  color: string;
103
104
  }
104
105
 
106
+ /** A time label at its place on the axis, which holds still while the cursor moves past. */
107
+ const PositionedTimeLabel = memo(function PositionedTimeLabel({ label, color, left, right, transform }: {
108
+ label: string;
109
+ color: string | undefined;
110
+ left: number | string | undefined;
111
+ right: number | string | undefined;
112
+ transform: number | string | undefined;
113
+ }) {
114
+ return (
115
+ <Text
116
+ fg={color}
117
+ selectable={false}
118
+ // The label against the right edge, which a floating pane's resize grip may cover.
119
+ data-gloom-edge={right !== undefined ? "end" : undefined}
120
+ style={{
121
+ position: "absolute",
122
+ top: 0,
123
+ whiteSpace: "pre",
124
+ pointerEvents: "none",
125
+ ...(left !== undefined ? { left } : {}),
126
+ ...(right !== undefined ? { right } : {}),
127
+ ...(transform !== undefined ? { transform } : {}),
128
+ }}
129
+ >
130
+ {label}
131
+ </Text>
132
+ );
133
+ });
134
+
135
+ /** A stretch of the axis text in the terminal, which renders only when its text does. */
136
+ const TimeLabelSegment = memo(function TimeLabelSegment({ width, text, color, end }: {
137
+ width: number;
138
+ text: string;
139
+ color: string | undefined;
140
+ end: boolean;
141
+ }) {
142
+ return (
143
+ <Box width={width} overflow="hidden" data-gloom-edge={end ? "end-segment" : undefined}>
144
+ <Text fg={color}>{text}</Text>
145
+ </Box>
146
+ );
147
+ });
148
+
105
149
  export function StaticXAxisLabels({
106
150
  labels,
107
151
  positionedLabels,
@@ -235,38 +279,27 @@ export function StaticXAxisLabels({
235
279
  >
236
280
  {visiblePositionedLabels.length > 0 && (isDesktop || visibleLabels.length === 0) ? (
237
281
  <Box position="absolute" left={0} top={0} width={width} height={1} style={isDesktop ? { width: "100%" } : undefined}>
238
- {positionedPlacements.map(({ entry, index, edgeStyle }) => {
239
- return (
240
- <Text
241
- key={`${entry.label}:${entry.ratio}:${index}`}
242
- fg={color}
243
- selectable={false}
244
- // The label against the right edge, which a floating pane's resize grip may cover.
245
- data-gloom-edge={"right" in edgeStyle ? "end" : undefined}
246
- style={{
247
- position: "absolute",
248
- top: 0,
249
- whiteSpace: "pre",
250
- pointerEvents: "none",
251
- ...edgeStyle,
252
- }}
253
- >
254
- {entry.label}
255
- </Text>
256
- );
257
- })}
282
+ {positionedPlacements.map(({ entry, index, edgeStyle }) => (
283
+ <PositionedTimeLabel
284
+ key={`${entry.label}:${entry.ratio}:${index}`}
285
+ label={entry.label}
286
+ color={color}
287
+ left={edgeStyle.left}
288
+ right={edgeStyle.right}
289
+ transform={edgeStyle.transform}
290
+ />
291
+ ))}
258
292
  </Box>
259
293
  ) : (
260
294
  <Box width={width} height={1} flexDirection="row">
261
295
  {visibleLabels.map((label, index) => (
262
- <Box
296
+ <TimeLabelSegment
263
297
  key={`${label}:${index}`}
264
- width={segmentWidths[index]}
265
- overflow="hidden"
266
- data-gloom-edge={index === visibleLabels.length - 1 && visibleLabels.length > 1 ? "end-segment" : undefined}
267
- >
268
- <Text fg={color}>{flowText[index]}</Text>
269
- </Box>
298
+ width={segmentWidths[index]!}
299
+ text={flowText[index]!}
300
+ color={color}
301
+ end={index === visibleLabels.length - 1 && visibleLabels.length > 1}
302
+ />
270
303
  ))}
271
304
  </Box>
272
305
  )}
@@ -1,4 +1,14 @@
1
- import { useCallback, useEffect, useId, useMemo, useRef, useState, useSyncExternalStore, type ReactNode } from "react";
1
+ import {
2
+ useCallback,
3
+ useEffect,
4
+ useId,
5
+ useMemo,
6
+ useRef,
7
+ useState,
8
+ useSyncExternalStore,
9
+ type ComponentProps,
10
+ type ReactNode,
11
+ } from "react";
2
12
  import { useCompositeChartKeyboard } from "./use-composite-chart-keyboard";
3
13
  import { useCompositeViewport } from "./use-composite-viewport";
4
14
  import { CompositePanelSurface } from "./panel-surface";
@@ -40,6 +50,12 @@ import { useChartViewResetListener } from "../core/view-reset";
40
50
  import { useShowChartTextFallback } from "../native/use-chart-text-fallback";
41
51
  import { StaticXAxisLabels, StaticXMarkerLabels, StaticXMarkerOverlay } from "./axis-overlays";
42
52
  import { formatCompositeCursorAxisDate } from "./format";
53
+ import {
54
+ createCompositeCursorSource,
55
+ createValueStore,
56
+ useCursorScene,
57
+ type CompositeCursorSource,
58
+ } from "./cursor-source";
43
59
  import {
44
60
  resolveCompositeWheelPan,
45
61
  resolveCompositeWheelZoom,
@@ -51,10 +67,8 @@ import { useCompositeValueScales } from "./use-composite-value-scales";
51
67
  import { COMPOSITE_RIGHT_OFFSET_RATIO } from "./time-scale";
52
68
  import {
53
69
  allocateCompositePanelHeights,
54
- applyCompositeChartCursor,
55
70
  buildCompositeChartScene,
56
71
  compositeCursorAsOf,
57
- compositeLinkedCursorTime,
58
72
  resizeCompositePanel,
59
73
  resolveAdjacentCompositeCursorDate,
60
74
  } from "./scene";
@@ -93,6 +107,11 @@ const NO_X_MARKERS: readonly CompositeChartXMarker[] = [];
93
107
  const subscribeToNothing = () => () => {};
94
108
  const holdsNothing = () => false;
95
109
 
110
+ function finiteTimestampOrNull(date: Date | null | undefined): number | null {
111
+ const timestamp = date?.getTime() ?? null;
112
+ return timestamp !== null && Number.isFinite(timestamp) ? timestamp : null;
113
+ }
114
+
96
115
  /**
97
116
  * Desktop: the rows below the plot span the chart's box and their labels the
98
117
  * width the gutters leave, so when a resize draws the box at a new size
@@ -215,7 +234,9 @@ function ThemedCompositeChart({
215
234
  const { cellWidthPx = 8, cellHeightPx = 18, pixelRatio = 1, fractionalViewport = false } = useUiCapabilities();
216
235
  const isDesktopWeb = useUiCapabilities().nativePaneChrome === true;
217
236
  const showTextFallback = useShowChartTextFallback();
218
- const [internalCursorDate, setInternalCursorDate] = useState<Date | null>(null);
237
+ // The chart's own cursor, in epoch ms. A pointer move sets it without
238
+ // rendering the chart: only what draws the crosshair renders (see `cursorSource`).
239
+ const [ownCursor] = useState(() => createValueStore<number | null>(null));
219
240
  const [toolSpan, setToolSpan] = useState<ChartToolSpan | null>(null);
220
241
  const [pointerDragging, setPointerDragging] = useState(false);
221
242
  const paneFocused = usePaneFocused();
@@ -255,8 +276,7 @@ function ThemedCompositeChart({
255
276
  // pointer moves it as on any chart, and the pointer leaving returns it.
256
277
  const restingCursor = cursorDate !== undefined && !onCursorDateChange;
257
278
  const ownsCursor = cursorDate === undefined || restingCursor;
258
- const resolvedCursorDate = cursorDate === undefined ? internalCursorDate
259
- : restingCursor ? internalCursorDate ?? cursorDate : cursorDate;
279
+ const ownerCursorTimestamp = finiteTimestampOrNull(cursorDate);
260
280
  const totalWidth = Math.max(1, Math.floor(width));
261
281
  const totalHeight = Math.max(1, Math.floor(height));
262
282
  const seriesIdentityRef = useRef<ResolvedSeries[]>([]);
@@ -483,10 +503,12 @@ function ThemedCompositeChart({
483
503
  };
484
504
  return downsampleCompositeChartScene(laidOut, downsampleWidth);
485
505
  }, [downsampleWidth, layoutPanels, maximizedPanelId, plotWidth, projectedScene]);
486
- const resolvedCursorTimestamp = resolvedCursorDate?.getTime() ?? null;
487
- const normalizedCursorTimestamp = resolvedCursorTimestamp !== null && Number.isFinite(resolvedCursorTimestamp)
488
- ? resolvedCursorTimestamp
489
- : null;
506
+ // The cursor shown: the chart's own, or else the owner's.
507
+ const currentCursorTimestamp = useCallback(
508
+ () => (ownsCursor ? ownCursor.get() : null) ?? ownerCursorTimestamp,
509
+ [ownCursor, ownerCursorTimestamp, ownsCursor],
510
+ );
511
+ const normalizedCursorTimestamp = currentCursorTimestamp();
490
512
  // A custom x axis is not time, so there is no time to share. Otherwise an
491
513
  // interactive chart in a pane shares its crosshair with every chart in the
492
514
  // pane's layout tab, its siblings in the pane included: each chart is its
@@ -506,43 +528,40 @@ function ThemedCompositeChart({
506
528
  const sharedTime = link?.time;
507
529
  // Charts sharing a cursor show one: another chart's while it holds it, in
508
530
  // place of this one's own. An owner's resting cursor, such as a table's
509
- // selected row, comes back when it clears. A chart renders again when the
510
- // bar the shared cursor lands on here changes, not on every move: a daily
511
- // chart under a 30-minute one's cursor moves once a session.
531
+ // selected row, comes back when it clears. Whether one shows renders the
532
+ // chart; where it is renders only what draws it (see `cursorSource`).
512
533
  const showsSharedCursor = useSyncExternalStore(subscribeToLink, useCallback(() => sharedTime?.() != null, [sharedTime]));
513
- const sharedCursorBar = useSyncExternalStore(subscribeToLink, useCallback(() => {
514
- const time = sharedTime?.() ?? null;
515
- return time === null || !baseScene ? null : compositeLinkedCursorTime(baseScene, time);
516
- }, [baseScene, sharedTime]));
517
534
  const holdsSharedCursor = useSyncExternalStore(subscribeToLink, link?.held ?? holdsNothing);
518
535
  const pinnedCursor = useSyncExternalStore(subscribeToLink, link?.pinned ?? holdsNothing);
519
536
  const publishCursor = link?.publish;
520
- const scene = useMemo(() => {
521
- if (!baseScene) return null;
522
- if (showsSharedCursor) {
523
- return applyCompositeChartCursor(baseScene, sharedCursorBar === null ? null : new Date(sharedCursorBar), "linked");
524
- }
525
- return applyCompositeChartCursor(
526
- baseScene,
527
- normalizedCursorTimestamp === null ? null : new Date(normalizedCursorTimestamp),
528
- );
529
- }, [baseScene, normalizedCursorTimestamp, sharedCursorBar, showsSharedCursor]);
537
+ const cursorSource = useMemo<CompositeCursorSource | null>(() => baseScene ? createCompositeCursorSource({
538
+ baseScene,
539
+ own: ownsCursor ? ownCursor : null,
540
+ fallback: ownerCursorTimestamp,
541
+ link,
542
+ }) : null, [baseScene, link, ownCursor, ownerCursorTimestamp, ownsCursor]);
530
543
  const lastCursorTimestampRef = useRef<number | null>(normalizedCursorTimestamp);
531
544
  const renderedCursorTimestampRef = useRef<number | null>(normalizedCursorTimestamp);
532
- if (renderedCursorTimestampRef.current !== normalizedCursorTimestamp) {
533
- renderedCursorTimestampRef.current = normalizedCursorTimestamp;
534
- lastCursorTimestampRef.current = normalizedCursorTimestamp;
535
- }
545
+ // The cursor last shown, which a move to the same time does not report
546
+ // again. It follows the chart's own cursor as it moves, between renders.
547
+ const syncShownCursor = useCallback(() => {
548
+ const shown = currentCursorTimestamp();
549
+ if (renderedCursorTimestampRef.current === shown) return;
550
+ renderedCursorTimestampRef.current = shown;
551
+ lastCursorTimestampRef.current = shown;
552
+ }, [currentCursorTimestamp]);
553
+ syncShownCursor();
554
+ useEffect(() => ownCursor.subscribe(syncShownCursor), [ownCursor, syncShownCursor]);
536
555
 
537
556
  const updateCursor = useCallback((date: Date | null) => {
538
557
  const timestamp = date?.getTime() ?? null;
539
558
  const nextTimestamp = timestamp !== null && Number.isFinite(timestamp) ? timestamp : null;
540
559
  if (lastCursorTimestampRef.current === nextTimestamp) return;
541
560
  lastCursorTimestampRef.current = nextTimestamp;
542
- if (ownsCursor) setInternalCursorDate(date);
561
+ if (ownsCursor) ownCursor.set(nextTimestamp);
543
562
  onCursorDateChange?.(date);
544
563
  publishCursor?.(date && baseScene && nextTimestamp !== null ? compositeCursorAsOf(baseScene, date) : null);
545
- }, [baseScene, onCursorDateChange, ownsCursor, publishCursor]);
564
+ }, [baseScene, onCursorDateChange, ownCursor, ownsCursor, publishCursor]);
546
565
  // Another chart taking the cursor, or clearing it, takes it from this one,
547
566
  // so it does not come back here later. Read live: a move since the render
548
567
  // makes this chart's cursor the shared one again.
@@ -570,12 +589,15 @@ function ThemedCompositeChart({
570
589
  // The last time sits in a ref, so a moving crosshair costs no extra render,
571
590
  // and the footer's pin is there from the start: a hint appearing mid-hover
572
591
  // would move the plot under the pointer.
573
- const cursorAt = scene?.cursorDate?.getTime() ?? null;
574
592
  const lastCursorAtRef = useRef<{ time: number; shared: boolean } | null>(null);
575
- if (cursorAt !== null) {
576
- const shared = showsSharedCursor ? sharedTime?.() ?? null : null;
593
+ const noteShownCursor = useCallback(() => {
594
+ const cursorAt = cursorSource?.scene().cursorDate?.getTime() ?? null;
595
+ if (cursorAt === null) return;
596
+ const shared = sharedTime?.() ?? null;
577
597
  lastCursorAtRef.current = shared !== null ? { time: shared, shared: true } : { time: cursorAt, shared: false };
578
- }
598
+ }, [cursorSource, sharedTime]);
599
+ noteShownCursor();
600
+ useEffect(() => cursorSource?.subscribe(noteShownCursor), [cursorSource, noteShownCursor]);
579
601
  const pinnable = !!link?.pin;
580
602
  const togglePin = useCallback(() => {
581
603
  if (!link?.pin) return;
@@ -702,7 +724,8 @@ function ThemedCompositeChart({
702
724
  interactive,
703
725
  navigable,
704
726
  showLegend,
705
- scene,
727
+ scene: baseScene,
728
+ cursor: cursorSource,
706
729
  cursorDate,
707
730
  updateCursor: updateKeyboardCursor,
708
731
  pin: pinnable ? { pinned: pinnedCursor, toggle: togglePin } : null,
@@ -882,7 +905,7 @@ function ThemedCompositeChart({
882
905
  () => baseScene && showTimeAxis ? buildCompositeTimeAxisLayout(baseScene, plotWidth) : null,
883
906
  [baseScene, plotWidth, showTimeAxis],
884
907
  );
885
- const emptyTimeAxisLayout = !scene && showTimeAxis && effectiveViewport
908
+ const emptyTimeAxisLayout = !baseScene && showTimeAxis && effectiveViewport
886
909
  ? buildCompositeViewportTimeAxisLayout(effectiveViewport, plotWidth)
887
910
  : null;
888
911
 
@@ -898,7 +921,7 @@ function ThemedCompositeChart({
898
921
  ? { width: "auto", height: "auto", right: `calc(${rightPadding} * var(--cell-w))`, bottom: `calc(${timeAxisRows + xMarkerRows} * var(--cell-h))` }
899
922
  : undefined;
900
923
 
901
- if (!scene) {
924
+ if (!baseScene || !cursorSource) {
902
925
  const emptyPlotHeight = Math.max(0, totalHeight - legendRows - timeAxisRows - xMarkerRows);
903
926
  return (
904
927
  <Box
@@ -985,29 +1008,18 @@ function ThemedCompositeChart({
985
1008
  // while a tool picked from the keys is in hand, so the plot says which one.
986
1009
  const toolbarFolded = showToolbar && chartLayout.toolbarHidden === true && armedTool === null;
987
1010
  // Bars shorter than a day carry a time of day the cursor reads out.
988
- const intradayBars = scene.timeZone !== undefined || visibleSeries.some((entry) => (
1011
+ const intradayBars = baseScene.timeZone !== undefined || visibleSeries.some((entry) => (
989
1012
  !!entry.historyResolution && isIntradayResolution(entry.historyResolution)
990
1013
  ));
991
- const timeAxisCursorColumn = scene.cursorXRatio === null
992
- ? null
993
- : scene.cursorXRatio * Math.max(plotWidth - 1, 0);
994
- const timeAxisCursorPixelX = timeAxisCursorColumn === null
995
- ? null
996
- : timeAxisCursorColumn * cellWidthPx;
997
- const timeAxisCursorLabel = xAxis?.formatCursor && scene.cursorXRatio !== null
998
- ? xAxis.formatCursor(scene.cursorXRatio)
999
- : scene.cursorDate
1000
- ? formatCompositeCursorAxisDate(scene.cursorDate, scene.startTime, scene.endTime, scene.timeZone, intradayBars)
1001
- : null;
1002
1014
  // The crosshair labels the moving end, so the axis only adds the anchor.
1003
1015
  const timeAxisMarkers = toolSpan
1004
1016
  ? [{
1005
1017
  ratio: toolSpan.startXRatio,
1006
1018
  label: formatCompositeCursorAxisDate(
1007
1019
  new Date(toolSpan.startTime),
1008
- scene.startTime,
1009
- scene.endTime,
1010
- scene.timeZone,
1020
+ baseScene.startTime,
1021
+ baseScene.endTime,
1022
+ baseScene.timeZone,
1011
1023
  intradayBars,
1012
1024
  ),
1013
1025
  color: toolSpan.color,
@@ -1028,10 +1040,10 @@ function ThemedCompositeChart({
1028
1040
  data-gloom-data={navigationFrame ? `${navigationFrame.dataStart}:${navigationFrame.dataEnd}` : undefined}
1029
1041
  >
1030
1042
  {showLegend ? (
1031
- <CompositeLegend
1043
+ <CursorLegend
1032
1044
  // Every series' value at the crosshair, the latest ones when the
1033
1045
  // pointer leaves; the price and the time under it sit on the axes.
1034
- scene={scene}
1046
+ cursor={cursorSource}
1035
1047
  series={visibleLegendSeries}
1036
1048
  visibleSeriesIds={visibleSeriesIds}
1037
1049
  lineCues={lineCues}
@@ -1122,11 +1134,12 @@ function ThemedCompositeChart({
1122
1134
  onRestore={setDrawings}
1123
1135
  />
1124
1136
  ) : null}
1125
- {scene.panels.map((panel, index) => (
1137
+ {baseScene.panels.map((panel, index) => (
1126
1138
  <CompositePanelSurface
1127
1139
  key={panel.id}
1128
1140
  panel={panel}
1129
- scene={scene}
1141
+ scene={baseScene}
1142
+ cursor={cursorSource}
1130
1143
  plotWidth={plotWidth}
1131
1144
  leftAxisWidth={leftAxisWidth}
1132
1145
  rightAxisWidth={rightAxisWidth}
@@ -1217,14 +1230,15 @@ function ThemedCompositeChart({
1217
1230
  data-gloom-role="composite-chart-time-scale"
1218
1231
  >
1219
1232
  {leftPadding > 0 ? <Box width={leftPadding} /> : null}
1220
- <StaticXAxisLabels
1233
+ <CursorTimeAxis
1234
+ cursor={cursorSource}
1235
+ formatCursor={xAxis?.formatCursor}
1236
+ intradayBars={intradayBars}
1237
+ cellWidthPx={cellWidthPx}
1221
1238
  labels={xAxis?.ticks ? [] : xAxis?.labels ? [...xAxis.labels] : [timeAxisLayout.text]}
1222
1239
  positionedLabels={xAxis?.ticks ?? (xAxis?.labels ? undefined : timeAxisLayout.ticks)}
1223
1240
  width={plotWidth}
1224
1241
  color={resolvedColors.textDim}
1225
- cursorColumn={timeAxisCursorColumn}
1226
- cursorPixelX={timeAxisCursorPixelX}
1227
- cursorLabel={timeAxisCursorLabel}
1228
1242
  cursorColor={resolvedColors.crosshair}
1229
1243
  cursorBackgroundColor={resolvedColors.background}
1230
1244
  extraMarkers={timeAxisMarkers}
@@ -1246,3 +1260,44 @@ function ThemedCompositeChart({
1246
1260
  </Box>
1247
1261
  );
1248
1262
  }
1263
+
1264
+ /** The legend, rendering with the crosshair: its values are the series' at the cursor. */
1265
+ function CursorLegend({ cursor, ...props }: Omit<ComponentProps<typeof CompositeLegend>, "scene"> & {
1266
+ cursor: CompositeCursorSource;
1267
+ }) {
1268
+ return <CompositeLegend {...props} scene={useCursorScene(cursor)} />;
1269
+ }
1270
+
1271
+ /** The time axis, rendering with the crosshair: its label sits at the cursor, and the ticks under it step aside. */
1272
+ function CursorTimeAxis({
1273
+ cursor,
1274
+ formatCursor,
1275
+ intradayBars,
1276
+ cellWidthPx,
1277
+ width,
1278
+ ...props
1279
+ }: Omit<ComponentProps<typeof StaticXAxisLabels>, "cursorColumn" | "cursorPixelX" | "cursorLabel"> & {
1280
+ cursor: CompositeCursorSource;
1281
+ formatCursor?: (ratio: number) => string;
1282
+ intradayBars: boolean;
1283
+ cellWidthPx: number;
1284
+ }) {
1285
+ const scene = useCursorScene(cursor);
1286
+ const cursorColumn = scene.cursorXRatio === null
1287
+ ? null
1288
+ : scene.cursorXRatio * Math.max(width - 1, 0);
1289
+ const cursorLabel = formatCursor && scene.cursorXRatio !== null
1290
+ ? formatCursor(scene.cursorXRatio)
1291
+ : scene.cursorDate
1292
+ ? formatCompositeCursorAxisDate(scene.cursorDate, scene.startTime, scene.endTime, scene.timeZone, intradayBars)
1293
+ : null;
1294
+ return (
1295
+ <StaticXAxisLabels
1296
+ {...props}
1297
+ width={width}
1298
+ cursorColumn={cursorColumn}
1299
+ cursorPixelX={cursorColumn === null ? null : cursorColumn * cellWidthPx}
1300
+ cursorLabel={cursorLabel}
1301
+ />
1302
+ );
1303
+ }
@@ -0,0 +1,111 @@
1
+ import { useSyncExternalStore } from "react";
2
+ import { applyCompositeChartCursor, compositeLinkedCursorTime } from "./scene";
3
+ import type { CompositeChartScene } from "./types";
4
+
5
+ type Listener = () => void;
6
+
7
+ /** A value that changes without rendering what holds it: only its readers render. */
8
+ export interface ValueStore<T> {
9
+ get(): T;
10
+ set(value: T): void;
11
+ subscribe(listener: Listener): () => void;
12
+ }
13
+
14
+ export function createValueStore<T>(initial: T): ValueStore<T> {
15
+ let value = initial;
16
+ const listeners = new Set<Listener>();
17
+ return {
18
+ get: () => value,
19
+ set(next) {
20
+ if (Object.is(next, value)) return;
21
+ value = next;
22
+ for (const listener of [...listeners]) listener();
23
+ },
24
+ subscribe(listener) {
25
+ listeners.add(listener);
26
+ return () => {
27
+ listeners.delete(listener);
28
+ };
29
+ },
30
+ };
31
+ }
32
+
33
+ /** The cursor charts in one tab share: the time another chart's crosshair is at. */
34
+ interface SharedCursorTime {
35
+ subscribe(listener: Listener): () => void;
36
+ time(): number | null;
37
+ }
38
+
39
+ /**
40
+ * The chart's scene with its crosshair applied, for the parts that draw the
41
+ * crosshair: the legend's values, the value and time axes' cursor labels and
42
+ * the plot's crosshair. A pointer move renders those alone; the chart, its
43
+ * series and its axes stay as they are.
44
+ */
45
+ export interface CompositeCursorSource {
46
+ /** The scene with the cursor, the same object until the cursor moves to another bar. */
47
+ scene(): CompositeChartScene;
48
+ subscribe(listener: Listener): () => void;
49
+ }
50
+
51
+ export interface CompositeCursorSourceOptions {
52
+ /** The scene the cursor is applied to, which has none of its own. */
53
+ baseScene: CompositeChartScene;
54
+ /** The chart's own cursor, in epoch ms, which the pointer and the keys move. Null when the owner holds it. */
55
+ own: ValueStore<number | null> | null;
56
+ /** The owner's cursor, in epoch ms: the one shown while the chart has none of its own. */
57
+ fallback: number | null;
58
+ /** Another chart's cursor, which shows in place of this one's while it is set. */
59
+ link?: SharedCursorTime;
60
+ }
61
+
62
+ export function createCompositeCursorSource({
63
+ baseScene,
64
+ own,
65
+ fallback,
66
+ link,
67
+ }: CompositeCursorSourceOptions): CompositeCursorSource {
68
+ let cachedKey: string | null = null;
69
+ let cached = baseScene;
70
+ const scene = () => {
71
+ const sharedTime = link?.time() ?? null;
72
+ let key: string;
73
+ let next: () => CompositeChartScene;
74
+ if (sharedTime !== null) {
75
+ // A chart renders again when the bar the shared cursor lands on here
76
+ // changes, not on every move: a daily chart under a 30-minute one's
77
+ // cursor moves once a session.
78
+ const bar = compositeLinkedCursorTime(baseScene, sharedTime);
79
+ key = `linked:${bar}`;
80
+ next = () => applyCompositeChartCursor(baseScene, bar === null ? null : new Date(bar), "linked");
81
+ } else {
82
+ const time = own?.get() ?? fallback;
83
+ key = `own:${time}`;
84
+ next = () => applyCompositeChartCursor(baseScene, time === null ? null : new Date(time));
85
+ }
86
+ if (key !== cachedKey) {
87
+ cachedKey = key;
88
+ cached = next();
89
+ }
90
+ return cached;
91
+ };
92
+ const subscribe = (listener: Listener) => {
93
+ const stopOwn = own?.subscribe(listener);
94
+ const stopLink = link?.subscribe(listener);
95
+ return () => {
96
+ stopOwn?.();
97
+ stopLink?.();
98
+ };
99
+ };
100
+ return { scene, subscribe };
101
+ }
102
+
103
+ /** The scene with the cursor, rendering again when the cursor moves to another bar. */
104
+ export function useCursorScene(source: CompositeCursorSource): CompositeChartScene {
105
+ return useSyncExternalStore(source.subscribe, source.scene, source.scene);
106
+ }
107
+
108
+ /** A store's value, rendering again when it changes. */
109
+ export function useValueStore<T>(store: ValueStore<T>): T {
110
+ return useSyncExternalStore(store.subscribe, store.get, store.get);
111
+ }