gloomberb 0.19.5 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +0 -4
- package/package.json +6 -5
- package/patches/@opentui%2Fcore@0.3.2.patch +86 -25
- package/patches/electrobun-devkit@2.0.5.patch +148 -0
- package/src/api-client/bond-trades.ts +59 -0
- package/src/api-client/data.ts +21 -0
- package/src/api-client/equity-screener.ts +23 -0
- package/src/api-client/index.ts +2 -0
- package/src/api-client/types/account.ts +86 -0
- package/src/api-client/types/assist.ts +32 -0
- package/src/api-client/types/auth.ts +63 -0
- package/src/api-client/types/billing.ts +54 -0
- package/src/api-client/types/chat.ts +180 -0
- package/src/api-client/types/congress.ts +107 -0
- package/src/api-client/types/credit.ts +110 -0
- package/src/api-client/types/econ.ts +158 -0
- package/src/api-client/types/equity-diagnostic.ts +73 -0
- package/src/api-client/types/filings-and-calls.ts +350 -0
- package/src/api-client/types/index.ts +25 -0
- package/src/api-client/types/jobs.ts +147 -0
- package/src/api-client/types/market.ts +122 -0
- package/src/api-client/types/news.ts +91 -0
- package/src/api-client/types/notes-and-theses.ts +172 -0
- package/src/api-client/types/quotes.ts +28 -0
- package/src/api-client/types/scanners.ts +125 -0
- package/src/api-client/types/screener.ts +65 -0
- package/src/api-client/types/search.ts +107 -0
- package/src/api-client/types/sync.ts +14 -0
- package/src/api-client/types/team-collections.ts +43 -0
- package/src/api-client/types/team-views.ts +32 -0
- package/src/api-client/types/teams.ts +135 -0
- package/src/api-client/types/ticker-data.ts +57 -0
- package/src/api-client/types/tweets.ts +59 -0
- package/src/api-client/types/world-venues.ts +23 -0
- package/src/app/pane-runtime/index.tsx +2 -0
- package/src/app/pane-runtime/plugin-bindings.ts +10 -1
- package/src/app/runtime/desktop-deeplink.ts +41 -6
- package/src/app/star-prompt/status-line.tsx +1 -1
- package/src/app.tsx +64 -23
- package/src/architecture/ui-tokens-allowlist.json +0 -8
- package/src/cli/commands/market.ts +149 -10
- package/src/cli/commands/search.ts +21 -3
- package/src/cli/commands/ticker.ts +90 -36
- package/src/cli/desktop-pane-shot-browser.ts +69 -3
- package/src/cli/glossary.ts +3 -3
- package/src/cli/known-gaps.ts +8 -0
- package/src/cli/listing-arg.ts +12 -0
- package/src/cli/pane-functions/capabilities.ts +2 -0
- package/src/cli/pane-functions/catalog.ts +25 -5
- package/src/cli/pane-functions/function-help.ts +8 -5
- package/src/cli/pane-functions/headless.ts +4 -3
- package/src/cli/pane-functions/resolver.ts +75 -2
- package/src/cli/quote-answer.ts +9 -0
- package/src/cli/symbol-list.ts +54 -2
- package/src/cli/symbol-rows.ts +14 -2
- package/src/cli/ticker-resolution.ts +89 -20
- package/src/components/chart/composite/axis-overlays.tsx +60 -27
- package/src/components/chart/composite/composite-chart.tsx +118 -63
- package/src/components/chart/composite/cursor-source.ts +111 -0
- package/src/components/chart/composite/format.ts +168 -6
- package/src/components/chart/composite/legend.tsx +8 -4
- package/src/components/chart/composite/panel-labels.ts +20 -1
- package/src/components/chart/composite/panel-surface.tsx +201 -92
- package/src/components/chart/composite/price-axis-labels.tsx +92 -46
- package/src/components/chart/composite/price-series.ts +31 -8
- package/src/components/chart/composite/scene.ts +154 -59
- package/src/components/chart/composite/series-axis-tags.tsx +4 -2
- package/src/components/chart/composite/time-axis.ts +13 -5
- package/src/components/chart/composite/time-scale.ts +211 -56
- package/src/components/chart/composite/types.ts +11 -1
- package/src/components/chart/composite/use-composite-chart-keyboard.ts +43 -14
- package/src/components/chart/curve/curve-surface.tsx +5 -2
- package/src/components/chart/curve/model.ts +4 -1
- package/src/components/chart/native/use-bitmap-metrics.ts +81 -0
- package/src/components/chart/static/series.ts +3 -0
- package/src/components/command-bar/commands/collection-list.ts +81 -0
- package/src/components/command-bar/commands/direct/index.ts +6 -0
- package/src/components/command-bar/commands/registry.ts +8 -0
- package/src/components/command-bar/layout-items/current-layout.ts +22 -1
- package/src/components/command-bar/layout-items/focused-pane.ts +22 -1
- package/src/components/command-bar/pane-templates/items.ts +19 -3
- package/src/components/command-bar/pane-templates/workflow.ts +5 -0
- package/src/components/command-bar/routes/root/results.ts +23 -3
- package/src/components/command-bar/routes/root/selection.ts +4 -2
- package/src/components/command-bar/routes/root/shortcut-feedback.ts +1 -1
- package/src/components/command-bar/routes/root/shortcut-items.ts +3 -4
- package/src/components/command-bar/routes/root/shortcuts.ts +58 -14
- package/src/components/command-bar/routes/root/ticker-first.ts +32 -0
- package/src/components/command-bar/surface/environment.ts +2 -0
- package/src/components/command-bar/view-model.ts +7 -0
- package/src/components/command-bar/workflow/ops.ts +2 -1
- package/src/components/command-bar/workflow/tickers.ts +20 -0
- package/src/components/data-table/export.ts +4 -1
- package/src/components/layout/detached-pane-shell.tsx +10 -37
- package/src/components/layout/double-escape-close.ts +90 -0
- package/src/components/layout/header.tsx +3 -2
- package/src/components/layout/market-summary.ts +6 -3
- package/src/components/layout/pane/footer/index.tsx +2 -6
- package/src/components/layout/pane/footer/model.ts +6 -12
- package/src/components/layout/shell/active-drag.ts +53 -11
- package/src/components/layout/shell/drag/magnets.ts +128 -19
- package/src/components/layout/shell/menu.ts +15 -1
- package/src/components/layout/shell/pane/actions.ts +10 -2
- package/src/components/layout/shell/pane/management-shortcuts.ts +13 -51
- package/src/components/layout/shell/ticker-link-menu.ts +12 -3
- package/src/components/layout/status-bar.tsx +24 -78
- package/src/components/layout/status-widget-space.ts +5 -5
- package/src/components/onboarding/onboarding-keyboard.ts +5 -1
- package/src/components/onboarding/onboarding-wizard.tsx +15 -4
- package/src/components/onboarding/portfolio-step/positions-panel.tsx +9 -6
- package/src/components/onboarding/use-onboarding-progress.ts +20 -1
- package/src/components/price-sparkline/view.tsx +14 -6
- package/src/components/ticker/badge/index.tsx +8 -4
- package/src/components/ticker/badge/list.tsx +23 -7
- package/src/components/ui/column-grid.tsx +8 -2
- package/src/components/ui/data-table/index.tsx +5 -1
- package/src/components/ui/data-table/opentui/model.ts +4 -1
- package/src/components/ui/data-table/render-cell.ts +19 -0
- package/src/components/ui/delayed-mark.tsx +59 -7
- package/src/components/ui/icon.tsx +1 -8
- package/src/components/ui/menu.tsx +6 -1
- package/src/components/ui/tabs.tsx +5 -2
- package/src/core/state/app/layout.ts +18 -3
- package/src/core/state/app/state.ts +2 -0
- package/src/core/state/app/types.ts +5 -0
- package/src/data/config/layout.ts +3 -0
- package/src/data/config/store/normalize.ts +39 -4
- package/src/i18n/es.ts +13 -3
- package/src/i18n/ja.ts +13 -3
- package/src/i18n/ko.ts +13 -3
- package/src/i18n/zh-cn.ts +13 -3
- package/src/i18n/zh-tw.ts +13 -3
- package/src/layout/pane-manager/floating-placement.ts +7 -4
- package/src/layout/pane-manager/floating.ts +5 -2
- package/src/market-data/bond-funds.ts +19 -0
- package/src/market-data/futures-contract.ts +14 -3
- package/src/market-data/market/freshness.ts +18 -0
- package/src/market-data/market/status.ts +15 -2
- package/src/plugins/builtin/bond-calculator/headless.ts +2 -1
- package/src/plugins/builtin/bond-calculator/index.tsx +1 -1
- package/src/plugins/builtin/bond-calculator/model.ts +14 -5
- package/src/plugins/builtin/bond-calculator/pane.tsx +1 -1
- package/src/plugins/builtin/buildout/cells.tsx +25 -45
- package/src/plugins/builtin/buildout/detail/company.tsx +3 -3
- package/src/plugins/builtin/buildout/detail/index.tsx +1 -1
- package/src/plugins/builtin/buildout/detail/intel.tsx +4 -7
- package/src/plugins/builtin/buildout/detail/site.tsx +4 -4
- package/src/plugins/builtin/buildout/detail/ui.tsx +39 -38
- package/src/plugins/builtin/buildout/format.ts +23 -1
- package/src/plugins/builtin/buildout/model/types.ts +1 -0
- package/src/plugins/builtin/buildout/pane/index.tsx +2 -8
- package/src/plugins/builtin/buildout/table-model.ts +12 -4
- package/src/plugins/builtin/cds/headless.ts +1 -0
- package/src/plugins/builtin/cds/index.tsx +1 -1
- package/src/plugins/builtin/chat/content/composer.tsx +21 -27
- package/src/plugins/builtin/chat/content/index.tsx +31 -3
- package/src/plugins/builtin/chat/content/shortcuts.ts +4 -2
- package/src/plugins/builtin/chat/content/snapshot.ts +0 -3
- package/src/plugins/builtin/cloud/auth-actions.tsx +51 -23
- package/src/plugins/builtin/cloud/plugin.tsx +2 -0
- package/src/plugins/builtin/cloud/trial-offer-status-widget.tsx +3 -3
- package/src/plugins/builtin/cloud/upgrade-status-widget.tsx +44 -12
- package/src/plugins/builtin/congress-trades/model.ts +2 -1
- package/src/plugins/builtin/congress-trades/pane.tsx +3 -0
- package/src/plugins/builtin/correlation/headless.ts +3 -2
- package/src/plugins/builtin/crypto-board/pane.tsx +5 -4
- package/src/plugins/builtin/custom-view/index.tsx +1 -1
- package/src/plugins/builtin/custom-view/loader.ts +85 -8
- package/src/plugins/builtin/custom-view/view-spec.ts +28 -0
- package/src/plugins/builtin/debt-maturities/headless.ts +11 -2
- package/src/plugins/builtin/debt-maturities/model.ts +66 -0
- package/src/plugins/builtin/debt-maturities/pane.tsx +23 -4
- package/src/plugins/builtin/earnings-ripple/pane.tsx +1 -1
- package/src/plugins/builtin/econ/calendar-model.ts +28 -6
- package/src/plugins/builtin/equity-screener/client.ts +1 -1
- package/src/plugins/builtin/equity-screener/criterion-editor.tsx +16 -19
- package/src/plugins/builtin/equity-screener/headless.ts +37 -3
- package/src/plugins/builtin/equity-screener/ideas.ts +67 -3
- package/src/plugins/builtin/equity-screener/model.ts +238 -27
- package/src/plugins/builtin/equity-screener/pane.tsx +88 -18
- package/src/plugins/builtin/equity-screener/screen-check.ts +7 -4
- package/src/plugins/builtin/equity-screener/watchlist.ts +33 -0
- package/src/plugins/builtin/executives/format.ts +5 -4
- package/src/plugins/builtin/executives/pane.tsx +1 -1
- package/src/plugins/builtin/futures-curve/client.ts +19 -0
- package/src/plugins/builtin/futures-curve/headless.ts +52 -13
- package/src/plugins/builtin/futures-curve/index.tsx +1 -1
- package/src/plugins/builtin/futures-curve/model.ts +77 -6
- package/src/plugins/builtin/futures-curve/pane.tsx +19 -3
- package/src/plugins/builtin/help/index.tsx +55 -1
- package/src/plugins/builtin/insider/model.ts +30 -2
- package/src/plugins/builtin/jobs/model.ts +2 -2
- package/src/plugins/builtin/macro-day/client.ts +41 -0
- package/src/plugins/builtin/macro-day/headless.ts +19 -9
- package/src/plugins/builtin/macro-day/model.ts +3 -1
- package/src/plugins/builtin/market-movers/index.tsx +4 -3
- package/src/plugins/builtin/mna/distress/headless.ts +1 -0
- package/src/plugins/builtin/mna/model.ts +2 -2
- package/src/plugins/builtin/notes/files.ts +2 -0
- package/src/plugins/builtin/notes/owner.tsx +20 -1
- package/src/plugins/builtin/notes/quick-notes-pane.tsx +22 -4
- package/src/plugins/builtin/notes/store.ts +6 -1
- package/src/plugins/builtin/perps/pane.tsx +3 -1
- package/src/plugins/builtin/portfolio-list/cli/bulk-symbols.ts +17 -0
- package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +2 -1
- package/src/plugins/builtin/portfolio-list/cli/watchlist-command.ts +2 -1
- package/src/plugins/builtin/portfolio-list/header.tsx +1 -1
- package/src/plugins/builtin/rate-path/headless.ts +24 -10
- package/src/plugins/builtin/research/corporate-actions-pane.tsx +29 -25
- package/src/plugins/builtin/research/event-model.ts +10 -3
- package/src/plugins/builtin/research/events-headless.ts +20 -2
- package/src/plugins/builtin/sec/fund-facts.ts +17 -1
- package/src/plugins/builtin/sec/index.tsx +1 -1
- package/src/plugins/builtin/series-inventory.ts +1 -0
- package/src/plugins/builtin/shared/earnings-report.ts +7 -2
- package/src/plugins/builtin/shared/members-menu.tsx +103 -38
- package/src/plugins/builtin/shared/use-quote-board.ts +85 -46
- package/src/plugins/builtin/short-interest/headless.ts +1 -1
- package/src/plugins/builtin/short-interest/model.ts +15 -6
- package/src/plugins/builtin/short-interest/publications-model.ts +22 -1
- package/src/plugins/builtin/short-interest/publications-pane.tsx +13 -4
- package/src/plugins/builtin/short-interest/types.ts +2 -0
- package/src/plugins/builtin/short-interest/watch-model.ts +1 -1
- package/src/plugins/builtin/thirteenf/overlap-pane.tsx +3 -0
- package/src/plugins/builtin/thirteenf/pane.tsx +3 -0
- package/src/plugins/builtin/ticker-detail/overview/model.ts +5 -3
- package/src/plugins/builtin/ticker-detail/overview-tab.tsx +4 -4
- package/src/plugins/builtin/time-sales/pane.tsx +3 -2
- package/src/plugins/builtin/trace-bonds/client.ts +7 -4
- package/src/plugins/builtin/trace-bonds/detail.tsx +198 -0
- package/src/plugins/builtin/trace-bonds/headless.ts +62 -4
- package/src/plugins/builtin/trace-bonds/history.ts +155 -0
- package/src/plugins/builtin/trace-bonds/index.tsx +1 -1
- package/src/plugins/builtin/trace-bonds/pane.tsx +64 -5
- package/src/plugins/builtin/volatility/client.ts +6 -1
- package/src/plugins/builtin/volatility/headless.ts +0 -1
- package/src/plugins/builtin/yield-curve/curves.ts +15 -0
- package/src/plugins/builtin/yield-curve/headless.ts +6 -1
- package/src/plugins/builtin/yield-curve/index.tsx +5 -8
- package/src/plugins/host-modules.ts +22 -3
- package/src/plugins/host-smoke.ts +6 -3
- package/src/plugins/installer.ts +16 -3
- package/src/plugins/plugin-names.ts +11 -2
- package/src/portfolio/collection-name.ts +19 -0
- package/src/remote/controller.ts +9 -2
- package/src/remote/schema.ts +2 -1
- package/src/renderers/browser/http-proxy-transport.ts +78 -8
- package/src/renderers/cloudflare/http-proxy.ts +73 -3
- package/src/renderers/cloudflare/proxy-session.ts +47 -24
- package/src/renderers/cloudflare/worker.ts +44 -4
- package/src/renderers/desktop/geometry.ts +279 -0
- package/src/renderers/desktop/screen-setup.ts +246 -0
- package/src/renderers/desktop/sequential-window-host.ts +179 -0
- package/src/renderers/desktop/test-utils.ts +71 -0
- package/src/renderers/desktop/window-controller.ts +433 -0
- package/src/renderers/desktop/window-host.ts +70 -0
- package/src/renderers/desktop/window-layouts.ts +630 -0
- package/src/renderers/dom/data-frames.ts +15 -4
- package/src/renderers/dom/desktop/icons.tsx +0 -2
- package/src/renderers/dom/styles.css +0 -3
- package/src/renderers/electrobun/bun/application-menu/click.ts +1 -0
- package/src/renderers/electrobun/bun/application-menu/index.ts +4 -1
- package/src/renderers/electrobun/bun/desktop/backend-requests.ts +19 -8
- package/src/renderers/electrobun/bun/desktop/backend.ts +320 -19
- package/src/renderers/electrobun/bun/desktop/detached-windows.ts +83 -61
- package/src/renderers/electrobun/bun/desktop/host-requests.ts +4 -14
- package/src/renderers/electrobun/bun/desktop/initialization.ts +30 -11
- package/src/renderers/electrobun/bun/desktop/install-records.ts +59 -0
- package/src/renderers/electrobun/bun/desktop/installer-folder.ts +208 -592
- package/src/renderers/electrobun/bun/desktop/macos-objc.ts +14 -0
- package/src/renderers/electrobun/bun/desktop/screen-setup-file.ts +55 -0
- package/src/renderers/electrobun/bun/desktop/state-broadcaster.ts +44 -8
- package/src/renderers/electrobun/bun/desktop/update.ts +1 -1
- package/src/renderers/electrobun/bun/desktop/workspace/index.ts +298 -97
- package/src/renderers/electrobun/bun/desktop/workspace/requests.ts +44 -6
- package/src/renderers/electrobun/bun/index.ts +22 -109
- package/src/renderers/electrobun/bun/window/create.ts +23 -3
- package/src/renderers/electrobun/bun/window/electrobun-window-host.ts +306 -0
- package/src/renderers/electrobun/bun/window/events.ts +4 -4
- package/src/renderers/electrobun/bun/window/focus.ts +0 -25
- package/src/renderers/electrobun/bun/window/frame.ts +2 -1
- package/src/renderers/electrobun/bun/window/native-min-size.ts +322 -0
- package/src/renderers/electrobun/bun/window/remembered-frame.ts +4 -82
- package/src/renderers/electrobun/shared/protocol.ts +44 -2
- package/src/renderers/electrobun/view/backend-rpc.ts +16 -1
- package/src/renderers/electrobun/view/desktop/window/bridge.ts +63 -3
- package/src/renderers/electrobun/view/main.tsx +13 -7
- package/src/series/fred-argument.ts +17 -0
- package/src/sources/gloomberb-cloud/index.ts +5 -7
- package/src/sources/provider-router/batches.ts +18 -3
- package/src/sources/provider-router/financial-routes.ts +7 -1
- package/src/sources/provider-router/financials.ts +18 -4
- package/src/state/app/context/index.tsx +16 -2
- package/src/state/desktop-windows.ts +63 -0
- package/src/sync/other-window-tabs.ts +62 -0
- package/src/tickers/company-name-listing.ts +23 -3
- package/src/tickers/listing-fate.ts +147 -1
- package/src/tickers/terminal-codes.ts +5 -0
- package/src/time-series/types.ts +6 -0
- package/src/types/config.ts +10 -1
- package/src/types/data-provider.ts +14 -0
- package/src/types/desktop-window.ts +71 -2
- package/src/types/financials.ts +19 -3
- package/src/types/headless.ts +21 -0
- package/src/types/plugin.ts +6 -0
- package/src/ui/index.tsx +14 -13
- package/src/ui/same-props.ts +58 -0
- package/src/utils/cli-output.ts +33 -4
- package/src/utils/double-escape-close.ts +38 -16
- package/src/utils/format.ts +30 -5
- package/src/utils/futures-generic.ts +12 -0
- package/src/utils/http-proxy-upstream.ts +6 -2
- package/src/utils/plugin-proxy-hosts.json +0 -4
- package/src/utils/plugin-proxy-hosts.ts +22 -0
- package/src/utils/price-earnings.ts +18 -0
- package/src/utils/sec-filings.ts +7 -1
- package/patches/electrobun@1.18.1.patch +0 -633
- package/src/api-client/types.ts +0 -2441
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
import {
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
487
|
-
const
|
|
488
|
-
?
|
|
489
|
-
|
|
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.
|
|
510
|
-
//
|
|
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
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
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
|
-
|
|
533
|
-
|
|
534
|
-
|
|
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)
|
|
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
|
-
|
|
576
|
-
const
|
|
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 = !
|
|
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 (!
|
|
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 =
|
|
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
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
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
|
-
<
|
|
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
|
-
|
|
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
|
-
{
|
|
1137
|
+
{baseScene.panels.map((panel, index) => (
|
|
1126
1138
|
<CompositePanelSurface
|
|
1127
1139
|
key={panel.id}
|
|
1128
1140
|
panel={panel}
|
|
1129
|
-
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
|
-
<
|
|
1233
|
+
<CursorTimeAxis
|
|
1234
|
+
cursor={cursorSource}
|
|
1235
|
+
formatCursor={xAxis?.formatCursor}
|
|
1236
|
+
intradayBars={intradayBars}
|
|
1237
|
+
cellWidthPx={cellWidthPx}
|
|
1221
1238
|
labels={xAxis?.ticks ? [] : xAxis?.labels ? [...xAxis.labels] : [timeAxisLayout.text]}
|
|
1222
1239
|
positionedLabels={xAxis?.ticks ?? (xAxis?.labels ? undefined : timeAxisLayout.ticks)}
|
|
1223
1240
|
width={plotWidth}
|
|
1224
1241
|
color={resolvedColors.textDim}
|
|
1225
|
-
cursorColumn={timeAxisCursorColumn}
|
|
1226
|
-
cursorPixelX={timeAxisCursorPixelX}
|
|
1227
|
-
cursorLabel={timeAxisCursorLabel}
|
|
1228
1242
|
cursorColor={resolvedColors.crosshair}
|
|
1229
1243
|
cursorBackgroundColor={resolvedColors.background}
|
|
1230
1244
|
extraMarkers={timeAxisMarkers}
|
|
@@ -1246,3 +1260,44 @@ function ThemedCompositeChart({
|
|
|
1246
1260
|
</Box>
|
|
1247
1261
|
);
|
|
1248
1262
|
}
|
|
1263
|
+
|
|
1264
|
+
/** The legend, rendering with the crosshair: its values are the series' at the cursor. */
|
|
1265
|
+
function CursorLegend({ cursor, ...props }: Omit<ComponentProps<typeof CompositeLegend>, "scene"> & {
|
|
1266
|
+
cursor: CompositeCursorSource;
|
|
1267
|
+
}) {
|
|
1268
|
+
return <CompositeLegend {...props} scene={useCursorScene(cursor)} />;
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
/** The time axis, rendering with the crosshair: its label sits at the cursor, and the ticks under it step aside. */
|
|
1272
|
+
function CursorTimeAxis({
|
|
1273
|
+
cursor,
|
|
1274
|
+
formatCursor,
|
|
1275
|
+
intradayBars,
|
|
1276
|
+
cellWidthPx,
|
|
1277
|
+
width,
|
|
1278
|
+
...props
|
|
1279
|
+
}: Omit<ComponentProps<typeof StaticXAxisLabels>, "cursorColumn" | "cursorPixelX" | "cursorLabel"> & {
|
|
1280
|
+
cursor: CompositeCursorSource;
|
|
1281
|
+
formatCursor?: (ratio: number) => string;
|
|
1282
|
+
intradayBars: boolean;
|
|
1283
|
+
cellWidthPx: number;
|
|
1284
|
+
}) {
|
|
1285
|
+
const scene = useCursorScene(cursor);
|
|
1286
|
+
const cursorColumn = scene.cursorXRatio === null
|
|
1287
|
+
? null
|
|
1288
|
+
: scene.cursorXRatio * Math.max(width - 1, 0);
|
|
1289
|
+
const cursorLabel = formatCursor && scene.cursorXRatio !== null
|
|
1290
|
+
? formatCursor(scene.cursorXRatio)
|
|
1291
|
+
: scene.cursorDate
|
|
1292
|
+
? formatCompositeCursorAxisDate(scene.cursorDate, scene.startTime, scene.endTime, scene.timeZone, intradayBars)
|
|
1293
|
+
: null;
|
|
1294
|
+
return (
|
|
1295
|
+
<StaticXAxisLabels
|
|
1296
|
+
{...props}
|
|
1297
|
+
width={width}
|
|
1298
|
+
cursorColumn={cursorColumn}
|
|
1299
|
+
cursorPixelX={cursorColumn === null ? null : cursorColumn * cellWidthPx}
|
|
1300
|
+
cursorLabel={cursorLabel}
|
|
1301
|
+
/>
|
|
1302
|
+
);
|
|
1303
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { useSyncExternalStore } from "react";
|
|
2
|
+
import { applyCompositeChartCursor, compositeLinkedCursorTime } from "./scene";
|
|
3
|
+
import type { CompositeChartScene } from "./types";
|
|
4
|
+
|
|
5
|
+
type Listener = () => void;
|
|
6
|
+
|
|
7
|
+
/** A value that changes without rendering what holds it: only its readers render. */
|
|
8
|
+
export interface ValueStore<T> {
|
|
9
|
+
get(): T;
|
|
10
|
+
set(value: T): void;
|
|
11
|
+
subscribe(listener: Listener): () => void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function createValueStore<T>(initial: T): ValueStore<T> {
|
|
15
|
+
let value = initial;
|
|
16
|
+
const listeners = new Set<Listener>();
|
|
17
|
+
return {
|
|
18
|
+
get: () => value,
|
|
19
|
+
set(next) {
|
|
20
|
+
if (Object.is(next, value)) return;
|
|
21
|
+
value = next;
|
|
22
|
+
for (const listener of [...listeners]) listener();
|
|
23
|
+
},
|
|
24
|
+
subscribe(listener) {
|
|
25
|
+
listeners.add(listener);
|
|
26
|
+
return () => {
|
|
27
|
+
listeners.delete(listener);
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The cursor charts in one tab share: the time another chart's crosshair is at. */
|
|
34
|
+
interface SharedCursorTime {
|
|
35
|
+
subscribe(listener: Listener): () => void;
|
|
36
|
+
time(): number | null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The chart's scene with its crosshair applied, for the parts that draw the
|
|
41
|
+
* crosshair: the legend's values, the value and time axes' cursor labels and
|
|
42
|
+
* the plot's crosshair. A pointer move renders those alone; the chart, its
|
|
43
|
+
* series and its axes stay as they are.
|
|
44
|
+
*/
|
|
45
|
+
export interface CompositeCursorSource {
|
|
46
|
+
/** The scene with the cursor, the same object until the cursor moves to another bar. */
|
|
47
|
+
scene(): CompositeChartScene;
|
|
48
|
+
subscribe(listener: Listener): () => void;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface CompositeCursorSourceOptions {
|
|
52
|
+
/** The scene the cursor is applied to, which has none of its own. */
|
|
53
|
+
baseScene: CompositeChartScene;
|
|
54
|
+
/** The chart's own cursor, in epoch ms, which the pointer and the keys move. Null when the owner holds it. */
|
|
55
|
+
own: ValueStore<number | null> | null;
|
|
56
|
+
/** The owner's cursor, in epoch ms: the one shown while the chart has none of its own. */
|
|
57
|
+
fallback: number | null;
|
|
58
|
+
/** Another chart's cursor, which shows in place of this one's while it is set. */
|
|
59
|
+
link?: SharedCursorTime;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function createCompositeCursorSource({
|
|
63
|
+
baseScene,
|
|
64
|
+
own,
|
|
65
|
+
fallback,
|
|
66
|
+
link,
|
|
67
|
+
}: CompositeCursorSourceOptions): CompositeCursorSource {
|
|
68
|
+
let cachedKey: string | null = null;
|
|
69
|
+
let cached = baseScene;
|
|
70
|
+
const scene = () => {
|
|
71
|
+
const sharedTime = link?.time() ?? null;
|
|
72
|
+
let key: string;
|
|
73
|
+
let next: () => CompositeChartScene;
|
|
74
|
+
if (sharedTime !== null) {
|
|
75
|
+
// A chart renders again when the bar the shared cursor lands on here
|
|
76
|
+
// changes, not on every move: a daily chart under a 30-minute one's
|
|
77
|
+
// cursor moves once a session.
|
|
78
|
+
const bar = compositeLinkedCursorTime(baseScene, sharedTime);
|
|
79
|
+
key = `linked:${bar}`;
|
|
80
|
+
next = () => applyCompositeChartCursor(baseScene, bar === null ? null : new Date(bar), "linked");
|
|
81
|
+
} else {
|
|
82
|
+
const time = own?.get() ?? fallback;
|
|
83
|
+
key = `own:${time}`;
|
|
84
|
+
next = () => applyCompositeChartCursor(baseScene, time === null ? null : new Date(time));
|
|
85
|
+
}
|
|
86
|
+
if (key !== cachedKey) {
|
|
87
|
+
cachedKey = key;
|
|
88
|
+
cached = next();
|
|
89
|
+
}
|
|
90
|
+
return cached;
|
|
91
|
+
};
|
|
92
|
+
const subscribe = (listener: Listener) => {
|
|
93
|
+
const stopOwn = own?.subscribe(listener);
|
|
94
|
+
const stopLink = link?.subscribe(listener);
|
|
95
|
+
return () => {
|
|
96
|
+
stopOwn?.();
|
|
97
|
+
stopLink?.();
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
return { scene, subscribe };
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** The scene with the cursor, rendering again when the cursor moves to another bar. */
|
|
104
|
+
export function useCursorScene(source: CompositeCursorSource): CompositeChartScene {
|
|
105
|
+
return useSyncExternalStore(source.subscribe, source.scene, source.scene);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** A store's value, rendering again when it changes. */
|
|
109
|
+
export function useValueStore<T>(store: ValueStore<T>): T {
|
|
110
|
+
return useSyncExternalStore(store.subscribe, store.get, store.get);
|
|
111
|
+
}
|
|
@@ -191,13 +191,27 @@ function ticksFitRows(domain: CompositeAxisDomain, values: number[]): boolean {
|
|
|
191
191
|
return true;
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
+
// Every label on an axis reads its ticks again (see `compactAxisNumber`).
|
|
195
|
+
const tickValues = new WeakMap<CompositeAxisDomain, readonly number[]>();
|
|
196
|
+
|
|
194
197
|
/** Round values inside a linear domain, so every gridline carries a readable
|
|
195
198
|
* value. A log axis, or a short terminal panel no round step fits, keeps its
|
|
196
199
|
* top, middle and bottom values. */
|
|
197
|
-
function axisTickValues(domain: CompositeAxisDomain): number[] {
|
|
200
|
+
function axisTickValues(domain: CompositeAxisDomain): readonly number[] {
|
|
201
|
+
let values = tickValues.get(domain);
|
|
202
|
+
if (!values) {
|
|
203
|
+
values = computeAxisTickValues(domain);
|
|
204
|
+
tickValues.set(domain, values);
|
|
205
|
+
}
|
|
206
|
+
return values;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function computeAxisTickValues(domain: CompositeAxisDomain): number[] {
|
|
198
210
|
const span = domain.max - domain.min;
|
|
199
211
|
if (domain.scale === "log" || !Number.isFinite(span) || span <= 0) return edgeTickValues(domain);
|
|
200
212
|
const maxTicks = Math.max(2, domain.maxTicks ?? DEFAULT_AXIS_MAX_TICKS);
|
|
213
|
+
const grid = axisTickGrid(domain);
|
|
214
|
+
if (grid) return gridAxisTickValues(domain, grid, span, maxTicks);
|
|
201
215
|
// Walk the 1-2-5 ladder around the target spacing and keep the step whose
|
|
202
216
|
// tick count lands nearest the target, one extra tick allowed.
|
|
203
217
|
let step = adjacentNiceStep(adjacentNiceStep(niceCeilStep(span / (maxTicks - 1)), -1), -1);
|
|
@@ -216,6 +230,66 @@ function axisTickValues(domain: CompositeAxisDomain): number[] {
|
|
|
216
230
|
return best.length >= Math.max(2, edges.length) ? best : edges;
|
|
217
231
|
}
|
|
218
232
|
|
|
233
|
+
// Half a 32nd: the finest step a 32nds axis ticks on when its series name no grid of their own.
|
|
234
|
+
const HALF_THIRTY_SECOND = 1 / 64;
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* The grid a linear axis's ticks fall on: its series' own (a Treasury
|
|
238
|
+
* future's fraction of a 32nd), else half a 32nd on an axis quoted in 32nds.
|
|
239
|
+
* None on a decimal axis.
|
|
240
|
+
*/
|
|
241
|
+
function axisTickGrid(domain: CompositeAxisDomain): number | undefined {
|
|
242
|
+
if (domain.scale === "log") return undefined;
|
|
243
|
+
const grid = domain.tickGrid ?? (domain.unit.trim() === "32nds" ? HALF_THIRTY_SECOND : undefined);
|
|
244
|
+
return grid !== undefined && Number.isFinite(grid) && grid > 0 ? grid : undefined;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// Steps a 32nds axis takes, in 32nds, between its finest grid and a whole point.
|
|
248
|
+
const THIRTY_SECONDS_STEPS = [1, 2, 3, 4, 6, 8, 12, 16];
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Steps on a fractional grid, as a Treasury price reads: the grid doubled up
|
|
252
|
+
* to a 32nd, then 1, 2, 3, 4, 6, 8, 12 and 16 32nds, then whole points on the
|
|
253
|
+
* 1-2-5 ladder. Each is a multiple of the grid and no wider than the axis.
|
|
254
|
+
*/
|
|
255
|
+
function gridSteps(grid: number, span: number): number[] {
|
|
256
|
+
const steps: number[] = [];
|
|
257
|
+
for (let step = grid; step < 1 / 32 - 1e-12; step *= 2) steps.push(step);
|
|
258
|
+
steps.push(...THIRTY_SECONDS_STEPS.map((count) => count / 32));
|
|
259
|
+
for (let step = 1; step <= span * (1 + 1e-9); step = adjacentNiceStep(step, 1)) steps.push(step);
|
|
260
|
+
return steps.filter((step) => step >= grid * (1 - 1e-9) && step <= span * (1 + 1e-9)
|
|
261
|
+
&& Math.abs(step / grid - Math.round(step / grid)) < 1e-9);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Ticks on a fractional grid (`gridSteps`), keeping the step whose count
|
|
266
|
+
* lands nearest the target, as the decimal ladder does. Where no step gives
|
|
267
|
+
* as many as the top, middle and bottom, those are kept instead, each moved
|
|
268
|
+
* onto the grid: no label reads 104-25.60.
|
|
269
|
+
*/
|
|
270
|
+
function gridAxisTickValues(domain: CompositeAxisDomain, grid: number, span: number, maxTicks: number): number[] {
|
|
271
|
+
let best: number[] = [];
|
|
272
|
+
for (const step of gridSteps(grid, span)) {
|
|
273
|
+
const values = stepMultiples(domain.min, domain.max, step);
|
|
274
|
+
if (values.length >= 2 && values.length <= maxTicks + 1
|
|
275
|
+
&& (best.length === 0 || Math.abs(values.length - maxTicks) < Math.abs(best.length - maxTicks))
|
|
276
|
+
&& ticksFitRows(domain, values)) {
|
|
277
|
+
best = values;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
const edges = edgeTickValues(domain);
|
|
281
|
+
if (best.length >= Math.max(2, edges.length)) return best;
|
|
282
|
+
const onGrid = edges.map((value, index) => {
|
|
283
|
+
// The top rounds down and the bottom up, so neither leaves the axis.
|
|
284
|
+
const units = value / grid;
|
|
285
|
+
const whole = index === 0 ? Math.floor(units + 1e-9) : index === edges.length - 1 ? Math.ceil(units - 1e-9) : Math.round(units);
|
|
286
|
+
return Number((whole * grid).toPrecision(12));
|
|
287
|
+
}).filter((value) => value >= domain.min - grid * 1e-9 && value <= domain.max + grid * 1e-9);
|
|
288
|
+
const snapped = [...new Set(onGrid)];
|
|
289
|
+
return snapped.length >= best.length && snapped.length > 0 ? snapped
|
|
290
|
+
: best.length > 0 ? best : [Number((Math.round((domain.min + domain.max) / 2 / grid) * grid).toPrecision(12))];
|
|
291
|
+
}
|
|
292
|
+
|
|
219
293
|
/** The narrowest distance between neighbouring ticks. A log axis bunches its
|
|
220
294
|
* lowest ticks together, so the tightest pair is what every label has to stay
|
|
221
295
|
* legible against. */
|
|
@@ -397,6 +471,12 @@ export function formatCompositeCursorValue(value: number, domain: CompositeAxisD
|
|
|
397
471
|
return formatCompositeAxisValue(value, domain);
|
|
398
472
|
}
|
|
399
473
|
|
|
474
|
+
/**
|
|
475
|
+
* An axis label for a value. It must read only the value and the axis: the
|
|
476
|
+
* ticks and gutter widths it labels are kept per formatter and axis (see
|
|
477
|
+
* `axisResultCache`), so one that reads anything else (a currency, a setting)
|
|
478
|
+
* is a new function whenever that changes.
|
|
479
|
+
*/
|
|
400
480
|
export type CompositeAxisValueFormatter = (value: number, domain: CompositeAxisDomain) => string;
|
|
401
481
|
|
|
402
482
|
type LabeledTick = { value: number; label: string };
|
|
@@ -409,10 +489,11 @@ function repeatsLabel(ticks: LabeledTick[]): boolean {
|
|
|
409
489
|
* (2k 2k 1.9k). The axis then climbs the 1-2-5 ladder until its labels
|
|
410
490
|
* differ, and failing that keeps its top and bottom, or the top alone. */
|
|
411
491
|
function distinctAxisTicks(domain: CompositeAxisDomain, format: CompositeAxisValueFormatter): LabeledTick[] {
|
|
412
|
-
const label = (values: number[]) => values.map((value) => ({ value, label: format(value, domain) }));
|
|
492
|
+
const label = (values: readonly number[]) => values.map((value) => ({ value, label: format(value, domain) }));
|
|
413
493
|
const ticks = label(axisTickValues(domain));
|
|
414
494
|
if (ticks.length < 2 || !repeatsLabel(ticks)) return ticks;
|
|
415
|
-
|
|
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
|
-
):
|
|
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
|