gloomberb 0.20.13 → 0.20.16
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/package.json +2 -1
- package/patches/@opentui%2Fcore@0.3.2.patch +22 -4
- package/src/account/auth-dialog.tsx +22 -4
- package/src/account/auth-form.tsx +6 -1
- package/src/account/checkout-handoff.tsx +7 -14
- package/src/account/device-signin-dialog.tsx +35 -24
- package/src/api-client/crypto-markets.ts +10 -0
- package/src/api-client/errors.ts +3 -1
- package/src/api-client/index.ts +54 -0
- package/src/api-client/install-experiments.ts +8 -7
- package/src/api-client/money-markets.ts +7 -0
- package/src/api-client/paths.ts +2 -1
- package/src/api-client/product-waitlist.ts +63 -0
- package/src/api-client/request.ts +16 -4
- package/src/api-client/types/billing.ts +45 -0
- package/src/api-client/yearly-plan.ts +132 -0
- package/src/app/global-shortcuts.ts +5 -3
- package/src/app/pane-runtime/index.tsx +2 -2
- package/src/app/pane-runtime/plugin-bindings.ts +3 -1
- package/src/app/pane-runtime/ticker-open-runtime.ts +6 -1
- package/src/app/since-last-visit/keys.ts +26 -0
- package/src/app/since-last-visit/model.ts +266 -0
- package/src/app/since-last-visit/strip.tsx +193 -0
- package/src/app/since-last-visit/use-since-last-visit.ts +289 -0
- package/src/app/since-last-visit/visit-tracker.ts +191 -0
- package/src/app.tsx +15 -0
- package/src/architecture/floating-promise-allowlist.json +0 -1
- package/src/brokers/signed-in/sign-in-dialog.tsx +38 -38
- package/src/cli/commands/market.ts +103 -27
- package/src/cli/commands/overview.ts +18 -4
- package/src/cli/commands/system.ts +29 -1
- package/src/cli/commands/ticker.ts +12 -5
- package/src/cli/desktop-pane-shot-api-policy.ts +4 -1
- package/src/cli/desktop-pane-shot-browser.ts +2 -1
- package/src/cli/desktop-pane-shot-view.ts +3 -7
- package/src/cli/desktop-pane-shot.ts +26 -28
- package/src/cli/errors.ts +3 -1
- package/src/cli/freshness.ts +7 -2
- package/src/cli/glossary.ts +10 -5
- package/src/cli/help.ts +1 -0
- package/src/cli/helpers.ts +8 -16
- package/src/cli/history-export.ts +4 -0
- package/src/cli/history-rows.ts +24 -0
- package/src/cli/index.ts +4 -0
- package/src/cli/known-gaps.ts +2 -2
- package/src/cli/listing-arg.ts +79 -11
- package/src/cli/not-a-ticker.ts +4 -0
- package/src/cli/options.ts +29 -1
- package/src/cli/pane-functions/catalog.ts +70 -12
- package/src/cli/pane-functions/function-help.ts +1 -1
- package/src/cli/pane-functions/headless.ts +68 -3
- package/src/cli/pane-functions/index.ts +2 -2
- package/src/cli/pane-functions/options.ts +7 -0
- package/src/cli/pane-functions/resolver.ts +104 -15
- package/src/cli/pane-functions/screenshot-payload.ts +3 -0
- package/src/cli/report-tables.ts +20 -5
- package/src/cli/result.ts +22 -4
- package/src/cli/shot-temp-dir.ts +30 -0
- package/src/cli/suffixed-listing-rows.ts +11 -0
- package/src/cli/symbol-args.ts +5 -3
- package/src/cli/symbol-list.ts +23 -10
- package/src/cli/symbol-rows.ts +135 -3
- package/src/cli/treasury-yields.ts +15 -1
- package/src/components/chart/composite/composite-chart.tsx +3 -3
- package/src/components/chart/composite/format.ts +2 -1
- package/src/components/chart/composite/panel-surface/axis-markers.ts +133 -0
- package/src/components/chart/composite/panel-surface/level-labels.tsx +78 -0
- package/src/components/chart/composite/panel-surface/overlays.ts +108 -0
- package/src/components/chart/composite/panel-surface/pan-coast.ts +54 -0
- package/src/components/chart/composite/panel-surface/panel-cursor.tsx +138 -0
- package/src/components/chart/composite/panel-surface/panel-levels.ts +47 -0
- package/src/components/chart/composite/panel-surface/plot-gestures.ts +403 -0
- package/src/components/chart/composite/panel-surface/plot-pointer.ts +65 -0
- package/src/components/chart/composite/panel-surface/plot-wheel.ts +102 -0
- package/src/components/chart/composite/panel-surface/pointer.ts +12 -0
- package/src/components/chart/composite/panel-surface/props.ts +79 -0
- package/src/components/chart/composite/panel-surface/tool-readout.ts +151 -0
- package/src/components/chart/composite/panel-surface/value-axis-gestures.ts +152 -0
- package/src/components/chart/composite/panel-surface.tsx +81 -1177
- package/src/components/command-bar/commands/collection-list.ts +1 -0
- package/src/components/command-bar/commands/direct/index.ts +31 -8
- package/src/components/command-bar/commands/registry.ts +7 -0
- package/src/components/command-bar/routes/root/command-items.ts +8 -0
- package/src/components/command-bar/routes/root/results.ts +19 -2
- package/src/components/command-bar/routes/root/runtime.ts +3 -2
- package/src/components/command-bar/routes/root/selection.ts +3 -2
- package/src/components/command-bar/routes/root/shortcuts.ts +15 -0
- package/src/components/company-logo.tsx +10 -3
- package/src/components/data-table/sections.ts +6 -1
- package/src/components/layout/pane/title.ts +16 -6
- package/src/components/layout/shell/index.tsx +5 -1
- package/src/components/layout/shell/ticker-link-menu.ts +12 -9
- package/src/components/pane-settings-dialog/tui.tsx +6 -3
- package/src/components/pane-settings-dialog.tsx +2 -1
- package/src/components/pane-template-wizard.tsx +2 -0
- package/src/components/ticker/badge/format.ts +12 -3
- package/src/components/ticker/badge/index.tsx +9 -3
- package/src/components/ticker/list-table-view.tsx +119 -17
- package/src/components/ui/choice-dialog.tsx +1 -1
- package/src/components/ui/confirm-dialog.tsx +3 -2
- package/src/components/ui/data-table/display-columns.ts +16 -0
- package/src/components/ui/data-table/index.tsx +40 -9
- package/src/components/ui/data-table/types.ts +14 -0
- package/src/components/ui/frame.tsx +7 -3
- package/src/components/ui/icon.tsx +4 -2
- package/src/components/ui/list-view.tsx +8 -0
- package/src/components/ui/number-prompt-dialog.tsx +2 -1
- package/src/components/use-pane-notice-footer.tsx +3 -1
- package/src/core/state/app/layout-reducer.ts +3 -1
- package/src/core/state/app/layout.ts +2 -2
- package/src/data/config/layout.ts +14 -0
- package/src/data/config/store/normalize.ts +11 -1
- package/src/docs/snapshot.json +2 -2
- package/src/i18n/es.ts +39 -0
- package/src/i18n/ja.ts +39 -0
- package/src/i18n/ko.ts +39 -0
- package/src/i18n/zh-cn.ts +39 -0
- package/src/i18n/zh-tw.ts +39 -0
- package/src/layout/pane-follow.ts +141 -4
- package/src/layout/pane-layout-move.ts +10 -7
- package/src/layout/ticker-navigation.ts +13 -19
- package/src/layout/ticker-retarget.ts +3 -2
- package/src/market-data/market/format.ts +35 -1
- package/src/market-data/market/index-level.ts +19 -0
- package/src/market-data/quotes/contributions.ts +13 -0
- package/src/market-data/quotes/export-identity.ts +36 -1
- package/src/market-data/quotes/resolution.ts +16 -0
- package/src/plugins/builtin/account-management/keyboard.ts +14 -0
- package/src/plugins/builtin/account-management/model.ts +2 -0
- package/src/plugins/builtin/account-management/pane.tsx +79 -7
- package/src/plugins/builtin/account-management/password-dialog.tsx +2 -2
- package/src/plugins/builtin/account-management/payment-recovery-row.tsx +97 -0
- package/src/plugins/builtin/account-management/yearly-plan-row.tsx +359 -0
- package/src/plugins/builtin/analytics/risk-client.ts +12 -2
- package/src/plugins/builtin/analytics/risk-headless.ts +66 -6
- package/src/plugins/builtin/analytics/risk-math.ts +23 -6
- package/src/plugins/builtin/analytics/risk-model.ts +20 -9
- package/src/plugins/builtin/analytics/risk-pane.tsx +2 -2
- package/src/plugins/builtin/awards/pane.tsx +6 -8
- package/src/plugins/builtin/changelog/index.tsx +6 -44
- package/src/plugins/builtin/changelog/versions.ts +17 -68
- package/src/plugins/builtin/chart-composer/catalog-inventory.ts +5 -2
- package/src/plugins/builtin/chart-composer/editor.tsx +1 -0
- package/src/plugins/builtin/chart-composer/pane.tsx +1 -1
- package/src/plugins/builtin/chart-composer/quick-add.tsx +4 -1
- package/src/plugins/builtin/chart-composer/series-catalog.ts +17 -1
- package/src/plugins/builtin/cloud/askg/executor.ts +2 -1
- package/src/plugins/builtin/cloud/askg/sources.ts +2 -1
- package/src/plugins/builtin/cloud/plugin.tsx +2 -0
- package/src/plugins/builtin/cloud/thesis/module.tsx +2 -0
- package/src/plugins/builtin/cloud/upgrade-status-widget.tsx +6 -2
- package/src/plugins/builtin/cpi/headless.ts +6 -1
- package/src/plugins/builtin/cpi/model.ts +17 -0
- package/src/plugins/builtin/cpi/pane.tsx +4 -2
- package/src/plugins/builtin/crypto-board/client.ts +6 -1
- package/src/plugins/builtin/crypto-board/headless.ts +10 -2
- package/src/plugins/builtin/crypto-board/model.ts +89 -11
- package/src/plugins/builtin/crypto-board/pane.tsx +20 -5
- package/src/plugins/builtin/debt-maturities/model.ts +1 -1
- package/src/plugins/builtin/dividend-yield/client.ts +24 -2
- package/src/plugins/builtin/dividend-yield/headless.ts +4 -2
- package/src/plugins/builtin/dividend-yield/ranking.ts +2 -1
- package/src/plugins/builtin/dividend-yield/view.ts +5 -1
- package/src/plugins/builtin/earnings/board-table.ts +1 -1
- package/src/plugins/builtin/earnings/board.tsx +36 -16
- package/src/plugins/builtin/earnings/highlight.ts +47 -0
- package/src/plugins/builtin/earnings/history-table.ts +9 -1
- package/src/plugins/builtin/earnings/index.tsx +1 -1
- package/src/plugins/builtin/earnings-calls/pane.tsx +2 -2
- package/src/plugins/builtin/earnings-ripple/index.tsx +2 -0
- package/src/plugins/builtin/econ/calendar-model.ts +17 -1
- package/src/plugins/builtin/econ/fred-catalog.ts +33 -4
- package/src/plugins/builtin/econ-statistics/headless.ts +21 -0
- package/src/plugins/builtin/estimate-revisions/model.ts +1 -1
- package/src/plugins/builtin/exposure/index.tsx +1 -1
- package/src/plugins/builtin/macro-day/headless.ts +21 -10
- package/src/plugins/builtin/macro-day/model.ts +42 -3
- package/src/plugins/builtin/macro-day/pane.tsx +26 -8
- package/src/plugins/builtin/macro-day/releases.ts +24 -1
- package/src/plugins/builtin/market-valuation/detail.tsx +3 -3
- package/src/plugins/builtin/market-valuation/headless.ts +11 -4
- package/src/plugins/builtin/market-valuation/pane.tsx +3 -1
- package/src/plugins/builtin/market-valuation/view.ts +14 -0
- package/src/plugins/builtin/money-markets/client.ts +4 -1
- package/src/plugins/builtin/money-markets/headless.ts +15 -4
- package/src/plugins/builtin/money-markets/index.tsx +1 -1
- package/src/plugins/builtin/money-markets/pane.tsx +7 -1
- package/src/plugins/builtin/news/wire/news/detail-view.tsx +20 -8
- package/src/plugins/builtin/pe-band/pane.tsx +1 -1
- package/src/plugins/builtin/portfolio-list/cli/bulk-symbols.ts +4 -2
- package/src/plugins/builtin/portfolio-list/cli/period-report.ts +61 -11
- package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +11 -3
- package/src/plugins/builtin/portfolio-list/cli/render.ts +8 -1
- package/src/plugins/builtin/portfolio-list/cli/watchlist-command.ts +178 -17
- package/src/plugins/builtin/portfolio-list/headless.ts +33 -6
- package/src/plugins/builtin/portfolio-list/pane/groups.tsx +220 -0
- package/src/plugins/builtin/portfolio-list/pane/index.tsx +95 -18
- package/src/plugins/builtin/portfolio-list/pane/period-pnl.ts +24 -6
- package/src/plugins/builtin/portfolio-list/period-pnl.ts +16 -1
- package/src/plugins/builtin/portfolio-list/summary/index.tsx +4 -1
- package/src/plugins/builtin/portfolio-list/summary/totals.ts +6 -4
- package/src/plugins/builtin/portfolio-list/table.tsx +38 -16
- package/src/plugins/builtin/research/corporate-actions-pane.tsx +4 -2
- package/src/plugins/builtin/research/relative-valuation-headless.ts +15 -5
- package/src/plugins/builtin/research/relative-valuation-model.ts +7 -1
- package/src/plugins/builtin/research/relative-valuation-pane.tsx +7 -4
- package/src/plugins/builtin/shared/cloud-upgrade.ts +4 -2
- package/src/plugins/builtin/shared/cpi-year-gap.ts +67 -0
- package/src/plugins/builtin/shared/headless-options.ts +1 -1
- package/src/plugins/builtin/social-mentions/model.ts +2 -2
- package/src/plugins/builtin/thirteenf/pane.tsx +1 -1
- package/src/plugins/builtin/ticker-detail/adr-pair/headless.ts +45 -2
- package/src/plugins/builtin/ticker-detail/financials/model.ts +51 -16
- package/src/plugins/builtin/ticker-detail/financials/nopat.ts +16 -0
- package/src/plugins/builtin/ticker-detail/financials/ratios.ts +44 -13
- package/src/plugins/builtin/ticker-detail/financials/schema.ts +33 -2
- package/src/plugins/builtin/ticker-detail/financials/tab.tsx +4 -2
- package/src/plugins/builtin/ticker-detail/headless-schema.ts +30 -4
- package/src/plugins/builtin/ticker-detail/headless.ts +280 -35
- package/src/plugins/builtin/ticker-detail/overview/components.tsx +4 -5
- package/src/plugins/builtin/ticker-detail/overview/model.ts +9 -2
- package/src/plugins/builtin/ticker-detail/overview-tab.tsx +10 -2
- package/src/plugins/builtin/ticker-detail/pharma-signals/eligibility.ts +32 -0
- package/src/plugins/builtin/ticker-detail/pharma-signals/tab.tsx +162 -0
- package/src/plugins/builtin/ticker-detail/pharma-signals/waitlist.ts +126 -0
- package/src/plugins/builtin/ticker-detail/research-groups.ts +6 -4
- package/src/plugins/builtin/ticker-detail/research-tabs.ts +11 -0
- package/src/portfolio/collection-name.ts +2 -1
- package/src/portfolio/column-values.ts +34 -12
- package/src/portfolio/listed-symbol.ts +4 -2
- package/src/portfolio/period-pnl.ts +51 -1
- package/src/portfolio/suffixed-listings.ts +3 -1
- package/src/portfolio/watchlist-groups.ts +212 -0
- package/src/react/ticker-source.ts +3 -1
- package/src/renderers/dom/dialog-host.tsx +5 -5
- package/src/renderers/dom/styles.css +7 -0
- package/src/renderers/electrobun/view/remote/capability-invoker.ts +1 -1
- package/src/renderers/opentui/dialog-host.tsx +3 -4
- package/src/sources/gloomberb-cloud/normalizers.ts +5 -0
- package/src/sources/provider-router/history.ts +5 -2
- package/src/state/app/bootstrap.ts +11 -0
- package/src/state/app/context/index.tsx +6 -0
- package/src/sync/collections-contributor.ts +5 -2
- package/src/sync/config-merge.ts +10 -2
- package/src/sync/sanitize.ts +28 -0
- package/src/telemetry/usage-counts.ts +17 -0
- package/src/test-support/plugin-persistence.ts +12 -0
- package/src/tickers/company-name-listing.ts +4 -3
- package/src/tickers/company-name.ts +19 -1
- package/src/tickers/instrument-coverage.ts +27 -0
- package/src/tickers/search/home-listing.ts +38 -1
- package/src/tickers/search/index.ts +3 -2
- package/src/tickers/search/ranking.ts +21 -2
- package/src/time-series/base-series.ts +4 -0
- package/src/time-series/chart-seed.ts +1 -1
- package/src/time-series/financial-period-coverage.ts +4 -12
- package/src/time-series/parsed-history-cache.ts +1 -1
- package/src/time-series/resolve.ts +1 -1
- package/src/time-series/types.ts +5 -2
- package/src/time-series/use-chart-resolution.ts +6 -1
- package/src/types/config.ts +32 -0
- package/src/types/financials.ts +13 -0
- package/src/types/headless.ts +7 -0
- package/src/types/plugin-context.ts +5 -0
- package/src/types/ticker.ts +14 -0
- package/src/ui/ascii-font.ts +1 -4
- package/src/ui/dialog-stack.ts +17 -0
- package/src/ui/dialog.tsx +6 -2
- package/src/utils/async-deadline.ts +2 -2
- package/src/utils/crypto-pair.ts +9 -0
- package/src/utils/csv.ts +44 -5
- package/src/utils/exchanges.ts +13 -0
- package/src/utils/financial-statements.ts +60 -3
- package/src/utils/futures-generic.ts +17 -0
- package/src/utils/trailing-dividend.ts +13 -3
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { useMemo, type ComponentProps, type RefObject } from "react";
|
|
2
|
+
import { ChartSurface, Text, useUiCapabilities, type BoxRenderable } from "../../../../ui";
|
|
3
|
+
import { useCursorScene, useValueStore, type CompositeCursorSource, type ValueStore } from "../cursor-source";
|
|
4
|
+
import type { CompositeAxisValueFormatter } from "../format";
|
|
5
|
+
import { writeLevelText, type ProjectedLevel } from "../levels";
|
|
6
|
+
import type { useCompositePanelBitmap } from "../panel-bitmap";
|
|
7
|
+
import { cursorAxisLabel, resolvePanelCrosshair, resolveSeriesAxisTags, resolveSeriesCursorYRatio } from "../panel-labels";
|
|
8
|
+
import { PriceAxisLabels } from "../price-axis-labels";
|
|
9
|
+
import { renderCompositePanelText } from "../text-renderer";
|
|
10
|
+
import type { CompositeAxisSide, CompositePanelScene } from "../types";
|
|
11
|
+
import type { KeyboardToolDrag } from "../use-composite-chart-keyboard";
|
|
12
|
+
import type { LevelGrab } from "./panel-levels";
|
|
13
|
+
|
|
14
|
+
export const DESKTOP_PLOT_STYLE = { flex: "1 1 0px", width: "auto", minWidth: 0, height: "auto", alignSelf: "stretch" } as const;
|
|
15
|
+
/** Over a level that drags, or while one does: it moves up and down only. */
|
|
16
|
+
const DESKTOP_PLOT_LEVEL_STYLE = { ...DESKTOP_PLOT_STYLE, cursor: "ns-resize" } as const;
|
|
17
|
+
export const DESKTOP_PLOT_PICK_STYLE = { ...DESKTOP_PLOT_STYLE, cursor: "crosshair" } as const;
|
|
18
|
+
|
|
19
|
+
/** What a panel's crosshair is read from: everything else in the panel holds still while it moves. */
|
|
20
|
+
export interface PanelCursorView {
|
|
21
|
+
panel: CompositePanelScene;
|
|
22
|
+
cursor: CompositeCursorSource;
|
|
23
|
+
pointerY: ValueStore<number | null>;
|
|
24
|
+
keyboardDrag: KeyboardToolDrag | null;
|
|
25
|
+
sharedCursor: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** The crosshair over a panel, read by the parts that draw it, so a pointer move renders only them. */
|
|
29
|
+
export function usePanelCursor({ panel, cursor, pointerY, keyboardDrag, sharedCursor }: PanelCursorView) {
|
|
30
|
+
const scene = useCursorScene(cursor);
|
|
31
|
+
const cursorYRatio = useValueStore(pointerY);
|
|
32
|
+
// A keyboard placement's end sits at the level the user put it, so it
|
|
33
|
+
// draws a level line where otherwise only the pointer would.
|
|
34
|
+
const heldCursorYRatio = keyboardDrag ? keyboardDrag.drag.endYRatio : sharedCursor ? null : cursorYRatio;
|
|
35
|
+
const seriesCursorYRatio = useMemo(
|
|
36
|
+
() => resolveSeriesCursorYRatio(panel, scene),
|
|
37
|
+
[panel, scene],
|
|
38
|
+
);
|
|
39
|
+
return {
|
|
40
|
+
scene,
|
|
41
|
+
cursorYRatio,
|
|
42
|
+
activeCursorYRatio: scene.cursorXRatio === null ? null : heldCursorYRatio ?? seriesCursorYRatio,
|
|
43
|
+
// The chart under the pointer draws both lines: the level line follows the
|
|
44
|
+
// pointer, and its value sits on the axes, beside each series' own tag on
|
|
45
|
+
// the desktop and the web. A keyboard or shared cursor knows its column
|
|
46
|
+
// only, so a chart following another chart's cursor draws the time line
|
|
47
|
+
// alone. A tool placed from the keyboard is the exception: its end is a level.
|
|
48
|
+
pointerCursorYRatio: scene.cursorXRatio === null ? null : heldCursorYRatio,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The plot, with the crosshair over it and, in a terminal without graphics, the text that draws both. */
|
|
53
|
+
export function PanelPlotSurface({
|
|
54
|
+
view,
|
|
55
|
+
plotRef,
|
|
56
|
+
bitmap,
|
|
57
|
+
crosshairColor,
|
|
58
|
+
textColor,
|
|
59
|
+
textFallback,
|
|
60
|
+
plotWidth,
|
|
61
|
+
projectedLevels,
|
|
62
|
+
selectedLevelId,
|
|
63
|
+
levelGrab,
|
|
64
|
+
...surface
|
|
65
|
+
}: Omit<ComponentProps<typeof ChartSurface>, "ref" | "crosshair" | "children"> & {
|
|
66
|
+
view: PanelCursorView;
|
|
67
|
+
plotRef: RefObject<BoxRenderable | null>;
|
|
68
|
+
bitmap: ReturnType<typeof useCompositePanelBitmap>;
|
|
69
|
+
crosshairColor: string;
|
|
70
|
+
textColor: string;
|
|
71
|
+
textFallback: boolean;
|
|
72
|
+
plotWidth: number;
|
|
73
|
+
projectedLevels: readonly ProjectedLevel[];
|
|
74
|
+
selectedLevelId: string | null;
|
|
75
|
+
levelGrab: LevelGrab;
|
|
76
|
+
}) {
|
|
77
|
+
const { panel } = view;
|
|
78
|
+
const { scene, cursorYRatio, pointerCursorYRatio } = usePanelCursor(view);
|
|
79
|
+
const crosshair = useMemo(
|
|
80
|
+
() => resolvePanelCrosshair(panel, bitmap, scene, pointerCursorYRatio, crosshairColor),
|
|
81
|
+
[bitmap, crosshairColor, panel, pointerCursorYRatio, scene],
|
|
82
|
+
);
|
|
83
|
+
const textLines = useMemo(
|
|
84
|
+
() => textFallback
|
|
85
|
+
? writeLevelText(
|
|
86
|
+
renderCompositePanelText(panel, plotWidth, scene.cursorXRatio, pointerCursorYRatio),
|
|
87
|
+
projectedLevels,
|
|
88
|
+
selectedLevelId,
|
|
89
|
+
)
|
|
90
|
+
: [],
|
|
91
|
+
[panel, plotWidth, pointerCursorYRatio, projectedLevels, scene.cursorXRatio, selectedLevelId, textFallback],
|
|
92
|
+
);
|
|
93
|
+
const grab = typeof levelGrab === "function" ? cursorYRatio !== null && levelGrab(cursorYRatio) : levelGrab;
|
|
94
|
+
return (
|
|
95
|
+
<ChartSurface
|
|
96
|
+
ref={plotRef}
|
|
97
|
+
{...surface}
|
|
98
|
+
style={grab && surface.style ? DESKTOP_PLOT_LEVEL_STYLE : surface.style}
|
|
99
|
+
cursor={grab && surface.cursor ? "ns-resize" : surface.cursor}
|
|
100
|
+
crosshair={crosshair}
|
|
101
|
+
>
|
|
102
|
+
{textLines.map((line, index) => <Text key={index} fg={textColor}>{line}</Text>)}
|
|
103
|
+
</ChartSurface>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** A value axis, with the cursor's value on it and, on the desktop, each series' value at the cursor. */
|
|
108
|
+
export function PanelValueAxis({
|
|
109
|
+
view,
|
|
110
|
+
formatAxisValue,
|
|
111
|
+
side,
|
|
112
|
+
...axis
|
|
113
|
+
}: Omit<ComponentProps<typeof PriceAxisLabels>, "cursorRow" | "cursorPixelY" | "cursorLabel" | "seriesTags" | "side"> & {
|
|
114
|
+
view: PanelCursorView;
|
|
115
|
+
formatAxisValue?: CompositeAxisValueFormatter;
|
|
116
|
+
side: CompositeAxisSide;
|
|
117
|
+
}) {
|
|
118
|
+
const { panel } = view;
|
|
119
|
+
const isDesktopWeb = useUiCapabilities().nativePaneChrome === true;
|
|
120
|
+
const { cellHeightPx = 18 } = useUiCapabilities();
|
|
121
|
+
const { scene, activeCursorYRatio, pointerCursorYRatio } = usePanelCursor(view);
|
|
122
|
+
// The pointer's value on the axes follows the level line it belongs to.
|
|
123
|
+
const axisCursorYRatio = isDesktopWeb ? pointerCursorYRatio : activeCursorYRatio;
|
|
124
|
+
const seriesTags = useMemo(
|
|
125
|
+
() => isDesktopWeb ? resolveSeriesAxisTags(panel, scene, formatAxisValue).filter((tag) => tag.side === side) : undefined,
|
|
126
|
+
[formatAxisValue, isDesktopWeb, panel, scene, side],
|
|
127
|
+
);
|
|
128
|
+
return (
|
|
129
|
+
<PriceAxisLabels
|
|
130
|
+
{...axis}
|
|
131
|
+
side={side}
|
|
132
|
+
cursorRow={activeCursorYRatio === null ? null : Math.round(activeCursorYRatio * Math.max(panel.height - 1, 0))}
|
|
133
|
+
cursorPixelY={activeCursorYRatio === null ? null : activeCursorYRatio * Math.max(panel.height * cellHeightPx - 1, 0)}
|
|
134
|
+
cursorLabel={cursorAxisLabel(panel, side, axisCursorYRatio, formatAxisValue)}
|
|
135
|
+
seriesTags={seriesTags}
|
|
136
|
+
/>
|
|
137
|
+
);
|
|
138
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { useMemo, useRef, useState } from "react";
|
|
2
|
+
import { hitTestLevel, levelGrabRatio, projectLevels, type ProjectedLevel } from "../levels";
|
|
3
|
+
import type { CompositePanelSurfaceProps } from "./props";
|
|
4
|
+
|
|
5
|
+
/** Over a level a drag moves: always while one moves, never, or at the pointer's height. */
|
|
6
|
+
export type LevelGrab = boolean | ((cursorYRatio: number) => boolean);
|
|
7
|
+
|
|
8
|
+
/** A level being dragged, where it is now: it is saved once, when the pointer lets go. */
|
|
9
|
+
export interface LevelDraft {
|
|
10
|
+
id: string;
|
|
11
|
+
value: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const NO_LEVELS: readonly ProjectedLevel[] = [];
|
|
15
|
+
|
|
16
|
+
/** The chart's levels on this panel: where each draws, the one being dragged, and where a drag would grab one. */
|
|
17
|
+
export function usePanelLevels({
|
|
18
|
+
panel,
|
|
19
|
+
levels,
|
|
20
|
+
armedTool,
|
|
21
|
+
onPickTime,
|
|
22
|
+
onPickPrice,
|
|
23
|
+
}: Pick<CompositePanelSurfaceProps, "panel" | "levels" | "armedTool" | "onPickTime" | "onPickPrice">) {
|
|
24
|
+
// A dragged level moves here and is saved once, when the pointer lets go.
|
|
25
|
+
const [levelDraft, setLevelDraft] = useState<LevelDraft | null>(null);
|
|
26
|
+
const levelDraftRef = useRef(levelDraft);
|
|
27
|
+
levelDraftRef.current = levelDraft;
|
|
28
|
+
const levelDomain = useMemo(() => {
|
|
29
|
+
const series = levels ? panel.series.find((entry) => entry.source.id === levels.seriesId) : undefined;
|
|
30
|
+
return series ? panel.axes[series.source.axis] ?? null : null;
|
|
31
|
+
}, [levels, panel]);
|
|
32
|
+
const projectedLevels = useMemo(
|
|
33
|
+
() => levels && levelDomain ? projectLevels(levels.items, levelDomain, levelDraft) : NO_LEVELS,
|
|
34
|
+
[levelDomain, levelDraft, levels],
|
|
35
|
+
);
|
|
36
|
+
// Over a line a plain drag moves, and while one moves, the pointer says it
|
|
37
|
+
// goes up and down. Where the pointer is, the plot reads (see `PanelPlotSurface`).
|
|
38
|
+
const levelGrab = useMemo<LevelGrab>(() => {
|
|
39
|
+
if (levelDraft) return true;
|
|
40
|
+
if (!levels?.onEdit || onPickTime || onPickPrice || (armedTool && armedTool !== "level")) return false;
|
|
41
|
+
return (cursorYRatio) => {
|
|
42
|
+
const hit = hitTestLevel(projectedLevels, cursorYRatio, levelGrabRatio(panel.height));
|
|
43
|
+
return !!hit?.editable && !!hit.draggable;
|
|
44
|
+
};
|
|
45
|
+
}, [armedTool, levelDraft, levels?.onEdit, onPickPrice, onPickTime, panel.height, projectedLevels]);
|
|
46
|
+
return { levelDraftRef, setLevelDraft, levelDomain, projectedLevels, levelGrab };
|
|
47
|
+
}
|
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
import { useCallback, useRef, type Dispatch, type RefObject, type SetStateAction } from "react";
|
|
2
|
+
import type { useNativeRenderer } from "../../../../ui";
|
|
3
|
+
import type { MeasuredCellSize } from "../../../../ui/measured-cells";
|
|
4
|
+
import { consumeChartMouseEvent, getGlobalMouseX, type ChartMouseEvent, type LocalPlotPointer } from "../../core/pointer";
|
|
5
|
+
import { nextDrawingId, nextLevelId } from "../drawing-store";
|
|
6
|
+
import { hitTestLevel, levelGrabRatio, roundLevelValue, type ProjectedLevel } from "../levels";
|
|
7
|
+
import {
|
|
8
|
+
AXIS_DOUBLE_PRESS_MS,
|
|
9
|
+
manualValueAxes,
|
|
10
|
+
panReleaseVelocity,
|
|
11
|
+
PLOT_DOUBLE_CLICK_MS,
|
|
12
|
+
releaseEditableFocus,
|
|
13
|
+
startPanGesture,
|
|
14
|
+
type PanGesture,
|
|
15
|
+
type PanSample,
|
|
16
|
+
} from "../panel-gestures";
|
|
17
|
+
import { resolveCompositeCursorDate, unprojectCompositeValue } from "../scene";
|
|
18
|
+
import {
|
|
19
|
+
hitTestDrawings,
|
|
20
|
+
isDrawingTool,
|
|
21
|
+
resolveChartToolKind,
|
|
22
|
+
resolveDrawingFromDrag,
|
|
23
|
+
resolveZoomBoxRange,
|
|
24
|
+
shiftDrawing,
|
|
25
|
+
type ChartToolDrag,
|
|
26
|
+
} from "../tools";
|
|
27
|
+
import type { CompositeAxisDomain } from "../types";
|
|
28
|
+
import { panValueRange } from "../value-scale";
|
|
29
|
+
import type { LevelDraft } from "./panel-levels";
|
|
30
|
+
import { pointerRow } from "./pointer";
|
|
31
|
+
import type { CompositePanelSurfaceProps } from "./props";
|
|
32
|
+
|
|
33
|
+
/** What a press on the plot is doing until it lets go. */
|
|
34
|
+
type PlotDrag =
|
|
35
|
+
| PanGesture
|
|
36
|
+
| {
|
|
37
|
+
kind: "edit";
|
|
38
|
+
drawingId: string;
|
|
39
|
+
pointIndex: number | null;
|
|
40
|
+
lastXRatio: number;
|
|
41
|
+
lastYRatio: number;
|
|
42
|
+
}
|
|
43
|
+
| { kind: "level-move"; id: string }
|
|
44
|
+
| ChartToolDrag;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* A press on the plot and what it drags: a pan (which coasts on the desktop
|
|
48
|
+
* when let go while moving), a tool in hand, a drawing or a level; with
|
|
49
|
+
* nothing to drag, a pick, or a double press that maximizes the panel.
|
|
50
|
+
*/
|
|
51
|
+
export function usePlotGestures({
|
|
52
|
+
panel,
|
|
53
|
+
scene,
|
|
54
|
+
frame,
|
|
55
|
+
viewport,
|
|
56
|
+
armedTool,
|
|
57
|
+
drawings,
|
|
58
|
+
drawColor,
|
|
59
|
+
levels,
|
|
60
|
+
plotWidth,
|
|
61
|
+
onActivate,
|
|
62
|
+
onPointerPress,
|
|
63
|
+
onPickTime,
|
|
64
|
+
onPickPrice,
|
|
65
|
+
onSelectDrawing,
|
|
66
|
+
onEditDrawing,
|
|
67
|
+
onDraw,
|
|
68
|
+
onSelectLevel,
|
|
69
|
+
onPanViewport,
|
|
70
|
+
onSetViewport,
|
|
71
|
+
onSetValueScale,
|
|
72
|
+
onDragActiveChange,
|
|
73
|
+
onToggleMaximized,
|
|
74
|
+
isDesktopWeb,
|
|
75
|
+
renderer,
|
|
76
|
+
plotSize,
|
|
77
|
+
plotAspect,
|
|
78
|
+
plotSpanFactor,
|
|
79
|
+
setToolDrag,
|
|
80
|
+
levelDomain,
|
|
81
|
+
projectedLevels,
|
|
82
|
+
levelDraftRef,
|
|
83
|
+
setLevelDraft,
|
|
84
|
+
plotPointer,
|
|
85
|
+
pointerRatios,
|
|
86
|
+
updateCursor,
|
|
87
|
+
stopCoast,
|
|
88
|
+
startCoast,
|
|
89
|
+
}: Pick<
|
|
90
|
+
CompositePanelSurfaceProps,
|
|
91
|
+
| "panel" | "scene" | "frame" | "viewport" | "armedTool" | "drawings" | "drawColor" | "levels" | "plotWidth"
|
|
92
|
+
| "onActivate" | "onPointerPress" | "onPickTime" | "onPickPrice" | "onSelectDrawing" | "onEditDrawing" | "onDraw"
|
|
93
|
+
| "onSelectLevel" | "onPanViewport" | "onSetViewport" | "onSetValueScale" | "onDragActiveChange" | "onToggleMaximized"
|
|
94
|
+
> & {
|
|
95
|
+
isDesktopWeb: boolean;
|
|
96
|
+
renderer: ReturnType<typeof useNativeRenderer>;
|
|
97
|
+
plotSize: MeasuredCellSize;
|
|
98
|
+
plotAspect: number;
|
|
99
|
+
plotSpanFactor: number;
|
|
100
|
+
setToolDrag: Dispatch<SetStateAction<ChartToolDrag | null>>;
|
|
101
|
+
levelDomain: CompositeAxisDomain | null;
|
|
102
|
+
projectedLevels: readonly ProjectedLevel[];
|
|
103
|
+
levelDraftRef: RefObject<LevelDraft | null>;
|
|
104
|
+
setLevelDraft: Dispatch<SetStateAction<LevelDraft | null>>;
|
|
105
|
+
plotPointer: (event: ChartMouseEvent) => LocalPlotPointer | null;
|
|
106
|
+
pointerRatios: (event: ChartMouseEvent) => { xRatio: number; yRatio: number } | null;
|
|
107
|
+
updateCursor: (event: ChartMouseEvent) => boolean;
|
|
108
|
+
stopCoast: () => void;
|
|
109
|
+
startCoast: (velocity: number, positionsPerCell: number) => void;
|
|
110
|
+
}) {
|
|
111
|
+
// The last press on bare plot, for a double press where the host does not count clicks.
|
|
112
|
+
const lastPlotPressRef = useRef<{ at: number; x: number; y: number } | null>(null);
|
|
113
|
+
const dragRef = useRef<PlotDrag | null>(null);
|
|
114
|
+
// Where the pointer was during a pan, for the speed it lets go at.
|
|
115
|
+
const panSamplesRef = useRef<PanSample[]>([]);
|
|
116
|
+
const startDrag = useCallback((event: ChartMouseEvent) => {
|
|
117
|
+
onActivate?.();
|
|
118
|
+
onPointerPress();
|
|
119
|
+
// The plot consumes the press, so the browser never moves focus off a text
|
|
120
|
+
// field for us. Hand it back, but only for a press that truly landed here:
|
|
121
|
+
// a dialog over the plot must keep the focus it just took.
|
|
122
|
+
if (isDesktopWeb) releaseEditableFocus(event);
|
|
123
|
+
consumeChartMouseEvent(event);
|
|
124
|
+
if (onPickTime) {
|
|
125
|
+
const pointer = plotPointer(event);
|
|
126
|
+
const date = pointer ? resolveCompositeCursorDate(scene, pointer.cellX) : null;
|
|
127
|
+
if (date) onPickTime(date);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
if (onPickPrice) {
|
|
131
|
+
// Only the levels' own panel has their prices; a press elsewhere picks nothing.
|
|
132
|
+
const ratios = pointerRatios(event);
|
|
133
|
+
const value = ratios && levelDomain ? unprojectCompositeValue(ratios.yRatio, levelDomain) : null;
|
|
134
|
+
if (value !== null && levelDomain) onPickPrice(roundLevelValue(value, levelDomain));
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
// A keyboard-armed tool covers terminals that never forward modifier drags.
|
|
138
|
+
const tool = resolveChartToolKind(event.modifiers) ?? armedTool;
|
|
139
|
+
if (tool === "level" && levels?.onEdit && levelDomain) {
|
|
140
|
+
const ratios = pointerRatios(event);
|
|
141
|
+
if (!ratios) return;
|
|
142
|
+
const hit = hitTestLevel(projectedLevels, ratios.yRatio, levelGrabRatio(panel.height));
|
|
143
|
+
if (hit) {
|
|
144
|
+
onSelectLevel(hit.id);
|
|
145
|
+
if (hit.editable) dragRef.current = { kind: "level-move", id: hit.id };
|
|
146
|
+
} else {
|
|
147
|
+
const value = unprojectCompositeValue(ratios.yRatio, levelDomain);
|
|
148
|
+
if (value !== null) {
|
|
149
|
+
const id = nextLevelId();
|
|
150
|
+
levels.onEdit({ kind: "add", id, value: roundLevelValue(value, levelDomain) });
|
|
151
|
+
onSelectLevel(id);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
updateCursor(event);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (tool) {
|
|
158
|
+
const ratios = pointerRatios(event);
|
|
159
|
+
if (!ratios) return;
|
|
160
|
+
// With a drawing tool in hand, grabbing an existing shape edits it
|
|
161
|
+
// instead of starting a new one on top of it.
|
|
162
|
+
const hit = isDrawingTool(tool)
|
|
163
|
+
? hitTestDrawings(drawings, scene, panel, ratios, plotAspect)
|
|
164
|
+
: null;
|
|
165
|
+
if (hit) {
|
|
166
|
+
onSelectDrawing(hit.drawing.id);
|
|
167
|
+
dragRef.current = {
|
|
168
|
+
kind: "edit",
|
|
169
|
+
drawingId: hit.drawing.id,
|
|
170
|
+
pointIndex: hit.pointIndex,
|
|
171
|
+
lastXRatio: ratios.xRatio,
|
|
172
|
+
lastYRatio: ratios.yRatio,
|
|
173
|
+
};
|
|
174
|
+
updateCursor(event);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
const started: ChartToolDrag = {
|
|
178
|
+
kind: tool,
|
|
179
|
+
startXRatio: ratios.xRatio,
|
|
180
|
+
startYRatio: ratios.yRatio,
|
|
181
|
+
endXRatio: ratios.xRatio,
|
|
182
|
+
endYRatio: ratios.yRatio,
|
|
183
|
+
path: [{ xRatio: ratios.xRatio, yRatio: ratios.yRatio }],
|
|
184
|
+
};
|
|
185
|
+
if (isDrawingTool(tool)) onSelectDrawing(null);
|
|
186
|
+
dragRef.current = { ...started, path: [...started.path] };
|
|
187
|
+
setToolDrag(started);
|
|
188
|
+
updateCursor(event);
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
// With no tool in hand, a press on a drawing or a level picks it so Backspace
|
|
192
|
+
// or Delete can remove it; the press still pans, and one on bare plot lets go.
|
|
193
|
+
const ratios = pointerRatios(event);
|
|
194
|
+
let bare = true;
|
|
195
|
+
if (ratios) {
|
|
196
|
+
const drawingHit = drawings.length > 0 ? hitTestDrawings(drawings, scene, panel, ratios, plotAspect) : null;
|
|
197
|
+
const levelHit = !drawingHit && levels?.onEdit && levelDomain
|
|
198
|
+
? hitTestLevel(projectedLevels, ratios.yRatio, levelGrabRatio(panel.height))
|
|
199
|
+
: null;
|
|
200
|
+
onSelectDrawing(drawingHit ? drawingHit.drawing.id : null);
|
|
201
|
+
onSelectLevel(levelHit?.editable ? levelHit.id : null);
|
|
202
|
+
bare = !drawingHit && !levelHit;
|
|
203
|
+
// An order's line drags without the level tool; other levels keep the press for panning.
|
|
204
|
+
if (levelHit?.editable && levelHit.draggable) {
|
|
205
|
+
dragRef.current = { kind: "level-move", id: levelHit.id };
|
|
206
|
+
lastPlotPressRef.current = null;
|
|
207
|
+
updateCursor(event);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
// A double click on bare plot gives the panel the whole chart, or the
|
|
212
|
+
// others back (the terminal counts two presses on one spot). Its first
|
|
213
|
+
// press must have landed here too: a double click on a button that goes
|
|
214
|
+
// away under it (All panels) ends on this plot, and is not one of its.
|
|
215
|
+
if (!bare) lastPlotPressRef.current = null;
|
|
216
|
+
if (onToggleMaximized && bare) {
|
|
217
|
+
const now = Date.now();
|
|
218
|
+
const last = lastPlotPressRef.current;
|
|
219
|
+
const double = typeof event.detail === "number"
|
|
220
|
+
? event.detail >= 2 && !!last && now - last.at < PLOT_DOUBLE_CLICK_MS
|
|
221
|
+
: !!last && now - last.at < AXIS_DOUBLE_PRESS_MS && Math.abs(last.x - event.x) <= 1 && Math.abs(last.y - event.y) <= 1;
|
|
222
|
+
lastPlotPressRef.current = double ? null : { at: now, x: event.x, y: event.y };
|
|
223
|
+
if (double) {
|
|
224
|
+
dragRef.current = null;
|
|
225
|
+
onToggleMaximized();
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
if (!updateCursor(event)) return;
|
|
230
|
+
const values = manualValueAxes(panel);
|
|
231
|
+
panSamplesRef.current = [{ at: performance.now(), x: getGlobalMouseX(event, renderer) }];
|
|
232
|
+
dragRef.current = {
|
|
233
|
+
...startPanGesture(
|
|
234
|
+
frame,
|
|
235
|
+
viewport,
|
|
236
|
+
plotSize.width,
|
|
237
|
+
getGlobalMouseX(event, renderer),
|
|
238
|
+
plotSpanFactor,
|
|
239
|
+
),
|
|
240
|
+
// A panel scaled by hand moves up and down with the drag as well.
|
|
241
|
+
...(values.length > 0 ? { startCellY: pointerRow(event), values } : {}),
|
|
242
|
+
};
|
|
243
|
+
}, [
|
|
244
|
+
armedTool,
|
|
245
|
+
drawings,
|
|
246
|
+
frame,
|
|
247
|
+
levelDomain,
|
|
248
|
+
levels,
|
|
249
|
+
onActivate,
|
|
250
|
+
onPickTime,
|
|
251
|
+
onPickPrice,
|
|
252
|
+
onPointerPress,
|
|
253
|
+
onSelectDrawing,
|
|
254
|
+
onSelectLevel,
|
|
255
|
+
panel,
|
|
256
|
+
plotAspect,
|
|
257
|
+
projectedLevels,
|
|
258
|
+
plotPointer,
|
|
259
|
+
plotSize.width,
|
|
260
|
+
plotSpanFactor,
|
|
261
|
+
plotWidth,
|
|
262
|
+
pointerRatios,
|
|
263
|
+
renderer,
|
|
264
|
+
scene,
|
|
265
|
+
updateCursor,
|
|
266
|
+
viewport,
|
|
267
|
+
onToggleMaximized,
|
|
268
|
+
]);
|
|
269
|
+
const pressCursor = useCallback((event: ChartMouseEvent) => {
|
|
270
|
+
onActivate?.();
|
|
271
|
+
updateCursor(event);
|
|
272
|
+
}, [onActivate, updateCursor]);
|
|
273
|
+
const dragViewport = useCallback((event: ChartMouseEvent) => {
|
|
274
|
+
const drag = dragRef.current;
|
|
275
|
+
if (!drag) return;
|
|
276
|
+
consumeChartMouseEvent(event);
|
|
277
|
+
updateCursor(event);
|
|
278
|
+
if (drag.kind === "level-move") {
|
|
279
|
+
const ratios = pointerRatios(event);
|
|
280
|
+
const value = ratios && levelDomain ? unprojectCompositeValue(ratios.yRatio, levelDomain) : null;
|
|
281
|
+
if (value === null || !levelDomain) return;
|
|
282
|
+
const draft = { id: drag.id, value: roundLevelValue(value, levelDomain) };
|
|
283
|
+
// The release reads the ref, and a quick drag lets go before the next render.
|
|
284
|
+
levelDraftRef.current = draft;
|
|
285
|
+
setLevelDraft(draft);
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
if (drag.kind === "edit") {
|
|
289
|
+
const ratios = pointerRatios(event);
|
|
290
|
+
if (!ratios) return;
|
|
291
|
+
// Read the deltas before advancing the ref: the state updater runs later,
|
|
292
|
+
// and a mutable capture would hand it a zero move every time.
|
|
293
|
+
const deltaXRatio = ratios.xRatio - drag.lastXRatio;
|
|
294
|
+
const deltaYRatio = ratios.yRatio - drag.lastYRatio;
|
|
295
|
+
const { drawingId, pointIndex } = drag;
|
|
296
|
+
drag.lastXRatio = ratios.xRatio;
|
|
297
|
+
drag.lastYRatio = ratios.yRatio;
|
|
298
|
+
onEditDrawing(
|
|
299
|
+
drawingId,
|
|
300
|
+
(drawing) => shiftDrawing(drawing, scene, panel, deltaXRatio, deltaYRatio, pointIndex),
|
|
301
|
+
);
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
if (drag.kind !== "pan") {
|
|
305
|
+
const ratios = pointerRatios(event);
|
|
306
|
+
if (!ratios) return;
|
|
307
|
+
drag.endXRatio = ratios.xRatio;
|
|
308
|
+
drag.endYRatio = ratios.yRatio;
|
|
309
|
+
if (drag.kind === "pencil") drag.path.push({ xRatio: ratios.xRatio, yRatio: ratios.yRatio });
|
|
310
|
+
setToolDrag({ ...drag, path: [...drag.path] });
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
const globalX = getGlobalMouseX(event, renderer);
|
|
314
|
+
panSamplesRef.current.push({ at: performance.now(), x: globalX });
|
|
315
|
+
if (panSamplesRef.current.length > 12) panSamplesRef.current.shift();
|
|
316
|
+
if (drag.frame !== frame) {
|
|
317
|
+
// Data refreshed mid-drag. The new frame maps positions differently, so
|
|
318
|
+
// continue from where the plot is now instead of replaying the drag.
|
|
319
|
+
Object.assign(drag, startPanGesture(frame, viewport, plotSize.width, globalX, plotSpanFactor));
|
|
320
|
+
}
|
|
321
|
+
onPanViewport(
|
|
322
|
+
(globalX - drag.startGlobalX) * drag.positionsPerCell,
|
|
323
|
+
{ frame: drag.frame, from: drag.startViewport },
|
|
324
|
+
);
|
|
325
|
+
if (drag.values && drag.startCellY !== undefined) {
|
|
326
|
+
const deltaRatio = (pointerRow(event) - drag.startCellY) / Math.max(plotSize.height, 1);
|
|
327
|
+
for (const axis of drag.values) {
|
|
328
|
+
onSetValueScale(panel.id, axis.side, axis.key, panValueRange(axis.start, axis.scale, deltaRatio));
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}, [
|
|
332
|
+
frame,
|
|
333
|
+
levelDomain,
|
|
334
|
+
onEditDrawing,
|
|
335
|
+
onPanViewport,
|
|
336
|
+
onSetValueScale,
|
|
337
|
+
plotSize.height,
|
|
338
|
+
panel,
|
|
339
|
+
plotSize.width,
|
|
340
|
+
plotSpanFactor,
|
|
341
|
+
plotWidth,
|
|
342
|
+
pointerRatios,
|
|
343
|
+
renderer,
|
|
344
|
+
scene,
|
|
345
|
+
updateCursor,
|
|
346
|
+
viewport,
|
|
347
|
+
]);
|
|
348
|
+
const finishToolDrag = useCallback(() => {
|
|
349
|
+
const drag = dragRef.current;
|
|
350
|
+
if (!drag || drag.kind === "pan") return;
|
|
351
|
+
dragRef.current = null;
|
|
352
|
+
if (drag.kind === "edit") return;
|
|
353
|
+
if (drag.kind === "level-move") {
|
|
354
|
+
const draft = levelDraftRef.current;
|
|
355
|
+
setLevelDraft(null);
|
|
356
|
+
if (draft) levels?.onEdit?.({ kind: "move", id: draft.id, value: draft.value });
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
setToolDrag(null);
|
|
360
|
+
if (isDrawingTool(drag.kind)) {
|
|
361
|
+
const drawing = resolveDrawingFromDrag(scene, panel, drag, drawColor, nextDrawingId());
|
|
362
|
+
if (drawing) onDraw(drawing);
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
if (drag.kind !== "zoom") return;
|
|
366
|
+
const range = resolveZoomBoxRange(scene, drag, frame.minimumSpanMs);
|
|
367
|
+
if (range) onSetViewport(range);
|
|
368
|
+
}, [drawColor, frame.minimumSpanMs, levels, onDraw, onSetViewport, panel, scene]);
|
|
369
|
+
const resetDrag = useCallback(() => {
|
|
370
|
+
const drag = dragRef.current;
|
|
371
|
+
if (drag?.kind === "pan") {
|
|
372
|
+
dragRef.current = null;
|
|
373
|
+
startCoast(panReleaseVelocity(panSamplesRef.current, performance.now()), drag.positionsPerCell);
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
finishToolDrag();
|
|
377
|
+
}, [finishToolDrag, startCoast]);
|
|
378
|
+
// Said once per change, so a pointer move costs the chart nothing.
|
|
379
|
+
const reportedDragRef = useRef(false);
|
|
380
|
+
const reportDrag = useCallback((dragging: boolean) => {
|
|
381
|
+
if (reportedDragRef.current === dragging) return;
|
|
382
|
+
reportedDragRef.current = dragging;
|
|
383
|
+
onDragActiveChange?.(dragging);
|
|
384
|
+
}, [onDragActiveChange]);
|
|
385
|
+
const pressPlot = useCallback((event: ChartMouseEvent) => {
|
|
386
|
+
stopCoast();
|
|
387
|
+
const before = dragRef.current;
|
|
388
|
+
startDrag(event);
|
|
389
|
+
if (dragRef.current !== null && dragRef.current !== before) reportDrag(true);
|
|
390
|
+
}, [reportDrag, startDrag, stopCoast]);
|
|
391
|
+
const releasePlot = useCallback(() => {
|
|
392
|
+
resetDrag();
|
|
393
|
+
reportDrag(false);
|
|
394
|
+
}, [reportDrag, resetDrag]);
|
|
395
|
+
const handleMouseMove = useCallback((event: ChartMouseEvent) => {
|
|
396
|
+
// A release over a neighbouring pane never reaches this surface, so treat a
|
|
397
|
+
// plain move, which only fires with no button held, as the missing release.
|
|
398
|
+
finishToolDrag();
|
|
399
|
+
reportDrag(false);
|
|
400
|
+
updateCursor(event);
|
|
401
|
+
}, [finishToolDrag, reportDrag, updateCursor]);
|
|
402
|
+
return { pressPlot, pressCursor, dragViewport, releasePlot, handleMouseMove };
|
|
403
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { useCallback, type RefObject } from "react";
|
|
2
|
+
import type { BoxRenderable, useNativeRenderer } from "../../../../ui";
|
|
3
|
+
import type { MeasuredCellSize } from "../../../../ui/measured-cells";
|
|
4
|
+
import { consumeChartMouseEvent, getLocalPlotPointer, type ChartMouseEvent } from "../../core/pointer";
|
|
5
|
+
import type { ValueStore } from "../cursor-source";
|
|
6
|
+
import { resolveCompositeCursorDate } from "../scene";
|
|
7
|
+
import type { CompositePanelSurfaceProps } from "./props";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The pointer over the plot, read back into the scene's columns and rows, and
|
|
11
|
+
* the crosshair it moves: the date goes to the chart, the height stays here.
|
|
12
|
+
*/
|
|
13
|
+
export function usePlotPointer({
|
|
14
|
+
plotRef,
|
|
15
|
+
renderer,
|
|
16
|
+
plotSize,
|
|
17
|
+
plotWidth,
|
|
18
|
+
panelHeight,
|
|
19
|
+
scene,
|
|
20
|
+
pointerY,
|
|
21
|
+
onCursorDateChange,
|
|
22
|
+
}: Pick<CompositePanelSurfaceProps, "plotWidth" | "scene" | "onCursorDateChange"> & {
|
|
23
|
+
plotRef: RefObject<BoxRenderable | null>;
|
|
24
|
+
renderer: ReturnType<typeof useNativeRenderer>;
|
|
25
|
+
plotSize: MeasuredCellSize;
|
|
26
|
+
panelHeight: number;
|
|
27
|
+
pointerY: ValueStore<number | null>;
|
|
28
|
+
}) {
|
|
29
|
+
/** Where the pointer is over the plot, in the scene's columns and rows. */
|
|
30
|
+
const plotPointer = useCallback((event: ChartMouseEvent) => {
|
|
31
|
+
const pointer = getLocalPlotPointer(event, plotRef.current as unknown as Parameters<typeof getLocalPlotPointer>[1], renderer);
|
|
32
|
+
if (!pointer || (plotSize.width === plotWidth && plotSize.height === panelHeight)) return pointer;
|
|
33
|
+
return {
|
|
34
|
+
...pointer,
|
|
35
|
+
cellX: plotSize.width > 0 ? pointer.cellX * (plotWidth / plotSize.width) : pointer.cellX,
|
|
36
|
+
cellY: plotSize.height > 0 ? pointer.cellY * (panelHeight / plotSize.height) : pointer.cellY,
|
|
37
|
+
};
|
|
38
|
+
}, [panelHeight, plotSize.height, plotSize.width, plotWidth, renderer]);
|
|
39
|
+
const pointerRatios = useCallback((event: ChartMouseEvent) => {
|
|
40
|
+
const pointer = plotPointer(event);
|
|
41
|
+
if (!pointer) return null;
|
|
42
|
+
return {
|
|
43
|
+
xRatio: plotWidth <= 1 ? 0 : Math.max(0, Math.min(1, pointer.cellX / (plotWidth - 1))),
|
|
44
|
+
yRatio: panelHeight <= 1 ? 0.5 : Math.max(0, Math.min(1, pointer.cellY / (panelHeight - 1))),
|
|
45
|
+
};
|
|
46
|
+
}, [panelHeight, plotPointer, plotWidth]);
|
|
47
|
+
const updateCursor = useCallback((event: ChartMouseEvent): boolean => {
|
|
48
|
+
const pointer = plotPointer(event);
|
|
49
|
+
if (!pointer) return false;
|
|
50
|
+
const nextDate = resolveCompositeCursorDate(scene, pointer.cellX);
|
|
51
|
+
if (!nextDate) return false;
|
|
52
|
+
const nextYRatio = panelHeight <= 1
|
|
53
|
+
? 0.5
|
|
54
|
+
: Math.max(0, Math.min(1, pointer.cellY / (panelHeight - 1)));
|
|
55
|
+
pointerY.set(nextYRatio);
|
|
56
|
+
onCursorDateChange(nextDate);
|
|
57
|
+
consumeChartMouseEvent(event);
|
|
58
|
+
return true;
|
|
59
|
+
}, [onCursorDateChange, panelHeight, plotPointer, pointerY, scene]);
|
|
60
|
+
const clearCursor = useCallback(() => {
|
|
61
|
+
pointerY.set(null);
|
|
62
|
+
onCursorDateChange(null);
|
|
63
|
+
}, [onCursorDateChange, pointerY]);
|
|
64
|
+
return { plotPointer, pointerRatios, updateCursor, clearCursor };
|
|
65
|
+
}
|